Commit cfe92185ea984254bbb1b13aaf2362b86d756f57

Authored by perry.werneck@gmail.com
1 parent cf558eee

Iniciando implementação de charsets configurados

@@ -88,16 +88,16 @@ static KeySym StringToKeysym(char *s); @@ -88,16 +88,16 @@ static KeySym StringToKeysym(char *s);
88 // static void set_charset_name(char *csname); 88 // static void set_charset_name(char *csname);
89 // static char *charset_name = CN; 89 // static char *charset_name = CN;
90 90
91 -static void charset_defaults(void) 91 +static void charset_defaults(H3270 *hSession)
92 { 92 {
93 /* Go to defaults first. */ 93 /* Go to defaults first. */
94 - (void) memcpy((char *)ebc2cg, (const char *)ebc2cg0, 256);  
95 - (void) memcpy((char *)cg2ebc, (const char *)cg2ebc0, 256);  
96 - (void) memcpy((char *)ebc2asc, (const char *)ebc2asc0, 256);  
97 - (void) memcpy((char *)asc2ebc, (const char *)asc2ebc0, 256); 94 + (void) memcpy((char *)ebc2cg, (const char *)ebc2cg0, 256);
  95 + (void) memcpy((char *)cg2ebc, (const char *)cg2ebc0, 256);
  96 + (void) memcpy((char *) hSession->charset.ebc2asc, (const char *)ebc2asc0, 256);
  97 + (void) memcpy((char *)asc2ebc, (const char *)asc2ebc0, 256);
98 #if defined(X3270_FT) /*[*/ 98 #if defined(X3270_FT) /*[*/
99 - (void) memcpy((char *)ft2asc, (const char *)ft2asc0, 256);  
100 - (void) memcpy((char *)asc2ft, (const char *)asc2ft0, 256); 99 + (void) memcpy((char *)ft2asc, (const char *)ft2asc0, 256);
  100 + (void) memcpy((char *)asc2ft, (const char *)asc2ft0, 256);
101 #endif /*]*/ 101 #endif /*]*/
102 clear_xks(); 102 clear_xks();
103 } 103 }
@@ -116,11 +116,11 @@ struct charset_buffer @@ -116,11 +116,11 @@ struct charset_buffer
116 }; 116 };
117 117
118 118
119 -static void save_charset(struct charset_buffer *save) 119 +static void save_charset(H3270 *hSession, struct charset_buffer *save)
120 { 120 {
121 (void) memcpy((char *)save->ebc2cg, (char *)ebc2cg, 256); 121 (void) memcpy((char *)save->ebc2cg, (char *)ebc2cg, 256);
122 (void) memcpy((char *)save->cg2ebc, (char *)cg2ebc, 256); 122 (void) memcpy((char *)save->cg2ebc, (char *)cg2ebc, 256);
123 - (void) memcpy((char *)save->ebc2asc, (char *)ebc2asc, 256); 123 + (void) memcpy((char *)save->ebc2asc, (char *) hSession->charset.ebc2asc, 256);
124 (void) memcpy((char *)save->asc2ebc, (char *)asc2ebc, 256); 124 (void) memcpy((char *)save->asc2ebc, (char *)asc2ebc, 256);
125 #if defined(X3270_FT) /*[*/ 125 #if defined(X3270_FT) /*[*/
126 (void) memcpy((char *)save->ft2asc, (char *)ft2asc, 256); 126 (void) memcpy((char *)save->ft2asc, (char *)ft2asc, 256);
@@ -128,11 +128,11 @@ static void save_charset(struct charset_buffer *save) @@ -128,11 +128,11 @@ static void save_charset(struct charset_buffer *save)
128 #endif /*]*/ 128 #endif /*]*/
129 } 129 }
130 130
131 -static void restore_charset(struct charset_buffer *save) 131 +static void restore_charset(H3270 *hSession, struct charset_buffer *save)
132 { 132 {
133 (void) memcpy((char *)ebc2cg, (char *)save->ebc2cg, 256); 133 (void) memcpy((char *)ebc2cg, (char *)save->ebc2cg, 256);
134 (void) memcpy((char *)cg2ebc, (char *)save->cg2ebc, 256); 134 (void) memcpy((char *)cg2ebc, (char *)save->cg2ebc, 256);
135 - (void) memcpy((char *)ebc2asc, (char *)save->ebc2asc, 256); 135 + (void) memcpy((char *)hSession->charset.ebc2asc, (char *)save->ebc2asc, 256);
136 (void) memcpy((char *)asc2ebc, (char *)save->asc2ebc, 256); 136 (void) memcpy((char *)asc2ebc, (char *)save->asc2ebc, 256);
137 #if defined(X3270_FT) /*[*/ 137 #if defined(X3270_FT) /*[*/
138 (void) memcpy((char *)ft2asc, (char *)save->ft2asc, 256); 138 (void) memcpy((char *)ft2asc, (char *)save->ft2asc, 256);
@@ -189,7 +189,7 @@ enum cs_result charset_init(H3270 *hSession, const char *csname) @@ -189,7 +189,7 @@ enum cs_result charset_init(H3270 *hSession, const char *csname)
189 /* Do nothing, successfully. */ 189 /* Do nothing, successfully. */
190 if (csname == CN || !strcasecmp(csname, "us")) 190 if (csname == CN || !strcasecmp(csname, "us"))
191 { 191 {
192 - charset_defaults(); 192 + charset_defaults(hSession);
193 set_cgcsgids(hSession,CN); 193 set_cgcsgids(hSession,CN);
194 set_display_charset(hSession, "ISO-8859-1"); 194 set_display_charset(hSession, "ISO-8859-1");
195 return CS_OKAY; 195 return CS_OKAY;
@@ -220,8 +220,8 @@ enum cs_result charset_init(H3270 *hSession, const char *csname) @@ -220,8 +220,8 @@ enum cs_result charset_init(H3270 *hSession, const char *csname)
220 cftcs = lib3270_get_resource_string(hSession,"ftCharset",csname,NULL); 220 cftcs = lib3270_get_resource_string(hSession,"ftCharset",csname,NULL);
221 221
222 /* Save the current definitions, and start over with the defaults. */ 222 /* Save the current definitions, and start over with the defaults. */
223 - save_charset(&save);  
224 - charset_defaults(); 223 + save_charset(hSession,&save);
  224 + charset_defaults(hSession);
225 225
226 /* Check for auto-keymap. */ 226 /* Check for auto-keymap. */
227 ak = lib3270_get_resource_string(hSession,"autoKeymap", csname, NULL); 227 ak = lib3270_get_resource_string(hSession,"autoKeymap", csname, NULL);
@@ -243,7 +243,7 @@ enum cs_result charset_init(H3270 *hSession, const char *csname) @@ -243,7 +243,7 @@ enum cs_result charset_init(H3270 *hSession, const char *csname)
243 #endif /*]*/ 243 #endif /*]*/
244 244
245 if (rc != CS_OKAY) 245 if (rc != CS_OKAY)
246 - restore_charset(&save); 246 + restore_charset(hSession,&save);
247 247
248 /* 248 /*
249 #if defined(X3270_DBCS) 249 #if defined(X3270_DBCS)
@@ -515,7 +515,7 @@ static void remap_one(H3270 *hSession, unsigned char ebc, KeySym iso, remap_scop @@ -515,7 +515,7 @@ static void remap_one(H3270 *hSession, unsigned char ebc, KeySym iso, remap_scop
515 } 515 }
516 if (ebc > 0x40) 516 if (ebc > 0x40)
517 { 517 {
518 - ebc2asc[ebc] = iso; 518 + hSession->charset.ebc2asc[ebc] = iso;
519 if (!one_way) 519 if (!one_way)
520 asc2ebc[iso] = ebc; 520 asc2ebc[iso] = ebc;
521 } 521 }
@@ -548,14 +548,14 @@ static void remap_one(H3270 *hSession, unsigned char ebc, KeySym iso, remap_scop @@ -548,14 +548,14 @@ static void remap_one(H3270 *hSession, unsigned char ebc, KeySym iso, remap_scop
548 * and the ISO code that we would normally 548 * and the ISO code that we would normally
549 * use to display that EBCDIC code. 549 * use to display that EBCDIC code.
550 */ 550 */
551 - ft2asc[iso] = ebc2asc[ebc];  
552 - asc2ft[ebc2asc[ebc]] = iso; 551 + ft2asc[iso] = hSession->charset.ebc2asc[ebc];
  552 + asc2ft[hSession->charset.ebc2asc[ebc]] = iso;
553 } 553 }
554 } 554 }
555 #endif /*]*/ 555 #endif /*]*/
556 } else { 556 } else {
557 /* Auto-keymap. */ 557 /* Auto-keymap. */
558 - add_xk(iso, (KeySym)ebc2asc[ebc]); 558 + add_xk(iso, (KeySym)hSession->charset.ebc2asc[ebc]);
559 } 559 }
560 } 560 }
561 561
@@ -638,7 +638,7 @@ static enum cs_result remap_chars(H3270 *hSession, const char *csname, char *spe @@ -638,7 +638,7 @@ static enum cs_result remap_chars(H3270 *hSession, const char *csname, char *spe
638 for (i = 0; i < 256; i++) { 638 for (i = 0; i < 256; i++) {
639 if ((i & 0x7f) > 0x20 && i != 0x7f && 639 if ((i & 0x7f) > 0x20 && i != 0x7f &&
640 asc2ebc[i] != 0 && 640 asc2ebc[i] != 0 &&
641 - ebc2asc[asc2ebc[i]] != i) { 641 + hSession->charset.ebc2asc[asc2ebc[i]] != i) {
642 asc2ebc[i] = 0; 642 asc2ebc[i] = 0;
643 } 643 }
644 } 644 }
@@ -723,7 +723,7 @@ check_charset(void) @@ -723,7 +723,7 @@ check_charset(void)
723 723
724 void set_display_charset(H3270 *session, const char *dcs) 724 void set_display_charset(H3270 *session, const char *dcs)
725 { 725 {
726 - session->charset = strdup(dcs); 726 + session->charset.display = strdup(dcs);
727 } 727 }
728 728
729 LIB3270_EXPORT const char * lib3270_get_default_charset(void) 729 LIB3270_EXPORT const char * lib3270_get_default_charset(void)
@@ -731,10 +731,10 @@ LIB3270_EXPORT const char * lib3270_get_default_charset(void) @@ -731,10 +731,10 @@ LIB3270_EXPORT const char * lib3270_get_default_charset(void)
731 return "ISO-8859-1"; 731 return "ISO-8859-1";
732 } 732 }
733 733
734 -LIB3270_EXPORT const char * lib3270_get_charset(H3270 *session) 734 +LIB3270_EXPORT const char * lib3270_get_charset(H3270 *hSession)
735 { 735 {
736 - CHECK_SESSION_HANDLE(session);  
737 - return session->charset ? session->charset : lib3270_get_default_charset(); 736 + CHECK_SESSION_HANDLE(hSession);
  737 + return hSession->charset.display ? hSession->charset.display : "ISO-8859-1";
738 } 738 }
739 739
740 static KeySym StringToKeysym(char *s) 740 static KeySym StringToKeysym(char *s)
@@ -167,7 +167,7 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len) @@ -167,7 +167,7 @@ static int upload_convert(H3270 *hSession, unsigned char *buf, int len)
167 } 167 }
168 168
169 /* Translate to a quadrant index. */ 169 /* Translate to a quadrant index. */
170 - ixp = strchr(alphas, ebc2asc[c]); 170 + ixp = strchr(alphas, hSession->charset.ebc2asc[c]);
171 if (ixp == (char *)NULL) 171 if (ixp == (char *)NULL)
172 { 172 {
173 /* Try a different quadrant. */ 173 /* Try a different quadrant. */
@@ -349,7 +349,7 @@ static void cut_control_code(H3270 *hSession) @@ -349,7 +349,7 @@ static void cut_control_code(H3270 *hSession)
349 bp = buf = lib3270_malloc(81); 349 bp = buf = lib3270_malloc(81);
350 350
351 for (i = 0; i < 80; i++) 351 for (i = 0; i < 80; i++)
352 - *bp++ = ebc2asc[hSession->ea_buf[O_CC_MESSAGE + i].cc]; 352 + *bp++ = hSession->charset.ebc2asc[hSession->ea_buf[O_CC_MESSAGE + i].cc];
353 353
354 *bp-- = '\0'; 354 *bp-- = '\0';
355 355
@@ -465,9 +465,11 @@ static void cut_retransmit(H3270 *hSession) @@ -465,9 +465,11 @@ static void cut_retransmit(H3270 *hSession)
465 static unsigned 465 static unsigned
466 from6(unsigned char c) 466 from6(unsigned char c)
467 { 467 {
  468 + H3270 *hSession = lib3270_get_default_session_handle();
  469 +
468 char *p; 470 char *p;
469 471
470 - c = ebc2asc[c]; 472 + c = hSession->charset.ebc2asc[c];
471 p = strchr(table6, c); 473 p = strchr(table6, c);
472 if (p == CN) 474 if (p == CN)
473 return 0; 475 return 0;
@@ -337,9 +337,9 @@ void screen_update(H3270 *session, int bstart, int bend) @@ -337,9 +337,9 @@ void screen_update(H3270 *session, int bstart, int bend)
337 else 337 else
338 { 338 {
339 if(lib3270_get_toggle(session,LIB3270_TOGGLE_MONOCASE)) 339 if(lib3270_get_toggle(session,LIB3270_TOGGLE_MONOCASE))
340 - addch(session,baddr,asc2uc[ebc2asc[session->ea_buf[baddr].cc]],attr,&first,&last); 340 + addch(session,baddr,asc2uc[session->charset.ebc2asc[session->ea_buf[baddr].cc]],attr,&first,&last);
341 else 341 else
342 - addch(session,baddr,ebc2asc[session->ea_buf[baddr].cc],attr,&first,&last); 342 + addch(session,baddr,session->charset.ebc2asc[session->ea_buf[baddr].cc],attr,&first,&last);
343 } 343 }
344 } 344 }
345 } 345 }
@@ -64,6 +64,7 @@ unknown(unsigned char value) @@ -64,6 +64,7 @@ unknown(unsigned char value)
64 const char * 64 const char *
65 see_ebc(unsigned char ch) 65 see_ebc(unsigned char ch)
66 { 66 {
  67 + H3270 *hSession = lib3270_get_default_session_handle();
67 static char buf[8]; 68 static char buf[8];
68 69
69 switch (ch) { 70 switch (ch) {
@@ -91,8 +92,8 @@ see_ebc(unsigned char ch) @@ -91,8 +92,8 @@ see_ebc(unsigned char ch)
91 return "SO"; 92 return "SO";
92 } 93 }
93 94
94 - if (ebc2asc[ch])  
95 - (void) sprintf(buf,"%c", ebc2asc[ch]); 95 + if (hSession->charset.ebc2asc[ch])
  96 + (void) sprintf(buf,"%c", hSession->charset.ebc2asc[ch]);
96 else 97 else
97 (void) sprintf(buf, "\\%o", ch); 98 (void) sprintf(buf, "\\%o", ch);
98 99
@@ -84,7 +84,7 @@ void lib3270_session_free(H3270 *h) @@ -84,7 +84,7 @@ void lib3270_session_free(H3270 *h)
84 // Release memory 84 // Release memory
85 #define release_pointer(x) lib3270_free(x); x = NULL; 85 #define release_pointer(x) lib3270_free(x); x = NULL;
86 86
87 - release_pointer(h->charset); 87 + release_pointer(h->charset.display);
88 release_pointer(h->paste_buffer); 88 release_pointer(h->paste_buffer);
89 89
90 release_pointer(h->ibuf); 90 release_pointer(h->ibuf);
@@ -218,7 +218,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model) @@ -218,7 +218,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model)
218 hSession->unlock_delay = 1; 218 hSession->unlock_delay = 1;
219 hSession->icrnl = 1; 219 hSession->icrnl = 1;
220 hSession->onlcr = 1; 220 hSession->onlcr = 1;
221 - hSession->host_charset = "bracket"; 221 + hSession->charset.host = "bracket";
222 hSession->sock = -1; 222 hSession->sock = -1;
223 hSession->model_num = -1; 223 hSession->model_num = -1;
224 hSession->cstate = LIB3270_NOT_CONNECTED; 224 hSession->cstate = LIB3270_NOT_CONNECTED;
@@ -300,7 +300,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model) @@ -300,7 +300,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model)
300 trace("Termtype: %s",hSession->termtype); 300 trace("Termtype: %s",hSession->termtype);
301 301
302 if (hSession->apl_mode) 302 if (hSession->apl_mode)
303 - hSession->host_charset = "apl"; 303 + hSession->charset.host = "apl";
304 304
305 } 305 }
306 306
@@ -324,10 +324,10 @@ H3270 * lib3270_session_new(const char *model) @@ -324,10 +324,10 @@ H3270 * lib3270_session_new(const char *model)
324 if(screen_init(hSession)) 324 if(screen_init(hSession))
325 return NULL; 325 return NULL;
326 326
327 - trace("Charset: %s",hSession->host_charset);  
328 - if (charset_init(hSession,hSession->host_charset) != CS_OKAY) 327 + trace("Charset: %s",hSession->charset.host);
  328 + if (charset_init(hSession,hSession->charset.host) != CS_OKAY)
329 { 329 {
330 - Warning(hSession, _( "Cannot find charset \"%s\", using defaults" ), hSession->host_charset); 330 + Warning(hSession, _( "Cannot find charset \"%s\", using defaults" ), hSession->charset.host);
331 (void) charset_init(hSession,CN); 331 (void) charset_init(hSession,CN);
332 } 332 }
333 333
@@ -436,7 +436,7 @@ const unsigned short asc2ft0[256] = { @@ -436,7 +436,7 @@ const unsigned short asc2ft0[256] = {
436 436
437 unsigned short ebc2cg[256]; 437 unsigned short ebc2cg[256];
438 unsigned short cg2ebc[256]; 438 unsigned short cg2ebc[256];
439 -unsigned short ebc2asc[256]; 439 +// unsigned short ebc2asc[256];
440 unsigned short asc2ebc[256]; 440 unsigned short asc2ebc[256];
441 unsigned short asc2ft[256]; 441 unsigned short asc2ft[256];
442 unsigned short ft2asc[256]; 442 unsigned short ft2asc[256];
@@ -449,7 +449,7 @@ LIB3270_INTERNAL void initialize_tables(H3270 *hSession) @@ -449,7 +449,7 @@ LIB3270_INTERNAL void initialize_tables(H3270 *hSession)
449 /* Go to defaults first. */ 449 /* Go to defaults first. */
450 memcpy(ebc2cg, ebc2cg0, sizeof(ebc2cg)); 450 memcpy(ebc2cg, ebc2cg0, sizeof(ebc2cg));
451 memcpy(cg2ebc, cg2ebc0, sizeof(cg2ebc)); 451 memcpy(cg2ebc, cg2ebc0, sizeof(cg2ebc));
452 - memcpy(ebc2asc, ebc2asc0, sizeof(ebc2asc)); 452 + memcpy(hSession->charset.ebc2asc, ebc2asc0, sizeof(hSession->charset.ebc2asc));
453 memcpy(asc2ebc, asc2ebc0, sizeof(asc2ebc)); 453 memcpy(asc2ebc, asc2ebc0, sizeof(asc2ebc));
454 454
455 #ifdef EXTENDED_TABLES 455 #ifdef EXTENDED_TABLES
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 LIB3270_INTERNAL void initialize_tables(H3270 *hSession); 19 LIB3270_INTERNAL void initialize_tables(H3270 *hSession);
20 LIB3270_INTERNAL unsigned short ebc2cg[256]; 20 LIB3270_INTERNAL unsigned short ebc2cg[256];
21 LIB3270_INTERNAL unsigned short cg2ebc[256]; 21 LIB3270_INTERNAL unsigned short cg2ebc[256];
22 -LIB3270_INTERNAL unsigned short ebc2asc[256]; 22 +// LIB3270_INTERNAL unsigned short ebc2asc[256];
23 LIB3270_INTERNAL unsigned short asc2ebc[256]; 23 LIB3270_INTERNAL unsigned short asc2ebc[256];
24 LIB3270_INTERNAL unsigned short ft2asc[256]; 24 LIB3270_INTERNAL unsigned short ft2asc[256];
25 LIB3270_INTERNAL unsigned short asc2ft[256]; 25 LIB3270_INTERNAL unsigned short asc2ft[256];