Commit 82aa7d9f9e0f7bc8b1168ae504b4f5e0eb2506b6

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

Incluindo configuração de charset

src/include/lib3270/charset.h
... ... @@ -33,6 +33,22 @@
33 33  
34 34 #define LIB3270_CHARSET_H_INCLUDED 1
35 35  
  36 + struct lib3270_charset
  37 + {
  38 + const char * host;
  39 + const char * display;
  40 +
  41 + // Translation tables
  42 + unsigned short ebc2asc[256];
  43 + unsigned short asc2ebc[256];
  44 +
  45 + unsigned short asc2ft[256];
  46 + unsigned short ft2asc[256];
  47 +
  48 + unsigned short asc2uc[256];
  49 +
  50 + };
  51 +
36 52 typedef enum
37 53 {
38 54 CS_ONLY,
... ... @@ -40,7 +56,7 @@
40 56 BOTH
41 57 } lib3270_remap_scope;
42 58  
43   - LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, const char *name);
44   - LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way);
  59 + LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name);
  60 + LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way);
45 61  
46 62 #endif // LIB3270_CHARSET_H_INCLUDED
... ...
src/include/lib3270/session.h
... ... @@ -34,6 +34,7 @@
34 34 #define LIB3270_SESSION_H_INCLUDED 1
35 35 #include <sys/time.h>
36 36 #include <lib3270/popup.h>
  37 + #include <lib3270/charset.h>
37 38  
38 39 #define LIB3270_LUNAME_LENGTH 16
39 40 #define LIB3270_FULL_MODEL_NAME_LENGTH 13
... ... @@ -143,26 +144,7 @@
143 144 char * proxy; /**< Proxy server (type:host[:port]) */
144 145 char * termname;
145 146  
146   - struct lib3270_charset
147   - {
148   - const char * host;
149   - const char * display;
150   -
151   - // Translation tables
152   - unsigned short ebc2asc[256];
153   - unsigned short asc2ebc[256];
154   -
155   - unsigned short asc2ft[256];
156   - unsigned short ft2asc[256];
157   -
158   - unsigned short asc2uc[256];
159   -
160   -// unsigned short ebc2cg[256];
161   -// unsigned short cg2ebc[256];
162   -// unsigned short asc2cg[256];
163   -// unsigned short cg2asc[256];
164   -
165   - } charset;
  147 + struct lib3270_charset charset;
166 148  
167 149 LIB3270_MESSAGE oia_status;
168 150  
... ...
src/include/pw3270.h
... ... @@ -87,6 +87,8 @@
87 87  
88 88 LIB3270_EXPORT gchar * pw3270_file_chooser(GtkFileChooserAction action, const gchar *name, const gchar *title, const gchar *file, const gchar *ext);
89 89  
  90 + LIB3270_EXPORT void pw3270_set_host_charset(GtkWidget *widget, const gchar *name);
  91 +
90 92 typedef enum pw3270_src
91 93 {
92 94 PW3270_SRC_ALL, /**< Screen contents */
... ...
src/include/pw3270/v3270.h
... ... @@ -160,6 +160,8 @@
160 160 LIB3270_EXPORT int v3270_connect(GtkWidget *widget, const gchar *host);
161 161 LIB3270_EXPORT void v3270_disconnect(GtkWidget *widget);
162 162  
  163 + LIB3270_EXPORT int v3270_set_host_charset(GtkWidget *widget, const gchar *name);
  164 +
163 165 // Clipboard
164 166 typedef enum _v3270_select_format
165 167 {
... ...
src/lib3270/charset.c
... ... @@ -36,7 +36,7 @@
36 36  
37 37 #include "globals.h"
38 38 #include "X11keysym.h"
39   -#include <lib3270/charset.h">
  39 +#include <lib3270/charset.h>
40 40  
41 41 /*
42 42 * EBCDIC-to-Unicode translation tables.
... ... @@ -220,6 +220,20 @@ static const remap charset[] =
220 220 }
221 221 },
222 222  
  223 + {
  224 + "cp500",
  225 + (const unsigned short const [])
  226 + {
  227 + 0x004a, '[',
  228 + 0x004f, '!',
  229 + 0x005a, ']',
  230 + 0x005f, '^',
  231 + 0x00b0, XK_percent,
  232 + 0x00ba, XK_notsign,
  233 + 0x00bb, XK_bar
  234 + }
  235 + },
  236 +
223 237 // Terminate list
224 238 {
225 239 NULL
... ... @@ -236,7 +250,7 @@ static void copy_charset(const unsigned short *from, unsigned short *to)
236 250 to[f+UT_OFFSET] = from[f];
237 251 }
238 252  
239   -LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, const char *name)
  253 +LIB3270_EXPORT int lib3270_set_host_charset(H3270 *hSession, const char *name)
240 254 {
241 255 int f;
242 256  
... ... @@ -259,7 +273,7 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co
259 273 #endif
260 274  
261 275 if(!(name && strcasecmp(name,hSession->charset.host)))
262   - return &hSession->charset;
  276 + return 0;
263 277  
264 278 for(f=0;charset[f].name != NULL;f++)
265 279 {
... ... @@ -272,14 +286,11 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co
272 286  
273 287 for(c=0;charset[f].chr[c];c+=2)
274 288 lib3270_remap(hSession,charset[f].chr[c],charset[f].chr[c+1], BOTH, 0);
275   - errno = 0;
276   - return &hSession->charset;
  289 + return 0;
277 290 }
278 291 }
279 292  
280   - errno = ENOENT;
281   -
282   - return NULL;
  293 + return ENOENT;
283 294  
284 295 }
285 296  
... ... @@ -358,7 +369,8 @@ LIB3270_ACTION( charsettable )
358 369 // Process a single character definition.
359 370 LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way)
360 371 {
361   -// unsigned char cg;
  372 + // unsigned char cg;
  373 + CHECK_SESSION_HANDLE(hSession);
362 374  
363 375 // Ignore mappings of EBCDIC control codes and the space character.
364 376 if (ebc <= 0x40)
... ...
src/lib3270/session.c
... ... @@ -46,7 +46,7 @@
46 46 #include "3270ds.h"
47 47 // #include "tablesc.h"
48 48 #include "popupsc.h"
49   -#include "charset.h"
  49 +//#include "charset.h"
50 50  
51 51 /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/
52 52  
... ... @@ -187,7 +187,7 @@ static void lib3270_session_init(H3270 *hSession, const char *model, const char
187 187 memset(hSession,0,sizeof(H3270));
188 188 hSession->sz = sizeof(H3270);
189 189  
190   - lib3270_load_charset(hSession,charset);
  190 + lib3270_set_host_charset(hSession,charset);
191 191  
192 192 // Default calls
193 193 hSession->write = lib3270_sock_send;
... ... @@ -321,7 +321,7 @@ H3270 * lib3270_session_new(const char *model)
321 321  
322 322 hSession = default_session = lib3270_malloc(sizeof(H3270));
323 323  
324   - lib3270_session_init(hSession, model, "bracket");
  324 + lib3270_session_init(hSession, model, _( "bracket" ) );
325 325  
326 326 if(screen_init(hSession))
327 327 return NULL;
... ...
src/pw3270/main.c
... ... @@ -60,6 +60,7 @@
60 60 static const gchar * togglereset = NULL;
61 61 static const gchar * logfile = NULL;
62 62 static const gchar * tracefile = NULL;
  63 + static const gchar * charset = NULL;
63 64  
64 65 #ifdef HAVE_GTKMAC
65 66 GtkOSXApplication * osxapp = NULL;
... ... @@ -403,6 +404,7 @@ int main(int argc, char *argv[])
403 404 { "systype", 't', 0, G_OPTION_ARG_STRING, &system, N_( "Host system type" ), "S390" },
404 405 { "toggleset", 'S', 0, G_OPTION_ARG_STRING, &toggleset, N_( "Set toggles ON" ), NULL },
405 406 { "togglereset", 'R', 0, G_OPTION_ARG_STRING, &togglereset, N_( "Set toggles OFF" ), NULL },
  407 + { "charset", 'C', 0, G_OPTION_ARG_STRING, &charset, N_( "Set host charset" ), N_( "bracket" ) },
406 408  
407 409 #if defined( HAVE_SYSLOG )
408 410 { "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[])
542 544 g_strfreev(str);
543 545 }
544 546  
  547 + if(charset)
  548 + {
  549 + pw3270_set_host_charset(toplevel,charset);
  550 + }
545 551  
546 552 toplevel_setup(GTK_WINDOW(toplevel));
547 553  
... ...
src/pw3270/tools.c
... ... @@ -28,6 +28,7 @@
28 28 */
29 29  
30 30 #include "globals.h"
  31 + #include <lib3270/charset.h>
31 32  
32 33 #if defined WIN32
33 34 BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd);
... ... @@ -196,3 +197,29 @@ LIB3270_EXPORT gchar * pw3270_get_datadir(const gchar *first_element, ...)
196 197 va_end(args);
197 198 return path;
198 199 }
  200 +
  201 +LIB3270_EXPORT void pw3270_set_host_charset(GtkWidget *widget, const gchar *name)
  202 +{
  203 + H3270 * hSession = pw3270_get_session(widget);
  204 +
  205 + if(!hSession)
  206 + return;
  207 +
  208 + if(!lib3270_set_host_charset(hSession,name))
  209 + return;
  210 +
  211 + // Charset setup failed, notify user
  212 + GtkWidget * dialog = gtk_message_dialog_new( GTK_WINDOW(widget),
  213 + GTK_DIALOG_DESTROY_WITH_PARENT,
  214 + GTK_MESSAGE_ERROR,
  215 + GTK_BUTTONS_OK,
  216 + "%s", _( "Can't set host charset" ) );
  217 +
  218 +
  219 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),_( "There's no available settings for charset \"%s\"" ),name);
  220 + gtk_window_set_title(GTK_WINDOW(dialog),_( "Charset error" ));
  221 +
  222 + gtk_dialog_run(GTK_DIALOG (dialog));
  223 + gtk_widget_destroy(dialog);
  224 +
  225 +}
... ...
src/pw3270/v3270/widget.c
... ... @@ -1528,6 +1528,12 @@ gboolean v3270_is_connected(GtkWidget *widget)
1528 1528 return lib3270_connected(GTK_V3270(widget)->host) ? TRUE : FALSE;
1529 1529 }
1530 1530  
  1531 +int v3270_set_host_charset(GtkWidget *widget, const gchar *name)
  1532 +{
  1533 + g_return_val_if_fail(GTK_IS_V3270(widget),FALSE);
  1534 + return lib3270_set_host_charset(GTK_V3270(widget)->host,name);
  1535 +}
  1536 +
1531 1537 GtkWidget * v3270_get_default_widget(void)
1532 1538 {
1533 1539 H3270 * hSession = lib3270_get_default_session_handle();
... ...