Commit 8471bd91389ffe773c9f1ea68b74fb99c8195ddc
1 parent
95351721
Exists in
master
and in
5 other branches
Implementando leitura da tela em formato html
Showing
5 changed files
with
123 additions
and
14 deletions
Show diff stats
src/include/lib3270/html.h
| @@ -30,6 +30,16 @@ | @@ -30,6 +30,16 @@ | ||
| 30 | 30 | ||
| 31 | #define LIB3270_HTML_H_INCLUDED 1 | 31 | #define LIB3270_HTML_H_INCLUDED 1 |
| 32 | 32 | ||
| 33 | + typedef enum _lib3270_html_option | ||
| 34 | + { | ||
| 35 | + LIB3270_HTML_OPTION_ALL = 0x0001, | ||
| 36 | + LIB3270_HTML_OPTION_HEADERS = 0x0002, | ||
| 37 | + LIB3270_HTML_OPTION_FORM = 0x0004, | ||
| 38 | + | ||
| 39 | + } LIB3270_HTML_OPTION; | ||
| 40 | + | ||
| 41 | + LIB3270_EXPORT char * lib3270_get_as_html(H3270 *session, LIB3270_HTML_OPTION option); | ||
| 42 | + | ||
| 33 | 43 | ||
| 34 | #endif // LIB3270_HTML_H_INCLUDED | 44 | #endif // LIB3270_HTML_H_INCLUDED |
| 35 | 45 |
src/lib3270/html.c
| @@ -34,6 +34,12 @@ | @@ -34,6 +34,12 @@ | ||
| 34 | #include "globals.h" | 34 | #include "globals.h" |
| 35 | #include "utilc.h" | 35 | #include "utilc.h" |
| 36 | 36 | ||
| 37 | + struct chr_xlat | ||
| 38 | + { | ||
| 39 | + unsigned char chr; | ||
| 40 | + const char * xlat; | ||
| 41 | + }; | ||
| 42 | + | ||
| 37 | /*--[ Defines ]--------------------------------------------------------------------------------------*/ | 43 | /*--[ Defines ]--------------------------------------------------------------------------------------*/ |
| 38 | 44 | ||
| 39 | enum html_element | 45 | enum html_element |
| @@ -41,6 +47,8 @@ | @@ -41,6 +47,8 @@ | ||
| 41 | HTML_ELEMENT_LINE_BREAK, | 47 | HTML_ELEMENT_LINE_BREAK, |
| 42 | HTML_ELEMENT_BEGIN_COLOR, | 48 | HTML_ELEMENT_BEGIN_COLOR, |
| 43 | HTML_ELEMENT_END_COLOR, | 49 | HTML_ELEMENT_END_COLOR, |
| 50 | + HTML_ELEMENT_HEADER, | ||
| 51 | + HTML_ELEMENT_FOOTER, | ||
| 44 | 52 | ||
| 45 | HTML_ELEMENT_COUNT | 53 | HTML_ELEMENT_COUNT |
| 46 | }; | 54 | }; |
| @@ -54,6 +62,8 @@ | @@ -54,6 +62,8 @@ | ||
| 54 | #endif // Debug | 62 | #endif // Debug |
| 55 | "<span style=\"color:%s;background-color:%s\">", | 63 | "<span style=\"color:%s;background-color:%s\">", |
| 56 | "</span>", | 64 | "</span>", |
| 65 | + "<!DOCTYPE html><html><head><meta http-equiv=\"content-type\" content=\"text/html;charset=%s\"/></head><body style=\"font-family:courier;background-color:%s\">", | ||
| 66 | + "</body></html>" | ||
| 57 | }; | 67 | }; |
| 58 | 68 | ||
| 59 | static const char * html_color[] = | 69 | static const char * html_color[] = |
| @@ -131,7 +141,25 @@ | @@ -131,7 +141,25 @@ | ||
| 131 | info->bg = bg; | 141 | info->bg = bg; |
| 132 | } | 142 | } |
| 133 | 143 | ||
| 134 | - LIB3270_EXPORT char * lib3270_get_as_html(H3270 *session, unsigned char all) | 144 | + static const append_char(struct html_info *info, const struct chr_xlat *xlat, unsigned char chr) |
| 145 | + { | ||
| 146 | + char txt[] = { chr, 0 }; | ||
| 147 | + int f; | ||
| 148 | + | ||
| 149 | + for(f=0;xlat[f].chr;f++) | ||
| 150 | + { | ||
| 151 | + if(xlat[f].chr == chr) | ||
| 152 | + { | ||
| 153 | + append_string(info,xlat[f].xlat); | ||
| 154 | + return; | ||
| 155 | + } | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + append_string(info,txt); | ||
| 159 | + | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + LIB3270_EXPORT char * lib3270_get_as_html(H3270 *session, LIB3270_HTML_OPTION option) | ||
| 135 | { | 163 | { |
| 136 | int row, col, baddr; | 164 | int row, col, baddr; |
| 137 | struct html_info info; | 165 | struct html_info info; |
| @@ -142,6 +170,13 @@ | @@ -142,6 +170,13 @@ | ||
| 142 | info.fg = 0xFF; | 170 | info.fg = 0xFF; |
| 143 | info.bg = 0xFF; | 171 | info.bg = 0xFF; |
| 144 | 172 | ||
| 173 | + if(option & LIB3270_HTML_OPTION_HEADERS) | ||
| 174 | + { | ||
| 175 | + char *txt = xs_buffer(element_text[HTML_ELEMENT_HEADER],lib3270_get_charset(session),html_color[0]); | ||
| 176 | + append_string(&info,txt); | ||
| 177 | + lib3270_free(txt); | ||
| 178 | + } | ||
| 179 | + | ||
| 145 | baddr = 0; | 180 | baddr = 0; |
| 146 | for(row=0;row < session->rows;row++) | 181 | for(row=0;row < session->rows;row++) |
| 147 | { | 182 | { |
| @@ -149,12 +184,54 @@ | @@ -149,12 +184,54 @@ | ||
| 149 | 184 | ||
| 150 | for(col = 0; col < session->cols;col++) | 185 | for(col = 0; col < session->cols;col++) |
| 151 | { | 186 | { |
| 152 | - if(all || session->text[baddr].attr & LIB3270_ATTR_SELECTED) | 187 | + if((option && LIB3270_HTML_OPTION_ALL) || (session->text[baddr].attr & LIB3270_ATTR_SELECTED)) |
| 153 | { | 188 | { |
| 154 | - char txt[] = { session->text[baddr].chr, 0 }; | ||
| 155 | cr++; | 189 | cr++; |
| 156 | update_colors(&info,session->text[baddr].attr); | 190 | update_colors(&info,session->text[baddr].attr); |
| 157 | - append_string(&info,txt); | 191 | + |
| 192 | + if(session->text[baddr].attr & LIB3270_ATTR_CG) | ||
| 193 | + { | ||
| 194 | + static const struct chr_xlat xlat[] = | ||
| 195 | + { | ||
| 196 | + { 0xd3, "+" }, // CG 0xab, plus | ||
| 197 | + { 0xa2, "-" }, // CG 0x92, horizontal line | ||
| 198 | + { 0x85, "|" }, // CG 0x184, vertical line | ||
| 199 | + { 0xd4, "+" }, // CG 0xac, LR corner | ||
| 200 | + { 0xd5, "+" }, // CG 0xad, UR corner | ||
| 201 | + { 0xc5, "+" }, // CG 0xa4, UL corner | ||
| 202 | + { 0xc4, "+" }, // CG 0xa3, LL corner | ||
| 203 | + { 0xc6, "|" }, // CG 0xa5, left tee | ||
| 204 | + { 0xd6, "|" }, // CG 0xae, right tee | ||
| 205 | + { 0xc7, "-" }, // CG 0xa6, bottom tee | ||
| 206 | + { 0xd7, "-" }, // CG 0xaf, top tee | ||
| 207 | + { 0x8c, "≤" }, // CG 0xf7, less or equal "≤" | ||
| 208 | + { 0xae, "≥" }, // CG 0xd9, greater or equal "≥" | ||
| 209 | + { 0xbe, "≠" }, // CG 0x3e, not equal "≠" | ||
| 210 | + { 0xad, "[" }, // "[" | ||
| 211 | + { 0xbd, "]" }, // "]" | ||
| 212 | + | ||
| 213 | + { 0x00, NULL } | ||
| 214 | + }; | ||
| 215 | + | ||
| 216 | + append_char(&info, xlat, session->text[baddr].chr); | ||
| 217 | + | ||
| 218 | + } | ||
| 219 | + else | ||
| 220 | + { | ||
| 221 | + static const struct chr_xlat xlat[] = | ||
| 222 | + { | ||
| 223 | + { '"', """ }, | ||
| 224 | + { '&', "&" }, | ||
| 225 | + { '<', "<" }, | ||
| 226 | + { '>', ">" }, | ||
| 227 | + | ||
| 228 | + { 0x00, NULL } | ||
| 229 | + }; | ||
| 230 | + | ||
| 231 | + append_char(&info, xlat, session->text[baddr].chr); | ||
| 232 | + | ||
| 233 | + } | ||
| 234 | + | ||
| 158 | } | 235 | } |
| 159 | baddr++; | 236 | baddr++; |
| 160 | } | 237 | } |
| @@ -166,6 +243,9 @@ | @@ -166,6 +243,9 @@ | ||
| 166 | if(info.fg != 0xFF) | 243 | if(info.fg != 0xFF) |
| 167 | append_string(&info,element_text[HTML_ELEMENT_END_COLOR]); | 244 | append_string(&info,element_text[HTML_ELEMENT_END_COLOR]); |
| 168 | 245 | ||
| 246 | + if(option & LIB3270_HTML_OPTION_HEADERS) | ||
| 247 | + append_element(&info,HTML_ELEMENT_FOOTER); | ||
| 248 | + | ||
| 169 | return lib3270_realloc(info.text,strlen(info.text)+2); | 249 | return lib3270_realloc(info.text,strlen(info.text)+2); |
| 170 | } | 250 | } |
| 171 | 251 |
src/pw3270/actions.c
| @@ -38,6 +38,10 @@ | @@ -38,6 +38,10 @@ | ||
| 38 | #include <lib3270/trace.h> | 38 | #include <lib3270/trace.h> |
| 39 | #include <stdlib.h> | 39 | #include <stdlib.h> |
| 40 | 40 | ||
| 41 | + #ifdef DEBUG | ||
| 42 | + #include <lib3270/html.h> | ||
| 43 | + #endif | ||
| 44 | + | ||
| 41 | #define ERROR_DOMAIN g_quark_from_static_string(PACKAGE_NAME) | 45 | #define ERROR_DOMAIN g_quark_from_static_string(PACKAGE_NAME) |
| 42 | #define TOGGLE_GDKDEBUG LIB3270_TOGGLE_COUNT+1 | 46 | #define TOGGLE_GDKDEBUG LIB3270_TOGGLE_COUNT+1 |
| 43 | 47 | ||
| @@ -179,6 +183,26 @@ static void kp_add_action(GtkAction *action, GtkWidget *widget) | @@ -179,6 +183,26 @@ static void kp_add_action(GtkAction *action, GtkWidget *widget) | ||
| 179 | 183 | ||
| 180 | } | 184 | } |
| 181 | 185 | ||
| 186 | +#ifdef DEBUG | ||
| 187 | +static void copy_as_html_action(GtkAction *action, GtkWidget *widget) | ||
| 188 | +{ | ||
| 189 | + char * text; | ||
| 190 | + gchar * utf; | ||
| 191 | + H3270 * session = v3270_get_session(widget); | ||
| 192 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD); | ||
| 193 | + | ||
| 194 | + trace_action(action,widget); | ||
| 195 | + | ||
| 196 | + text = lib3270_get_as_html(session,LIB3270_HTML_OPTION_ALL|LIB3270_HTML_OPTION_FORM); | ||
| 197 | + utf = g_convert(text, -1, "UTF-8", lib3270_get_charset(session), NULL, NULL, NULL); | ||
| 198 | + lib3270_free(text); | ||
| 199 | + | ||
| 200 | + gtk_clipboard_set_text(clipboard,utf,-1); | ||
| 201 | + g_free(utf); | ||
| 202 | + | ||
| 203 | +} | ||
| 204 | +#endif // DEBUG | ||
| 205 | + | ||
| 182 | static void connect_standard_action(GtkAction *action, GtkWidget *widget, const gchar *name) | 206 | static void connect_standard_action(GtkAction *action, GtkWidget *widget, const gchar *name) |
| 183 | { | 207 | { |
| 184 | #undef DECLARE_LIB3270_ACTION | 208 | #undef DECLARE_LIB3270_ACTION |
| @@ -219,6 +243,7 @@ static void connect_standard_action(GtkAction *action, GtkWidget *widget, const | @@ -219,6 +243,7 @@ static void connect_standard_action(GtkAction *action, GtkWidget *widget, const | ||
| 219 | { "kpsubtract", kp_subtract_action }, | 243 | { "kpsubtract", kp_subtract_action }, |
| 220 | { "kpadd", kp_add_action }, | 244 | { "kpadd", kp_add_action }, |
| 221 | #ifdef DEBUG | 245 | #ifdef DEBUG |
| 246 | + { "copyashtml", copy_as_html_action }, | ||
| 222 | { "download", download_action }, | 247 | { "download", download_action }, |
| 223 | { "upload", upload_action }, | 248 | { "upload", upload_action }, |
| 224 | #endif // DEBUG | 249 | #endif // DEBUG |
src/pw3270/window.c
| @@ -461,16 +461,6 @@ | @@ -461,16 +461,6 @@ | ||
| 461 | // Finish setup | 461 | // Finish setup |
| 462 | #ifdef DEBUG | 462 | #ifdef DEBUG |
| 463 | lib3270_testpattern(host); | 463 | lib3270_testpattern(host); |
| 464 | - | ||
| 465 | - { | ||
| 466 | - #warning Temporario | ||
| 467 | - char * text = lib3270_get_as_html(host,1); | ||
| 468 | - | ||
| 469 | - printf("\n%s\n",text); | ||
| 470 | - | ||
| 471 | - lib3270_free(text); | ||
| 472 | - } | ||
| 473 | - | ||
| 474 | #endif | 464 | #endif |
| 475 | 465 | ||
| 476 | trace("%s ends",__FUNCTION__); | 466 | trace("%s ends",__FUNCTION__); |
ui/99debug.xml
| @@ -31,6 +31,10 @@ | @@ -31,6 +31,10 @@ | ||
| 31 | <ui> | 31 | <ui> |
| 32 | <menubar name='topmenu'> | 32 | <menubar name='topmenu'> |
| 33 | 33 | ||
| 34 | + <menu name='EditMenu' label='_Edit' > | ||
| 35 | + <menuitem action='copyashtml' label='Copy as HTML' /> | ||
| 36 | + </menu> | ||
| 37 | + | ||
| 34 | <menu name='View' > | 38 | <menu name='View' > |
| 35 | <menu name='TraceOptions' label='Trace' > | 39 | <menu name='TraceOptions' label='Trace' > |
| 36 | <menuitem action='toggle' id='dstrace' label='DS Trace' /> | 40 | <menuitem action='toggle' id='dstrace' label='DS Trace' /> |