Commit 76e230f530e7c55a95dbefc4e3cd03d430634e52

Authored by perry.werneck@gmail.com
1 parent 050ff3dd

Biblioteca de versao 5 precisa trabalhar toda em latin-1 igual ao windows deixan…

…do a conversao para UTF-8 por conta do gtk para manter um unico mecanismo de conversao
@@ -44,19 +44,27 @@ @@ -44,19 +44,27 @@
44 #include "charsetc.h" 44 #include "charsetc.h"
45 #include "kybdc.h" 45 #include "kybdc.h"
46 #include "popupsc.h" 46 #include "popupsc.h"
47 -#if defined(X3270_DISPLAY) || (defined(C3270) && !defined(_WIN32)) /*[*/ 47 +
  48 +/*
  49 +#if defined(X3270_DISPLAY) || (defined(C3270) && !defined(_WIN32))
48 #include "screenc.h" 50 #include "screenc.h"
49 -#endif /*]*/ 51 +#endif
  52 +*/
  53 +
50 #include "tablesc.h" 54 #include "tablesc.h"
51 #include "utf8c.h" 55 #include "utf8c.h"
52 #include "utilc.h" 56 #include "utilc.h"
53 #include "widec.h" 57 #include "widec.h"
54 58
55 #include <errno.h> 59 #include <errno.h>
56 -#include <locale.h>  
57 -#if !defined(_WIN32) /*[*/ 60 +
  61 +//#include <locale.h>
  62 +
  63 +/*
  64 +#if !defined(_WIN32)
58 #include <langinfo.h> 65 #include <langinfo.h>
59 -#endif /*]*/ 66 +#endif
  67 +*/
60 68
61 // #include <lib3270/api.h> 69 // #include <lib3270/api.h>
62 70
@@ -72,9 +80,13 @@ unsigned long cgcsgid_dbcs = 0L; @@ -72,9 +80,13 @@ unsigned long cgcsgid_dbcs = 0L;
72 char *default_display_charset = "3270cg-1a,3270cg-1,iso8859-1"; 80 char *default_display_charset = "3270cg-1a,3270cg-1,iso8859-1";
73 char *converter_names; 81 char *converter_names;
74 char *encoding; 82 char *encoding;
75 -#if defined(X3270_DISPLAY) /*[*/ 83 +
  84 +/*
  85 +#if defined(X3270_DISPLAY)
76 unsigned char xk_selector = 0; 86 unsigned char xk_selector = 0;
77 #endif 87 #endif
  88 +*/
  89 +
78 unsigned char auto_keymap = 0; 90 unsigned char auto_keymap = 0;
79 91
80 /* Statics. */ 92 /* Statics. */
@@ -82,12 +94,13 @@ static enum cs_result resource_charset(char *csname, char *cs, char *ftcs); @@ -82,12 +94,13 @@ static enum cs_result resource_charset(char *csname, char *cs, char *ftcs);
82 typedef enum { CS_ONLY, FT_ONLY, BOTH } remap_scope; 94 typedef enum { CS_ONLY, FT_ONLY, BOTH } remap_scope;
83 static enum cs_result remap_chars(char *csname, char *spec, remap_scope scope, 95 static enum cs_result remap_chars(char *csname, char *spec, remap_scope scope,
84 int *ne); 96 int *ne);
85 -static void remap_one(unsigned char ebc, KeySym iso, remap_scope scope,  
86 - Boolean one_way); 97 +static void remap_one(unsigned char ebc, KeySym iso, remap_scope scope,Boolean one_way);
  98 +
87 #if defined(DEBUG_CHARSET) /*[*/ 99 #if defined(DEBUG_CHARSET) /*[*/
88 static enum cs_result check_charset(void); 100 static enum cs_result check_charset(void);
89 static char *char_if_ascii7(unsigned long l); 101 static char *char_if_ascii7(unsigned long l);
90 #endif /*]*/ 102 #endif /*]*/
  103 +
91 static void set_cgcsgids(char *spec); 104 static void set_cgcsgids(char *spec);
92 static int set_cgcsgid(char *spec, unsigned long *idp); 105 static int set_cgcsgid(char *spec, unsigned long *idp);
93 106
@@ -113,6 +126,7 @@ static unsigned char save_ebc2cg[256]; @@ -113,6 +126,7 @@ static unsigned char save_ebc2cg[256];
113 static unsigned char save_cg2ebc[256]; 126 static unsigned char save_cg2ebc[256];
114 static unsigned char save_ebc2asc[256]; 127 static unsigned char save_ebc2asc[256];
115 static unsigned char save_asc2ebc[256]; 128 static unsigned char save_asc2ebc[256];
  129 +
116 #if defined(X3270_FT) /*[*/ 130 #if defined(X3270_FT) /*[*/
117 static unsigned char save_ft2asc[256]; 131 static unsigned char save_ft2asc[256];
118 static unsigned char save_asc2ft[256]; 132 static unsigned char save_asc2ft[256];
@@ -145,8 +159,7 @@ restore_charset(void) @@ -145,8 +159,7 @@ restore_charset(void)
145 } 159 }
146 160
147 /* Get a character set definition. */ 161 /* Get a character set definition. */
148 -static char *  
149 -get_charset_def(const char *csname) 162 +static char * get_charset_def(const char *csname)
150 { 163 {
151 return get_fresource("%s.%s", ResCharset, csname); 164 return get_fresource("%s.%s", ResCharset, csname);
152 } 165 }
@@ -183,9 +196,11 @@ enum cs_result charset_init(H3270 *session, char *csname) @@ -183,9 +196,11 @@ enum cs_result charset_init(H3270 *session, char *csname)
183 char *cs, *ftcs; 196 char *cs, *ftcs;
184 enum cs_result rc; 197 enum cs_result rc;
185 char *ccs, *cftcs; 198 char *ccs, *cftcs;
186 -#if defined(X3270_DISPLAY) /*[*/ 199 +/*
  200 +#if defined(X3270_DISPLAY)
187 char *xks; 201 char *xks;
188 -#endif /*]*/ 202 +#endif
  203 +*/
189 char *ak; 204 char *ak;
190 205
191 /* 206 /*
@@ -85,15 +85,15 @@ static char *print_window_command = CN; @@ -85,15 +85,15 @@ static char *print_window_command = CN;
85 85
86 /* 86 /*
87 * Map default 3279 colors. This code is duplicated three times. ;-( 87 * Map default 3279 colors. This code is duplicated three times. ;-(
88 - */ 88 + */ /*
89 static int 89 static int
90 color_from_fa(unsigned char fa) 90 color_from_fa(unsigned char fa)
91 { 91 {
92 static int field_colors[4] = { 92 static int field_colors[4] = {
93 - COLOR_GREEN, /* default */  
94 - COLOR_RED, /* intensified */  
95 - COLOR_BLUE, /* protected */  
96 - COLOR_WHITE /* protected, intensified */ 93 + COLOR_GREEN, // default
  94 + COLOR_RED, // intensified
  95 + COLOR_BLUE, // protected
  96 + COLOR_WHITE // protected, intensified
97 # define DEFCOLOR_MAP(f) \ 97 # define DEFCOLOR_MAP(f) \
98 ((((f) & FA_PROTECT) >> 4) | (((f) & FA_INT_HIGH_SEL) >> 3)) 98 ((((f) & FA_PROTECT) >> 4) | (((f) & FA_INT_HIGH_SEL) >> 3))
99 }; 99 };
@@ -103,10 +103,10 @@ color_from_fa(unsigned char fa) @@ -103,10 +103,10 @@ color_from_fa(unsigned char fa)
103 else 103 else
104 return COLOR_GREEN; 104 return COLOR_GREEN;
105 } 105 }
106 - 106 +*/
107 /* 107 /*
108 * Map 3279 colors onto HTML colors. 108 * Map 3279 colors onto HTML colors.
109 - */ 109 + */ /*
110 static char * 110 static char *
111 html_color(int color) 111 html_color(int color)
112 { 112 {
@@ -133,7 +133,7 @@ html_color(int color) @@ -133,7 +133,7 @@ html_color(int color)
133 else 133 else
134 return "black"; 134 return "black";
135 } 135 }
136 - 136 +*/
137 137
138 /* 138 /*
139 * Print the ASCIIfied contents of the screen onto a stream. 139 * Print the ASCIIfied contents of the screen onto a stream.
@@ -145,6 +145,9 @@ html_color(int color) @@ -145,6 +145,9 @@ html_color(int color)
145 Boolean 145 Boolean
146 fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html) 146 fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html)
147 { 147 {
  148 + return False;
  149 +
  150 +/*
148 register int i; 151 register int i;
149 char c; 152 char c;
150 int ns = 0; 153 int ns = 0;
@@ -172,10 +175,10 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html) @@ -172,10 +175,10 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html)
172 current_high = fa_high; 175 current_high = fa_high;
173 176
174 for (i = 0; i < h3270.rows*h3270.cols; i++) { 177 for (i = 0; i < h3270.rows*h3270.cols; i++) {
175 -#if defined(X3270_DBCS) /*[*/ 178 +#if defined(X3270_DBCS)
176 char mb[16]; 179 char mb[16];
177 Boolean is_dbcs = False; 180 Boolean is_dbcs = False;
178 -#endif /*]*/ 181 +#endif
179 182
180 if (i && !(i % h3270.cols)) { 183 if (i && !(i % h3270.cols)) {
181 nr++; 184 nr++;
@@ -195,9 +198,9 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html) @@ -195,9 +198,9 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html)
195 } 198 }
196 if (FA_IS_ZERO(fa)) 199 if (FA_IS_ZERO(fa))
197 c = ' '; 200 c = ' ';
198 -#if defined(X3270_DBCS) /*[*/ 201 +#if defined(X3270_DBCS)
199 else { 202 else {
200 - /* XXX: DBCS/html interactions are not done */ 203 + // XXX: DBCS/html interactions are not done
201 switch (ctlr_dbcs_state(i)) { 204 switch (ctlr_dbcs_state(i)) {
202 case DBCS_NONE: 205 case DBCS_NONE:
203 case DBCS_SB: 206 case DBCS_SB:
@@ -213,10 +216,10 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html) @@ -213,10 +216,10 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html)
213 break; 216 break;
214 } 217 }
215 } 218 }
216 -#else /*][*/ 219 +#else
217 else 220 else
218 c = ebc2asc[h3270.ea_buf[i].cc]; 221 c = ebc2asc[h3270.ea_buf[i].cc];
219 -#endif /*]*/ 222 +#endif
220 if (c == ' ') 223 if (c == ' ')
221 ns++; 224 ns++;
222 else { 225 else {
@@ -270,13 +273,13 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html) @@ -270,13 +273,13 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html)
270 } 273 }
271 } 274 }
272 any = True; 275 any = True;
273 -#if defined(X3270_DBCS) /*[*/ 276 +#if defined(X3270_DBCS)
274 if (is_dbcs) { 277 if (is_dbcs) {
275 (void) fputs(mb, f); 278 (void) fputs(mb, f);
276 i++; 279 i++;
277 } 280 }
278 else 281 else
279 -#endif /*]*/ 282 +#endif
280 { 283 {
281 if (use_html && c == '<') 284 if (use_html && c == '<')
282 fprintf(f, "&lt;"); 285 fprintf(f, "&lt;");
@@ -300,6 +303,7 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html) @@ -300,6 +303,7 @@ fprint_screen(FILE *f, Boolean even_if_empty, Boolean use_html)
300 current_high? "</b>": ""); 303 current_high? "</b>": "");
301 } 304 }
302 return True; 305 return True;
  306 +*/
303 } 307 }
304 308
305 /* Termination code for print text process. */ /* 309 /* Termination code for print text process. */ /*
@@ -793,11 +793,13 @@ do_screentrace(void) @@ -793,11 +793,13 @@ do_screentrace(void)
793 { 793 {
794 register int i; 794 register int i;
795 795
  796 +/*
796 if (fprint_screen(screentracef, False, False)) { 797 if (fprint_screen(screentracef, False, False)) {
797 for (i = 0; i < h3270.cols; i++) 798 for (i = 0; i < h3270.cols; i++)
798 (void) fputc('=', screentracef); 799 (void) fputc('=', screentracef);
799 (void) fputc('\n', screentracef); 800 (void) fputc('\n', screentracef);
800 } 801 }
  802 +*/
801 } 803 }
802 804
803 void 805 void
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
45 char *locale_codeset = CN; 45 char *locale_codeset = CN;
46 46
47 static int utf8_ix = -1; 47 static int utf8_ix = -1;
48 -static Boolean is_utf8 = False; 48 +// static Boolean is_utf8 = False;
49 #if defined(X3270_DBCS) /*[*/ 49 #if defined(X3270_DBCS) /*[*/
50 static Boolean is_gb18030 = False; 50 static Boolean is_gb18030 = False;
51 #endif /*]*/ 51 #endif /*]*/
@@ -73,8 +73,8 @@ enum UTF_IX { @@ -73,8 +73,8 @@ enum UTF_IX {
73 /* 73 /*
74 * Names of the above (real) character sets. These are the names used in 74 * Names of the above (real) character sets. These are the names used in
75 * displayCharset resources. 75 * displayCharset resources.
76 - */  
77 -static char *dcs[] = { /* same order as enum UTF_IX and utf8_tab[] */ 76 + */ /*
  77 +static char *dcs[] = { // same order as enum UTF_IX and utf8_tab[]
78 "iso8859-1", 78 "iso8859-1",
79 "iso8859-2", 79 "iso8859-2",
80 "iso8859-7", 80 "iso8859-7",
@@ -85,6 +85,7 @@ static char *dcs[] = { /* same order as enum UTF_IX and utf8_tab[] */ @@ -85,6 +85,7 @@ static char *dcs[] = { /* same order as enum UTF_IX and utf8_tab[] */
85 "koi8-r", 85 "koi8-r",
86 CN 86 CN
87 }; 87 };
  88 +*/
88 89
89 /* 90 /*
90 * UTF-8 translation tables. 91 * UTF-8 translation tables.
@@ -336,33 +337,34 @@ static char *utf8_tab[U_MAX][96] = { @@ -336,33 +337,34 @@ static char *utf8_tab[U_MAX][96] = {
336 337
337 /* 338 /*
338 * Save the codeset from the locale, and set globals based on known values. 339 * Save the codeset from the locale, and set globals based on known values.
339 - */ 340 + */ /*
340 void 341 void
341 set_codeset(char *codeset_name) 342 set_codeset(char *codeset_name)
342 { 343 {
343 char *new_codeset; 344 char *new_codeset;
344 345
345 -#if defined(X3270_DBCS) /*[*/ 346 +#if defined(X3270_DBCS)
346 is_gb18030 = !strcasecmp(codeset_name, "gb18030"); 347 is_gb18030 = !strcasecmp(codeset_name, "gb18030");
347 -#endif /*]*/ 348 +#endif
348 349
349 -#if !defined(TCL3270) /*[*/ 350 +#if !defined(TCL3270)
350 is_utf8 = (!strcasecmp(codeset_name, "utf-8") || 351 is_utf8 = (!strcasecmp(codeset_name, "utf-8") ||
351 !strcasecmp(codeset_name, "utf8") || 352 !strcasecmp(codeset_name, "utf8") ||
352 !strcasecmp(codeset_name, "utf_8")); 353 !strcasecmp(codeset_name, "utf_8"));
353 -#else /*][*/  
354 - /*  
355 - * tcl3270 is always in UTF-8 mode, because it needs to  
356 - * supply UTF-8 strings to libtcl.  
357 - */ 354 +#else
  355 + //
  356 + // tcl3270 is always in UTF-8 mode, because it needs to
  357 + // supply UTF-8 strings to libtcl.
  358 + //
358 is_utf8 = 1; 359 is_utf8 = 1;
359 -#endif /*]*/ 360 +#endif
360 361
361 Trace("%s locale_codeset: %p new_codeset: %p (%s)",__FUNCTION__,locale_codeset,codeset_name,codeset_name); 362 Trace("%s locale_codeset: %p new_codeset: %p (%s)",__FUNCTION__,locale_codeset,codeset_name,codeset_name);
362 new_codeset = NewString(codeset_name); 363 new_codeset = NewString(codeset_name);
363 Replace(locale_codeset, new_codeset); 364 Replace(locale_codeset, new_codeset);
364 Trace("%s",__FUNCTION__); 365 Trace("%s",__FUNCTION__);
365 } 366 }
  367 +*/
366 368
367 /* 369 /*
368 * Set globals based on an x3270 character set list. 370 * Set globals based on an x3270 character set list.
@@ -371,7 +373,7 @@ set_codeset(char *codeset_name) @@ -371,7 +373,7 @@ set_codeset(char *codeset_name)
371 * used by utf8_expand() below. 373 * used by utf8_expand() below.
372 * 374 *
373 * set_codeset, above, must be called _before_ this function. 375 * set_codeset, above, must be called _before_ this function.
374 - */ 376 + */ /*
375 Boolean 377 Boolean
376 utf8_set_display_charsets(char *cslist, char *csname) 378 utf8_set_display_charsets(char *cslist, char *csname)
377 { 379 {
@@ -382,44 +384,44 @@ utf8_set_display_charsets(char *cslist, char *csname) @@ -382,44 +384,44 @@ utf8_set_display_charsets(char *cslist, char *csname)
382 384
383 utf8_ix = -1; 385 utf8_ix = -1;
384 386
385 -#if defined(X3270_DBCS) /*[*/ 387 +#if defined(X3270_DBCS)
386 if (strchr(cslist, '+') != CN) 388 if (strchr(cslist, '+') != CN)
387 dbcs = True; 389 dbcs = True;
388 -#endif /*]*/ 390 +#endif
389 391
390 if (!is_utf8) { 392 if (!is_utf8) {
391 -#if defined(X3270_DBCS) /*[*/ 393 +#if defined(X3270_DBCS)
392 if (is_gb18030) { 394 if (is_gb18030) {
393 - /*  
394 - * A convenient lie.  
395 - * If the locale is GB18030, use the UTF-8  
396 - * expansion mechanism to translate 0xa0 through  
397 - * 0xff, using a table entry that expands to GB18030  
398 - * multi-byte sequences rather than UTF-8.  
399 - *  
400 - * Note that there appears to be a bug in ncursesw  
401 - * (or something it depends on) that turns these  
402 - * characters into garbage. Hopefully this bug will  
403 - * be fixed and this code will start working properly.  
404 - *  
405 - * As a workarond, everything works properly in a  
406 - * Chinese UTF-8 locale.  
407 - */ 395 + //
  396 + // A convenient lie.
  397 + // If the locale is GB18030, use the UTF-8
  398 + // expansion mechanism to translate 0xa0 through
  399 + // 0xff, using a table entry that expands to GB18030
  400 + // multi-byte sequences rather than UTF-8.
  401 + //
  402 + // Note that there appears to be a bug in ncursesw
  403 + // (or something it depends on) that turns these
  404 + // characters into garbage. Hopefully this bug will
  405 + // be fixed and this code will start working properly.
  406 + //
  407 + // As a workarond, everything works properly in a
  408 + // Chinese UTF-8 locale.
  409 + //
408 utf8_ix = PSEUDO_GB18030; 410 utf8_ix = PSEUDO_GB18030;
409 } 411 }
410 -#endif /*]*/ 412 +#endif
411 return True; 413 return True;
412 } 414 }
413 415
414 -#if defined(X3270_DBCS) /*[*/  
415 - /* For DBCS, map 0xa0..0xff as Latin-1. */ 416 +#if defined(X3270_DBCS)
  417 + // For DBCS, map 0xa0..0xff as Latin-1.
416 if (dbcs) { 418 if (dbcs) {
417 utf8_ix = U_ISO8859_1; 419 utf8_ix = U_ISO8859_1;
418 return True; 420 return True;
419 } 421 }
420 -#endif /*]*/ 422 +#endif
421 423
422 - /* Skip 3270cg sets. */ 424 + // Skip 3270cg sets.
423 ptr = dup = NewString(cslist); 425 ptr = dup = NewString(cslist);
424 while ((tok = strtok(ptr, ",")) != CN) { 426 while ((tok = strtok(ptr, ",")) != CN) {
425 ptr = NULL; 427 ptr = NULL;
@@ -433,7 +435,7 @@ utf8_set_display_charsets(char *cslist, char *csname) @@ -433,7 +435,7 @@ utf8_set_display_charsets(char *cslist, char *csname)
433 return False; 435 return False;
434 } 436 }
435 437
436 - /* Look up the charset. */ 438 + // Look up the charset.
437 for (i = 0; dcs[i] != CN; i++) { 439 for (i = 0; dcs[i] != CN; i++) {
438 if (!strcasecmp(dcs[i], tok)) 440 if (!strcasecmp(dcs[i], tok))
439 break; 441 break;
@@ -448,7 +450,7 @@ utf8_set_display_charsets(char *cslist, char *csname) @@ -448,7 +450,7 @@ utf8_set_display_charsets(char *cslist, char *csname)
448 Free(dup); 450 Free(dup);
449 return True; 451 return True;
450 } 452 }
451 - 453 +*/
452 /* Expand an 8-bit character in the 'implied' character set. */ 454 /* Expand an 8-bit character in the 'implied' character set. */
453 char * 455 char *
454 utf8_expand(unsigned char c) 456 utf8_expand(unsigned char c)
@@ -483,8 +485,7 @@ utf8_expand(unsigned char c) @@ -483,8 +485,7 @@ utf8_expand(unsigned char c)
483 * character set. 485 * character set.
484 * Returns 0 if the lookup fails. 486 * Returns 0 if the lookup fails.
485 */ 487 */
486 -unsigned char  
487 -utf8_lookup(char *mbs, enum ulfail *fail, int *consumed) 488 +unsigned char utf8_lookup(char *mbs, enum ulfail *fail, int *consumed)
488 { 489 {
489 int i; 490 int i;
490 int mblen = strlen(mbs); 491 int mblen = strlen(mbs);
@@ -24,9 +24,9 @@ enum ulfail { @@ -24,9 +24,9 @@ enum ulfail {
24 ULFAIL_INVALID /* invalid sequence */ 24 ULFAIL_INVALID /* invalid sequence */
25 }; 25 };
26 26
27 -LIB3270_INTERNAL char *locale_codeset; 27 +// LIB3270_INTERNAL char *locale_codeset;
28 28
29 -LIB3270_INTERNAL void set_codeset(char *codeset_name);  
30 -LIB3270_INTERNAL Boolean utf8_set_display_charsets(char *cslist, char *csname);  
31 -LIB3270_INTERNAL char *utf8_expand(unsigned char c);  
32 -LIB3270_INTERNAL unsigned char utf8_lookup(char *mbs, enum ulfail *fail, int *consumed); 29 +// LIB3270_INTERNAL void set_codeset(char *codeset_name);
  30 +// LIB3270_INTERNAL Boolean utf8_set_display_charsets(char *cslist, char *csname);
  31 + LIB3270_INTERNAL char *utf8_expand(unsigned char c);
  32 + LIB3270_INTERNAL unsigned char utf8_lookup(char *mbs, enum ulfail *fail, int *consumed);