From 8471bd91389ffe773c9f1ea68b74fb99c8195ddc Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Fri, 18 May 2012 19:25:42 +0000 Subject: [PATCH] Implementando leitura da tela em formato html --- src/include/lib3270/html.h | 10 ++++++++++ src/lib3270/html.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/pw3270/actions.c | 25 +++++++++++++++++++++++++ src/pw3270/window.c | 10 ---------- ui/99debug.xml | 4 ++++ 5 files changed, 123 insertions(+), 14 deletions(-) diff --git a/src/include/lib3270/html.h b/src/include/lib3270/html.h index bbe7027..85d7c47 100644 --- a/src/include/lib3270/html.h +++ b/src/include/lib3270/html.h @@ -30,6 +30,16 @@ #define LIB3270_HTML_H_INCLUDED 1 + typedef enum _lib3270_html_option + { + LIB3270_HTML_OPTION_ALL = 0x0001, + LIB3270_HTML_OPTION_HEADERS = 0x0002, + LIB3270_HTML_OPTION_FORM = 0x0004, + + } LIB3270_HTML_OPTION; + + LIB3270_EXPORT char * lib3270_get_as_html(H3270 *session, LIB3270_HTML_OPTION option); + #endif // LIB3270_HTML_H_INCLUDED diff --git a/src/lib3270/html.c b/src/lib3270/html.c index b82ef0f..b26084b 100644 --- a/src/lib3270/html.c +++ b/src/lib3270/html.c @@ -34,6 +34,12 @@ #include "globals.h" #include "utilc.h" + struct chr_xlat + { + unsigned char chr; + const char * xlat; + }; + /*--[ Defines ]--------------------------------------------------------------------------------------*/ enum html_element @@ -41,6 +47,8 @@ HTML_ELEMENT_LINE_BREAK, HTML_ELEMENT_BEGIN_COLOR, HTML_ELEMENT_END_COLOR, + HTML_ELEMENT_HEADER, + HTML_ELEMENT_FOOTER, HTML_ELEMENT_COUNT }; @@ -54,6 +62,8 @@ #endif // Debug "", "", + "", + "" }; static const char * html_color[] = @@ -131,7 +141,25 @@ info->bg = bg; } - LIB3270_EXPORT char * lib3270_get_as_html(H3270 *session, unsigned char all) + static const append_char(struct html_info *info, const struct chr_xlat *xlat, unsigned char chr) + { + char txt[] = { chr, 0 }; + int f; + + for(f=0;xlat[f].chr;f++) + { + if(xlat[f].chr == chr) + { + append_string(info,xlat[f].xlat); + return; + } + } + + append_string(info,txt); + + } + + LIB3270_EXPORT char * lib3270_get_as_html(H3270 *session, LIB3270_HTML_OPTION option) { int row, col, baddr; struct html_info info; @@ -142,6 +170,13 @@ info.fg = 0xFF; info.bg = 0xFF; + if(option & LIB3270_HTML_OPTION_HEADERS) + { + char *txt = xs_buffer(element_text[HTML_ELEMENT_HEADER],lib3270_get_charset(session),html_color[0]); + append_string(&info,txt); + lib3270_free(txt); + } + baddr = 0; for(row=0;row < session->rows;row++) { @@ -149,12 +184,54 @@ for(col = 0; col < session->cols;col++) { - if(all || session->text[baddr].attr & LIB3270_ATTR_SELECTED) + if((option && LIB3270_HTML_OPTION_ALL) || (session->text[baddr].attr & LIB3270_ATTR_SELECTED)) { - char txt[] = { session->text[baddr].chr, 0 }; cr++; update_colors(&info,session->text[baddr].attr); - append_string(&info,txt); + + if(session->text[baddr].attr & LIB3270_ATTR_CG) + { + static const struct chr_xlat xlat[] = + { + { 0xd3, "+" }, // CG 0xab, plus + { 0xa2, "-" }, // CG 0x92, horizontal line + { 0x85, "|" }, // CG 0x184, vertical line + { 0xd4, "+" }, // CG 0xac, LR corner + { 0xd5, "+" }, // CG 0xad, UR corner + { 0xc5, "+" }, // CG 0xa4, UL corner + { 0xc4, "+" }, // CG 0xa3, LL corner + { 0xc6, "|" }, // CG 0xa5, left tee + { 0xd6, "|" }, // CG 0xae, right tee + { 0xc7, "-" }, // CG 0xa6, bottom tee + { 0xd7, "-" }, // CG 0xaf, top tee + { 0x8c, "≤" }, // CG 0xf7, less or equal "≤" + { 0xae, "≥" }, // CG 0xd9, greater or equal "≥" + { 0xbe, "≠" }, // CG 0x3e, not equal "≠" + { 0xad, "[" }, // "[" + { 0xbd, "]" }, // "]" + + { 0x00, NULL } + }; + + append_char(&info, xlat, session->text[baddr].chr); + + } + else + { + static const struct chr_xlat xlat[] = + { + { '"', """ }, + { '&', "&" }, + { '<', "<" }, + { '>', ">" }, + + { 0x00, NULL } + }; + + append_char(&info, xlat, session->text[baddr].chr); + + } + } baddr++; } @@ -166,6 +243,9 @@ if(info.fg != 0xFF) append_string(&info,element_text[HTML_ELEMENT_END_COLOR]); + if(option & LIB3270_HTML_OPTION_HEADERS) + append_element(&info,HTML_ELEMENT_FOOTER); + return lib3270_realloc(info.text,strlen(info.text)+2); } diff --git a/src/pw3270/actions.c b/src/pw3270/actions.c index 0182238..239d929 100644 --- a/src/pw3270/actions.c +++ b/src/pw3270/actions.c @@ -38,6 +38,10 @@ #include #include + #ifdef DEBUG + #include + #endif + #define ERROR_DOMAIN g_quark_from_static_string(PACKAGE_NAME) #define TOGGLE_GDKDEBUG LIB3270_TOGGLE_COUNT+1 @@ -179,6 +183,26 @@ static void kp_add_action(GtkAction *action, GtkWidget *widget) } +#ifdef DEBUG +static void copy_as_html_action(GtkAction *action, GtkWidget *widget) +{ + char * text; + gchar * utf; + H3270 * session = v3270_get_session(widget); + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD); + + trace_action(action,widget); + + text = lib3270_get_as_html(session,LIB3270_HTML_OPTION_ALL|LIB3270_HTML_OPTION_FORM); + utf = g_convert(text, -1, "UTF-8", lib3270_get_charset(session), NULL, NULL, NULL); + lib3270_free(text); + + gtk_clipboard_set_text(clipboard,utf,-1); + g_free(utf); + +} +#endif // DEBUG + static void connect_standard_action(GtkAction *action, GtkWidget *widget, const gchar *name) { #undef DECLARE_LIB3270_ACTION @@ -219,6 +243,7 @@ static void connect_standard_action(GtkAction *action, GtkWidget *widget, const { "kpsubtract", kp_subtract_action }, { "kpadd", kp_add_action }, #ifdef DEBUG + { "copyashtml", copy_as_html_action }, { "download", download_action }, { "upload", upload_action }, #endif // DEBUG diff --git a/src/pw3270/window.c b/src/pw3270/window.c index 957fed4..aa72aa1 100644 --- a/src/pw3270/window.c +++ b/src/pw3270/window.c @@ -461,16 +461,6 @@ // Finish setup #ifdef DEBUG lib3270_testpattern(host); - - { - #warning Temporario - char * text = lib3270_get_as_html(host,1); - - printf("\n%s\n",text); - - lib3270_free(text); - } - #endif trace("%s ends",__FUNCTION__); diff --git a/ui/99debug.xml b/ui/99debug.xml index 8ed848c..f4ec67f 100644 --- a/ui/99debug.xml +++ b/ui/99debug.xml @@ -31,6 +31,10 @@ + + + + -- libgit2 0.21.2