diff --git a/src/include/lib3270/charset.h b/src/include/lib3270/charset.h new file mode 100644 index 0000000..49c5c41 --- /dev/null +++ b/src/include/lib3270/charset.h @@ -0,0 +1,46 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como charset.h e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * licinio@bb.com.br (Licínio Luis Branco) + * kraucer@bb.com.br (Kraucer Fernandes Mazuco) + * + */ + +#ifndef LIB3270_CHARSET_H_INCLUDED + + #define LIB3270_CHARSET_H_INCLUDED 1 + + typedef enum + { + CS_ONLY, + FT_ONLY, + 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); + +#endif // LIB3270_CHARSET_H_INCLUDED diff --git a/src/lib3270/charset.c b/src/lib3270/charset.c index 4094f42..255cb00 100644 --- a/src/lib3270/charset.c +++ b/src/lib3270/charset.c @@ -36,15 +36,7 @@ #include "globals.h" #include "X11keysym.h" - -typedef enum -{ - CS_ONLY, - FT_ONLY, - BOTH -} remap_scope; - -static void remap_char(H3270 *hSession, unsigned short ebc, unsigned short iso, remap_scope scope, unsigned char one_way); +#include /* * EBCDIC-to-Unicode translation tables. @@ -208,16 +200,32 @@ static const unsigned short asc2uc[UT_SIZE] = /*f8*/ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde }; +typedef struct _info +{ + const char * name; + const unsigned short const * chr; +} remap; +static const remap charset[] = +{ + { + "bracket", + (const unsigned short const []) + { + 0x00ad, '[', + 0x00ba, XK_Yacute, + 0x00bd, ']', + 0x00bb, XK_diaeresis, + 0x0000, 0x0000 + } + }, -// -// bracket: "0xad: [ \n 0xba: XK_Yacute \n0xbd: ] \n 0xbb: XK_diaeresis \n" -// -// remap_char(hSession,0xad, '[', BOTH, 0); -// remap_char(hSession,0xba, XK_Yacute, BOTH, 0); -// remap_char(hSession,0xbd, ']', BOTH, 0); -// remap_char(hSession,0xbb, XK_diaeresis, remap_scope scope,0); -// + // Terminate list + { + NULL + } + +}; /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ @@ -232,8 +240,8 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co { int f; - hSession->charset.host = "us"; - hSession->charset.display = "ISO-8859-1"; + hSession->charset.host = "us"; + hSession->charset.display = "ISO-8859-1"; // lib3270_write_log(hSession,"charset","host.charset=%s display.charset=%s", // hSession->charset.host,hSession->charset.display); @@ -250,17 +258,29 @@ LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, co memcpy(hSession->charset.asc2ft, asc2ft, sizeof(hSession->charset.asc2ft)); #endif - //if(!(name && strcasecmp(name,hSession->charset.host))) - // return &hSession->charset; + if(!(name && strcasecmp(name,hSession->charset.host))) + return &hSession->charset; + + for(f=0;charset[f].name != NULL;f++) + { + if(!strcasecmp(name,charset[f].name)) + { + // Found required charset + int c; + + hSession->charset.host = charset[f].name; + + 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; + } + } - // Bracket - remap_char(hSession,0xad, '[', BOTH, 0); - remap_char(hSession,0xba, XK_Yacute, BOTH, 0); - remap_char(hSession,0xbd, ']', BOTH, 0); - remap_char(hSession,0xbb, XK_diaeresis, BOTH, 0); + errno = ENOENT; + return NULL; - return &hSession->charset; } @@ -336,7 +356,7 @@ LIB3270_ACTION( charsettable ) } // Process a single character definition. -static void remap_char(H3270 *hSession, unsigned short ebc, unsigned short iso, remap_scope scope, unsigned char one_way) +LIB3270_EXPORT void lib3270_remap(H3270 *hSession, unsigned short ebc, unsigned short iso, lib3270_remap_scope scope, unsigned char one_way) { // unsigned char cg; diff --git a/src/lib3270/charset.h b/src/lib3270/charset.h deleted file mode 100644 index bfe5d42..0000000 --- a/src/lib3270/charset.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a - * aplicativos mainframe. Registro no INPI sob o nome G3270. - * - * Copyright (C) <2008> - * - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela - * Free Software Foundation. - * - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para - * obter mais detalhes. - * - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin - * St, Fifth Floor, Boston, MA 02110-1301 USA - * - * Este programa está nomeado como charset.h e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * - */ - -#ifndef LIB3270_CHARSET_H_INCLUDED - - #define LIB3270_CHARSET_H_INCLUDED 1 - - LIB3270_INTERNAL const unsigned short ebc2asc0[256]; - LIB3270_INTERNAL const unsigned short asc2ft0[256]; - - const struct lib3270_charset lib3270_default_charset; - - LIB3270_EXPORT struct lib3270_charset * lib3270_load_charset(H3270 *hSession, const char *name); - -#endif // LIB3270_CHARSET_H_INCLUDED diff --git a/src/lib3270/globals.h b/src/lib3270/globals.h index 0b6a30b..da0a77c 100644 --- a/src/lib3270/globals.h +++ b/src/lib3270/globals.h @@ -331,6 +331,10 @@ enum keytype KT_GE }; +/* default charset translation tables */ +LIB3270_INTERNAL const unsigned short ebc2asc0[256]; +LIB3270_INTERNAL const unsigned short asc2ft0[256]; + /* Library internal calls */ LIB3270_INTERNAL void key_ACharacter(H3270 *hSession, unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped); -- libgit2 0.21.2