Commit 73f75e3f3cdf9ebcbcd6e9256d8b39744a679c7f

Authored by Perry Werneck
1 parent 29817c0e

Updating action table.

Showing 2 changed files with 29 additions and 43 deletions   Show diff stats
src/lib3270/actions.c
@@ -38,42 +38,50 @@ @@ -38,42 +38,50 @@
38 /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/ 38 /*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
39 39
40 /** 40 /**
41 - * @brief Launch an action by name. 41 + * @brief Get LIB3270 action table;
42 * 42 *
43 */ 43 */
44 -LIB3270_EXPORT int lib3270_action(H3270 *hSession, const char *name)  
45 -{ 44 + LIB3270_EXPORT const LIB3270_ACTION_ENTRY * lib3270_get_action_table()
  45 + {
46 #undef DECLARE_LIB3270_ACTION 46 #undef DECLARE_LIB3270_ACTION
47 #undef DECLARE_LIB3270_CLEAR_SELECTION_ACTION 47 #undef DECLARE_LIB3270_CLEAR_SELECTION_ACTION
48 #undef DECLARE_LIB3270_KEY_ACTION 48 #undef DECLARE_LIB3270_KEY_ACTION
49 #undef DECLARE_LIB3270_CURSOR_ACTION 49 #undef DECLARE_LIB3270_CURSOR_ACTION
50 #undef DECLARE_LIB3270_FKEY_ACTION 50 #undef DECLARE_LIB3270_FKEY_ACTION
51 51
52 - #define DECLARE_LIB3270_ACTION( name, description ) { #name, lib3270_ ## name },  
53 - #define DECLARE_LIB3270_CLEAR_SELECTION_ACTION( name, description ) { #name, lib3270_ ## name },  
54 - #define DECLARE_LIB3270_KEY_ACTION( name, description ) { #name, lib3270_ ## name },  
55 - #define DECLARE_LIB3270_CURSOR_ACTION( name, description ) { #name, lib3270_cursor_ ## name }, 52 + #define DECLARE_LIB3270_ACTION( name, description ) { #name, description, lib3270_ ## name },
  53 + #define DECLARE_LIB3270_CLEAR_SELECTION_ACTION( name, description ) { #name, description, lib3270_ ## name },
  54 + #define DECLARE_LIB3270_KEY_ACTION( name, description ) { #name, description, lib3270_ ## name },
  55 + #define DECLARE_LIB3270_CURSOR_ACTION( name, description ) { #name, description, lib3270_cursor_ ## name },
56 #define DECLARE_LIB3270_FKEY_ACTION( name, description ) // name 56 #define DECLARE_LIB3270_FKEY_ACTION( name, description ) // name
57 57
58 - static const struct _action  
59 - {  
60 - const char * name;  
61 - int (*call)(H3270 *h);  
62 - } action[] = 58 + static const LIB3270_ACTION_ENTRY actions[] =
63 { 59 {
64 #include <lib3270/action_table.h> 60 #include <lib3270/action_table.h>
  61 + { NULL, NULL, NULL }
65 }; 62 };
66 63
  64 + return actions;
  65 + }
  66 +
  67 +
  68 +/**
  69 + * @brief Launch an action by name.
  70 + *
  71 + */
  72 +LIB3270_EXPORT int lib3270_action(H3270 *hSession, const char *name)
  73 +{
  74 + const LIB3270_ACTION_ENTRY *actions = lib3270_get_action_table();
67 size_t f; 75 size_t f;
68 76
69 CHECK_SESSION_HANDLE(hSession); 77 CHECK_SESSION_HANDLE(hSession);
70 78
71 - for(f=0; f< (sizeof(action)/sizeof(action[0])); f++) 79 + for(f=0; actions[f].name; f++)
72 { 80 {
73 - if(!strcasecmp(name,action[f].name)) 81 + if(!strcasecmp(name,actions[f].name))
74 { 82 {
75 - lib3270_trace_event(hSession,"Action %s activated\n",name);  
76 - return action[f].call(hSession); 83 + lib3270_trace_event(hSession,"Action: %s\n",actions[f].name);
  84 + return actions[f].call(hSession);
77 } 85 }
78 86
79 } 87 }
src/lib3270/macros.c
@@ -343,30 +343,6 @@ @@ -343,30 +343,6 @@
343 {NULL, NULL} 343 {NULL, NULL}
344 }; 344 };
345 345
346 - #undef DECLARE_LIB3270_ACTION  
347 - #undef DECLARE_LIB3270_CLEAR_SELECTION_ACTION  
348 - #undef DECLARE_LIB3270_KEY_ACTION  
349 - #undef DECLARE_LIB3270_CURSOR_ACTION  
350 - #undef DECLARE_LIB3270_FKEY_ACTION  
351 -  
352 - static const struct _action  
353 - {  
354 - const char *name;  
355 - int (*exec)(H3270 *session);  
356 - }  
357 - action[] =  
358 - {  
359 - #define DECLARE_LIB3270_ACTION( name, description ) { #name, lib3270_ ## name },  
360 - #define DECLARE_LIB3270_KEY_ACTION( name, description ) { #name, lib3270_ ## name },  
361 - #define DECLARE_LIB3270_CURSOR_ACTION( name, description ) { #name, lib3270_cursor_ ## name },  
362 - #define DECLARE_LIB3270_FKEY_ACTION( name, description ) /* */  
363 -  
364 - #include <lib3270/action_table.h>  
365 -  
366 - {NULL, NULL}  
367 - };  
368 -  
369 -  
370 int argc; 346 int argc;
371 int f; 347 int f;
372 348
@@ -387,11 +363,13 @@ @@ -387,11 +363,13 @@
387 if(argc == 1) 363 if(argc == 1)
388 { 364 {
389 // Search for action 365 // Search for action
390 - for(f=0;action[f].name;f++) 366 + const LIB3270_ACTION_ENTRY *actions = lib3270_get_action_table();
  367 +
  368 + for(f=0;actions[f].name;f++)
391 { 369 {
392 - if(!strcasecmp(action[f].name,argv[0])) 370 + if(!strcasecmp(actions[f].name,argv[0]))
393 { 371 {
394 - int rc = action[f].exec(session); 372 + int rc = actions[f].call(session);
395 return xs_buffer("%d",rc); 373 return xs_buffer("%d",rc);
396 } 374 }
397 } 375 }