From d0b858337543d62ff6a6abbf7fe1a69cd38b8e3c Mon Sep 17 00:00:00 2001 From: perry.werneck@gmail.com Date: Mon, 24 Aug 2015 18:52:23 +0000 Subject: [PATCH] Incluindo suporte à chamada de ações pelo nome (para uso em scripts) --- actions.c | 143 ++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------------------- sources.mak | 2 +- 2 files changed, 45 insertions(+), 100 deletions(-) diff --git a/actions.c b/actions.c index 82d7e5f..bdf830e 100644 --- a/actions.c +++ b/actions.c @@ -18,122 +18,67 @@ * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA, 02111-1307, USA * - * Este programa está nomeado como actions.c e possui 877 linhas de código. + * Este programa está nomeado como actions.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) - * licinio@bb.com.br (Licínio Luis Branco) - * kraucer@bb.com.br (Kraucer Fernandes Mazuco) - * macmiranda@bb.com.br (Marco Aurélio Caldas Miranda) * */ -/* - * actions.c - * The X actions table and action debugging code. - */ - #include "globals.h" -#include "appres.h" +#include -#include "actionsc.h" -#include "hostc.h" -#include "kybdc.h" -#include "popupsc.h" -#include "printc.h" -#include "resources.h" -#include "togglesc.h" -#include "trace_dsc.h" -#include "utilc.h" -#include "xioc.h" +/*---[ Globals ]--------------------------------------------------------------------------------------------------------------*/ -#if defined(X3270_FT) /*[*/ -#include "ftc.h" -#endif /*]*/ -// #if defined(X3270_DISPLAY) -// #include "keypadc.h" -//#endif -#if defined(X3270_DISPLAY) || defined(C3270) || defined(WC3270) /*[*/ -#include "screenc.h" -#endif /*]*/ +/*---[ Statics ]--------------------------------------------------------------------------------------------------------------*/ -#error Deprecated +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ -/* +/** + * @brief Launch an action by name. + * + */ +LIB3270_EXPORT int lib3270_action(H3270 *hSession, const char *name) +{ + #undef DECLARE_LIB3270_ACTION + #undef DECLARE_LIB3270_CLEAR_SELECTION_ACTION + #undef DECLARE_LIB3270_KEY_ACTION + #undef DECLARE_LIB3270_CURSOR_ACTION + #undef DECLARE_LIB3270_FKEY_ACTION -#if defined(X3270_DISPLAY) -#include + #define DECLARE_LIB3270_ACTION( name ) { #name, lib3270_ ## name }, + #define DECLARE_LIB3270_CLEAR_SELECTION_ACTION( name ) { #name, lib3270_ ## name }, + #define DECLARE_LIB3270_KEY_ACTION( name ) { #name, lib3270_ ## name }, + #define DECLARE_LIB3270_CURSOR_ACTION( name ) { #name, lib3270_cursor_ ## name }, + #define DECLARE_LIB3270_FKEY_ACTION( name ) // name -#define MODMAP_SIZE 8 -#define MAP_SIZE 13 -#define MAX_MODS_PER 4 -static struct { - const char *name[MAX_MODS_PER]; - unsigned int mask; - Boolean is_meta; -} skeymask[MAP_SIZE] = { - { { "Shift" }, ShiftMask, False }, - { { (char *)NULL } //, LockMask, False }, - { { "Ctrl" }, ControlMask, False }, - { { CN }, Mod1Mask, False }, - { { CN }, Mod2Mask, False }, - { { CN }, Mod3Mask, False }, - { { CN }, Mod4Mask, False }, - { { CN }, Mod5Mask, False }, - { { "Button1" }, Button1Mask, False }, - { { "Button2" }, Button2Mask, False }, - { { "Button3" }, Button3Mask, False }, - { { "Button4" }, Button4Mask, False }, - { { "Button5" }, Button5Mask, False } -}; -static Boolean know_mods = False; -#endif */ + static const struct _action + { + const char * name; + int (*call)(H3270 *h); + } action[] = + { + #include + }; -/* Actions that are aliases for other actions. */ -/* -static char *aliased_actions[] = { - "Close", "HardPrint", "Open", NULL -}; -*/ + size_t f; -/* -enum iaction ia_cause; -const char *ia_name[] = { - "String", "Paste", "Screen redraw", "Keypad", "Default", "Key", - "Macro", "Script", "Peek", "Typeahead", "File transfer", "Command", - "Keymap", "Idle" -}; -*/ + CHECK_SESSION_HANDLE(hSession); -/* - * Return a name for an action. - */ /* -const char * action_name(XtActionProc action) -{ - // TODO (perry#1#): Remove all calls to action_name; move all action processing to main program. - return "Action"; -} -*/ -/* - * Check the number of argument to an action, and possibly pop up a usage - * message. - * - * Returns 0 if the argument count is correct, -1 otherwise. - */ /* -int -check_usage(XtActionProc action, Cardinal nargs, Cardinal nargs_min, - Cardinal nargs_max) -{ - if (nargs >= nargs_min && nargs <= nargs_max) - return 0; - if (nargs_min == nargs_max) - popup_an_error("Action requires %d argument%s",action, nargs_min, nargs_min == 1 ? "" : "s"); - else - popup_an_error("Action requires %d or %d arguments",nargs_min, nargs_max); -// cancel_if_idle_command(); - return -1; -} */ + for(f=0; f< (sizeof(action)/sizeof(action[0])); f++) + { + if(!strcasecmp(name,action[f].name)) + { + lib3270_trace_event(hSession,"Action %s activated\n",name); + return action[f].call(hSession); + } + + } + lib3270_trace_event(hSession,"Unknown action %s\n",name); + errno = ENOENT; + return -1; +} diff --git a/sources.mak b/sources.mak index f58a492..d885cd1 100644 --- a/sources.mak +++ b/sources.mak @@ -28,7 +28,7 @@ TERMINAL_SOURCES = bounds.c ctlr.c util.c toggles.c screen.c selection.c kybd.c telnet.c \ host.c sf.c ansi.c resolver.c charset.c \ version.c session.c state.c html.c trace_ds.c see.c \ - paste.c ssl.c + paste.c ssl.c actions.c # tables.c utf8.c -- libgit2 0.21.2