From 5fa8530ba3c1999ec7daf3c4ca68ea97162eeccc Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Mon, 6 Aug 2012 14:27:28 +0000 Subject: [PATCH] Mais métodos passam a utilizar a estrutura de sessão --- src/include/lib3270/session.h | 9 +++++++++ src/lib3270/glue.c | 718 ++-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/lib3270/rpq.c | 159 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------- src/lib3270/telnet.c | 40 ++++++++++++++++++++-------------------- 4 files changed, 110 insertions(+), 816 deletions(-) diff --git a/src/include/lib3270/session.h b/src/include/lib3270/session.h index 16dacf6..cb55b24 100644 --- a/src/include/lib3270/session.h +++ b/src/include/lib3270/session.h @@ -262,6 +262,15 @@ // ft_dft.c int dft_buffersize; /**< Buffer size (LIMIN, LIMOUT) */ + // rpq.c + int rpq_complained : 1; +#if !defined(_WIN32) + int omit_due_space_limit : 1; +#endif + + char * rpq_warnbuf; + int rpq_wbcnt; + // Widget info void * widget; diff --git a/src/lib3270/glue.c b/src/lib3270/glue.c index af5ff90..7c8210d 100644 --- a/src/lib3270/glue.c +++ b/src/lib3270/glue.c @@ -18,7 +18,7 @@ * 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 glue.c e possui 1103 linhas de código. + * Este programa está nomeado como glue.c e possui - linhas de código. * * Contatos: * @@ -26,7 +26,6 @@ * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) * licinio@bb.com.br (Licínio Luis Branco) * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) * */ @@ -91,175 +90,9 @@ int lib3270_unloaded(void) __attribute__((destructor)); #endif -#ifdef DEBUG - static int init_calls = 0; -#endif - -// static void lib3270_session_init(H3270 *hSession, const char *model); - #define LAST_ARG "--" /*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ -// const char * programname; -// AppRes appres; -// int children = 0; -// Boolean exiting = False; -// char * command_string = CN; - -// #if defined(WC3270) || defined(LIB3270) -// char *profile_name = CN; -// #endif - -/* - * Set default options - */ -static void initialize(void) -{ -// memset(&appres,0,sizeof(appres)); - -#ifdef DEBUG - init_calls++; - trace("Initializing library (calls: %d)",init_calls); -#endif - -// h3270.selected = 0; -// h3270.select.start = h3270.select.end = 0; -// initialize_toggles(&h3270); - -#if defined(_WIN32) - (void) get_version_info(); -#endif - - trace("%s (init_calls: %d)",__FUNCTION__,init_calls); - - /* Set the defaults. */ -// appres.mono = False; -// appres.extended = True; - -//#if defined(C3270) /*[*/ -// h3270.m3279 = True; -//#endif /*]*/ - -// appres.modified_sel = False; -// appres.apl_mode = False; - -/* -#if defined(C3270) || defined(TCL3270) - appres.scripted = False; -#else - appres.scripted = True; -#endif -*/ - -// appres.numeric_lock = False; -// appres.secure = False; - -#if defined(C3270) /*[*/ -// appres.oerr_lock = True; -#else /*][*/ -// appres.oerr_lock = False; -#endif /*]*/ - -// appres.typeahead = True; -// appres.debug_tracing = True; - -//#if defined(C3270) -// appres.compose_map = "latin1"; -//#endif - -// appres.model = ""; -// appres.hostsfile = CN; -// appres.port = "telnet"; - -// #if !defined(_WIN32) /*[*/ -// appres.charset = "bracket"; -// #else /*][*/ -// -// if (is_nt) -// appres.charset = "bracket"; -// else -// appres.charset = "bracket437"; -//#endif /*]*/ - -// appres.termname = CN; -// appres.macros = CN; - -#if defined(X3270_TRACE) /*[*/ - -/* -#if !defined(_WIN32) - appres.trace_dir = "/tmp"; -#endif -*/ - -/* -#if defined(X3270_DISPLAY) || defined(WC3270) - appres.trace_monitor = True; -#endif -*/ - -#endif /*]*/ - -// appres.oversize = CN; - -#if defined(C3270) /*[*/ -// appres.meta_escape = "auto"; -// appres.curses_keypad = True; -// appres.cbreak_mode = False; -#endif /*]*/ - -#if defined(X3270_ANSI) -// appres.icrnl = True; -// appres.inlcr = False; -// appres.onlcr = True; -// appres.erase = "^H"; -// appres.kill = "^U"; -// appres.werase = "^W"; -// appres.rprnt = "^R"; -// appres.lnext = "^V"; -// appres.intr = "^C"; -// appres.quit = "^\\"; -// appres.eof = "^D"; -#endif /*]*/ - -// appres.unlock_delay = True; - -//#if defined(X3270_FT) /*[*/ -// appres.dft_buffer_size = DFT_BUF; -//#endif /*]*/ - -/* -#if defined(C3270) && !defined(LIB3270) - appres.toggle[CURSOR_POS].value = True; -#endif -*/ - -/* -#if defined(X3270_SCRIPT) || defined(TCL3270) - appres.toggle[AID_WAIT].value = True; -#endif -*/ - -/* -#if defined(C3270) && defined(X3270_SCRIPT) - appres.plugin_command = "x3270hist.pl"; -#endif -*/ - -/* -#if defined(C3270) && defined(_WIN32) - appres.highlight_underline = True; -#endif -*/ - -/* -#if defined(C3270) && !defined(_WIN32) && !defined(LIB3270) - // Merge in the profile. - merge_profile(); -#endif -*/ - -} #if defined WIN32 @@ -268,7 +101,7 @@ BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd) // Trace("%s - Library %s",__FUNCTION__,(dwcallpurpose == DLL_PROCESS_ATTACH) ? "Loaded" : "Unloaded"); if(dwcallpurpose == DLL_PROCESS_ATTACH) - initialize(); + get_version_info(); return TRUE; } @@ -277,8 +110,6 @@ BOOL WINAPI DllMain(HANDLE hinst, DWORD dwcallpurpose, LPVOID lpvResvd) int lib3270_loaded(void) { -// Trace("%s - Library loaded",__FUNCTION__); - initialize(); return 0; } @@ -290,555 +121,10 @@ int lib3270_unloaded(void) #endif -#define offset(n) (void *) &appres.n -#define toggle_offset(index) offset(toggle[index].value) - -/* - -static const struct lib3270_option options[] = -{ - // TODO (perry#5#): Add option descriptions. -//#if defined(C3270) -// { OptAllBold, OPT_BOOLEAN, True, ResAllBold, offset(all_bold_on), NULL }, -// { OptAltScreen,OPT_STRING, False, ResAltScreen, offset(altscreen), NULL }, -//#endif -// { OptAplMode, OPT_BOOLEAN, True, ResAplMode, offset(apl_mode), NULL }, -#if defined(C3270) -// { OptCbreak, OPT_BOOLEAN, True, ResCbreak, offset(cbreak_mode), NULL }, -#endif -#if defined(HAVE_LIBSSL) - { OptCertFile, OPT_STRING, False, ResCertFile, offset(cert_file), NULL }, -#endif -// { OptCharset, OPT_STRING, False, ResCharset, offset(charset), NULL }, - { OptClear, OPT_SKIP2, False, NULL, NULL, NULL }, -// { OptDefScreen,OPT_STRING, False, ResDefScreen, offset(defscreen), NULL }, -//#if defined(X3270_TRACE) -// { OptDsTrace, OPT_BOOLEAN, True, ResDsTrace, toggle_offset(DS_TRACE), NULL }, -//#endif -// { OptHostsFile,OPT_STRING, False, ResHostsFile, offset(hostsfile), NULL }, -//#if defined(C3270) -// { OptKeymap, OPT_STRING, False, ResKeymap, offset(key_map), N_( "Specifies a keymap name and optional modifiers." ) }, -// #endif - -// #if defined(X3270_DBCS) -// { OptLocalEncoding,OPT_STRING,False,ResLocalEncoding,offset(local_encoding), NULL }, -//#endif -// { OptModel, OPT_STRING, False, ResKeymap, offset(model), N_( "Set terminal model (screen size)" ) }, -// #if !defined(_WIN32) -// { OptMono, OPT_BOOLEAN, True, ResMono, offset(mono), N_( "Forces monochrome display" ) }, -// #endif -// { OptOnce, OPT_BOOLEAN, True, ResOnce, offset(once), NULL }, -// { OptOversize, OPT_STRING, False, ResOversize, offset(oversize), N_( "Sets the screen dimensions to be larger than the default for the chosen model (COLSxROWS)." ) }, -// { OptPort, OPT_STRING, False, ResPort, offset(port), N_( "The name of the default TCP port to connect" ) }, -#if defined(C3270) && !defined(LIB3270) -// { OptPrinterLu,OPT_STRING, False, ResPrinterLu, offset(printer_lu), NULL }, -#endif -// { OptProxy, OPT_STRING, False, ResProxy, offset(proxy), N_( "Proxy server (type:host[:port])" ) }, -#if defined(S3270) - { OptScripted, OPT_NOP, False, ResScripted, NULL, NULL }, -#endif -//#if defined(C3270) -// { OptSecure, OPT_BOOLEAN, True, ResSecure, offset(secure), NULL }, -//#endif -// { OptSet, OPT_SKIP2, False, NULL, NULL, NULL }, -#if defined(X3270_SCRIPT) -// { OptSocket, OPT_BOOLEAN, True, ResSocket, offset(socket), NULL }, -#endif - -// { OptTermName, OPT_STRING, False, ResTermName, offset(termname), N_( "Specifies the terminal name to be transmitted over the telnet connection." ) }, - -#if defined(WC3270) -// { OptTitle, OPT_STRING, False, ResTitle, offset(title), NULL }, -#endif -#if defined(X3270_TRACE) -// { OptTraceFile,OPT_STRING, False, ResTraceFile, offset(trace_file), NULL }, -// { OptTraceFileSize,OPT_STRING,False,ResTraceFileSize,offset(trace_file_size), NULL }, -#endif - { "-xrm", OPT_XRM, False, NULL, NULL, NULL }, - { LAST_ARG, OPT_DONE, False, NULL, NULL, NULL }, - { CN, OPT_SKIP2, False, NULL, NULL, NULL } -}; -*/ - -/* - * Get library option table - */ - /* -const struct lib3270_option * get_3270_option_table(int sz) -{ - if(sz == sizeof(struct lib3270_option)) - return options; - return NULL; -} -*/ - -/* - * Parse '-xrm' options. - * Understands only: - * {c,s,tcl}3270.: value - * Asterisks and class names need not apply. - */ -/* -static struct { - const char *name; - void *address; - enum resource_type { XRM_STRING, XRM_BOOLEAN, XRM_INT } type; -} resources[] = { -// { ResAllBold, offset(all_bold), XRM_STRING }, -// { ResAltScreen, offset(altscreen), XRM_STRING }, -// { ResBsdTm, offset(bsd_tm), XRM_BOOLEAN }, -#if defined(HAVE_LIBSSL) - { ResCertFile, offset(cert_file), XRM_STRING }, -#endif -// { ResCharset, offset(charset), XRM_STRING }, -// { ResColor8, offset(color8), XRM_BOOLEAN }, -// { ResConfDir, offset(conf_dir), XRM_STRING }, -// { ResDefScreen, offset(defscreen), XRM_STRING }, -#if defined(X3270_ANSI) -// { ResEof, offset(eof), XRM_STRING }, -// { ResErase, offset(erase), XRM_STRING }, -#endif -// { ResExtended, offset(extended), XRM_BOOLEAN }, -#if defined(X3270_FT) -// { ResFtCommand, offset(ft_command), XRM_STRING }, - { ResDftBufferSize,offset(dft_buffer_size),XRM_INT }, -#endif -//#if defined(WC3270) -// { "hostname", offset(hostname), XRM_STRING }, -//#endif -// { ResHostsFile, offset(hostsfile), XRM_STRING }, -#if defined(X3270_ANSI) -// { ResIcrnl, offset(icrnl), XRM_BOOLEAN }, -// { ResInlcr, offset(inlcr), XRM_BOOLEAN }, -// { ResOnlcr, offset(onlcr), XRM_BOOLEAN }, -// { ResIntr, offset(intr), XRM_STRING }, -#endif -//#if defined(X3270_SCRIPT) -// { ResPluginCommand, offset(plugin_command), XRM_STRING }, -//#endif -//#if defined(C3270) && defined(_WIN32) -// { ResHighlightUnderline, offset(highlight_underline), XRM_BOOLEAN }, -//#endif -#if defined(C3270) && defined(X3270_SCRIPT) - { ResIdleCommand,offset(idle_command), XRM_STRING }, - { ResIdleCommandEnabled,offset(idle_command_enabled), XRM_BOOLEAN }, - { ResIdleTimeout,offset(idle_timeout), XRM_STRING }, -#endif -#if defined(C3270) -// { ResKeymap, offset(key_map), XRM_STRING }, -// { ResMetaEscape,offset(meta_escape), XRM_STRING }, -// { ResCursesKeypad,offset(curses_keypad),XRM_BOOLEAN }, -// { ResCbreak, offset(cbreak_mode), XRM_BOOLEAN }, -#endif -#if defined(X3270_ANSI) -// { ResKill, offset(kill), XRM_STRING }, -// { ResLnext, offset(lnext), XRM_STRING }, -#endif -// { ResLoginMacro,offset(login_macro), XRM_STRING }, -// { ResM3279, offset(m3279), XRM_BOOLEAN }, -// { ResModel, offset(model), XRM_STRING }, -// { ResModifiedSel, offset(modified_sel), XRM_BOOLEAN }, -//#if defined(C3270) && !defined(_WIN32) -// { ResMono, offset(mono), XRM_BOOLEAN }, -//#endif -// { ResNumericLock, offset(numeric_lock), XRM_BOOLEAN }, -// { ResOerrLock, offset(oerr_lock), XRM_BOOLEAN }, -// { ResOversize, offset(oversize), XRM_STRING }, -// { ResPort, offset(port), XRM_STRING }, -#if defined(C3270) -// { ResPrinterLu, offset(printer_lu), XRM_STRING }, - { ResPrintTextCommand, NULL, XRM_STRING }, -#endif -// { ResProxy, offset(proxy), XRM_STRING }, -#if defined(X3270_ANSI) -// { ResQuit, offset(quit), XRM_STRING }, -// { ResRprnt, offset(rprnt), XRM_STRING }, -#endif -// { ResSecure, offset(secure), XRM_BOOLEAN }, -// { ResTermName, offset(termname), XRM_STRING }, -#if defined(WC3270) - { ResTitle, offset(title), XRM_STRING }, -#endif -#if defined(X3270_TRACE) -//#if !defined(_WIN32) -// { ResTraceDir, offset(trace_dir), XRM_STRING }, -//#endif -// { ResTraceFile, offset(trace_file), XRM_STRING }, -// { ResTraceFileSize,offset(trace_file_size),XRM_STRING }, -#if defined(WC3270) - { ResTraceMonitor,offset(trace_monitor),XRM_BOOLEAN }, -#endif -#endif -// { ResTypeahead, offset(typeahead), XRM_BOOLEAN }, -// { ResUnlockDelay,offset(unlock_delay), XRM_BOOLEAN }, -#if defined(X3270_ANSI) -// { ResWerase, offset(werase), XRM_STRING }, -#endif - - { CN, 0, XRM_STRING } -}; -*/ - -/* - * Compare two strings, allowing the second to differ by uppercasing the - * first character of the second. - */ /* -static int -strncapcmp(const char *known, const char *unknown, unsigned unk_len) -{ - if (unk_len != strlen(known)) - return -1; - if (!strncmp(known, unknown, unk_len)) - return 0; - if (unk_len > 1 && - unknown[0] == toupper(known[0]) && - !strncmp(known + 1, unknown + 1, unk_len - 1)) - return 0; - return -1; -} -*/ - -#if !defined(ME) /*[*/ -#if defined(C3270) /*[*/ -#if defined(WC3270) /*[*/ -#define ME "wc3270" -#else /*][*/ -#define ME "c3270" -#endif /*]*/ -#elif defined(TCL3270) /*][*/ -#define ME "tcl3270" -#else /*][*/ -#define ME "s3270" -#endif /*]*/ -#endif /*]*/ - -/* -void -parse_xrm(const char *arg, const char *where) -{ - static char me_dot[] = ME "."; - static char me_star[] = ME "*"; - unsigned match_len; - const char *s; - unsigned rnlen; - int i; - char *t; - void *address = NULL; - enum resource_type type = XRM_STRING; -#if defined(C3270) - char *add_buf = CN; - char *hide; - Boolean arbitrary = False; -#endif - - // Enforce "-3270." or "-3270*" or "*". - if (!strncmp(arg, me_dot, sizeof(me_dot)-1)) - match_len = sizeof(me_dot)-1; - else if (!strncmp(arg, me_star, sizeof(me_star)-1)) - match_len = sizeof(me_star)-1; - else if (arg[0] == '*') - match_len = 1; - else { - xs_warning("%s: Invalid resource syntax '%.*s', name must " - "begin with '%s'", - where, (int) sizeof(me_dot)-1, arg, me_dot); - return; - } - - // Separate the parts. - s = arg + match_len; - while (*s && *s != ':' && !isspace(*s)) - s++; - rnlen = s - (arg + match_len); - if (!rnlen) { - xs_warning("%s: Invalid resource syntax, missing resource " - "name", where); - return; - } - while (isspace(*s)) - s++; - if (*s != ':') { - xs_warning("%s: Invalid resource syntax, missing ':'", where); - return; - } - s++; - while (isspace(*s)) - s++; - - // Look up the name. - for (i = 0; resources[i].name != CN; i++) { - if (!strncapcmp(resources[i].name, arg + match_len, rnlen)) { - address = resources[i].address; - type = resources[i].type; -#if defined(C3270) - if (address == NULL) { - add_buf = lib3270_malloc(strlen(s) + 1); - address = add_buf; - } -#endif - break; - } - } - -#if defined(C3270) - if (address == NULL) { - if (!strncasecmp(ResKeymap ".", arg + match_len, - strlen(ResKeymap ".")) || - !strncasecmp(ResCharset ".", arg + match_len, - strlen(ResCharset ".")) || - !strncasecmp(ResDisplayCharset ".", arg + match_len, - strlen(ResDisplayCharset ".")) || - !strncasecmp(ResCodepage ".", arg + match_len, - strlen(ResCodepage ".")) || - !strncasecmp("host.", arg + match_len, 5) || - !strncasecmp("printer.", arg + match_len, 8) || -#if defined(_WIN32) - !strncasecmp(ResHostColorFor, arg + match_len, - strlen(ResHostColorFor)) || - !strncasecmp(ResConsoleColorForHostColor, arg + match_len, - strlen(ResConsoleColorForHostColor)) -#else - !strncasecmp(ResCursesColorFor, arg + match_len, - strlen(ResCursesColorFor)) -#endif - ) { - address = &hide; - type = XRM_STRING; - arbitrary = True; - } - } -#endif - if (address == NULL) { - xs_warning("%s: Unknown resource name: %.*s", - where, (int)rnlen, arg + match_len); - return; - } - switch (type) { - case XRM_BOOLEAN: - if (!strcasecmp(s, "true") || - !strcasecmp(s, "t") || - !strcmp(s, "1")) { - *(Boolean *)address = True; - } else if (!strcasecmp(s, "false") || - !strcasecmp(s, "f") || - !strcmp(s, "0")) { - *(Boolean *)address = False; - } else { - xs_warning("%s: Invalid Boolean value: %s", where, s); - } - break; - case XRM_STRING: - t = lib3270_malloc(strlen(s) + 1); - *(char **)address = t; - if (*s == '"') { - Boolean quoted = False; - char c; - - s++; - while ((c = *s++) != '\0') { - if (quoted) { - switch (c) { - case 'n': - *t++ = '\n'; - break; - case 'r': - *t++ = '\r'; - break; - case 'b': - *t++ = '\b'; - break; - default: - *t++ = c; - break; - } - quoted = False; - } else if (c == '\\') { - quoted = True; - } else if (c == '"') { - break; - } else { - *t++ = c; - } - } - *t = '\0'; - } else { - (void) strcpy(t, s); - } - break; - case XRM_INT: { - long n; - char *ptr; - - n = strtol(s, &ptr, 0); - if (*ptr != '\0') { - xs_warning("%s: Invalid Integer value: %s", where, s); - } else { - *(int *)address = (int)n; - } - break; - } - } - -#if defined(C3270) - // Add a new, arbitrarily-named resource. - if (arbitrary) { - char *rsname; - - rsname = lib3270_malloc(rnlen + 1); - (void) strncpy(rsname, arg + match_len, rnlen); - rsname[rnlen] = '\0'; - add_resource(rsname, hide); - } -#endif -} -*/ - -/* Read resources from a file. */ /* -int -read_resource_file(const char *filename, Boolean fatal) -{ - FILE *f; - int ilen; - char buf[4096]; - char *where; - int lno = 0; - - f = fopen(filename, "r"); - if (f == NULL) { - if (fatal) - xs_warning("Cannot open '%s': %s", filename, - strerror(errno)); - return -1; - } - - // Merge in what's in the file into the resource database. - where = lib3270_malloc(strlen(filename) + 64); - - ilen = 0; - while (fgets(buf + ilen, sizeof(buf) - ilen, f) != CN || ilen) { - char *s, *t; - unsigned sl; - Boolean bsl; - - lno++; - - // Stip any trailing newline. - sl = strlen(buf + ilen); - if (sl && (buf + ilen)[sl-1] == '\n') - (buf + ilen)[--sl] = '\0'; - - // - //Translate backslash-n to real newline characters, and - // remember if the last character is a backslash. - // - for (bsl = False, s = buf + ilen, t = s; *s; s++) { - if (bsl) { - if (*s == 'n') - *t++ = '\n'; - else - *t++ = *s; - bsl = False; - } else if (*s == '\\') - bsl = True; - else { - *t++ = *s; - bsl = False; - } - } - *t = '\0'; - - // Skip leading whitespace. - s = buf; - while (isspace(*s)) - s++; - - // Skip comments _before_ checking for line continuation. - if (*s == '!') { - ilen = 0; - continue; - } - if (*s == '#') { - (void) sprintf(where, "%s:%d: Invalid profile " - "syntax ('#' ignored)", filename, lno); - Warning(NULL,where); - ilen = 0; - continue; - } - - // If this line is a continuation, try again. - if (bsl) { - ilen += strlen(buf + ilen); - if (ilen >= sizeof(buf) - 1) { - (void) sprintf(where, "%s:%d: Line too long\n", - filename, lno); - Warning(NULL,where); - break; - } - continue; - } - - // Strip trailing whitespace and check for empty lines. - sl = strlen(s); - while (sl && isspace(s[sl-1])) - s[--sl] = '\0'; - if (!sl) { - ilen = 0; - continue; - } - - // Digest it. - (void) sprintf(where, "%s:%d", filename, lno); - parse_xrm(s, where); - - // Get ready for the next iteration. - ilen = 0; - } - lib3270_free(where); - return 0; -} - -// Boolean flipped = False; -*/ - -/* Replacements for functions in popups.c. */ - -// Boolean error_popup_visible = False; - - #ifdef DEBUG extern void lib3270_initialize(void) { - initialize(); } #endif -/* -void -action_output(const char *fmt, ...) -{ -// TODO (perry#1#): Implement a callback to browse the text string. - va_list args; - - va_start(args, fmt); - (void) vsprintf(vmsgbuf, fmt, args); - va_end(args); - if (sms_redirect()) { - sms_info("%s", vmsgbuf); - return; - } else { - FILE *aout; - -#if defined(C3270) || defined(WC3270) - screen_suspend(); -// aout = start_pager(); -// any_error_output = True; -#else - aout = stdout; -#endif - (void) fprintf(aout, "%s\n", vmsgbuf); - macro_output = True; - } -} -*/ - diff --git a/src/lib3270/rpq.c b/src/lib3270/rpq.c index 526cbd5..29db8f2 100644 --- a/src/lib3270/rpq.c +++ b/src/lib3270/rpq.c @@ -66,19 +66,21 @@ #include "sf.h" /* Statics */ -static Boolean select_rpq_terms(void); -static int get_rpq_timezone(void); -static int get_rpq_user(unsigned char buf[], const int buflen); +static Boolean select_rpq_terms(H3270 *hSession); +static int get_rpq_timezone(H3270 *hSession); +static int get_rpq_user(H3270 *hSession, unsigned char buf[], const int buflen); #if !defined(_WIN32) /*[*/ -static int get_rpq_address(unsigned char buf[], const int buflen); +static int get_rpq_address(H3270 *hSession, unsigned char buf[], const int buflen); #endif /*]*/ -static void rpq_warning(const char *fmt, ...); -static void rpq_dump_warnings(void); -static Boolean rpq_complained = False; +static void rpq_warning(H3270 *hSession, const char *fmt, ...) printflike(2,3); +static void rpq_dump_warnings(H3270 *hSession); -#if !defined(_WIN32) /*[*/ -static Boolean omit_due_space_limit = False; -#endif /*]*/ + +// static Boolean rpq_complained = 0; +// +// #if !defined(_WIN32) +//static Boolean omit_due_space_limit = 0; +//#endif /* * Define symbolic names for RPQ self-defining terms. @@ -101,9 +103,10 @@ static Boolean omit_due_space_limit = False; * specifies abbreviations, they work in a predictable manner. E.g., "TIME" * should match TIMESTAMP instead of TIMEZONE. */ -static struct rpq_keyword { - Boolean omit; /* set from X3270RPQ="kw1:kw2..." environment var */ - int oride; /* displacement */ +static struct rpq_keyword +{ + Boolean omit; /**< set from X3270RPQ="kw1:kw2..." environment var */ + int oride; /**< displacement */ const Boolean allow_oride; const unsigned char id; const char *text; @@ -112,7 +115,7 @@ static struct rpq_keyword { {True, 0, True, RPQ_ADDRESS, "ADDRESS"}, {True, 0, False, RPQ_TIMESTAMP, "TIMESTAMP"}, {True, 0, True, RPQ_TIMEZONE, "TIMEZONE"}, - {True, 0, True, RPQ_USER, "USER"}, + {True, 0, True, RPQ_USER, "USER"}, {True, 0, False, RPQ_VERSION, "VERSION"}, }; #define NS_RPQ (sizeof(rpq_keywords)/sizeof(rpq_keywords[0])) @@ -141,31 +144,31 @@ void do_qr_rpqnames(H3270 *hSession) */ space3270out(hSession,4+4+1+remaining); /* Maximum space for an RPQNAME item */ - SET32(h3270.obptr, 0); /* Device number, 0 = All */ - SET32(h3270.obptr, 0); /* Model number, 0 = All */ + SET32(hSession->obptr, 0); /* Device number, 0 = All */ + SET32(hSession->obptr, 0); /* Model number, 0 = All */ - rpql = h3270.obptr++; /* Save address to place data length. */ + rpql = hSession->obptr++; /* Save address to place data length. */ /* Create fixed length portion - program id: x3270 */ for (j = 0; j < 5; j++) { - *h3270.obptr++ = asc2ebc[(int)"x3270"[j]]; + *hSession->obptr++ = asc2ebc[(int)"x3270"[j]]; remaining--; } /* Create user selected variable-length self-defining terms. */ - select_rpq_terms(); + select_rpq_terms(hSession); for (j=0; jobptr; /* save starting address (to insert length later) */ + hSession->obptr++; /* skip length of term, fill in later */ + *hSession->obptr++ = term_id; /* identify this term */ /* * Adjust remaining space by the term prefix size so each case @@ -177,18 +180,18 @@ void do_qr_rpqnames(H3270 *hSession) switch (term_id) { /* build the term based on id */ case RPQ_USER: /* User text from env. vars */ - h3270.obptr += get_rpq_user(h3270.obptr, remaining); + hSession->obptr += get_rpq_user(hSession,hSession->obptr, remaining); break; case RPQ_TIMEZONE: /* UTC time offset */ omit_due_space_limit = (remaining < 2); if (!omit_due_space_limit) - SET16(h3270.obptr, get_rpq_timezone()); + SET16(hSession->obptr, get_rpq_timezone(hSession)); break; case RPQ_ADDRESS: /* Workstation address */ #if !defined(_WIN32) /*[*/ - hSession->obptr += get_rpq_address(hSession->obptr, remaining); + hSession->obptr += get_rpq_address(hSession, hSession->obptr, remaining); #endif /*]*/ break; @@ -204,7 +207,7 @@ void do_qr_rpqnames(H3270 *hSession) case RPQ_TIMESTAMP: /* program build time (yyyymmddhhmmss bcd) */ x = strlen(build_rpq_timestamp); - omit_due_space_limit = ((x+1)/2 > remaining); + omit_due_space_limit = ((x+1)/2 > remaining) ? 1 : 0; if (!omit_due_space_limit) { for (i=0; i < x; i+=2) { *hSession->obptr++ = ((*(build_rpq_timestamp+i) - '0') << 4) @@ -214,12 +217,12 @@ void do_qr_rpqnames(H3270 *hSession) break; default: /* unsupported ID, (can't happen) */ - Error(NULL,"Unsupported RPQ term"); + Error(hSession,_( "Unsupported RPQ term" )); break; } if (omit_due_space_limit) - rpq_warning("RPQ %s term omitted due to insufficient space", rpq_keywords[j].text); + rpq_warning(hSession, _( "RPQ %s term omitted due to insufficient space" ), rpq_keywords[j].text); /* * The item is built, insert item length as needed and * adjust space remaining. @@ -256,12 +259,11 @@ void do_qr_rpqnames(H3270 *hSession) /* Fill in overall length of RPQNAME info */ *rpql = (hSession->obptr - rpql); - rpq_dump_warnings(); + rpq_dump_warnings(hSession); } /* Utility function used by the RPQNAMES query reply. */ -static Boolean -select_rpq_terms(void) +static Boolean select_rpq_terms(H3270 *hSession) { int i,j,k,len; char *uplist; @@ -330,9 +332,7 @@ select_rpq_terms(void) if (rpq_keywords[j].allow_oride) { rpq_keywords[j].oride = p1-uplist+1; } else { - rpq_warning("RPQ %s term " - "override " - "ignored", p1); + rpq_warning(hSession, _("RPQ %s term override ignored"), p1); } } break; @@ -344,8 +344,7 @@ select_rpq_terms(void) for (k=0; k < NS_RPQ; k++) rpq_keywords[k].omit = is_no_form; } else { - rpq_warning("RPQ term \"%s\" is unrecognized", - kw); + rpq_warning(hSession,_( "RPQ term \"%s\" is unrecognized" ),kw); } } } @@ -364,8 +363,10 @@ select_rpq_terms(void) return False; } -/* Utility function used by the RPQNAMES query reply. */ -static int get_rpq_timezone(void) +/** + * Utility function used by the RPQNAMES query reply. + */ +static int get_rpq_timezone(H3270 *hSession) { /* * Return the signed number of minutes we're offset from UTC. @@ -399,7 +400,7 @@ static int get_rpq_timezone(void) x = strtol(p1, &p2, 10); if (errno != 0) { - rpq_warning("RPQ TIMEZONE term is invalid - use +/-hhmm"); + rpq_warning(hSession, _( "RPQ TIMEZONE term is invalid - use +/-hhmm" )); return 4; } if ((*p2 != '\0') && (*p2 != ':') && (!isspace(*p2))) @@ -408,7 +409,7 @@ static int get_rpq_timezone(void) hhmm = ldiv(x, 100L); if (hhmm.rem > 59L) { - rpq_warning("RPQ TIMEZONE term is invalid - use +/-hhmm"); + rpq_warning(hSession, _("RPQ TIMEZONE term is invalid - use +/-hhmm")); return 4; } @@ -421,14 +422,14 @@ static int get_rpq_timezone(void) */ if ((here = time(NULL)) == (time_t)(-1)) { - rpq_warning("RPQ: Unable to determine workstation local time"); + rpq_warning(hSession, _("RPQ: Unable to determine workstation local time")); return 1; } memcpy(&here_tm, localtime(&here), sizeof(struct tm)); if ((utc_tm = gmtime(&here)) == NULL) { - rpq_warning("RPQ: Unable to determine workstation UTC time"); + rpq_warning(hSession, _("RPQ: Unable to determine workstation UTC time")); return 2; } @@ -443,14 +444,13 @@ static int get_rpq_timezone(void) /* sanity check: difference cannot exceed +/- 12 hours */ if (labs(delta) > 720L) - rpq_warning("RPQ timezone exceeds 12 hour UTC offset"); + rpq_warning(hSession, _("RPQ timezone exceeds 12 hour UTC offset")); return (labs(delta) > 720L)? 3 : (int) delta; } /* Utility function used by the RPQNAMES query reply. */ -static int -get_rpq_user(unsigned char buf[], const int buflen) +static int get_rpq_user(H3270 *hSession, unsigned char buf[], const int buflen) { /* * Text may be specified in one of two ways, but not both. @@ -498,13 +498,13 @@ get_rpq_user(unsigned char buf[], const int buflen) if (isspace(c)) continue; /* skip white space */ if (!isxdigit(c)) { - rpq_warning("RPQ USER term has non-hex character"); + rpq_warning(hSession, _("RPQ USER term has non-hex character")); break; } x = (p_h - hexstr)/2; if (x >= buflen) { x = buflen; - rpq_warning("RPQ USER term truncated after %d bytes", x); + rpq_warning(hSession, _("RPQ USER term truncated after %d bytes"), x); break; /* too long, truncate */ } @@ -523,7 +523,7 @@ get_rpq_user(unsigned char buf[], const int buflen) */ is_first_hex_digit = ((strlen(hexstr) % 2) == 0); if (!is_first_hex_digit) - rpq_warning("RPQ USER term has odd number of hex digits"); + rpq_warning(hSession, _("RPQ USER term has odd number of hex digits")); *buf = 0; /* initialize first byte for possible implied leading zero */ for (p_h = &hexstr[0]; *p_h; p_h++) { @@ -548,7 +548,7 @@ get_rpq_user(unsigned char buf[], const int buflen) if ( x >= buflen) { x = buflen; - rpq_warning("RPQ USER term truncated after %d characters", x); + rpq_warning(hSession, _("RPQ USER term truncated after %d characters"), x); break; } @@ -566,14 +566,13 @@ get_rpq_user(unsigned char buf[], const int buflen) } #if !defined(_WIN32) /*[*/ -static int -get_rpq_address(unsigned char *buf, const int maxlen) +static int get_rpq_address(H3270 *hSession, unsigned char *buf, const int maxlen) { struct rpq_keyword *kw; int x = 0; if (maxlen < 2) { - omit_due_space_limit = True; + hSession->omit_due_space_limit = 1; return 0; } @@ -622,7 +621,7 @@ get_rpq_address(unsigned char *buf, const int maxlen) len = sizeof(struct in6_addr); break; default: - rpq_warning("RPQ ADDRESS term has unrecognized family %u",res->ai_family); + rpq_warning(hSession, _("RPQ ADDRESS term has unrecognized family %u"),res->ai_family); break; } @@ -630,12 +629,12 @@ get_rpq_address(unsigned char *buf, const int maxlen) x += len; (void) memcpy(buf, src, len); } else { - rpq_warning("RPQ ADDRESS term incomplete due to space limit"); + rpq_warning(hSession, _("RPQ ADDRESS term incomplete due to space limit")); } /* Give back storage obtained by getaddrinfo */ freeaddrinfo(res); } else { - rpq_warning("RPQ: can't resolve '%s': %s",rpqtext, gai_strerror(ga_err)); + rpq_warning(hSession, _("RPQ: can't resolve '%s': %s"),rpqtext, gai_strerror(ga_err)); } #else /*][*/ /* @@ -648,7 +647,7 @@ get_rpq_address(unsigned char *buf, const int maxlen) h = gethostbyname(rpqtext); if (h == NULL || h->h_addrtype != AF_INET) { - rpq_warning("RPQ: gethostbyname error"); + rpq_warning(hSession, _("RPQ: gethostbyname error")); return 0; } (void) memcpy(&ia, h->h_addr_list[0], h->h_length); @@ -659,7 +658,7 @@ get_rpq_address(unsigned char *buf, const int maxlen) (void) memcpy(buf, &ia, sizeof(in_addr_t)); x += sizeof(in_addr_t); } else { - rpq_warning("RPQ ADDRESS term incomplete due to space limit"); + rpq_warning(hSession, _("RPQ ADDRESS term incomplete due to space limit")); } #endif // HAVE_GETADDRINFO free(rpqtext); @@ -676,7 +675,7 @@ get_rpq_address(unsigned char *buf, const int maxlen) void *src = NULL; int len = 0; - if(net_getsockname(&h3270, &u, &addrlen) < 0) + if(net_getsockname(hSession, &u, &addrlen) < 0) return 0; SET16(buf, u.sa.sa_family); x += 2; @@ -692,14 +691,14 @@ get_rpq_address(unsigned char *buf, const int maxlen) break; #endif // HAVE_GETADDRINFO default: - rpq_warning("RPQ ADDRESS term has unrecognized family %u", u.sa.sa_family); + rpq_warning(hSession, _("RPQ ADDRESS term has unrecognized family %u"), u.sa.sa_family); break; } if (x + len <= maxlen) { (void) memcpy(buf, src, len); x += len; } else { - rpq_warning("RPQ ADDRESS term incomplete due to space limit"); + rpq_warning(hSession, _("RPQ ADDRESS term incomplete due to space limit")); } } return x; @@ -707,51 +706,51 @@ get_rpq_address(unsigned char *buf, const int maxlen) #endif /*]*/ #define RPQ_WARNBUF_SIZE 1024 -static char * rpq_warnbuf = CN; -static int rpq_wbcnt = 0; +//static char * rpq_warnbuf = CN; +//static int rpq_wbcnt = 0; -static void rpq_warning(const char *fmt, ...) +static void rpq_warning(H3270 *hSession, const char *fmt, ...) { va_list a; va_start(a, fmt); - lib3270_write_va_log(&h3270,"RPQ",fmt,a); + lib3270_write_va_log(hSession,"RPQ",fmt,a); va_end(a); /* * Only accumulate RPQ warnings if they * have not been displayed already. */ - if (!rpq_complained) + if (!hSession->rpq_complained) { va_start(a, fmt); - if (rpq_warnbuf == CN) - rpq_warnbuf = lib3270_malloc(RPQ_WARNBUF_SIZE); + if (hSession->rpq_warnbuf == CN) + hSession->rpq_warnbuf = lib3270_malloc(RPQ_WARNBUF_SIZE); - if (rpq_wbcnt < RPQ_WARNBUF_SIZE) + if (hSession->rpq_wbcnt < RPQ_WARNBUF_SIZE) { - *(rpq_warnbuf + rpq_wbcnt++) = '\n'; - *(rpq_warnbuf + rpq_wbcnt) = '\0'; + *(hSession->rpq_warnbuf + hSession->rpq_wbcnt++) = '\n'; + *(hSession->rpq_warnbuf + hSession->rpq_wbcnt) = '\0'; } - if (rpq_wbcnt < RPQ_WARNBUF_SIZE) + if (hSession->rpq_wbcnt < RPQ_WARNBUF_SIZE) { - rpq_wbcnt += vsnprintf(rpq_warnbuf + rpq_wbcnt,RPQ_WARNBUF_SIZE - rpq_wbcnt, fmt, a); + hSession->rpq_wbcnt += vsnprintf(hSession->rpq_warnbuf + hSession->rpq_wbcnt,RPQ_WARNBUF_SIZE - hSession->rpq_wbcnt, fmt, a); } va_end(a); } } -static void rpq_dump_warnings(void) +static void rpq_dump_warnings(H3270 *hSession) { /* If there's something to complain about, only complain once. */ - if (!rpq_complained && rpq_wbcnt) + if (!hSession->rpq_complained && hSession->rpq_wbcnt) { - popup_an_error(NULL,rpq_warnbuf); - rpq_wbcnt = 0; - rpq_complained = True; + popup_an_error(hSession,hSession->rpq_warnbuf); + hSession->rpq_wbcnt = 0; + hSession->rpq_complained = 1; - free(rpq_warnbuf); - rpq_warnbuf = CN; + lib3270_free(hSession->rpq_warnbuf); + hSession->rpq_warnbuf = CN; } } diff --git a/src/lib3270/telnet.c b/src/lib3270/telnet.c index d805a43..53a1e2b 100644 --- a/src/lib3270/telnet.c +++ b/src/lib3270/telnet.c @@ -2230,11 +2230,10 @@ static void cooked_init(H3270 *hSession) hSession->backslashed = 0; } -static void -ansi_process_s(const char *data) +static void ansi_process_s(H3270 *hSession, const char *data) { while (*data) - ansi_process(&h3270,(unsigned int) *data++); + ansi_process(hSession,(unsigned int) *data++); } static void forward_data(H3270 *hSession) @@ -2253,10 +2252,10 @@ static void do_data(H3270 *hSession, char c) if (c == '\t') ansi_process(hSession,(unsigned int) c); else - ansi_process_s(ctl_see((int) c)); + ansi_process_s(hSession,ctl_see((int) c)); } else - ansi_process_s("\007"); + ansi_process_s(hSession,"\007"); hSession->lnext = 0; hSession->backslashed = 0; @@ -2269,7 +2268,7 @@ static void do_intr(H3270 *hSession, char c) do_data(hSession,c); return; } - ansi_process_s(ctl_see((int) c)); + ansi_process_s(hSession,ctl_see((int) c)); cooked_init(hSession); net_interrupt(hSession); } @@ -2281,7 +2280,7 @@ static void do_quit(H3270 *hSession, char c) do_data(hSession,c); return; } - ansi_process_s(ctl_see((int) c)); + ansi_process_s(hSession,ctl_see((int) c)); cooked_init(hSession); net_break(hSession); } @@ -2293,7 +2292,7 @@ static void do_cerase(H3270 *hSession, char c) if (hSession->backslashed) { hSession->lbptr--; - ansi_process_s("\b"); + ansi_process_s(hSession,"\b"); do_data(hSession,c); return; } @@ -2309,7 +2308,7 @@ static void do_cerase(H3270 *hSession, char c) len = strlen(ctl_see((int) *--hSession->lbptr)); while (len--) - ansi_process_s("\b \b"); + ansi_process_s(hSession,"\b \b"); } } @@ -2339,7 +2338,7 @@ static void do_werase(H3270 *hSession, char c) len = strlen(ctl_see((int) ch)); while (len--) - ansi_process_s("\b \b"); + ansi_process_s(hSession,"\b \b"); } } @@ -2347,9 +2346,10 @@ static void do_kill(H3270 *hSession, char c) { int i, len; - if (hSession->backslashed) { + if (hSession->backslashed) + { hSession->lbptr--; - ansi_process_s("\b"); + ansi_process_s(hSession,"\b"); do_data(hSession,c); return; } @@ -2365,7 +2365,7 @@ static void do_kill(H3270 *hSession, char c) len = strlen(ctl_see((int) *--hSession->lbptr)); for (i = 0; i < len; i++) - ansi_process_s("\b \b"); + ansi_process_s(hSession,"\b \b"); } } @@ -2379,10 +2379,10 @@ static void do_rprnt(H3270 *hSession, char c) return; } - ansi_process_s(ctl_see((int) c)); - ansi_process_s("\r\n"); + ansi_process_s(hSession,ctl_see((int) c)); + ansi_process_s(hSession,"\r\n"); for (p = hSession->lbuf; p < hSession->lbptr; p++) - ansi_process_s(ctl_see((int) *p)); + ansi_process_s(hSession,ctl_see((int) *p)); } static void do_eof(H3270 *hSession, char c) @@ -2390,7 +2390,7 @@ static void do_eof(H3270 *hSession, char c) if (hSession->backslashed) { hSession->lbptr--; - ansi_process_s("\b"); + ansi_process_s(hSession,"\b"); do_data(hSession,c); return; } @@ -2415,13 +2415,13 @@ static void do_eol(H3270 *hSession, char c) if (hSession->lbptr+2 >= hSession->lbuf + BUFSZ) { - ansi_process_s("\007"); + ansi_process_s(hSession,"\007"); return; } *hSession->lbptr++ = '\r'; *hSession->lbptr++ = '\n'; - ansi_process_s("\r\n"); + ansi_process_s(hSession,"\r\n"); forward_data(hSession); } @@ -2433,7 +2433,7 @@ static void do_lnext(H3270 *hSession, char c) return; } hSession->lnext = 1; - ansi_process_s("^\b"); + ansi_process_s(hSession,"^\b"); } #endif /*]*/ -- libgit2 0.21.2