Commit 2497ea5bc2a8bbabeb6d4f474ac8c731896cf39c
1 parent
66621f13
Exists in
master
and in
3 other branches
Implementando leitura da tela em formato html
Showing
1 changed file
with
84 additions
and
4 deletions
Show diff stats
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 |