From 6c93bad80b1ce3c991fc721f0e4f2f0c95cf1643 Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Thu, 28 Nov 2013 15:04:29 +0000 Subject: [PATCH] Incluindo conversão ebcdic<->asc no módulo rexx --- po/pt_BR.po | 8 ++++---- src/classlib/local.cc | 14 ++++++++++++++ src/classlib/remote.cc | 13 +++++++++++++ src/classlib/session.cc | 17 +++++++++++++++++ src/include/lib3270/charset.h | 3 +++ src/include/pw3270/class.h | 6 ++++++ src/lib3270/charset.c | 31 +++++++++++++++++++++++++++++++ src/plugins/rx3270/pluginmain.cc | 15 +++++++++++++++ src/plugins/rx3270/rx3270.h | 2 ++ src/plugins/rx3270/rxapimain.cc | 2 ++ src/plugins/rx3270/sample/asc2ebc.rex | 13 +++++++++++++ src/plugins/rx3270/sample/ebc2asc.rex | 14 ++++++++++++++ src/plugins/rx3270/typed_routines.cc | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 13 files changed, 182 insertions(+), 4 deletions(-) create mode 100644 src/plugins/rx3270/sample/asc2ebc.rex create mode 100644 src/plugins/rx3270/sample/ebc2asc.rex diff --git a/po/pt_BR.po b/po/pt_BR.po index 934e6d6..20cfe06 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: pw3270 5.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2013-11-27 14:51-0200\n" +"POT-Creation-Date: 2013-11-28 10:23-0200\n" "PO-Revision-Date: 2013-11-12 08:07-0200\n" "Last-Translator: Perry Werneck \n" "Language-Team: Português \n" @@ -664,12 +664,12 @@ msgstr "Erro \"%s\" gravando arquivo local (rc=%d)" msgid "Error %d resolving %s" msgstr "Erro %d resolvendo %s" -#: telnet.c:3145 telnet.c:3156 +#: telnet.c:3146 telnet.c:3157 #, c-format msgid "Error in fcntl(%s) when setting non blocking mode" msgstr "Erro em fcntl(%s) ao ativar o modo não blocante" -#: telnet.c:3135 +#: telnet.c:3136 #, c-format msgid "Error in ioctl(%s) when setting no blocking mode" msgstr "Erro em ioctl(%s) ao ativar o modo não blocante" @@ -1692,7 +1692,7 @@ msgstr "Tipo de servidor:" msgid "TELNET Proxy: send error" msgstr "TELNET Proxy: Erro ao enviar" -#: telnet.c:3342 +#: telnet.c:3343 msgid "TLS negotiation failure" msgstr "Negociação TLS falhou" diff --git a/src/classlib/local.cc b/src/classlib/local.cc index efafeb8..76ee9c5 100644 --- a/src/classlib/local.cc +++ b/src/classlib/local.cc @@ -307,6 +307,8 @@ const char * (*_get_host_charset)(H3270 *hSession); int (*_print)(H3270 *hSession); int (*_erase_eof)(H3270 *hSession); + const char * (*_ebc2asc)(H3270 *hSession, unsigned char *buffer, size_t sz); + const char * (*_asc2ebc)(H3270 *hSession, unsigned char *buffer, size_t sz); public: @@ -358,6 +360,8 @@ { (void **) & _get_host_charset, "lib3270_get_host_charset" }, { (void **) & _erase_eof, "lib3270_eraseeof" }, { (void **) & _print, "lib3270_print" }, + { (void **) & _ebc2asc, "lib3270_ebc2asc" }, + { (void **) & _asc2ebc, "lib3270_asc2ebc" }, }; @@ -576,6 +580,16 @@ } + const char * asc2ebc(unsigned char *str, size_t sz) + { + return _asc2ebc(hSession,str,sz); + } + + const char * ebc2asc(unsigned char *str, size_t sz) + { + return _ebc2asc(hSession,str,sz); + } + }; session * session::create_local(void) diff --git a/src/classlib/remote.cc b/src/classlib/remote.cc index 0c1c72a..8ec461f 100644 --- a/src/classlib/remote.cc +++ b/src/classlib/remote.cc @@ -1188,6 +1188,19 @@ return query_intval(HLLAPI_PACKET_PRINT); } + const char * asc2ebc(unsigned char *str, size_t sz) + { + #warning Incomplete + return (const char *) str; + } + + const char * ebc2asc(unsigned char *str, size_t sz) + { + #warning Incomplete + return (const char *) str; + } + + }; session * session::create_remote(const char *session) diff --git a/src/classlib/session.cc b/src/classlib/session.cc index 2c526e0..b6cac4c 100644 --- a/src/classlib/session.cc +++ b/src/classlib/session.cc @@ -446,6 +446,23 @@ return get_local_text(get_text(baddr,len)); } + string session::asc2ebc(string &str) + { + size_t sz = str.size(); + unsigned char buffer[sz+1]; + + memcpy(buffer,str.c_str(),sz); + return string(asc2ebc(buffer,sz)); + } + + string session::ebc2asc(string &str) + { + size_t sz = str.size(); + unsigned char buffer[sz+1]; + memcpy(buffer,str.c_str(),sz); + return string(ebc2asc(buffer,sz)); + } + } diff --git a/src/include/lib3270/charset.h b/src/include/lib3270/charset.h index 9e9c9a9..495e521 100644 --- a/src/include/lib3270/charset.h +++ b/src/include/lib3270/charset.h @@ -64,6 +64,9 @@ 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, 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, size_t sz); + LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, size_t sz); + #ifdef __cplusplus } diff --git a/src/include/pw3270/class.h b/src/include/pw3270/class.h index 0d5e9c6..0745ba8 100644 --- a/src/include/pw3270/class.h +++ b/src/include/pw3270/class.h @@ -140,6 +140,12 @@ virtual int wait_for_text_at(int row, int col, const char *key, int timeout); virtual int emulate_input(const char *str) = 0; + // Ascii<->EBCDIC translation + virtual const char * asc2ebc(unsigned char *str, size_t sz = -1) = 0; + virtual const char * ebc2asc(unsigned char *str, size_t sz = -1) = 0; + string asc2ebc(string &str); + string ebc2asc(string &str); + // Get/Set/Test with charset translation string * get_string(int baddr, size_t len); string * get_string_at(int row, int col, size_t sz); diff --git a/src/lib3270/charset.c b/src/lib3270/charset.c index e33d0d0..57ea64a 100644 --- a/src/lib3270/charset.c +++ b/src/lib3270/charset.c @@ -402,6 +402,37 @@ LIB3270_ACTION( charsettable ) return 0; } +LIB3270_EXPORT const char * lib3270_asc2ebc(H3270 *hSession, unsigned char *buffer, size_t sz) +{ + int f; + if(sz < 0) + sz = strlen((const char *) buffer); + + if(sz > 0) + { + for(f=0;fcharset.asc2ebc[buffer[f]]; + } + + return (const char *) buffer; +} + +LIB3270_EXPORT const char * lib3270_ebc2asc(H3270 *hSession, unsigned char *buffer, size_t sz) +{ + int f; + if(sz < 0) + sz = strlen((const char *) buffer); + + if(sz > 0) + { + for(f=0;fcharset.ebc2asc[buffer[f]]; + } + + return (const char *) buffer; +} + + // 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) { diff --git a/src/plugins/rx3270/pluginmain.cc b/src/plugins/rx3270/pluginmain.cc index 348890c..102ae05 100644 --- a/src/plugins/rx3270/pluginmain.cc +++ b/src/plugins/rx3270/pluginmain.cc @@ -52,6 +52,7 @@ #include #include + /*--[ Globals ]--------------------------------------------------------------------------------------*/ #if GTK_CHECK_VERSION(2,32,0) @@ -134,6 +135,9 @@ string * get_host_charset(void); string * get_display_charset(void); + const char * asc2ebc(unsigned char *str, size_t sz = -1); + const char * ebc2asc(unsigned char *str, size_t sz = -1); + int quit(void); protected: @@ -756,3 +760,14 @@ int plugin::print(void) { return lib3270_print(hSession); } + +const char * plugin::asc2ebc(unsigned char *str, size_t sz) +{ + return lib3270_asc2ebc(hSession,str,sz); +} + +const char * plugin::ebc2asc(unsigned char *str, size_t sz) +{ + return lib3270_ebc2asc(hSession,str,sz); +} + diff --git a/src/plugins/rx3270/rx3270.h b/src/plugins/rx3270/rx3270.h index c22cdf0..2b13b09 100644 --- a/src/plugins/rx3270/rx3270.h +++ b/src/plugins/rx3270/rx3270.h @@ -85,6 +85,8 @@ REXX_TYPED_ROUTINE_PROTOTYPE(rx3270queryStringAt); REXX_TYPED_ROUTINE_PROTOTYPE(rx3270SetStringAt); REXX_TYPED_ROUTINE_PROTOTYPE(rx3270CloseApplication); + REXX_TYPED_ROUTINE_PROTOTYPE(ebc2asc); + REXX_TYPED_ROUTINE_PROTOTYPE(asc2ebc); REXX_METHOD_PROTOTYPE(rx3270_method_version); REXX_METHOD_PROTOTYPE(rx3270_method_revision); diff --git a/src/plugins/rx3270/rxapimain.cc b/src/plugins/rx3270/rxapimain.cc index 9e7ace2..4027dca 100644 --- a/src/plugins/rx3270/rxapimain.cc +++ b/src/plugins/rx3270/rxapimain.cc @@ -113,6 +113,8 @@ RexxRoutineEntry rx3270_functions[] = REXX_TYPED_ROUTINE(rx3270queryStringAt, rx3270queryStringAt), REXX_TYPED_ROUTINE(rx3270SetStringAt, rx3270SetStringAt), REXX_TYPED_ROUTINE(rx3270CloseApplication, rx3270CloseApplication), + REXX_TYPED_ROUTINE(ebc2asc, ebc2asc), + REXX_TYPED_ROUTINE(asc2ebc, asc2ebc), // rx3270Popup diff --git a/src/plugins/rx3270/sample/asc2ebc.rex b/src/plugins/rx3270/sample/asc2ebc.rex new file mode 100644 index 0000000..a75e797 --- /dev/null +++ b/src/plugins/rx3270/sample/asc2ebc.rex @@ -0,0 +1,13 @@ +/* + * Sample code for ASC -> EBCDIC conversion + * + */ + + STRING = "ASCII STRING" + + say c2x(asc2ebc(STRING)) + +return 0 + + +::requires "rx3270.cls" diff --git a/src/plugins/rx3270/sample/ebc2asc.rex b/src/plugins/rx3270/sample/ebc2asc.rex new file mode 100644 index 0000000..581285c --- /dev/null +++ b/src/plugins/rx3270/sample/ebc2asc.rex @@ -0,0 +1,14 @@ +/* + * Sample code for EBCDIC -> ASC conversion + * + */ + + STRING = x2c("C1E2C3C9C940E2E3D9C9D5C7") + + say length(string) + say ebc2asc(STRING) + +return 0 + + +::requires "rx3270.cls" diff --git a/src/plugins/rx3270/typed_routines.cc b/src/plugins/rx3270/typed_routines.cc index a88bae7..156b616 100644 --- a/src/plugins/rx3270/typed_routines.cc +++ b/src/plugins/rx3270/typed_routines.cc @@ -217,3 +217,51 @@ RexxRoutine0(int, rx3270CloseApplication) { return session::get_default()->quit(); } + + +RexxRoutine2(RexxStringObject, asc2ebc, CSTRING, str, OPTIONAL_int, sz) +{ + try + { + if(sz < 1) + sz = strlen(str); + + if(sz) + { + char buffer[sz+1]; + memcpy(buffer,str,sz); + buffer[sz] = 0; + return context->String((CSTRING) session::get_default()->asc2ebc((unsigned char *)buffer,sz)); + } + } + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); + } + + return context->String(""); +} + +RexxRoutine2(RexxStringObject, ebc2asc, CSTRING, str, OPTIONAL_int, sz) +{ + try + { + if(sz < 1) + sz = strlen(str); + + if(sz) + { + char buffer[sz+1]; + memcpy(buffer,str,sz); + buffer[sz] = 0; + return context->String((CSTRING) session::get_default()->ebc2asc((unsigned char *)buffer,sz)); + } + } + catch(std::exception &e) + { + context->RaiseException1(Rexx_Error_Application_error,context->NewStringFromAsciiz(e.what())); + } + + return context->String(""); +} + -- libgit2 0.21.2