Commit 4db7754a85adb9608bff4ab4f3874e4fda4ee159
1 parent
e9520a86
Exists in
master
and in
5 other branches
Implementando remapeamento de caracteres por arquivo .xml
Showing
6 changed files
with
91 additions
and
44 deletions
Show diff stats
pw3270.cbp
... | ... | @@ -135,7 +135,6 @@ |
135 | 135 | </Unit> |
136 | 136 | <Unit filename="src/lib3270/3270ds.h" /> |
137 | 137 | <Unit filename="src/lib3270/Makefile.in" /> |
138 | - <Unit filename="src/lib3270/X11keysym.h" /> | |
139 | 138 | <Unit filename="src/lib3270/actions.c"> |
140 | 139 | <Option compilerVar="CC" /> |
141 | 140 | </Unit> | ... | ... |
src/include/lib3270/charset.h
... | ... | @@ -39,9 +39,9 @@ |
39 | 39 | |
40 | 40 | struct lib3270_charset |
41 | 41 | { |
42 | - const char * host; | |
43 | - const char * display; | |
44 | - unsigned long cgcsgid; | |
42 | + char * host; | |
43 | + char * display; | |
44 | + unsigned long cgcsgid; | |
45 | 45 | |
46 | 46 | // Translation tables |
47 | 47 | unsigned short ebc2asc[256]; |
... | ... | @@ -60,7 +60,8 @@ |
60 | 60 | |
61 | 61 | LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name); |
62 | 62 | LIB3270_EXPORT const char * lib3270_get_host_charset(H3270 *hSession); |
63 | - LIB3270_EXPORT void lib3270_remap(H3270 *hSession,const char *host, const char *display, unsigned long cgcsgid, const unsigned short *chr); | |
63 | + LIB3270_EXPORT void lib3270_reset_charset(H3270 *hSession, const char * host, const char * display, unsigned long cgcsgid); | |
64 | + | |
64 | 65 | LIB3270_EXPORT void lib3270_remap_char(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way); |
65 | 66 | LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, int sz); |
66 | 67 | LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, int sz); | ... | ... |
src/lib3270/charset.c
... | ... | @@ -212,6 +212,15 @@ typedef struct _info |
212 | 212 | static const remap charset[] = |
213 | 213 | { |
214 | 214 | { |
215 | + "us", | |
216 | + LIB3270_DEFAULT_CGEN | LIB3270_DEFAULT_CSET, | |
217 | + (const unsigned short const []) | |
218 | + { | |
219 | + 0x0000, 0x0000 | |
220 | + } | |
221 | + }, | |
222 | + | |
223 | + { | |
215 | 224 | "bracket", |
216 | 225 | LIB3270_DEFAULT_CGEN|LIB3270_DEFAULT_CSET, |
217 | 226 | (const unsigned short const []) |
... | ... | @@ -255,31 +264,16 @@ static void copy_charset(const unsigned short *from, unsigned short *to) |
255 | 264 | to[f+UT_OFFSET] = from[f]; |
256 | 265 | } |
257 | 266 | |
258 | -LIB3270_EXPORT void lib3270_remap(H3270 *hSession,const char *host, const char *display, unsigned long cgcsgid, const unsigned short *chr) | |
259 | -{ | |
260 | - int c; | |
261 | - | |
262 | - hSession->charset.host = host; | |
263 | - hSession->charset.display = display; | |
264 | - hSession->charset.cgcsgid = cgcsgid; | |
265 | - | |
266 | - for(c=0;chr[c];c+=2) | |
267 | - { | |
268 | - lib3270_remap_char(hSession,chr[c],chr[c+1], BOTH, 0); | |
269 | - } | |
270 | - | |
271 | -} | |
272 | - | |
273 | -LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) | |
267 | +LIB3270_EXPORT void lib3270_reset_charset(H3270 *hSession, const char * host, const char * display, unsigned long cgcsgid) | |
274 | 268 | { |
275 | 269 | int f; |
276 | 270 | |
277 | - hSession->charset.host = "us"; | |
278 | - hSession->charset.display = "ISO-8859-1"; | |
279 | - hSession->charset.cgcsgid = LIB3270_DEFAULT_CGEN | LIB3270_DEFAULT_CSET; // 0x02b90025 | |
271 | + #define replace_pointer(x,v) if(x) { lib3270_free(x); }; x = strdup(v) | |
280 | 272 | |
281 | -// lib3270_write_log(hSession,"charset","host.charset=%s display.charset=%s", | |
282 | -// hSession->charset.host,hSession->charset.display); | |
273 | + replace_pointer(hSession->charset.host, host); | |
274 | + replace_pointer(hSession->charset.display,display); | |
275 | + | |
276 | + hSession->charset.cgcsgid = cgcsgid; | |
283 | 277 | |
284 | 278 | memcpy(hSession->charset.ebc2asc, ebc2asc0, sizeof(hSession->charset.ebc2asc)); |
285 | 279 | memcpy(hSession->charset.asc2ebc, asc2ebc0, sizeof(hSession->charset.asc2ebc)); |
... | ... | @@ -296,7 +290,19 @@ LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) |
296 | 290 | #endif |
297 | 291 | */ |
298 | 292 | |
299 | - if(!(name && strcasecmp(name,hSession->charset.host))) | |
293 | +} | |
294 | + | |
295 | +LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) | |
296 | +{ | |
297 | + int f; | |
298 | + | |
299 | + if(!name) | |
300 | + { | |
301 | + lib3270_reset_charset(hSession,"us","ISO-8859-1", LIB3270_DEFAULT_CGEN | LIB3270_DEFAULT_CSET); | |
302 | + return 0; | |
303 | + } | |
304 | + | |
305 | + if(hSession->charset.host && !strcasecmp(name,hSession->charset.host)) | |
300 | 306 | return 0; |
301 | 307 | |
302 | 308 | for(f=0;charset[f].name != NULL;f++) |
... | ... | @@ -304,16 +310,15 @@ LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) |
304 | 310 | if(!strcasecmp(name,charset[f].name)) |
305 | 311 | { |
306 | 312 | // Found required charset |
307 | - lib3270_remap(hSession,charset[f].name,"ISO-8859-1",charset[f].cgcsgid,charset[f].chr); | |
308 | - /* | |
309 | 313 | int c; |
310 | 314 | |
311 | - hSession->charset.host = charset[f].name; | |
312 | - hSession->charset.cgcsgid = charset[f].cgcsgid; | |
315 | + debug("%s: %s -> %s",__FUNCTION__,hSession->charset.host,charset[f].name); | |
316 | + | |
317 | + lib3270_reset_charset(hSession,charset[f].name,"ISO-8859-1", charset[f].cgcsgid); | |
313 | 318 | |
314 | 319 | for(c=0;charset[f].chr[c];c+=2) |
315 | 320 | lib3270_remap_char(hSession,charset[f].chr[c],charset[f].chr[c+1], BOTH, 0); |
316 | - */ | |
321 | + | |
317 | 322 | return 0; |
318 | 323 | } |
319 | 324 | } | ... | ... |
src/lib3270/session.c
... | ... | @@ -103,6 +103,9 @@ void lib3270_session_free(H3270 *h) |
103 | 103 | release_pointer(h->host.srvc); |
104 | 104 | release_pointer(h->host.qualified); |
105 | 105 | |
106 | + release_pointer(h->charset.host); | |
107 | + release_pointer(h->charset.display); | |
108 | + | |
106 | 109 | trace("Releasing session %p",h); |
107 | 110 | lib3270_free(h); |
108 | 111 | ... | ... |
src/pw3270/uiparser/keypad.c
... | ... | @@ -38,7 +38,7 @@ |
38 | 38 | int height = 1; |
39 | 39 | const gchar * tmp; |
40 | 40 | |
41 | - trace("%s(%s,%d,%d)",__FUNCTION__,element_name,(int) keypad->row, (int) keypad->col); | |
41 | +// trace("%s(%s,%d,%d)",__FUNCTION__,element_name,(int) keypad->row, (int) keypad->col); | |
42 | 42 | |
43 | 43 | keypad->widget = NULL; |
44 | 44 | ... | ... |
src/pw3270/v3270/charset.c
... | ... | @@ -45,10 +45,10 @@ |
45 | 45 | size_t len; |
46 | 46 | |
47 | 47 | struct { |
48 | - unsigned short ebc; | |
49 | - unsigned short iso; | |
50 | - unsigned char scope; | |
51 | - unsigned char oneway; | |
48 | + unsigned short ebc; | |
49 | + unsigned short iso; | |
50 | + lib3270_remap_scope scope; | |
51 | + unsigned char oneway; | |
52 | 52 | } map[256]; |
53 | 53 | |
54 | 54 | }; |
... | ... | @@ -303,6 +303,25 @@ |
303 | 303 | return (unsigned short) *id; |
304 | 304 | } |
305 | 305 | |
306 | + static lib3270_remap_scope getRemapScope(const gchar *str, GError **error) { | |
307 | + | |
308 | + static const char *text[] = { "CS_ONLY","FT_ONLY", "BOTH" }; | |
309 | + int i; | |
310 | + | |
311 | + if(!error) | |
312 | + { | |
313 | + for(i=0;i < N_ELEMENTS(text);i++) | |
314 | + { | |
315 | + if(!g_ascii_strcasecmp(str,text[i])) | |
316 | + return (lib3270_remap_scope) i; | |
317 | + } | |
318 | + | |
319 | + *error = g_error_new(ERROR_DOMAIN,EINVAL,"%s",_( "Invalid remap scope" )); | |
320 | + } | |
321 | + | |
322 | + return BOTH; | |
323 | + } | |
324 | + | |
306 | 325 | static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, struct parse *info, GError **error) |
307 | 326 | { |
308 | 327 | trace("%s(%s)",__FUNCTION__,element_name); |
... | ... | @@ -385,8 +404,9 @@ |
385 | 404 | oneway = "no"; |
386 | 405 | } |
387 | 406 | |
388 | - info->map[info->len].ebc = getChar(ebc,error); | |
389 | - info->map[info->len].iso = getChar(iso,error); | |
407 | + info->map[info->len].ebc = getChar(ebc,error); | |
408 | + info->map[info->len].iso = getChar(iso,error); | |
409 | + info->map[info->len].scope = getRemapScope(scope,error); | |
390 | 410 | |
391 | 411 | trace("%u: ebc=%04x iso=%04x %c",(unsigned int) info->len,info->map[info->len].ebc,info->map[info->len].iso,info->map[info->len].iso); |
392 | 412 | |
... | ... | @@ -424,7 +444,6 @@ |
424 | 444 | GError * error = NULL; |
425 | 445 | gchar * text = NULL; |
426 | 446 | struct parse cfg; |
427 | - v3270 * terminal = GTK_V3270(widget); | |
428 | 447 | |
429 | 448 | memset(&cfg,0,sizeof(cfg)); |
430 | 449 | |
... | ... | @@ -462,12 +481,32 @@ |
462 | 481 | gtk_dialog_run(GTK_DIALOG (dialog)); |
463 | 482 | gtk_widget_destroy(dialog); |
464 | 483 | |
484 | + } else { | |
485 | + | |
486 | + H3270 * hSession = v3270_get_session(widget); | |
487 | + | |
488 | + | |
489 | + if(hSession) | |
490 | + { | |
491 | + unsigned int i; | |
492 | + | |
493 | + trace("cgcsgid = %lx",cfg.cgcsgid); | |
494 | + trace("display = %s",cfg.display); | |
495 | + trace("host = %s",cfg.host); | |
496 | + trace("length = %u",(unsigned int) cfg.len); | |
497 | + | |
498 | + lib3270_reset_charset(hSession, cfg.host, cfg.display, cfg.cgcsgid); | |
499 | + | |
500 | + for(i=0;i < cfg.len; i++) | |
501 | + { | |
502 | + lib3270_remap_char(hSession,cfg.map[i].ebc,cfg.map[i].iso, BOTH, 0); | |
503 | + } | |
504 | + | |
505 | + } | |
506 | + | |
507 | + | |
465 | 508 | } |
466 | 509 | |
467 | - trace("cgcsgid = %lx",cfg.cgcsgid); | |
468 | - trace("display = %s",cfg.display); | |
469 | - trace("host = %s",cfg.host); | |
470 | - trace("length = %u",(unsigned int) cfg.len); | |
471 | 510 | |
472 | 511 | g_free(text); |
473 | 512 | g_free(cfg.host); | ... | ... |