diff --git a/pw3270.cbp b/pw3270.cbp index f159284..d21d364 100644 --- a/pw3270.cbp +++ b/pw3270.cbp @@ -135,7 +135,6 @@ - diff --git a/src/include/lib3270/charset.h b/src/include/lib3270/charset.h index 25729e4..d555886 100644 --- a/src/include/lib3270/charset.h +++ b/src/include/lib3270/charset.h @@ -39,9 +39,9 @@ struct lib3270_charset { - const char * host; - const char * display; - unsigned long cgcsgid; + char * host; + char * display; + unsigned long cgcsgid; // Translation tables unsigned short ebc2asc[256]; @@ -60,7 +60,8 @@ LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name); LIB3270_EXPORT const char * lib3270_get_host_charset(H3270 *hSession); - LIB3270_EXPORT void lib3270_remap(H3270 *hSession,const char *host, const char *display, unsigned long cgcsgid, const unsigned short *chr); + LIB3270_EXPORT void lib3270_reset_charset(H3270 *hSession, const char * host, const char * display, unsigned long cgcsgid); + LIB3270_EXPORT void lib3270_remap_char(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way); LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, int sz); LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, int sz); diff --git a/src/lib3270/charset.c b/src/lib3270/charset.c index 62ad497..b1f1878 100644 --- a/src/lib3270/charset.c +++ b/src/lib3270/charset.c @@ -212,6 +212,15 @@ typedef struct _info static const remap charset[] = { { + "us", + LIB3270_DEFAULT_CGEN | LIB3270_DEFAULT_CSET, + (const unsigned short const []) + { + 0x0000, 0x0000 + } + }, + + { "bracket", LIB3270_DEFAULT_CGEN|LIB3270_DEFAULT_CSET, (const unsigned short const []) @@ -255,31 +264,16 @@ static void copy_charset(const unsigned short *from, unsigned short *to) to[f+UT_OFFSET] = from[f]; } -LIB3270_EXPORT void lib3270_remap(H3270 *hSession,const char *host, const char *display, unsigned long cgcsgid, const unsigned short *chr) -{ - int c; - - hSession->charset.host = host; - hSession->charset.display = display; - hSession->charset.cgcsgid = cgcsgid; - - for(c=0;chr[c];c+=2) - { - lib3270_remap_char(hSession,chr[c],chr[c+1], BOTH, 0); - } - -} - -LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) +LIB3270_EXPORT void lib3270_reset_charset(H3270 *hSession, const char * host, const char * display, unsigned long cgcsgid) { int f; - hSession->charset.host = "us"; - hSession->charset.display = "ISO-8859-1"; - hSession->charset.cgcsgid = LIB3270_DEFAULT_CGEN | LIB3270_DEFAULT_CSET; // 0x02b90025 + #define replace_pointer(x,v) if(x) { lib3270_free(x); }; x = strdup(v) -// lib3270_write_log(hSession,"charset","host.charset=%s display.charset=%s", -// hSession->charset.host,hSession->charset.display); + replace_pointer(hSession->charset.host, host); + replace_pointer(hSession->charset.display,display); + + hSession->charset.cgcsgid = cgcsgid; memcpy(hSession->charset.ebc2asc, ebc2asc0, sizeof(hSession->charset.ebc2asc)); 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) #endif */ - if(!(name && strcasecmp(name,hSession->charset.host))) +} + +LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) +{ + int f; + + if(!name) + { + lib3270_reset_charset(hSession,"us","ISO-8859-1", LIB3270_DEFAULT_CGEN | LIB3270_DEFAULT_CSET); + return 0; + } + + if(hSession->charset.host && !strcasecmp(name,hSession->charset.host)) return 0; for(f=0;charset[f].name != NULL;f++) @@ -304,16 +310,15 @@ LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) if(!strcasecmp(name,charset[f].name)) { // Found required charset - lib3270_remap(hSession,charset[f].name,"ISO-8859-1",charset[f].cgcsgid,charset[f].chr); - /* int c; - hSession->charset.host = charset[f].name; - hSession->charset.cgcsgid = charset[f].cgcsgid; + debug("%s: %s -> %s",__FUNCTION__,hSession->charset.host,charset[f].name); + + lib3270_reset_charset(hSession,charset[f].name,"ISO-8859-1", charset[f].cgcsgid); for(c=0;charset[f].chr[c];c+=2) lib3270_remap_char(hSession,charset[f].chr[c],charset[f].chr[c+1], BOTH, 0); - */ + return 0; } } diff --git a/src/lib3270/session.c b/src/lib3270/session.c index f1ecba3..d9b81fb 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -103,6 +103,9 @@ void lib3270_session_free(H3270 *h) release_pointer(h->host.srvc); release_pointer(h->host.qualified); + release_pointer(h->charset.host); + release_pointer(h->charset.display); + trace("Releasing session %p",h); lib3270_free(h); diff --git a/src/pw3270/uiparser/keypad.c b/src/pw3270/uiparser/keypad.c index 39e4634..33c3ee6 100644 --- a/src/pw3270/uiparser/keypad.c +++ b/src/pw3270/uiparser/keypad.c @@ -38,7 +38,7 @@ int height = 1; const gchar * tmp; - trace("%s(%s,%d,%d)",__FUNCTION__,element_name,(int) keypad->row, (int) keypad->col); +// trace("%s(%s,%d,%d)",__FUNCTION__,element_name,(int) keypad->row, (int) keypad->col); keypad->widget = NULL; diff --git a/src/pw3270/v3270/charset.c b/src/pw3270/v3270/charset.c index 5b4c428..761fbef 100644 --- a/src/pw3270/v3270/charset.c +++ b/src/pw3270/v3270/charset.c @@ -45,10 +45,10 @@ size_t len; struct { - unsigned short ebc; - unsigned short iso; - unsigned char scope; - unsigned char oneway; + unsigned short ebc; + unsigned short iso; + lib3270_remap_scope scope; + unsigned char oneway; } map[256]; }; @@ -303,6 +303,25 @@ return (unsigned short) *id; } + static lib3270_remap_scope getRemapScope(const gchar *str, GError **error) { + + static const char *text[] = { "CS_ONLY","FT_ONLY", "BOTH" }; + int i; + + if(!error) + { + for(i=0;i < N_ELEMENTS(text);i++) + { + if(!g_ascii_strcasecmp(str,text[i])) + return (lib3270_remap_scope) i; + } + + *error = g_error_new(ERROR_DOMAIN,EINVAL,"%s",_( "Invalid remap scope" )); + } + + return BOTH; + } + static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, struct parse *info, GError **error) { trace("%s(%s)",__FUNCTION__,element_name); @@ -385,8 +404,9 @@ oneway = "no"; } - info->map[info->len].ebc = getChar(ebc,error); - info->map[info->len].iso = getChar(iso,error); + info->map[info->len].ebc = getChar(ebc,error); + info->map[info->len].iso = getChar(iso,error); + info->map[info->len].scope = getRemapScope(scope,error); 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); @@ -424,7 +444,6 @@ GError * error = NULL; gchar * text = NULL; struct parse cfg; - v3270 * terminal = GTK_V3270(widget); memset(&cfg,0,sizeof(cfg)); @@ -462,12 +481,32 @@ gtk_dialog_run(GTK_DIALOG (dialog)); gtk_widget_destroy(dialog); + } else { + + H3270 * hSession = v3270_get_session(widget); + + + if(hSession) + { + unsigned int i; + + trace("cgcsgid = %lx",cfg.cgcsgid); + trace("display = %s",cfg.display); + trace("host = %s",cfg.host); + trace("length = %u",(unsigned int) cfg.len); + + lib3270_reset_charset(hSession, cfg.host, cfg.display, cfg.cgcsgid); + + for(i=0;i < cfg.len; i++) + { + lib3270_remap_char(hSession,cfg.map[i].ebc,cfg.map[i].iso, BOTH, 0); + } + + } + + } - trace("cgcsgid = %lx",cfg.cgcsgid); - trace("display = %s",cfg.display); - trace("host = %s",cfg.host); - trace("length = %u",(unsigned int) cfg.len); g_free(text); g_free(cfg.host); -- libgit2 0.21.2