From 1ad4d6e6057227851a2194bf45d27aa8580c76fb Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 4 Sep 2019 15:24:04 -0300 Subject: [PATCH] Refacoring toggle engine. --- Makefile.in | 1 + lib3270.cbp | 11 ++++++++++- src/core/bounds.c | 2 +- src/core/ft/ft.c | 2 +- src/core/keyboard/kybd.c | 4 ++-- src/core/paste.c | 4 ++-- src/core/session.c | 2 +- src/core/state.c | 7 +------ src/core/toggles.c | 511 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/core/toggles/getset.c | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/toggles/init.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/toggles/listener.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/toggles/table.c | 342 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/core/util.c | 2 +- src/core/wait.c | 6 +++--- src/include/lib3270-internals.h | 2 +- src/include/lib3270/toggle.h | 16 +++++++++++++++- src/include/togglesc.h | 4 ++++ src/selection/actions.c | 4 ++-- src/selection/selection.c | 4 ++-- 20 files changed, 745 insertions(+), 535 deletions(-) delete mode 100644 src/core/toggles.c create mode 100644 src/core/toggles/getset.c create mode 100644 src/core/toggles/init.c create mode 100644 src/core/toggles/listener.c create mode 100644 src/core/toggles/table.c diff --git a/Makefile.in b/Makefile.in index c223eea..39c2fb5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -34,6 +34,7 @@ SOURCES= \ $(wildcard src/core/*.c) \ $(wildcard src/core/keyboard/*.c) \ $(wildcard src/core/actions/*.c) \ + $(wildcard src/core/toggles/*.c) \ $(wildcard src/core/ft/*.c) \ $(wildcard src/core/@OSNAME@/*.rc) \ $(wildcard src/core/@OSNAME@/*.c) \ diff --git a/lib3270.cbp b/lib3270.cbp index 51b0c27..e5442c6 100644 --- a/lib3270.cbp +++ b/lib3270.cbp @@ -167,7 +167,16 @@ - + + + + + + + diff --git a/src/core/bounds.c b/src/core/bounds.c index 9788337..46f26a1 100644 --- a/src/core/bounds.c +++ b/src/core/bounds.c @@ -76,7 +76,7 @@ LIB3270_EXPORT int lib3270_get_word_bounds(H3270 *session, int baddr, int *start CHECK_SESSION_HANDLE(session); - if(!lib3270_connected(session) || isspace(session->text[baddr].chr)) + if(!lib3270_is_connected(session) || isspace(session->text[baddr].chr)) return -1; if(start) diff --git a/src/core/ft/ft.c b/src/core/ft/ft.c index a825e2a..f8dcf04 100644 --- a/src/core/ft/ft.c +++ b/src/core/ft/ft.c @@ -262,7 +262,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state); // unsigned long length = 0L; // trace("%s(%s)",__FUNCTION__,local); - if(!lib3270_connected(session)) + if(!lib3270_is_connected(session)) { return ft_creation_failed(session,ENOTCONN,message,_( "Disconnected from host." )); } diff --git a/src/core/keyboard/kybd.c b/src/core/keyboard/kybd.c index 69cb8c5..a347773 100644 --- a/src/core/keyboard/kybd.c +++ b/src/core/keyboard/kybd.c @@ -135,7 +135,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type) struct ta *ta; // If no connection, forget it. - if (!lib3270_connected(hSession)) + if (!lib3270_is_connected(hSession)) { lib3270_ring_bell(hSession); lib3270_trace_event(hSession,"typeahead action dropped (not connected)\n"); @@ -2241,7 +2241,7 @@ LIB3270_EXPORT LIB3270_KEYBOARD_LOCK_STATE lib3270_wait_for_keyboard_unlock(H327 do { - if(!lib3270_connected(hSession)) + if(!lib3270_is_connected(hSession)) return LIB3270_KL_NOT_CONNECTED; if(KYBDLOCK_IS_OERR(hSession)) diff --git a/src/core/paste.c b/src/core/paste.c index 3a098ab..b78520a 100644 --- a/src/core/paste.c +++ b/src/core/paste.c @@ -323,7 +323,7 @@ LIB3270_EXPORT int lib3270_paste_text(H3270 *h, const unsigned char *str) int sz; CHECK_SESSION_HANDLE(h); - if(!lib3270_connected(h)) + if(!lib3270_is_connected(h)) { lib3270_ring_bell(h); errno = ENOTCONN; @@ -363,7 +363,7 @@ LIB3270_EXPORT int lib3270_paste_next(H3270 *hSession) FAIL_IF_NOT_ONLINE(hSession); - if(!(lib3270_connected(hSession) && hSession->paste_buffer)) + if(!(lib3270_is_connected(hSession) && hSession->paste_buffer)) { lib3270_ring_bell(hSession); return 0; diff --git a/src/core/session.c b/src/core/session.c index 119abf4..56735e6 100644 --- a/src/core/session.c +++ b/src/core/session.c @@ -70,7 +70,7 @@ void lib3270_session_free(H3270 *h) return; // Terminate session - if(lib3270_connected(h)) + if(lib3270_is_connected(h)) lib3270_disconnect(h); shutdown_toggles(h); diff --git a/src/core/state.c b/src/core/state.c index a7bbe1b..d675f65 100644 --- a/src/core/state.c +++ b/src/core/state.c @@ -46,11 +46,6 @@ LIB3270_EXPORT int lib3270_half_connected(const H3270 *h) return (h->cstate == LIB3270_RESOLVING || h->cstate == LIB3270_PENDING); } -LIB3270_EXPORT int lib3270_connected(const H3270 *h) -{ - return ((int) h->cstate >= (int)LIB3270_CONNECTED_INITIAL); -} - LIB3270_EXPORT int lib3270_is_disconnected(const H3270 *h) { return ((int) h->cstate == (int)LIB3270_NOT_CONNECTED); @@ -83,7 +78,7 @@ LIB3270_EXPORT int lib3270_in_tn3270e(const H3270 *h) LIB3270_EXPORT int lib3270_is_connected(const H3270 *h) { - return (h->cstate == LIB3270_CONNECTED_TN3270E); + return ((int) h->cstate >= (int)LIB3270_CONNECTED_INITIAL); } LIB3270_EXPORT int lib3270_in_e(const H3270 *h) diff --git a/src/core/toggles.c b/src/core/toggles.c deleted file mode 100644 index aace715..0000000 --- a/src/core/toggles.c +++ /dev/null @@ -1,511 +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. 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 toggles.c e possui - linhas de código. - * - * Contatos: - * - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) - * - */ - - -/** - * @file toggles.c - * @brief This module handles toggles. - */ - -#include -#include - -#ifdef WIN32 - #include - #include - #include -#else - #include -#endif // !WIN32 - -#include -#include -#include - -#include "ansic.h" -#include "ctlrc.h" -#include "popupsc.h" -#include "screenc.h" -#include "trace_dsc.h" -#include "togglesc.h" -#include "utilc.h" -#include - -static const struct _toggle_info -{ - const char * name; ///< @brief Toggle name. - const char def; ///< @brief Default value. - const char * label; ///< @brief Button label. - const char * summary; ///< @brief Short description. - const char * description; ///< @brief Toggle description. -} -toggle_info[LIB3270_TOGGLE_COUNT] = -{ - { - "monocase", - False, - N_( "Monocase" ), - N_( "Uppercase only" ), - N_( "If set, the terminal operates in uppercase-only mode" ) - }, - { - "cursorblink", - True, - N_( "Blinking Cursor" ), - N_( "Blinking Cursor" ), - N_( "If set, the cursor blinks" ) - }, - { - "showtiming", - True, - N_( "Show timer when processing" ), - N_( "Show timer when processing" ), - N_( "If set, the time taken by the host to process an AID is displayed on the status line" ) - }, - { - "cursorpos", - True, - N_( "Track Cursor" ), - N_( "Track Cursor" ), - N_( "Display the cursor location in the OIA (the status line)" ) - }, - { - "dstrace", - False, - N_( "Data Stream" ), - N_( "Trace Data Stream" ), - "" - }, - { - "linewrap", - False, - N_("Wrap around"), - N_("Wrap around"), - N_("If set, the NVT terminal emulator automatically assumes a NEWLINE character when it reaches the end of a line.") - }, - { - "blankfill", - False, - N_( "Blank Fill" ), - N_( "Blank Fill" ), - N_( "Automatically convert trailing blanks in a field to NULLs in order to insert a character, and will automatically convert leading NULLs to blanks so that input data is not squeezed to the left" ) - }, - { - "screentrace", - False, - N_( "Screens" ), - N_( "Trace screen contents" ), - "" - }, - { - "eventtrace", - False, - N_( "Events" ), - N_( "Trace interface and application events" ), - "" - }, - { - "marginedpaste", - False, - N_( "Paste with left margin" ), - N_( "Paste with left margin" ), - N_( "If set, puts restrictions on how pasted text is placed on the screen. The position of the cursor at the time the paste operation is begun is used as a left margin. No pasted text will fill any area of the screen to the left of that position. This option is useful for pasting into certain IBM editors that use the left side of the screen for control information" ) - }, - { - "rectselect", - False, - N_( "Select by rectangles" ), - N_( "Select by rectangles" ), - N_( "If set, the terminal will always select rectangular areas of the screen. Otherwise, it selects continuous regions of the screen" ) - }, - { - "crosshair", - False, - N_( "Cross hair cursor" ), - N_( "Cross hair cursor" ), - N_( "If set, the terminal will display a crosshair over the cursor: lines extending the full width and height of the screen, centered over the cursor position. This makes locating the cursor on the screen much easier" ) - }, - { - "fullscreen", - False, - N_( "Full Screen" ), - N_( "Full Screen" ), - N_( "If set, asks to place the toplevel window in the fullscreen state" ) - }, - { - "reconnect", - False, - N_( "Auto-Reconnect" ), - N_( "Auto-Reconnect" ), - N_( "Automatically reconnect to the host if it ever disconnects" ) - }, - { - "insert", - False, - N_( "Insert" ), - N_( "Set insert mode" ), - "" - }, - { - "smartpaste", - False, - N_( "Smart paste" ), - N_( "Smart paste" ), - "" - }, - { - "bold", - False, - N_( "Bold" ), - N_( "Bold" ), - "" - }, - { - "keepselected", - False, - N_( "Keep selected" ), - N_( "Keep selected" ), - "" - }, - { - "underline", - False, - N_( "Underline" ), - N_( "Show Underline" ), - "" - }, - { - "autoconnect", - False, - N_( "Auto connect" ), - N_( "Connect on startup" ), - "" - }, - { - "kpalternative", - False, - N_( "Use +/- for field navigation" ), - N_( "Use +/- for field navigation" ), - N_( "Use the keys +/- from keypad to select editable fields" ) - }, - { - "beep", - True, - N_( "Sound" ), - N_( "Alert sound" ), - N_( "Beep on errors" ) - }, - { - "fieldattr", - False, - N_( "Show Field" ), - N_( "Show Field attribute" ), - "" - }, - { - "altscreen", - True, - N_( "Alternate screen" ), - N_( "Resize on alternate screen" ), - N_( "Auto resize on altscreen" ) - }, - { - "keepalive", - True, - N_( "Network keep alive" ), - N_( "Network keep alive" ), - N_( "Enable network keep-alive with SO_KEEPALIVE" ) - }, - { - "nettrace", - False, - N_( "Network data" ), - N_( "Trace network data flow" ), - N_( "Enable network in/out trace" ) - }, - { - "ssltrace", - False, - N_( "SSL negotiation" ), - N_( "Trace SSL negotiation" ), - N_( "Enable security negotiation messages trace" ) - }, -}; - -LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix) -{ - CHECK_SESSION_HANDLE(session); - - if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) - return 0; - - return session->toggle[ix].value != 0; -} - -/** - * @brief Call the internal update routine and listeners. - */ -static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE ix) -{ - struct lib3270_toggle_callback * st; - - trace("%s: ix=%d upcall=%p",__FUNCTION__,ix,t->upcall); - t->upcall(session, t, LIB3270_TOGGLE_TYPE_INTERACTIVE); - - if(session->cbk.update_toggle) - session->cbk.update_toggle(session,ix,t->value,LIB3270_TOGGLE_TYPE_INTERACTIVE,toggle_info[ix].name); - - for(st = session->listeners.toggle.callbacks[ix]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next) - { - st->func(session, ix, t->value, st->data); - } - -} - -/** - * @brief Set toggle state. - * - * @param h Session handle. - * @param ix Toggle id. - * @param value New toggle state (non zero for true). - * - * @returns 0 if the toggle is already at the state, 1 if the toggle was changed; < 0 on error (sets errno). - */ -LIB3270_EXPORT int lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int value) -{ - char v = value ? True : False; - struct lib3270_toggle * t; - - CHECK_SESSION_HANDLE(session); - - if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) - return -(errno = EINVAL); - - t = &session->toggle[ix]; - - if(v == t->value) - return 0; - - t->value = v; - - toggle_notify(session,t,ix); - return 1; -} - -LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE ix) -{ - struct lib3270_toggle *t; - - CHECK_SESSION_HANDLE(session); - - if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) - return 0; - - t = &session->toggle[ix]; - - t->value = t->value ? False : True; - toggle_notify(session,t,ix); - - return (int) t->value; -} - -static void toggle_altscreen(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) -{ - if(!session->screen_alt) - set_viewsize(session,t->value ? 24 : session->max.rows,80); -} - -static void toggle_redraw(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) -{ - session->cbk.display(session); -} - -/** - * @brief No-op toggle. - */ -static void toggle_nop(H3270 GNUC_UNUSED(*session), struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) -{ -} - -static void toggle_keepalive(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) -{ - if(session->sock > 0) - { - // Update keep-alive option - int optval = t->value ? 1 : 0; - - if (setsockopt(session->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) - { - popup_a_sockerr(session, N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); - } - else - { - trace_dsn(session,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" ); - } - - } -} - -/** - * @brief Called from system initialization code to handle initial toggle settings. - */ -void initialize_toggles(H3270 *session) -{ - int f; - - for(f=0;ftoggle[f].upcall = toggle_nop; - - session->toggle[LIB3270_TOGGLE_RECTANGLE_SELECT].upcall = toggle_rectselect; - session->toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_redraw; - session->toggle[LIB3270_TOGGLE_UNDERLINE].upcall = toggle_redraw; - session->toggle[LIB3270_TOGGLE_ALTSCREEN].upcall = toggle_altscreen; - session->toggle[LIB3270_TOGGLE_KEEP_ALIVE].upcall = toggle_keepalive; - - for(f=0;ftoggle[f].value = toggle_info[f].def; - if(session->toggle[f].value) - session->toggle[f].upcall(session,&session->toggle[f],LIB3270_TOGGLE_TYPE_INITIAL); - } - -} - -/** - * @brief Called from system exit code to handle toggles. - */ -void shutdown_toggles(H3270 *session) -{ -#if defined(X3270_TRACE) - static const LIB3270_TOGGLE disable_on_shutdown[] = {LIB3270_TOGGLE_DS_TRACE, LIB3270_TOGGLE_EVENT_TRACE, LIB3270_TOGGLE_SCREEN_TRACE}; - - size_t f; - - for(f=0;f< (sizeof(disable_on_shutdown)/sizeof(disable_on_shutdown[0])); f++) - lib3270_set_toggle(session,disable_on_shutdown[f],0); - -#endif -} - -LIB3270_EXPORT const char * lib3270_get_toggle_summary(LIB3270_TOGGLE ix) -{ - if(ix < LIB3270_TOGGLE_COUNT) - return toggle_info[ix].summary; - return ""; -} - -LIB3270_EXPORT const char * lib3270_get_toggle_label(LIB3270_TOGGLE ix) -{ - if(ix < LIB3270_TOGGLE_COUNT) - return toggle_info[ix].label; - return ""; -} - - -LIB3270_EXPORT const char * lib3270_get_toggle_description(LIB3270_TOGGLE ix) -{ - if(ix < LIB3270_TOGGLE_COUNT) - return toggle_info[ix].description; - return ""; -} - -LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE ix) -{ - if(ix < LIB3270_TOGGLE_COUNT) - return toggle_info[ix].name; - return ""; -} - -LIB3270_EXPORT LIB3270_TOGGLE lib3270_get_toggle_id(const char *name) -{ - if(name) - { - int f; - for(f=0;ffunc = func; - st->data = data; - - if (hSession->listeners.toggle.last[tx]) - hSession->listeners.toggle.last[tx]->next = st; - else - hSession->listeners.toggle.callbacks[tx] = st; - - hSession->listeners.toggle.last[tx] = st; - - return (void *) st; - -} - -LIB3270_EXPORT int lib3270_unregister_toggle_listener(H3270 *hSession, LIB3270_TOGGLE tx, const void *id) -{ - struct lib3270_toggle_callback *st; - struct lib3270_toggle_callback *prev = (struct lib3270_toggle_callback *) NULL; - - for (st = hSession->listeners.toggle.callbacks[tx]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next) - { - if (st == (struct lib3270_toggle_callback *)id) - break; - - prev = st; - } - - if (st == (struct lib3270_toggle_callback *)NULL) - { - lib3270_write_log(hSession,"lib3270","Invalid call to (%s): %p wasnt found in the list",__FUNCTION__,id); - return errno = ENOENT; - } - - if (prev != (struct lib3270_toggle_callback *) NULL) - prev->next = st->next; - else - hSession->listeners.toggle.callbacks[tx] = (struct lib3270_toggle_callback *) st->next; - - for(st = hSession->listeners.toggle.callbacks[tx]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next) - hSession->listeners.toggle.last[tx] = st; - - lib3270_free((void *) id); - - return 0; - -} diff --git a/src/core/toggles/getset.c b/src/core/toggles/getset.c new file mode 100644 index 0000000..0e5de12 --- /dev/null +++ b/src/core/toggles/getset.c @@ -0,0 +1,120 @@ +/* + * "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. 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 - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + +/** + * @file toggles/getset.c + * @brief This module handles toggle changes. + */ + +#include +#include +#include +#include +#include "togglesc.h" + +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ + +LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix) +{ + CHECK_SESSION_HANDLE(session); + + if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) + return 0; + + return session->toggle[ix].value != 0; +} + +/** + * @brief Call the internal update routine and listeners. + */ +static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE ix) +{ + struct lib3270_toggle_callback * st; + + trace("%s: ix=%d upcall=%p",__FUNCTION__,ix,t->upcall); + t->upcall(session, t, LIB3270_TOGGLE_TYPE_INTERACTIVE); + + if(session->cbk.update_toggle) + session->cbk.update_toggle(session,ix,t->value,LIB3270_TOGGLE_TYPE_INTERACTIVE,toggle_descriptor[ix].name); + + for(st = session->listeners.toggle.callbacks[ix]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next) + { + st->func(session, ix, t->value, st->data); + } + +} + +/** + * @brief Set toggle state. + * + * @param h Session handle. + * @param ix Toggle id. + * @param value New toggle state (non zero for true). + * + * @returns 0 if the toggle is already at the state, 1 if the toggle was changed; < 0 on error (sets errno). + */ +LIB3270_EXPORT int lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int value) +{ + char v = value ? True : False; + struct lib3270_toggle * t; + + CHECK_SESSION_HANDLE(session); + + if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) + return -(errno = EINVAL); + + t = &session->toggle[ix]; + + if(v == t->value) + return 0; + + t->value = v; + + toggle_notify(session,t,ix); + return 1; +} + +LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE ix) +{ + struct lib3270_toggle *t; + + CHECK_SESSION_HANDLE(session); + + if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT) + return 0; + + t = &session->toggle[ix]; + + t->value = t->value ? False : True; + toggle_notify(session,t,ix); + + return (int) t->value; +} + diff --git a/src/core/toggles/init.c b/src/core/toggles/init.c new file mode 100644 index 0000000..b424d15 --- /dev/null +++ b/src/core/toggles/init.c @@ -0,0 +1,138 @@ +/* + * "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. 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 - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + +/** + * @file toggles/init.c + * @brief Initialize toggles. + */ + +#include +#include + +#ifdef WIN32 + #include + #include + #include +#else + #include +#endif // !WIN32 + +#include +#include +#include + +#include "ansic.h" +#include "ctlrc.h" +#include "popupsc.h" +#include "screenc.h" +#include "trace_dsc.h" +#include "togglesc.h" +#include "utilc.h" +#include + +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ + +static void toggle_altscreen(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) +{ + if(!session->screen_alt) + set_viewsize(session,t->value ? 24 : session->max.rows,80); +} + +static void toggle_redraw(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) +{ + session->cbk.display(session); +} + +/** + * @brief No-op toggle. + */ +static void toggle_nop(H3270 GNUC_UNUSED(*session), struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) +{ +} + +static void toggle_keepalive(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt)) +{ + if(session->sock > 0) + { + // Update keep-alive option + int optval = t->value ? 1 : 0; + + if (setsockopt(session->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0) + { + popup_a_sockerr(session, N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" )); + } + else + { + trace_dsn(session,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" ); + } + + } +} + +/** + * @brief Called from system initialization code to handle initial toggle settings. + */ +void initialize_toggles(H3270 *session) +{ + int f; + + for(f=0;ftoggle[f].upcall = toggle_nop; + + session->toggle[LIB3270_TOGGLE_RECTANGLE_SELECT].upcall = toggle_rectselect; + session->toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_redraw; + session->toggle[LIB3270_TOGGLE_UNDERLINE].upcall = toggle_redraw; + session->toggle[LIB3270_TOGGLE_ALTSCREEN].upcall = toggle_altscreen; + session->toggle[LIB3270_TOGGLE_KEEP_ALIVE].upcall = toggle_keepalive; + + for(f=0;ftoggle[f].value = toggle_descriptor[f].def; + if(session->toggle[f].value) + session->toggle[f].upcall(session,&session->toggle[f],LIB3270_TOGGLE_TYPE_INITIAL); + } + +} + +/** + * @brief Called from system exit code to handle toggles. + */ +void shutdown_toggles(H3270 *session) +{ +#if defined(X3270_TRACE) + static const LIB3270_TOGGLE disable_on_shutdown[] = {LIB3270_TOGGLE_DS_TRACE, LIB3270_TOGGLE_EVENT_TRACE, LIB3270_TOGGLE_SCREEN_TRACE}; + + size_t f; + + for(f=0;f< (sizeof(disable_on_shutdown)/sizeof(disable_on_shutdown[0])); f++) + lib3270_set_toggle(session,disable_on_shutdown[f],0); + +#endif +} diff --git a/src/core/toggles/listener.c b/src/core/toggles/listener.c new file mode 100644 index 0000000..ee870ad --- /dev/null +++ b/src/core/toggles/listener.c @@ -0,0 +1,98 @@ +/* + * "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. 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 - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + +/** + * @file toggles/listener.c + * @brief This module handles toggle listeners. + */ + +#include +#include +#include + +#include +#include +#include + +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ + +LIB3270_EXPORT const void * lib3270_register_toggle_listener(H3270 *hSession, LIB3270_TOGGLE tx, void (*func)(H3270 *, LIB3270_TOGGLE, char, void *),void *data) +{ + struct lib3270_toggle_callback *st; + + CHECK_SESSION_HANDLE(hSession); + + st = (struct lib3270_toggle_callback *) lib3270_malloc(sizeof(struct lib3270_toggle_callback)); + st->func = func; + st->data = data; + + if (hSession->listeners.toggle.last[tx]) + hSession->listeners.toggle.last[tx]->next = st; + else + hSession->listeners.toggle.callbacks[tx] = st; + + hSession->listeners.toggle.last[tx] = st; + + return (void *) st; + +} + +LIB3270_EXPORT int lib3270_unregister_toggle_listener(H3270 *hSession, LIB3270_TOGGLE tx, const void *id) +{ + struct lib3270_toggle_callback *st; + struct lib3270_toggle_callback *prev = (struct lib3270_toggle_callback *) NULL; + + for (st = hSession->listeners.toggle.callbacks[tx]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next) + { + if (st == (struct lib3270_toggle_callback *)id) + break; + + prev = st; + } + + if (st == (struct lib3270_toggle_callback *)NULL) + { + lib3270_write_log(hSession,"lib3270","Invalid call to (%s): %p wasnt found in the list",__FUNCTION__,id); + return errno = ENOENT; + } + + if (prev != (struct lib3270_toggle_callback *) NULL) + prev->next = st->next; + else + hSession->listeners.toggle.callbacks[tx] = (struct lib3270_toggle_callback *) st->next; + + for(st = hSession->listeners.toggle.callbacks[tx]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next) + hSession->listeners.toggle.last[tx] = st; + + lib3270_free((void *) id); + + return 0; + +} diff --git a/src/core/toggles/table.c b/src/core/toggles/table.c new file mode 100644 index 0000000..1610e39 --- /dev/null +++ b/src/core/toggles/table.c @@ -0,0 +1,342 @@ +/* + * "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. 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 - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + +/** + * @file toggles/init.c + * @brief Toggle description table. + */ + +#include +#include +#include +#include "togglesc.h" + +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ + +const LIB3270_TOGGLE_ENTRY toggle_descriptor[LIB3270_TOGGLE_COUNT+1] = +{ + { + "monocase", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Monocase" ), + N_( "Uppercase only" ), + N_( "If set, the terminal operates in uppercase-only mode" ) + }, + { + "cursorblink", + True, + NULL, // Default keycode + NULL, // Icon name + N_( "Blinking Cursor" ), + N_( "Blinking Cursor" ), + N_( "If set, the cursor blinks" ) + }, + { + "showtiming", + True, + NULL, // Default keycode + NULL, // Icon name + N_( "Show timer when processing" ), + N_( "Show timer when processing" ), + N_( "If set, the time taken by the host to process an AID is displayed on the status line" ) + }, + { + "cursorpos", + True, + NULL, // Default keycode + NULL, // Icon name + N_( "Track Cursor" ), + N_( "Track Cursor" ), + N_( "Display the cursor location in the OIA (the status line)" ) + }, + { + "dstrace", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Data Stream" ), + N_( "Trace Data Stream" ), + "" + }, + { + "linewrap", + False, + NULL, // Default keycode + NULL, // Icon name + N_("Wrap around"), + N_("Wrap around"), + N_("If set, the NVT terminal emulator automatically assumes a NEWLINE character when it reaches the end of a line.") + }, + { + "blankfill", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Blank Fill" ), + N_( "Blank Fill" ), + N_( "Automatically convert trailing blanks in a field to NULLs in order to insert a character, and will automatically convert leading NULLs to blanks so that input data is not squeezed to the left" ) + }, + { + "screentrace", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Screens" ), + N_( "Trace screen contents" ), + "" + }, + { + "eventtrace", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Events" ), + N_( "Trace interface and application events" ), + "" + }, + { + "marginedpaste", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Paste with left margin" ), + N_( "Paste with left margin" ), + N_( "If set, puts restrictions on how pasted text is placed on the screen. The position of the cursor at the time the paste operation is begun is used as a left margin. No pasted text will fill any area of the screen to the left of that position. This option is useful for pasting into certain IBM editors that use the left side of the screen for control information" ) + }, + { + "rectselect", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Select by rectangles" ), + N_( "Select by rectangles" ), + N_( "If set, the terminal will always select rectangular areas of the screen. Otherwise, it selects continuous regions of the screen" ) + }, + { + "crosshair", + False, + "x", // Default keycode + NULL, // Icon name + N_( "Cross hair cursor" ), + N_( "Cross hair cursor" ), + N_( "If set, the terminal will display a crosshair over the cursor: lines extending the full width and height of the screen, centered over the cursor position. This makes locating the cursor on the screen much easier" ) + }, + { + "fullscreen", + False, + "Home", // Default keycode + NULL, // Icon name + N_( "Full Screen" ), + N_( "Full Screen" ), + N_( "If set, asks to place the toplevel window in the fullscreen state" ) + }, + { + "reconnect", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Auto-Reconnect" ), + N_( "Auto-Reconnect" ), + N_( "Automatically reconnect to the host if it ever disconnects" ) + }, + { + "insert", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Insert" ), + N_( "Set insert mode" ), + "" + }, + { + "smartpaste", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Smart paste" ), + N_( "Smart paste" ), + "" + }, + { + "bold", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Bold" ), + N_( "Bold" ), + "" + }, + { + "keepselected", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Keep selected" ), + N_( "Keep selected" ), + "" + }, + { + "underline", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Underline" ), + N_( "Show Underline" ), + "" + }, + { + "autoconnect", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Auto connect" ), + N_( "Connect on startup" ), + "" + }, + { + "kpalternative", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Use +/- for field navigation" ), + N_( "Use +/- for field navigation" ), + N_( "Use the keys +/- from keypad to select editable fields" ) + }, + { + "beep", + True, + NULL, // Default keycode + NULL, // Icon name + N_( "Sound" ), + N_( "Alert sound" ), + N_( "Beep on errors" ) + }, + { + "fieldattr", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Show Field" ), + N_( "Show Field attributes" ), + "" + }, + { + "altscreen", + True, + NULL, // Default keycode + NULL, // Icon name + N_( "Alternate screen" ), + N_( "Resize on alternate screen" ), + N_( "Auto resize on altscreen" ) + }, + { + "keepalive", + True, + NULL, // Default keycode + NULL, // Icon name + N_( "Network keep alive" ), + N_( "Network keep alive" ), + N_( "Enable network keep-alive with SO_KEEPALIVE" ) + }, + { + "nettrace", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "Network data" ), + N_( "Trace network data flow" ), + N_( "Enable network in/out trace" ) + }, + { + "ssltrace", + False, + NULL, // Default keycode + NULL, // Icon name + N_( "SSL negotiation" ), + N_( "Trace SSL negotiation" ), + N_( "Enable security negotiation trace" ) + }, + + { + NULL, + 0, + NULL, + NULL, + NULL, + NULL, + NULL + } + +}; + +LIB3270_EXPORT const char * lib3270_get_toggle_summary(LIB3270_TOGGLE ix) +{ + if(ix < LIB3270_TOGGLE_COUNT) + return toggle_descriptor[ix].summary; + return ""; +} + +LIB3270_EXPORT const char * lib3270_get_toggle_label(LIB3270_TOGGLE ix) +{ + if(ix < LIB3270_TOGGLE_COUNT) + return toggle_descriptor[ix].label; + return ""; +} + + +LIB3270_EXPORT const char * lib3270_get_toggle_description(LIB3270_TOGGLE ix) +{ + if(ix < LIB3270_TOGGLE_COUNT) + return toggle_descriptor[ix].description; + return ""; +} + +LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE ix) +{ + if(ix < LIB3270_TOGGLE_COUNT) + return toggle_descriptor[ix].name; + return ""; +} + +LIB3270_EXPORT LIB3270_TOGGLE lib3270_get_toggle_id(const char *name) +{ + if(name) + { + int f; + for(f=0;fkybdlock && KYBDLOCK_IS_OERR(hSession)) return errno = EPERM; - if(!lib3270_connected(hSession)) + if(!lib3270_is_connected(hSession)) return errno = ENOTCONN; char * contents = lib3270_get_string_at_address(hSession, 0, -1, 0); @@ -120,7 +120,7 @@ int lib3270_wait_for_string_at_address(H3270 *hSession, int baddr, const char *k if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession)) return errno = EPERM; - if(!lib3270_connected(hSession)) + if(!lib3270_is_connected(hSession)) return errno = ENOTCONN; if(lib3270_cmp_string_at_address(hSession, baddr, key, 0) == 0) diff --git a/src/include/lib3270-internals.h b/src/include/lib3270-internals.h index cfcf557..f04a191 100644 --- a/src/include/lib3270-internals.h +++ b/src/include/lib3270-internals.h @@ -164,7 +164,7 @@ struct toggle_name { /// @brief State macros #define PCONNECTED lib3270_pconnected(hSession) #define HALF_CONNECTED lib3270_half_connected(hSession) -#define CONNECTED lib3270_connected(hSession) +#define CONNECTED lib3270_is_connected(hSession) #define IN_NEITHER lib3270_in_neither(hSession) #define IN_ANSI lib3270_in_ansi(hSession) diff --git a/src/include/lib3270/toggle.h b/src/include/lib3270/toggle.h index f68b51f..6daf6a4 100644 --- a/src/include/lib3270/toggle.h +++ b/src/include/lib3270/toggle.h @@ -37,6 +37,17 @@ extern "C" { #endif + typedef struct _lib3270_toggle_entry + { + const char *name; ///< @brief Toggle name. + const char def; ///< @brief Default value. + const char *key; ///< @brief Default key (or NULL if no default). + const char *icon; ///< @brief Icon name (from https://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html) + const char *label; ///< @brief Button label (or NULL). + const char *summary; ///< @brief Short description (or NULL). + const char *description; ///< @brief Toggle description. + } LIB3270_TOGGLE_ENTRY; + /** * @brief get toggle state. * @@ -56,6 +67,9 @@ * @param value New toggle state (non zero for true). * * @returns 0 if the toggle is already at the state, 1 if the toggle was changed; < 0 on error (sets errno). + * + * @retval -EINVAL Invalid toggle id. + * */ LIB3270_EXPORT int lib3270_set_toggle(H3270 *h, LIB3270_TOGGLE ix, int value); @@ -64,7 +78,7 @@ * * @param name Toggle name. * - * @return Toggle ID or -1 if it's invalid. + * @return Toggle ID or negative if it's invalid. * */ LIB3270_EXPORT LIB3270_TOGGLE lib3270_get_toggle_id(const char *name); diff --git a/src/include/togglesc.h b/src/include/togglesc.h index e1d4123..c881f8f 100644 --- a/src/include/togglesc.h +++ b/src/include/togglesc.h @@ -32,5 +32,9 @@ * @brief Global declarations for toggles.c. */ + #include + LIB3270_INTERNAL void initialize_toggles(H3270 *session); LIB3270_INTERNAL void shutdown_toggles(H3270 *session); + LIB3270_INTERNAL const LIB3270_TOGGLE_ENTRY toggle_descriptor[LIB3270_TOGGLE_COUNT+1]; + diff --git a/src/selection/actions.c b/src/selection/actions.c index 907d279..598bf3e 100644 --- a/src/selection/actions.c +++ b/src/selection/actions.c @@ -74,7 +74,7 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) CHECK_SESSION_HANDLE(session); - if(!lib3270_connected(session)) + if(!lib3270_is_connected(session)) return; start = session->selected ? session->select.start : session->cursor_addr; @@ -91,7 +91,7 @@ LIB3270_EXPORT int lib3270_select_region(H3270 *h, int start, int end) CHECK_SESSION_HANDLE(h); - if(!lib3270_connected(h)) + if(!lib3270_is_connected(h)) return ENOTCONN; maxlen = (h->view.rows * h->view.cols); diff --git a/src/selection/selection.c b/src/selection/selection.c index c0c2095..47cf8bf 100644 --- a/src/selection/selection.c +++ b/src/selection/selection.c @@ -206,7 +206,7 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba CHECK_SESSION_HANDLE(hSession); - if(!(lib3270_connected(hSession) && (hSession->text[baddr].attr & LIB3270_ATTR_SELECTED))) + if(!(lib3270_is_connected(hSession) && (hSession->text[baddr].attr & LIB3270_ATTR_SELECTED))) return rc; row = baddr / hSession->view.cols; @@ -282,7 +282,7 @@ LIB3270_EXPORT char * lib3270_get_string_at_address(H3270 *h, int offset, int le CHECK_SESSION_HANDLE(h); - if(!lib3270_connected(h)) + if(!lib3270_is_connected(h)) { errno = ENOTCONN; return NULL; -- libgit2 0.21.2