Commit 3061a0da2ccc57335d3ab547bda00ded2496fde2
1 parent
b3b06a9c
Exists in
master
and in
5 other branches
Incluindo funções para o plugin rexx
Showing
10 changed files
with
451 additions
and
24 deletions
Show diff stats
configure.ac
| @@ -51,6 +51,9 @@ AC_CONFIG_HEADER([src/include/lib3270/config.h]) | @@ -51,6 +51,9 @@ AC_CONFIG_HEADER([src/include/lib3270/config.h]) | ||
| 51 | dnl Initialise automake stuff. | 51 | dnl Initialise automake stuff. |
| 52 | AM_INIT_AUTOMAKE | 52 | AM_INIT_AUTOMAKE |
| 53 | 53 | ||
| 54 | +dnl Check for iconv | ||
| 55 | +AM_ICONV | ||
| 56 | + | ||
| 54 | #--[ Check for tools & Libraries ]---------------------------------------------------------------------------------------------------------------------------- | 57 | #--[ Check for tools & Libraries ]---------------------------------------------------------------------------------------------------------------------------- |
| 55 | 58 | ||
| 56 | AC_PROG_CXX | 59 | AC_PROG_CXX |
pw3270.cbp
| @@ -235,6 +235,8 @@ | @@ -235,6 +235,8 @@ | ||
| 235 | <Unit filename="src/plugins/rx3270/pluginmain.cc" /> | 235 | <Unit filename="src/plugins/rx3270/pluginmain.cc" /> |
| 236 | <Unit filename="src/plugins/rx3270/rx3270.h" /> | 236 | <Unit filename="src/plugins/rx3270/rx3270.h" /> |
| 237 | <Unit filename="src/plugins/rx3270/rxapimain.cc" /> | 237 | <Unit filename="src/plugins/rx3270/rxapimain.cc" /> |
| 238 | + <Unit filename="src/plugins/rx3270/text.cc" /> | ||
| 239 | + <Unit filename="src/plugins/rx3270/typed_routines.cc" /> | ||
| 238 | <Unit filename="src/pw3270/Makefile.in" /> | 240 | <Unit filename="src/pw3270/Makefile.in" /> |
| 239 | <Unit filename="src/pw3270/actions.c"> | 241 | <Unit filename="src/pw3270/actions.c"> |
| 240 | <Option compilerVar="CC" /> | 242 | <Option compilerVar="CC" /> |
src/include/lib3270.h
| @@ -667,6 +667,9 @@ | @@ -667,6 +667,9 @@ | ||
| 667 | LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h); | 667 | LIB3270_EXPORT int lib3270_in_tn3270e(H3270 *h); |
| 668 | LIB3270_EXPORT int lib3270_in_e(H3270 *h); | 668 | LIB3270_EXPORT int lib3270_in_e(H3270 *h); |
| 669 | 669 | ||
| 670 | + #define lib3270_is_connected(h) lib3270_in_tn3270e(h) | ||
| 671 | + #define lib3270_is_ready(h) lib3270_get_program_message(h) == LIB3270_MESSAGE_NONE | ||
| 672 | + | ||
| 670 | LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *session); | 673 | LIB3270_EXPORT LIB3270_SSL_STATE lib3270_get_secure(H3270 *session); |
| 671 | 674 | ||
| 672 | 675 | ||
| @@ -746,6 +749,8 @@ | @@ -746,6 +749,8 @@ | ||
| 746 | */ | 749 | */ |
| 747 | LIB3270_EXPORT const char * lib3270_get_charset(H3270 *session); | 750 | LIB3270_EXPORT const char * lib3270_get_charset(H3270 *session); |
| 748 | 751 | ||
| 752 | + LIB3270_EXPORT const char * lib3270_get_default_charset(void); | ||
| 753 | + | ||
| 749 | /** | 754 | /** |
| 750 | * Get selected area. | 755 | * Get selected area. |
| 751 | * | 756 | * |
src/include/lib3270/config.h.in
| @@ -38,6 +38,7 @@ | @@ -38,6 +38,7 @@ | ||
| 38 | #undef PACKAGE_REVISION | 38 | #undef PACKAGE_REVISION |
| 39 | 39 | ||
| 40 | #undef HAVE_GNUC_VISIBILITY | 40 | #undef HAVE_GNUC_VISIBILITY |
| 41 | + #undef HAVE_ICONV | ||
| 41 | #undef HAVE_LIBM | 42 | #undef HAVE_LIBM |
| 42 | #undef HAVE_LIBINTL | 43 | #undef HAVE_LIBINTL |
| 43 | #undef HAVE_GETADDRINFO | 44 | #undef HAVE_GETADDRINFO |
src/lib3270/charset.c
| @@ -726,10 +726,15 @@ void set_display_charset(H3270 *session, const char *dcs) | @@ -726,10 +726,15 @@ void set_display_charset(H3270 *session, const char *dcs) | ||
| 726 | session->charset = strdup(dcs); | 726 | session->charset = strdup(dcs); |
| 727 | } | 727 | } |
| 728 | 728 | ||
| 729 | +LIB3270_EXPORT const char * lib3270_get_default_charset(void) | ||
| 730 | +{ | ||
| 731 | + return "ISO-8859-1"; | ||
| 732 | +} | ||
| 733 | + | ||
| 729 | LIB3270_EXPORT const char * lib3270_get_charset(H3270 *session) | 734 | LIB3270_EXPORT const char * lib3270_get_charset(H3270 *session) |
| 730 | { | 735 | { |
| 731 | CHECK_SESSION_HANDLE(session); | 736 | CHECK_SESSION_HANDLE(session); |
| 732 | - return session->charset ? session->charset : "ISO-8859-1"; | 737 | + return session->charset ? session->charset : lib3270_get_default_charset(); |
| 733 | } | 738 | } |
| 734 | 739 | ||
| 735 | static KeySym StringToKeysym(char *s) | 740 | static KeySym StringToKeysym(char *s) |
src/plugins/rx3270/Makefile.in
| @@ -29,7 +29,7 @@ | @@ -29,7 +29,7 @@ | ||
| 29 | MODULE_NAME=rx3270 | 29 | MODULE_NAME=rx3270 |
| 30 | DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile | 30 | DEPENDS=*.h ../../include/*.h ../../include/lib3270/*.h Makefile |
| 31 | PLUGIN_SRC=pluginmain.cc | 31 | PLUGIN_SRC=pluginmain.cc |
| 32 | -EXTAPI_SRC=rxapimain.cc | 32 | +EXTAPI_SRC=rxapimain.cc text.cc typed_routines.cc |
| 33 | 33 | ||
| 34 | #---[ Tools ]------------------------------------------------------------------ | 34 | #---[ Tools ]------------------------------------------------------------------ |
| 35 | 35 |
src/plugins/rx3270/rx3270.h
| @@ -38,13 +38,45 @@ | @@ -38,13 +38,45 @@ | ||
| 38 | #include <lib3270/log.h> | 38 | #include <lib3270/log.h> |
| 39 | #include <oorexxapi.h> | 39 | #include <oorexxapi.h> |
| 40 | 40 | ||
| 41 | +#ifdef HAVE_ICONV | ||
| 42 | + #include <iconv.h> | ||
| 43 | +#endif | ||
| 44 | + | ||
| 45 | + | ||
| 41 | /*---[ Exports ]---------------------------------------------------------------------------------------------*/ | 46 | /*---[ Exports ]---------------------------------------------------------------------------------------------*/ |
| 42 | 47 | ||
| 43 | LIB3270_EXPORT RexxRoutineEntry rx3270_functions[]; | 48 | LIB3270_EXPORT RexxRoutineEntry rx3270_functions[]; |
| 44 | LIB3270_EXPORT RexxPackageEntry rx3270_package_entry; | 49 | LIB3270_EXPORT RexxPackageEntry rx3270_package_entry; |
| 45 | 50 | ||
| 51 | +/*---[ Rexx entry points ]-----------------------------------------------------------------------------------*/ | ||
| 52 | + | ||
| 53 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270version); | ||
| 54 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270QueryCState); | ||
| 55 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270Disconnect); | ||
| 56 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270Connect); | ||
| 57 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270isConnected); | ||
| 58 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270WaitForEvents); | ||
| 59 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270Sleep); | ||
| 60 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270SendENTERKey); | ||
| 61 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270SendPFKey); | ||
| 62 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270SendPAKey); | ||
| 63 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270WaitForTerminalReady); | ||
| 64 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270WaitForStringAt); | ||
| 65 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270GetStringAt); | ||
| 66 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270IsTerminalReady); | ||
| 67 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270ReadScreen); | ||
| 68 | + REXX_TYPED_ROUTINE_PROTOTYPE(rx3270queryStringAt); | ||
| 69 | + | ||
| 46 | /*---[ Globals ]---------------------------------------------------------------------------------------------*/ | 70 | /*---[ Globals ]---------------------------------------------------------------------------------------------*/ |
| 47 | 71 | ||
| 72 | + #define RX3270SESSION lib3270_get_default_session_handle() | ||
| 73 | + | ||
| 74 | + char * get_contents(H3270 *hSession, int start, int sz); | ||
| 75 | + | ||
| 76 | +#ifdef HAVE_ICONV | ||
| 77 | + extern iconv_t outputConv; | ||
| 78 | + extern iconv_t inputConv; | ||
| 79 | +#endif | ||
| 48 | 80 | ||
| 49 | /*--[ Prototipes ]-------------------------------------------------------------------------------------------*/ | 81 | /*--[ Prototipes ]-------------------------------------------------------------------------------------------*/ |
| 50 | 82 |
src/plugins/rx3270/rxapimain.cc
| @@ -36,15 +36,29 @@ | @@ -36,15 +36,29 @@ | ||
| 36 | */ | 36 | */ |
| 37 | 37 | ||
| 38 | #include "rx3270.h" | 38 | #include "rx3270.h" |
| 39 | + #include <lib3270/actions.h> | ||
| 40 | + | ||
| 41 | +#ifdef HAVE_ICONV | ||
| 42 | + #include <iconv.h> | ||
| 43 | +#endif | ||
| 44 | + | ||
| 45 | + #include <string.h> | ||
| 39 | 46 | ||
| 40 | #if defined WIN32 | 47 | #if defined WIN32 |
| 48 | + | ||
| 49 | + #define REXX_DEFAULT_CHARSET "CP1252" | ||
| 50 | + | ||
| 41 | BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd); | 51 | BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd); |
| 42 | static int librx3270_loaded(void); | 52 | static int librx3270_loaded(void); |
| 43 | static int librx3270_unloaded(void); | 53 | static int librx3270_unloaded(void); |
| 44 | #else | 54 | #else |
| 55 | + | ||
| 56 | + #define REXX_DEFAULT_CHARSET "UTF-8" | ||
| 57 | + | ||
| 45 | int librx3270_loaded(void) __attribute__((constructor)); | 58 | int librx3270_loaded(void) __attribute__((constructor)); |
| 46 | int librx3270_unloaded(void) __attribute__((destructor)); | 59 | int librx3270_unloaded(void) __attribute__((destructor)); |
| 47 | #endif | 60 | #endif |
| 61 | + | ||
| 48 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 62 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 49 | 63 | ||
| 50 | #if defined WIN32 | 64 | #if defined WIN32 |
| @@ -68,44 +82,84 @@ BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd) | @@ -68,44 +82,84 @@ BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd) | ||
| 68 | 82 | ||
| 69 | int librx3270_loaded(void) | 83 | int librx3270_loaded(void) |
| 70 | { | 84 | { |
| 71 | - trace("%s %04x %s %s",__FUNCTION__,REXX_CURRENT_INTERPRETER_VERSION,__DATE__,__TIME__); | 85 | +#ifdef HAVE_ICONV |
| 86 | + outputConv = iconv_open(REXX_DEFAULT_CHARSET, lib3270_get_default_charset()); | ||
| 87 | + inputConv = iconv_open(lib3270_get_default_charset(), REXX_DEFAULT_CHARSET); | ||
| 88 | +#endif | ||
| 89 | + | ||
| 72 | return 0; | 90 | return 0; |
| 73 | } | 91 | } |
| 74 | 92 | ||
| 75 | int librx3270_unloaded(void) | 93 | int librx3270_unloaded(void) |
| 76 | { | 94 | { |
| 77 | - trace("%s",__FUNCTION__); | ||
| 78 | - return 0; | ||
| 79 | -} | 95 | +#ifdef HAVE_ICONV |
| 80 | 96 | ||
| 81 | -RexxRoutine0(CSTRING, rx3270version) | ||
| 82 | -{ | ||
| 83 | - return lib3270_get_version(); | ||
| 84 | -} | 97 | + if(outputConv != (iconv_t) (-1)) |
| 98 | + iconv_close(outputConv); | ||
| 85 | 99 | ||
| 86 | -RexxRoutine0(CSTRING, rx3270QueryCState) | ||
| 87 | -{ | ||
| 88 | - return ""; | ||
| 89 | -} | 100 | + if(inputConv != (iconv_t) (-1)) |
| 101 | + iconv_close(inputConv); | ||
| 102 | +#endif | ||
| 90 | 103 | ||
| 91 | -RexxRoutine0(int, rx3270Disconnect) | ||
| 92 | -{ | ||
| 93 | return 0; | 104 | return 0; |
| 94 | } | 105 | } |
| 95 | 106 | ||
| 96 | -RexxRoutine2(int, rx3270Connect, CSTRING, hostname, int, timeout) | ||
| 97 | -{ | ||
| 98 | - return 0; | ||
| 99 | -} | ||
| 100 | 107 | ||
| 108 | +/* | ||
| 109 | +::method setStringAt | ||
| 110 | + use arg row, col, str | ||
| 111 | +return rx3270InputString(row,col,str) | ||
| 112 | + | ||
| 113 | +::method setCursorPosition | ||
| 114 | + use arg row, col | ||
| 115 | +return rx3270SetCursorPosition(row,col) | ||
| 116 | + | ||
| 117 | +::method RunMode | ||
| 118 | +return rx3270QueryRunMode() | ||
| 119 | + | ||
| 120 | +::method 'encoding=' | ||
| 121 | + use arg ptr | ||
| 122 | +return rx3270SetCharset(ptr) | ||
| 123 | + | ||
| 124 | +::method sendfile | ||
| 125 | + use arg from, tostrncasecmp | ||
| 126 | + | ||
| 127 | + status = rx3270BeginFileSend(from,to) | ||
| 128 | + if status <> 0 | ||
| 129 | + then return status | ||
| 130 | + | ||
| 131 | +return rx3270WaitForFTComplete() | ||
| 132 | + | ||
| 133 | +::method recvfile | ||
| 134 | + use arg from, to | ||
| 135 | + | ||
| 136 | + status = rx3270BeginFileRecv(from,to) | ||
| 137 | + if status <> 0 | ||
| 138 | + then return status | ||
| 139 | + | ||
| 140 | +return rx3270WaitForFTComplete() | ||
| 141 | +*/ | ||
| 101 | 142 | ||
| 102 | // now build the actual entry list | 143 | // now build the actual entry list |
| 103 | RexxRoutineEntry rx3270_functions[] = | 144 | RexxRoutineEntry rx3270_functions[] = |
| 104 | { | 145 | { |
| 105 | - REXX_TYPED_ROUTINE(rx3270version, rx3270version), | ||
| 106 | - REXX_TYPED_ROUTINE(rx3270QueryCState, rx3270QueryCState), | ||
| 107 | - REXX_TYPED_ROUTINE(rx3270Disconnect, rx3270Disconnect), | ||
| 108 | - REXX_TYPED_ROUTINE(rx3270Connect, rx3270Connect), | 146 | + REXX_TYPED_ROUTINE(rx3270version, rx3270version), |
| 147 | + REXX_TYPED_ROUTINE(rx3270QueryCState, rx3270QueryCState), | ||
| 148 | + REXX_TYPED_ROUTINE(rx3270Disconnect, rx3270Disconnect), | ||
| 149 | + REXX_TYPED_ROUTINE(rx3270Connect, rx3270Connect), | ||
| 150 | + REXX_TYPED_ROUTINE(rx3270isConnected, rx3270isConnected), | ||
| 151 | + REXX_TYPED_ROUTINE(rx3270WaitForEvents, rx3270WaitForEvents), | ||
| 152 | + REXX_TYPED_ROUTINE(rx3270Sleep, rx3270Sleep), | ||
| 153 | + REXX_TYPED_ROUTINE(rx3270SendENTERKey, rx3270SendENTERKey), | ||
| 154 | + REXX_TYPED_ROUTINE(rx3270SendPFKey, rx3270SendPFKey), | ||
| 155 | + REXX_TYPED_ROUTINE(rx3270SendPAKey, rx3270SendPAKey), | ||
| 156 | + REXX_TYPED_ROUTINE(rx3270WaitForTerminalReady, rx3270WaitForTerminalReady), | ||
| 157 | + REXX_TYPED_ROUTINE(rx3270WaitForStringAt, rx3270WaitForStringAt), | ||
| 158 | + REXX_TYPED_ROUTINE(rx3270GetStringAt, rx3270GetStringAt), | ||
| 159 | + REXX_TYPED_ROUTINE(rx3270IsTerminalReady, rx3270IsTerminalReady), | ||
| 160 | + REXX_TYPED_ROUTINE(rx3270ReadScreen, rx3270ReadScreen), | ||
| 161 | + REXX_TYPED_ROUTINE(rx3270queryStringAt, rx3270queryStringAt), | ||
| 162 | + | ||
| 109 | REXX_LAST_METHOD() | 163 | REXX_LAST_METHOD() |
| 110 | }; | 164 | }; |
| 111 | 165 |
| @@ -0,0 +1,81 @@ | @@ -0,0 +1,81 @@ | ||
| 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., 59 Temple | ||
| 19 | + * Place, Suite 330, Boston, MA, 02111-1307, USA | ||
| 20 | + * | ||
| 21 | + * Este programa está nomeado como text.cc 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 | + * | ||
| 28 | + */ | ||
| 29 | + | ||
| 30 | + #include "rx3270.h" | ||
| 31 | + #include <lib3270/actions.h> | ||
| 32 | + | ||
| 33 | + #include <string.h> | ||
| 34 | + | ||
| 35 | + | ||
| 36 | +/*--[ Globals ]--------------------------------------------------------------------------------------*/ | ||
| 37 | + | ||
| 38 | +#ifdef HAVE_ICONV | ||
| 39 | + iconv_t outputConv = (iconv_t) (-1); | ||
| 40 | + iconv_t inputConv = (iconv_t) (-1); | ||
| 41 | +#endif | ||
| 42 | + | ||
| 43 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
| 44 | + | ||
| 45 | +char * get_contents(H3270 *hSession, int start, int sz) | ||
| 46 | +{ | ||
| 47 | + unsigned char str[sz+1]; | ||
| 48 | + unsigned short attr[sz+1]; | ||
| 49 | + | ||
| 50 | + if(!lib3270_get_contents(hSession,start,start+sz,str,attr)) | ||
| 51 | + return NULL; | ||
| 52 | + | ||
| 53 | +#ifdef HAVE_ICONV | ||
| 54 | + // Convert received string to rexx encoding | ||
| 55 | + if(outputConv != (iconv_t)(-1)) | ||
| 56 | + { | ||
| 57 | + size_t in = strlen((char *) str); | ||
| 58 | + size_t out = (in << 1); | ||
| 59 | + char *ptr; | ||
| 60 | + char *buffer = (char *) malloc(out); | ||
| 61 | + char *ret; | ||
| 62 | + | ||
| 63 | + memset(ptr=buffer,0,out); | ||
| 64 | + | ||
| 65 | + iconv(outputConv,NULL,NULL,NULL,NULL); // Reset state | ||
| 66 | + | ||
| 67 | + if(iconv(outputConv,(char **) &str,&in,&ptr,&out) == ((size_t) -1)) | ||
| 68 | + ret = strdup((char *) str); | ||
| 69 | + else | ||
| 70 | + ret = strdup(buffer); | ||
| 71 | + | ||
| 72 | + free(buffer); | ||
| 73 | + | ||
| 74 | + return ret; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | +#endif // HAVE_ICONV | ||
| 78 | + | ||
| 79 | + return strdup((char *) str); | ||
| 80 | +} | ||
| 81 | + |
| @@ -0,0 +1,244 @@ | @@ -0,0 +1,244 @@ | ||
| 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., 59 Temple | ||
| 19 | + * Place, Suite 330, Boston, MA, 02111-1307, USA | ||
| 20 | + * | ||
| 21 | + * Este programa está nomeado como text.cc 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 | + * | ||
| 28 | + */ | ||
| 29 | + | ||
| 30 | + #include "rx3270.h" | ||
| 31 | + #include <lib3270/actions.h> | ||
| 32 | + | ||
| 33 | + #include <string.h> | ||
| 34 | + | ||
| 35 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | ||
| 36 | + | ||
| 37 | +RexxRoutine0(CSTRING, rx3270version) | ||
| 38 | +{ | ||
| 39 | + return lib3270_get_version(); | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +RexxRoutine0(CSTRING, rx3270QueryCState) | ||
| 43 | +{ | ||
| 44 | + #define DECLARE_XLAT_STATE( x ) { x, #x } | ||
| 45 | + | ||
| 46 | + static const struct _xlat_state | ||
| 47 | + { | ||
| 48 | + LIB3270_CSTATE state; | ||
| 49 | + const char * ret; | ||
| 50 | + } xlat_state[] = | ||
| 51 | + { | ||
| 52 | + { LIB3270_NOT_CONNECTED, "NOT_CONNECTED" }, | ||
| 53 | + { LIB3270_RESOLVING, "RESOLVING" }, | ||
| 54 | + { LIB3270_PENDING, "PENDING" }, | ||
| 55 | + { LIB3270_CONNECTED_INITIAL, "CONNECTED_INITIAL" }, | ||
| 56 | + { LIB3270_CONNECTED_ANSI, "CONNECTED_ANSI" }, | ||
| 57 | + { LIB3270_CONNECTED_3270, "CONNECTED_3270" }, | ||
| 58 | + { LIB3270_CONNECTED_INITIAL_E, "CONNECTED_INITIAL_E" }, | ||
| 59 | + { LIB3270_CONNECTED_NVT, "CONNECTED_NVT" }, | ||
| 60 | + { LIB3270_CONNECTED_SSCP, "CONNECTED_SSCP" }, | ||
| 61 | + { LIB3270_CONNECTED_TN3270E, "CONNECTED_TN3270E" }, | ||
| 62 | + }; | ||
| 63 | + | ||
| 64 | + size_t f; | ||
| 65 | + LIB3270_CSTATE state; | ||
| 66 | + | ||
| 67 | + state = lib3270_get_connection_state(RX3270SESSION); | ||
| 68 | + | ||
| 69 | + for(f=0;f < (sizeof(xlat_state)/sizeof(struct _xlat_state)); f++) | ||
| 70 | + { | ||
| 71 | + if(state == xlat_state[f].state) | ||
| 72 | + return xlat_state[f].ret; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + return "UNEXPECTED"; | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +RexxRoutine0(int, rx3270Disconnect) | ||
| 79 | +{ | ||
| 80 | + lib3270_disconnect(RX3270SESSION); | ||
| 81 | + return 0; | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +RexxRoutine2(int, rx3270Connect, CSTRING, hostname, int, wait) | ||
| 85 | +{ | ||
| 86 | + return lib3270_connect(RX3270SESSION, hostname, wait); | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +RexxRoutine0(int, rx3270isConnected) | ||
| 90 | +{ | ||
| 91 | + return lib3270_is_connected(RX3270SESSION) ? 1 : 0; | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +RexxRoutine0(int, rx3270WaitForEvents) | ||
| 95 | +{ | ||
| 96 | + H3270 * hSession = RX3270SESSION; | ||
| 97 | + | ||
| 98 | + if(!lib3270_is_connected(hSession)) | ||
| 99 | + return ENOTCONN; | ||
| 100 | + | ||
| 101 | + lib3270_main_iterate(hSession,1); | ||
| 102 | + | ||
| 103 | + return 0; | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +RexxRoutine1(int, rx3270Sleep, int, seconds) | ||
| 107 | +{ | ||
| 108 | + return lib3270_wait(RX3270SESSION,seconds); | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +RexxRoutine0(int, rx3270SendENTERKey) | ||
| 112 | +{ | ||
| 113 | + return lib3270_enter(RX3270SESSION); | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +RexxRoutine1(int, rx3270SendPFKey, int, key) | ||
| 117 | +{ | ||
| 118 | + return lib3270_pfkey(RX3270SESSION,key); | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +RexxRoutine1(int, rx3270SendPAKey, int, key) | ||
| 122 | +{ | ||
| 123 | + return lib3270_pakey(RX3270SESSION,key); | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +RexxRoutine1(int, rx3270WaitForTerminalReady, int, seconds) | ||
| 127 | +{ | ||
| 128 | + return lib3270_wait_for_ready(RX3270SESSION,seconds); | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | +RexxRoutine4(int, rx3270WaitForStringAt, int, row, int, col, CSTRING, key, int, timeout) | ||
| 132 | +{ | ||
| 133 | + H3270 * hSession = RX3270SESSION; | ||
| 134 | + time_t end = time(0) + timeout; | ||
| 135 | + int sz = strlen(key); | ||
| 136 | + int rows; | ||
| 137 | + int cols; | ||
| 138 | + int start; | ||
| 139 | + | ||
| 140 | + lib3270_get_screen_size(hSession,&rows,&cols); | ||
| 141 | + | ||
| 142 | + if(row < 0 || row > rows || col < 0 || col > cols) | ||
| 143 | + return EINVAL; | ||
| 144 | + | ||
| 145 | + start = ((row) * cols) + col; | ||
| 146 | + | ||
| 147 | + while(time(0) < end) | ||
| 148 | + { | ||
| 149 | + if(!lib3270_is_connected(hSession)) | ||
| 150 | + { | ||
| 151 | + return ENOTCONN; | ||
| 152 | + } | ||
| 153 | + else if(lib3270_is_ready(hSession)) | ||
| 154 | + { | ||
| 155 | + char *buffer = get_contents(hSession, start, start+sz); | ||
| 156 | + if(buffer) | ||
| 157 | + { | ||
| 158 | + int rc = strncasecmp((const char *) buffer,key,sz); | ||
| 159 | + free(buffer); | ||
| 160 | + if(rc == 0) | ||
| 161 | + return 0; | ||
| 162 | + } | ||
| 163 | + } | ||
| 164 | + | ||
| 165 | + lib3270_main_iterate(hSession,1); | ||
| 166 | + | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + return ETIMEDOUT; | ||
| 170 | + | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +RexxRoutine3(RexxStringObject, rx3270GetStringAt, int, row, int, col, int, sz) | ||
| 174 | +{ | ||
| 175 | + H3270 * hSession = RX3270SESSION; | ||
| 176 | + int rows; | ||
| 177 | + int cols; | ||
| 178 | + char * text; | ||
| 179 | + | ||
| 180 | + lib3270_get_screen_size(hSession,&rows,&cols); | ||
| 181 | + | ||
| 182 | + text = get_contents(hSession, ((row) * cols) + col, sz); | ||
| 183 | + if(text) | ||
| 184 | + { | ||
| 185 | + RexxStringObject ret = context->String((CSTRING) text); | ||
| 186 | + free(text); | ||
| 187 | + return ret; | ||
| 188 | + } | ||
| 189 | + | ||
| 190 | + return context->String(""); | ||
| 191 | +} | ||
| 192 | + | ||
| 193 | +RexxRoutine0(int, rx3270IsTerminalReady) | ||
| 194 | +{ | ||
| 195 | + return lib3270_is_ready(RX3270SESSION); | ||
| 196 | +} | ||
| 197 | + | ||
| 198 | +RexxRoutine3(RexxStringObject, rx3270ReadScreen, OPTIONAL_int, row, OPTIONAL_int, col, OPTIONAL_int, sz) | ||
| 199 | +{ | ||
| 200 | + H3270 * hSession = RX3270SESSION; | ||
| 201 | + int rows; | ||
| 202 | + int cols; | ||
| 203 | + char * text; | ||
| 204 | + int start; | ||
| 205 | + | ||
| 206 | + lib3270_get_screen_size(hSession,&rows,&cols); | ||
| 207 | + | ||
| 208 | + start = (row * cols) + col; | ||
| 209 | + | ||
| 210 | + if(sz == 0) | ||
| 211 | + sz = (rows*cols) - start; | ||
| 212 | + | ||
| 213 | + text = get_contents(hSession, start, sz); | ||
| 214 | + if(text) | ||
| 215 | + { | ||
| 216 | + RexxStringObject ret = context->String((CSTRING) text); | ||
| 217 | + free(text); | ||
| 218 | + return ret; | ||
| 219 | + } | ||
| 220 | + | ||
| 221 | + return context->String(""); | ||
| 222 | +} | ||
| 223 | + | ||
| 224 | +RexxRoutine3(int, rx3270queryStringAt, int, row, int, col, CSTRING, key) | ||
| 225 | +{ | ||
| 226 | + H3270 * hSession = RX3270SESSION; | ||
| 227 | + int rows; | ||
| 228 | + int cols; | ||
| 229 | + char * text; | ||
| 230 | + size_t sz = strlen(key); | ||
| 231 | + | ||
| 232 | + lib3270_get_screen_size(hSession,&rows,&cols); | ||
| 233 | + | ||
| 234 | + text = get_contents(hSession, (row * cols) + col, sz); | ||
| 235 | + if(text) | ||
| 236 | + { | ||
| 237 | + int rc = strncasecmp(text,key,sz); | ||
| 238 | + free(text); | ||
| 239 | + return rc; | ||
| 240 | + } | ||
| 241 | + | ||
| 242 | + return 0; | ||
| 243 | +} | ||
| 244 | + |