Commit d43c374ac92dbf1d16af0d5939c1b801f89fac66

Authored by perry.werneck@gmail.com
1 parent 2fd2b75a

Implementando configuração de charset

src/include/lib3270/charset.h 0 → 100644
... ... @@ -0,0 +1,46 @@
  1 +/*
  2 + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
  3 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
  4 + * aplicativos mainframe. Registro no INPI sob o nome G3270.
  5 + *
  6 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  7 + *
  8 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  9 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  10 + * Free Software Foundation.
  11 + *
  12 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  13 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  14 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  15 + * obter mais detalhes.
  16 + *
  17 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  18 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como charset.h e possui - linhas de código.
  22 + *
  23 + * Contatos:
  24 + *
  25 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  26 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  27 + * licinio@bb.com.br (Licínio Luis Branco)
  28 + * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
  29 + *
  30 + */
  31 +
  32 +#ifndef LIB3270_CHARSET_H_INCLUDED
  33 +
  34 + #define LIB3270_CHARSET_H_INCLUDED 1
  35 +
  36 + typedef enum
  37 + {
  38 + CS_ONLY,
  39 + FT_ONLY,
  40 + BOTH
  41 + } lib3270_remap_scope;
  42 +
  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);
  45 +
  46 +#endif // LIB3270_CHARSET_H_INCLUDED
... ...
src/lib3270/charset.c
... ... @@ -36,15 +36,7 @@
36 36  
37 37 #include "globals.h"
38 38 #include "X11keysym.h"
39   -
40   -typedef enum
41   -{
42   - CS_ONLY,
43   - FT_ONLY,
44   - BOTH
45   -} remap_scope;
46   -
47   -static void remap_char(H3270 *hSession, unsigned short ebc, unsigned short iso, remap_scope scope, unsigned char one_way);
  39 +#include <lib3270/charset.h">
48 40  
49 41 /*
50 42 * EBCDIC-to-Unicode translation tables.
... ... @@ -208,16 +200,32 @@ static const unsigned short asc2uc[UT_SIZE] =
208 200 /*f8*/ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde
209 201 };
210 202  
  203 +typedef struct _info
  204 +{
  205 + const char * name;
  206 + const unsigned short const * chr;
  207 +} remap;
211 208  
  209 +static const remap charset[] =
  210 +{
  211 + {
  212 + "bracket",
  213 + (const unsigned short const [])
  214 + {
  215 + 0x00ad, '[',
  216 + 0x00ba, XK_Yacute,
  217 + 0x00bd, ']',
  218 + 0x00bb, XK_diaeresis,
  219 + 0x0000, 0x0000
  220 + }
  221 + },
212 222  
213   -//
214   -// bracket: "0xad: [ \n 0xba: XK_Yacute \n0xbd: ] \n 0xbb: XK_diaeresis \n"
215   -//
216   -// remap_char(hSession,0xad, '[', BOTH, 0);
217   -// remap_char(hSession,0xba, XK_Yacute, BOTH, 0);
218   -// remap_char(hSession,0xbd, ']', BOTH, 0);
219   -// remap_char(hSession,0xbb, XK_diaeresis, remap_scope scope,0);
220   -//
  223 + // Terminate list
  224 + {
  225 + NULL
  226 + }
  227 +
  228 +};
221 229  
222 230 /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
223 231  
... ... @@ -232,8 +240,8 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co
232 240 {
233 241 int f;
234 242  
235   - hSession->charset.host = "us";
236   - hSession->charset.display = "ISO-8859-1";
  243 + hSession->charset.host = "us";
  244 + hSession->charset.display = "ISO-8859-1";
237 245  
238 246 // lib3270_write_log(hSession,"charset","host.charset=%s display.charset=%s",
239 247 // hSession->charset.host,hSession->charset.display);
... ... @@ -250,17 +258,29 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co
250 258 memcpy(hSession->charset.asc2ft, asc2ft, sizeof(hSession->charset.asc2ft));
251 259 #endif
252 260  
253   - //if(!(name && strcasecmp(name,hSession->charset.host)))
254   - // return &hSession->charset;
  261 + if(!(name && strcasecmp(name,hSession->charset.host)))
  262 + return &hSession->charset;
  263 +
  264 + for(f=0;charset[f].name != NULL;f++)
  265 + {
  266 + if(!strcasecmp(name,charset[f].name))
  267 + {
  268 + // Found required charset
  269 + int c;
  270 +
  271 + hSession->charset.host = charset[f].name;
  272 +
  273 + for(c=0;charset[f].chr[c];c+=2)
  274 + lib3270_remap(hSession,charset[f].chr[c],charset[f].chr[c+1], BOTH, 0);
  275 + errno = 0;
  276 + return &hSession->charset;
  277 + }
  278 + }
255 279  
256   - // Bracket
257   - remap_char(hSession,0xad, '[', BOTH, 0);
258   - remap_char(hSession,0xba, XK_Yacute, BOTH, 0);
259   - remap_char(hSession,0xbd, ']', BOTH, 0);
260   - remap_char(hSession,0xbb, XK_diaeresis, BOTH, 0);
  280 + errno = ENOENT;
261 281  
  282 + return NULL;
262 283  
263   - return &hSession->charset;
264 284 }
265 285  
266 286  
... ... @@ -336,7 +356,7 @@ LIB3270_ACTION( charsettable )
336 356 }
337 357  
338 358 // Process a single character definition.
339   -static void remap_char(H3270 *hSession, unsigned short ebc, unsigned short iso, remap_scope scope, unsigned char one_way)
  359 +LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way)
340 360 {
341 361 // unsigned char cg;
342 362  
... ...
src/lib3270/charset.h
... ... @@ -1,43 +0,0 @@
1   -/*
2   - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270
3   - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a
4   - * aplicativos mainframe. Registro no INPI sob o nome G3270.
5   - *
6   - * Copyright (C) <2008> <Banco do Brasil S.A.>
7   - *
8   - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
9   - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
10   - * Free Software Foundation.
11   - *
12   - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
13   - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
14   - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
15   - * obter mais detalhes.
16   - *
17   - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
18   - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
19   - * St, Fifth Floor, Boston, MA 02110-1301 USA
20   - *
21   - * Este programa está nomeado como charset.h e possui - linhas de código.
22   - *
23   - * Contatos:
24   - *
25   - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
26   - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
27   - * licinio@bb.com.br (Licínio Luis Branco)
28   - * kraucer@bb.com.br (Kraucer Fernandes Mazuco)
29   - *
30   - */
31   -
32   -#ifndef LIB3270_CHARSET_H_INCLUDED
33   -
34   - #define LIB3270_CHARSET_H_INCLUDED 1
35   -
36   - LIB3270_INTERNAL const unsigned short ebc2asc0[256];
37   - LIB3270_INTERNAL const unsigned short asc2ft0[256];
38   -
39   - const struct lib3270_charset lib3270_default_charset;
40   -
41   - LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, const char *name);
42   -
43   -#endif // LIB3270_CHARSET_H_INCLUDED
src/lib3270/globals.h
... ... @@ -331,6 +331,10 @@ enum keytype
331 331 KT_GE
332 332 };
333 333  
  334 +/* default charset translation tables */
  335 +LIB3270_INTERNAL const unsigned short ebc2asc0[256];
  336 +LIB3270_INTERNAL const unsigned short asc2ft0[256];
  337 +
334 338  
335 339 /* Library internal calls */
336 340 LIB3270_INTERNAL void key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped);
... ...