From 82aa7d9f9e0f7bc8b1168ae504b4f5e0eb2506b6 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Wed, 28 Aug 2013 11:37:59 +0000 Subject: [PATCH] Incluindo configuração de charset --- src/include/lib3270/charset.h | 20 ++++++++++++++++++-- src/include/lib3270/session.h | 22 ++-------------------- src/include/pw3270.h | 2 ++ src/include/pw3270/v3270.h | 2 ++ src/lib3270/charset.c | 30 +++++++++++++++++++++--------- src/lib3270/session.c | 6 +++--- src/pw3270/main.c | 6 ++++++ src/pw3270/tools.c | 27 +++++++++++++++++++++++++++ src/pw3270/v3270/widget.c | 6 ++++++ 9 files changed, 87 insertions(+), 34 deletions(-) diff --git a/src/include/lib3270/charset.h b/src/include/lib3270/charset.h index 49c5c41..c605377 100644 --- a/src/include/lib3270/charset.h +++ b/src/include/lib3270/charset.h @@ -33,6 +33,22 @@ #define LIB3270_CHARSET_H_INCLUDED 1 + struct lib3270_charset + { + const char * host; + const char * display; + + // Translation tables + unsigned short ebc2asc[256]; + unsigned short asc2ebc[256]; + + unsigned short asc2ft[256]; + unsigned short ft2asc[256]; + + unsigned short asc2uc[256]; + + }; + typedef enum { CS_ONLY, @@ -40,7 +56,7 @@ BOTH } lib3270_remap_scope; - LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, const char *name); - LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way); + LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name); + LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way); #endif // LIB3270_CHARSET_H_INCLUDED diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index 1476f17..989168c 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -34,6 +34,7 @@ #define LIB3270_SESSION_H_INCLUDED 1 #include #include + #include #define LIB3270_LUNAME_LENGTH 16 #define LIB3270_FULL_MODEL_NAME_LENGTH 13 @@ -143,26 +144,7 @@ char * proxy; /**< Proxy server (type:host[:port]) */ char * termname; - struct lib3270_charset - { - const char * host; - const char * display; - - // Translation tables - unsigned short ebc2asc[256]; - unsigned short asc2ebc[256]; - - unsigned short asc2ft[256]; - unsigned short ft2asc[256]; - - unsigned short asc2uc[256]; - -// unsigned short ebc2cg[256]; -// unsigned short cg2ebc[256]; -// unsigned short asc2cg[256]; -// unsigned short cg2asc[256]; - - } charset; + struct lib3270_charset charset; LIB3270_MESSAGE oia_status; diff --git a/src/include/pw3270.h b/src/include/pw3270.h index 1beef0f..567d2ce 100644 --- a/src/include/pw3270.h +++ b/src/include/pw3270.h @@ -87,6 +87,8 @@ LIB3270_EXPORT gchar * pw3270_file_chooser(GtkFileChooserAction action, const gchar *name, const gchar *title, const gchar *file, const gchar *ext); + LIB3270_EXPORT void pw3270_set_host_charset(GtkWidget *widget, const gchar *name); + typedef enum pw3270_src { PW3270_SRC_ALL, /**< Screen contents */ diff --git a/src/include/pw3270/v3270.h b/src/include/pw3270/v3270.h index d242213..397f021 100644 --- a/src/include/pw3270/v3270.h +++ b/src/include/pw3270/v3270.h @@ -160,6 +160,8 @@ LIB3270_EXPORT int v3270_connect(GtkWidget *widget, const gchar *host); LIB3270_EXPORT void v3270_disconnect(GtkWidget *widget); + LIB3270_EXPORT int v3270_set_host_charset(GtkWidget *widget, const gchar *name); + // Clipboard typedef enum _v3270_select_format { diff --git a/src/lib3270/charset.c b/src/lib3270/charset.c index 255cb00..f6aa31b 100644 --- a/src/lib3270/charset.c +++ b/src/lib3270/charset.c @@ -36,7 +36,7 @@ #include "globals.h" #include "X11keysym.h" -#include +#include /* * EBCDIC-to-Unicode translation tables. @@ -220,6 +220,20 @@ static const remap charset[] = } }, + { + "cp500", + (const unsigned short const []) + { + 0x004a, '[', + 0x004f, '!', + 0x005a, ']', + 0x005f, '^', + 0x00b0, XK_percent, + 0x00ba, XK_notsign, + 0x00bb, XK_bar + } + }, + // Terminate list { NULL @@ -236,7 +250,7 @@ static void copy_charset(const unsigned short *from, unsigned short *to) to[f+UT_OFFSET] = from[f]; } -LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, const char *name) +LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name) { int f; @@ -259,7 +273,7 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co #endif if(!(name && strcasecmp(name,hSession->charset.host))) - return &hSession->charset; + return 0; for(f=0;charset[f].name != NULL;f++) { @@ -272,14 +286,11 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co for(c=0;charset[f].chr[c];c+=2) lib3270_remap(hSession,charset[f].chr[c],charset[f].chr[c+1], BOTH, 0); - errno = 0; - return &hSession->charset; + return 0; } } - errno = ENOENT; - - return NULL; + return ENOENT; } @@ -358,7 +369,8 @@ LIB3270_ACTION( charsettable ) // Process a single character definition. LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way) { -// unsigned char cg; + // unsigned char cg; + CHECK_SESSION_HANDLE(hSession); // Ignore mappings of EBCDIC control codes and the space character. if (ebc <= 0x40) diff --git a/src/lib3270/session.c b/src/lib3270/session.c index 98586a2..bc1a6e3 100644 --- a/src/lib3270/session.c +++ b/src/lib3270/session.c @@ -46,7 +46,7 @@ #include "3270ds.h" // #include "tablesc.h" #include "popupsc.h" -#include "charset.h" +//#include "charset.h" /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ @@ -187,7 +187,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char memset(hSession,0,sizeof(H3270)); hSession->sz = sizeof(H3270); - lib3270_load_charset(hSession,charset); + lib3270_set_host_charset(hSession,charset); // Default calls hSession->write = lib3270_sock_send; @@ -321,7 +321,7 @@ H3270 * lib3270_session_new(const char *model) hSession = default_session = lib3270_malloc(sizeof(H3270)); - lib3270_session_init(hSession, model, "bracket"); + lib3270_session_init(hSession, model, _( "bracket" ) ); if(screen_init(hSession)) return NULL; diff --git a/src/pw3270/main.c b/src/pw3270/main.c index 6dfedc7..9e10373 100644 --- a/src/pw3270/main.c +++ b/src/pw3270/main.c @@ -60,6 +60,7 @@ static const gchar * togglereset = NULL; static const gchar * logfile = NULL; static const gchar * tracefile = NULL; + static const gchar * charset = NULL; #ifdef HAVE_GTKMAC GtkOSXApplication * osxapp = NULL; @@ -403,6 +404,7 @@ int main(int argc, char *argv[]) { "systype", 't', 0, G_OPTION_ARG_STRING, &system, N_( "Host system type" ), "S390" }, { "toggleset", 'S', 0, G_OPTION_ARG_STRING, &toggleset, N_( "Set toggles ON" ), NULL }, { "togglereset", 'R', 0, G_OPTION_ARG_STRING, &togglereset, N_( "Set toggles OFF" ), NULL }, + { "charset", 'C', 0, G_OPTION_ARG_STRING, &charset, N_( "Set host charset" ), N_( "bracket" ) }, #if defined( HAVE_SYSLOG ) { "syslog", 'l', 0, G_OPTION_ARG_NONE, &log_to_syslog, N_( "Send messages to syslog" ), NULL }, @@ -542,6 +544,10 @@ int main(int argc, char *argv[]) g_strfreev(str); } + if(charset) + { + pw3270_set_host_charset(toplevel,charset); + } toplevel_setup(GTK_WINDOW(toplevel)); diff --git a/src/pw3270/tools.c b/src/pw3270/tools.c index 3292d26..2f8c4c1 100644 --- a/src/pw3270/tools.c +++ b/src/pw3270/tools.c @@ -28,6 +28,7 @@ */ #include "globals.h" + #include #if defined WIN32 BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd); @@ -196,3 +197,29 @@ LIB3270_EXPORT gchar * pw3270_get_datadir(const gchar *first_element, ...) va_end(args); return path; } + +LIB3270_EXPORT void pw3270_set_host_charset(GtkWidget *widget, const gchar *name) +{ + H3270 * hSession = pw3270_get_session(widget); + + if(!hSession) + return; + + if(!lib3270_set_host_charset(hSession,name)) + return; + + // Charset setup failed, notify user + GtkWidget * dialog = gtk_message_dialog_new( GTK_WINDOW(widget), + GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + "%s", _( "Can't set host charset" ) ); + + + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),_( "There's no available settings for charset \"%s\"" ),name); + gtk_window_set_title(GTK_WINDOW(dialog),_( "Charset error" )); + + gtk_dialog_run(GTK_DIALOG (dialog)); + gtk_widget_destroy(dialog); + +} diff --git a/src/pw3270/v3270/widget.c b/src/pw3270/v3270/widget.c index 1c900f4..b234a9d 100644 --- a/src/pw3270/v3270/widget.c +++ b/src/pw3270/v3270/widget.c @@ -1528,6 +1528,12 @@ gboolean v3270_is_connected(GtkWidget *widget) return lib3270_connected(GTK_V3270(widget)->host) ? TRUE : FALSE; } +int v3270_set_host_charset(GtkWidget *widget, const gchar *name) +{ + g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); + return lib3270_set_host_charset(GTK_V3270(widget)->host,name); +} + GtkWidget * v3270_get_default_widget(void) { H3270 * hSession = lib3270_get_default_session_handle(); -- libgit2 0.21.2