Commit ad49222c0ad6be2bb5c9fb7c0ef01cf5a58f854c

Authored by Perry Werneck
1 parent c56038e1
Exists in master and in 1 other branch develop

Implementando remapeamento de caracteres por arquivo .xml

Showing 1 changed file with 50 additions and 11 deletions   Show diff stats
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);
... ...