Commit 1ad4d6e6057227851a2194bf45d27aa8580c76fb

Authored by Perry Werneck
1 parent 0a3ac259

Refacoring toggle engine.

Makefile.in
... ... @@ -34,6 +34,7 @@ SOURCES= \
34 34 $(wildcard src/core/*.c) \
35 35 $(wildcard src/core/keyboard/*.c) \
36 36 $(wildcard src/core/actions/*.c) \
  37 + $(wildcard src/core/toggles/*.c) \
37 38 $(wildcard src/core/ft/*.c) \
38 39 $(wildcard src/core/@OSNAME@/*.rc) \
39 40 $(wildcard src/core/@OSNAME@/*.c) \
... ...
lib3270.cbp
... ... @@ -167,7 +167,16 @@
167 167 <Unit filename="src/core/telnet.c">
168 168 <Option compilerVar="CC" />
169 169 </Unit>
170   - <Unit filename="src/core/toggles.c">
  170 + <Unit filename="src/core/toggles/getset.c">
  171 + <Option compilerVar="CC" />
  172 + </Unit>
  173 + <Unit filename="src/core/toggles/init.c">
  174 + <Option compilerVar="CC" />
  175 + </Unit>
  176 + <Unit filename="src/core/toggles/listener.c">
  177 + <Option compilerVar="CC" />
  178 + </Unit>
  179 + <Unit filename="src/core/toggles/table.c">
171 180 <Option compilerVar="CC" />
172 181 </Unit>
173 182 <Unit filename="src/core/trace_ds.c">
... ...
src/core/bounds.c
... ... @@ -76,7 +76,7 @@ LIB3270_EXPORT int lib3270_get_word_bounds(H3270 *session, int baddr, int *start
76 76  
77 77 CHECK_SESSION_HANDLE(session);
78 78  
79   - if(!lib3270_connected(session) || isspace(session->text[baddr].chr))
  79 + if(!lib3270_is_connected(session) || isspace(session->text[baddr].chr))
80 80 return -1;
81 81  
82 82 if(start)
... ...
src/core/ft/ft.c
... ... @@ -262,7 +262,7 @@ static void set_ft_state(H3270FT *session, LIB3270_FT_STATE state);
262 262 // unsigned long length = 0L;
263 263  
264 264 // trace("%s(%s)",__FUNCTION__,local);
265   - if(!lib3270_connected(session))
  265 + if(!lib3270_is_connected(session))
266 266 {
267 267 return ft_creation_failed(session,ENOTCONN,message,_( "Disconnected from host." ));
268 268 }
... ...
src/core/keyboard/kybd.c
... ... @@ -135,7 +135,7 @@ struct ta * new_ta(H3270 *hSession, enum _ta_type type)
135 135 struct ta *ta;
136 136  
137 137 // If no connection, forget it.
138   - if (!lib3270_connected(hSession))
  138 + if (!lib3270_is_connected(hSession))
139 139 {
140 140 lib3270_ring_bell(hSession);
141 141 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
2241 2241  
2242 2242 do
2243 2243 {
2244   - if(!lib3270_connected(hSession))
  2244 + if(!lib3270_is_connected(hSession))
2245 2245 return LIB3270_KL_NOT_CONNECTED;
2246 2246  
2247 2247 if(KYBDLOCK_IS_OERR(hSession))
... ...
src/core/paste.c
... ... @@ -323,7 +323,7 @@ LIB3270_EXPORT int lib3270_paste_text(H3270 *h, const unsigned char *str)
323 323 int sz;
324 324 CHECK_SESSION_HANDLE(h);
325 325  
326   - if(!lib3270_connected(h))
  326 + if(!lib3270_is_connected(h))
327 327 {
328 328 lib3270_ring_bell(h);
329 329 errno = ENOTCONN;
... ... @@ -363,7 +363,7 @@ LIB3270_EXPORT int lib3270_paste_next(H3270 *hSession)
363 363  
364 364 FAIL_IF_NOT_ONLINE(hSession);
365 365  
366   - if(!(lib3270_connected(hSession) && hSession->paste_buffer))
  366 + if(!(lib3270_is_connected(hSession) && hSession->paste_buffer))
367 367 {
368 368 lib3270_ring_bell(hSession);
369 369 return 0;
... ...
src/core/session.c
... ... @@ -70,7 +70,7 @@ void lib3270_session_free(H3270 *h)
70 70 return;
71 71  
72 72 // Terminate session
73   - if(lib3270_connected(h))
  73 + if(lib3270_is_connected(h))
74 74 lib3270_disconnect(h);
75 75  
76 76 shutdown_toggles(h);
... ...
src/core/state.c
... ... @@ -46,11 +46,6 @@ LIB3270_EXPORT int lib3270_half_connected(const H3270 *h)
46 46 return (h->cstate == LIB3270_RESOLVING || h->cstate == LIB3270_PENDING);
47 47 }
48 48  
49   -LIB3270_EXPORT int lib3270_connected(const H3270 *h)
50   -{
51   - return ((int) h->cstate >= (int)LIB3270_CONNECTED_INITIAL);
52   -}
53   -
54 49 LIB3270_EXPORT int lib3270_is_disconnected(const H3270 *h)
55 50 {
56 51 return ((int) h->cstate == (int)LIB3270_NOT_CONNECTED);
... ... @@ -83,7 +78,7 @@ LIB3270_EXPORT int lib3270_in_tn3270e(const H3270 *h)
83 78  
84 79 LIB3270_EXPORT int lib3270_is_connected(const H3270 *h)
85 80 {
86   - return (h->cstate == LIB3270_CONNECTED_TN3270E);
  81 + return ((int) h->cstate >= (int)LIB3270_CONNECTED_INITIAL);
87 82 }
88 83  
89 84 LIB3270_EXPORT int lib3270_in_e(const H3270 *h)
... ...
src/core/toggles.c
... ... @@ -1,511 +0,0 @@
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. 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., 51 Franklin
19   - * St, Fifth Floor, Boston, MA 02110-1301 USA
20   - *
21   - * Este programa está nomeado como toggles.c 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   -
31   -/**
32   - * @file toggles.c
33   - * @brief This module handles toggles.
34   - */
35   -
36   -#include <errno.h>
37   -#include <sys/types.h>
38   -
39   -#ifdef WIN32
40   - #include <winsock2.h>
41   - #include <windows.h>
42   - #include <ws2tcpip.h>
43   -#else
44   - #include <sys/socket.h>
45   -#endif // !WIN32
46   -
47   -#include <config.h>
48   -#include <lib3270/toggle.h>
49   -#include <lib3270-internals.h>
50   -
51   -#include "ansic.h"
52   -#include "ctlrc.h"
53   -#include "popupsc.h"
54   -#include "screenc.h"
55   -#include "trace_dsc.h"
56   -#include "togglesc.h"
57   -#include "utilc.h"
58   -#include <lib3270/log.h>
59   -
60   -static const struct _toggle_info
61   -{
62   - const char * name; ///< @brief Toggle name.
63   - const char def; ///< @brief Default value.
64   - const char * label; ///< @brief Button label.
65   - const char * summary; ///< @brief Short description.
66   - const char * description; ///< @brief Toggle description.
67   -}
68   -toggle_info[LIB3270_TOGGLE_COUNT] =
69   -{
70   - {
71   - "monocase",
72   - False,
73   - N_( "Monocase" ),
74   - N_( "Uppercase only" ),
75   - N_( "If set, the terminal operates in uppercase-only mode" )
76   - },
77   - {
78   - "cursorblink",
79   - True,
80   - N_( "Blinking Cursor" ),
81   - N_( "Blinking Cursor" ),
82   - N_( "If set, the cursor blinks" )
83   - },
84   - {
85   - "showtiming",
86   - True,
87   - N_( "Show timer when processing" ),
88   - N_( "Show timer when processing" ),
89   - N_( "If set, the time taken by the host to process an AID is displayed on the status line" )
90   - },
91   - {
92   - "cursorpos",
93   - True,
94   - N_( "Track Cursor" ),
95   - N_( "Track Cursor" ),
96   - N_( "Display the cursor location in the OIA (the status line)" )
97   - },
98   - {
99   - "dstrace",
100   - False,
101   - N_( "Data Stream" ),
102   - N_( "Trace Data Stream" ),
103   - ""
104   - },
105   - {
106   - "linewrap",
107   - False,
108   - N_("Wrap around"),
109   - N_("Wrap around"),
110   - N_("If set, the NVT terminal emulator automatically assumes a NEWLINE character when it reaches the end of a line.")
111   - },
112   - {
113   - "blankfill",
114   - False,
115   - N_( "Blank Fill" ),
116   - N_( "Blank Fill" ),
117   - 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" )
118   - },
119   - {
120   - "screentrace",
121   - False,
122   - N_( "Screens" ),
123   - N_( "Trace screen contents" ),
124   - ""
125   - },
126   - {
127   - "eventtrace",
128   - False,
129   - N_( "Events" ),
130   - N_( "Trace interface and application events" ),
131   - ""
132   - },
133   - {
134   - "marginedpaste",
135   - False,
136   - N_( "Paste with left margin" ),
137   - N_( "Paste with left margin" ),
138   - 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" )
139   - },
140   - {
141   - "rectselect",
142   - False,
143   - N_( "Select by rectangles" ),
144   - N_( "Select by rectangles" ),
145   - N_( "If set, the terminal will always select rectangular areas of the screen. Otherwise, it selects continuous regions of the screen" )
146   - },
147   - {
148   - "crosshair",
149   - False,
150   - N_( "Cross hair cursor" ),
151   - N_( "Cross hair cursor" ),
152   - 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" )
153   - },
154   - {
155   - "fullscreen",
156   - False,
157   - N_( "Full Screen" ),
158   - N_( "Full Screen" ),
159   - N_( "If set, asks to place the toplevel window in the fullscreen state" )
160   - },
161   - {
162   - "reconnect",
163   - False,
164   - N_( "Auto-Reconnect" ),
165   - N_( "Auto-Reconnect" ),
166   - N_( "Automatically reconnect to the host if it ever disconnects" )
167   - },
168   - {
169   - "insert",
170   - False,
171   - N_( "Insert" ),
172   - N_( "Set insert mode" ),
173   - ""
174   - },
175   - {
176   - "smartpaste",
177   - False,
178   - N_( "Smart paste" ),
179   - N_( "Smart paste" ),
180   - ""
181   - },
182   - {
183   - "bold",
184   - False,
185   - N_( "Bold" ),
186   - N_( "Bold" ),
187   - ""
188   - },
189   - {
190   - "keepselected",
191   - False,
192   - N_( "Keep selected" ),
193   - N_( "Keep selected" ),
194   - ""
195   - },
196   - {
197   - "underline",
198   - False,
199   - N_( "Underline" ),
200   - N_( "Show Underline" ),
201   - ""
202   - },
203   - {
204   - "autoconnect",
205   - False,
206   - N_( "Auto connect" ),
207   - N_( "Connect on startup" ),
208   - ""
209   - },
210   - {
211   - "kpalternative",
212   - False,
213   - N_( "Use +/- for field navigation" ),
214   - N_( "Use +/- for field navigation" ),
215   - N_( "Use the keys +/- from keypad to select editable fields" )
216   - },
217   - {
218   - "beep",
219   - True,
220   - N_( "Sound" ),
221   - N_( "Alert sound" ),
222   - N_( "Beep on errors" )
223   - },
224   - {
225   - "fieldattr",
226   - False,
227   - N_( "Show Field" ),
228   - N_( "Show Field attribute" ),
229   - ""
230   - },
231   - {
232   - "altscreen",
233   - True,
234   - N_( "Alternate screen" ),
235   - N_( "Resize on alternate screen" ),
236   - N_( "Auto resize on altscreen" )
237   - },
238   - {
239   - "keepalive",
240   - True,
241   - N_( "Network keep alive" ),
242   - N_( "Network keep alive" ),
243   - N_( "Enable network keep-alive with SO_KEEPALIVE" )
244   - },
245   - {
246   - "nettrace",
247   - False,
248   - N_( "Network data" ),
249   - N_( "Trace network data flow" ),
250   - N_( "Enable network in/out trace" )
251   - },
252   - {
253   - "ssltrace",
254   - False,
255   - N_( "SSL negotiation" ),
256   - N_( "Trace SSL negotiation" ),
257   - N_( "Enable security negotiation messages trace" )
258   - },
259   -};
260   -
261   -LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix)
262   -{
263   - CHECK_SESSION_HANDLE(session);
264   -
265   - if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT)
266   - return 0;
267   -
268   - return session->toggle[ix].value != 0;
269   -}
270   -
271   -/**
272   - * @brief Call the internal update routine and listeners.
273   - */
274   -static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE ix)
275   -{
276   - struct lib3270_toggle_callback * st;
277   -
278   - trace("%s: ix=%d upcall=%p",__FUNCTION__,ix,t->upcall);
279   - t->upcall(session, t, LIB3270_TOGGLE_TYPE_INTERACTIVE);
280   -
281   - if(session->cbk.update_toggle)
282   - session->cbk.update_toggle(session,ix,t->value,LIB3270_TOGGLE_TYPE_INTERACTIVE,toggle_info[ix].name);
283   -
284   - for(st = session->listeners.toggle.callbacks[ix]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next)
285   - {
286   - st->func(session, ix, t->value, st->data);
287   - }
288   -
289   -}
290   -
291   -/**
292   - * @brief Set toggle state.
293   - *
294   - * @param h Session handle.
295   - * @param ix Toggle id.
296   - * @param value New toggle state (non zero for true).
297   - *
298   - * @returns 0 if the toggle is already at the state, 1 if the toggle was changed; < 0 on error (sets errno).
299   - */
300   -LIB3270_EXPORT int lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int value)
301   -{
302   - char v = value ? True : False;
303   - struct lib3270_toggle * t;
304   -
305   - CHECK_SESSION_HANDLE(session);
306   -
307   - if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT)
308   - return -(errno = EINVAL);
309   -
310   - t = &session->toggle[ix];
311   -
312   - if(v == t->value)
313   - return 0;
314   -
315   - t->value = v;
316   -
317   - toggle_notify(session,t,ix);
318   - return 1;
319   -}
320   -
321   -LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE ix)
322   -{
323   - struct lib3270_toggle *t;
324   -
325   - CHECK_SESSION_HANDLE(session);
326   -
327   - if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT)
328   - return 0;
329   -
330   - t = &session->toggle[ix];
331   -
332   - t->value = t->value ? False : True;
333   - toggle_notify(session,t,ix);
334   -
335   - return (int) t->value;
336   -}
337   -
338   -static void toggle_altscreen(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt))
339   -{
340   - if(!session->screen_alt)
341   - set_viewsize(session,t->value ? 24 : session->max.rows,80);
342   -}
343   -
344   -static void toggle_redraw(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt))
345   -{
346   - session->cbk.display(session);
347   -}
348   -
349   -/**
350   - * @brief No-op toggle.
351   - */
352   -static void toggle_nop(H3270 GNUC_UNUSED(*session), struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt))
353   -{
354   -}
355   -
356   -static void toggle_keepalive(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt))
357   -{
358   - if(session->sock > 0)
359   - {
360   - // Update keep-alive option
361   - int optval = t->value ? 1 : 0;
362   -
363   - if (setsockopt(session->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0)
364   - {
365   - popup_a_sockerr(session, N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" ));
366   - }
367   - else
368   - {
369   - trace_dsn(session,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" );
370   - }
371   -
372   - }
373   -}
374   -
375   -/**
376   - * @brief Called from system initialization code to handle initial toggle settings.
377   - */
378   -void initialize_toggles(H3270 *session)
379   -{
380   - int f;
381   -
382   - for(f=0;f<LIB3270_TOGGLE_COUNT;f++)
383   - session->toggle[f].upcall = toggle_nop;
384   -
385   - session->toggle[LIB3270_TOGGLE_RECTANGLE_SELECT].upcall = toggle_rectselect;
386   - session->toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_redraw;
387   - session->toggle[LIB3270_TOGGLE_UNDERLINE].upcall = toggle_redraw;
388   - session->toggle[LIB3270_TOGGLE_ALTSCREEN].upcall = toggle_altscreen;
389   - session->toggle[LIB3270_TOGGLE_KEEP_ALIVE].upcall = toggle_keepalive;
390   -
391   - for(f=0;f<LIB3270_TOGGLE_COUNT;f++)
392   - {
393   - session->toggle[f].value = toggle_info[f].def;
394   - if(session->toggle[f].value)
395   - session->toggle[f].upcall(session,&session->toggle[f],LIB3270_TOGGLE_TYPE_INITIAL);
396   - }
397   -
398   -}
399   -
400   -/**
401   - * @brief Called from system exit code to handle toggles.
402   - */
403   -void shutdown_toggles(H3270 *session)
404   -{
405   -#if defined(X3270_TRACE)
406   - static const LIB3270_TOGGLE disable_on_shutdown[] = {LIB3270_TOGGLE_DS_TRACE, LIB3270_TOGGLE_EVENT_TRACE, LIB3270_TOGGLE_SCREEN_TRACE};
407   -
408   - size_t f;
409   -
410   - for(f=0;f< (sizeof(disable_on_shutdown)/sizeof(disable_on_shutdown[0])); f++)
411   - lib3270_set_toggle(session,disable_on_shutdown[f],0);
412   -
413   -#endif
414   -}
415   -
416   -LIB3270_EXPORT const char * lib3270_get_toggle_summary(LIB3270_TOGGLE ix)
417   -{
418   - if(ix < LIB3270_TOGGLE_COUNT)
419   - return toggle_info[ix].summary;
420   - return "";
421   -}
422   -
423   -LIB3270_EXPORT const char * lib3270_get_toggle_label(LIB3270_TOGGLE ix)
424   -{
425   - if(ix < LIB3270_TOGGLE_COUNT)
426   - return toggle_info[ix].label;
427   - return "";
428   -}
429   -
430   -
431   -LIB3270_EXPORT const char * lib3270_get_toggle_description(LIB3270_TOGGLE ix)
432   -{
433   - if(ix < LIB3270_TOGGLE_COUNT)
434   - return toggle_info[ix].description;
435   - return "";
436   -}
437   -
438   -LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE ix)
439   -{
440   - if(ix < LIB3270_TOGGLE_COUNT)
441   - return toggle_info[ix].name;
442   - return "";
443   -}
444   -
445   -LIB3270_EXPORT LIB3270_TOGGLE lib3270_get_toggle_id(const char *name)
446   -{
447   - if(name)
448   - {
449   - int f;
450   - for(f=0;f<LIB3270_TOGGLE_COUNT;f++)
451   - {
452   - if(!strcasecmp(name,toggle_info[f].name))
453   - return f;
454   - }
455   - }
456   - return -1;
457   -}
458   -
459   -LIB3270_EXPORT const void * lib3270_register_toggle_listener(H3270 *hSession, LIB3270_TOGGLE tx, void (*func)(H3270 *, LIB3270_TOGGLE, char, void *),void *data)
460   -{
461   - struct lib3270_toggle_callback *st;
462   -
463   - CHECK_SESSION_HANDLE(hSession);
464   -
465   - st = (struct lib3270_toggle_callback *) lib3270_malloc(sizeof(struct lib3270_toggle_callback));
466   - st->func = func;
467   - st->data = data;
468   -
469   - if (hSession->listeners.toggle.last[tx])
470   - hSession->listeners.toggle.last[tx]->next = st;
471   - else
472   - hSession->listeners.toggle.callbacks[tx] = st;
473   -
474   - hSession->listeners.toggle.last[tx] = st;
475   -
476   - return (void *) st;
477   -
478   -}
479   -
480   -LIB3270_EXPORT int lib3270_unregister_toggle_listener(H3270 *hSession, LIB3270_TOGGLE tx, const void *id)
481   -{
482   - struct lib3270_toggle_callback *st;
483   - struct lib3270_toggle_callback *prev = (struct lib3270_toggle_callback *) NULL;
484   -
485   - for (st = hSession->listeners.toggle.callbacks[tx]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next)
486   - {
487   - if (st == (struct lib3270_toggle_callback *)id)
488   - break;
489   -
490   - prev = st;
491   - }
492   -
493   - if (st == (struct lib3270_toggle_callback *)NULL)
494   - {
495   - lib3270_write_log(hSession,"lib3270","Invalid call to (%s): %p wasnt found in the list",__FUNCTION__,id);
496   - return errno = ENOENT;
497   - }
498   -
499   - if (prev != (struct lib3270_toggle_callback *) NULL)
500   - prev->next = st->next;
501   - else
502   - hSession->listeners.toggle.callbacks[tx] = (struct lib3270_toggle_callback *) st->next;
503   -
504   - for(st = hSession->listeners.toggle.callbacks[tx]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next)
505   - hSession->listeners.toggle.last[tx] = st;
506   -
507   - lib3270_free((void *) id);
508   -
509   - return 0;
510   -
511   -}
src/core/toggles/getset.c 0 → 100644
... ... @@ -0,0 +1,120 @@
  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. 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., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - 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 +
  31 +/**
  32 + * @file toggles/getset.c
  33 + * @brief This module handles toggle changes.
  34 + */
  35 +
  36 +#include <config.h>
  37 +#include <lib3270/toggle.h>
  38 +#include <lib3270-internals.h>
  39 +#include <lib3270/log.h>
  40 +#include "togglesc.h"
  41 +
  42 +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
  43 +
  44 +LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix)
  45 +{
  46 + CHECK_SESSION_HANDLE(session);
  47 +
  48 + if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT)
  49 + return 0;
  50 +
  51 + return session->toggle[ix].value != 0;
  52 +}
  53 +
  54 +/**
  55 + * @brief Call the internal update routine and listeners.
  56 + */
  57 +static void toggle_notify(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE ix)
  58 +{
  59 + struct lib3270_toggle_callback * st;
  60 +
  61 + trace("%s: ix=%d upcall=%p",__FUNCTION__,ix,t->upcall);
  62 + t->upcall(session, t, LIB3270_TOGGLE_TYPE_INTERACTIVE);
  63 +
  64 + if(session->cbk.update_toggle)
  65 + session->cbk.update_toggle(session,ix,t->value,LIB3270_TOGGLE_TYPE_INTERACTIVE,toggle_descriptor[ix].name);
  66 +
  67 + for(st = session->listeners.toggle.callbacks[ix]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next)
  68 + {
  69 + st->func(session, ix, t->value, st->data);
  70 + }
  71 +
  72 +}
  73 +
  74 +/**
  75 + * @brief Set toggle state.
  76 + *
  77 + * @param h Session handle.
  78 + * @param ix Toggle id.
  79 + * @param value New toggle state (non zero for true).
  80 + *
  81 + * @returns 0 if the toggle is already at the state, 1 if the toggle was changed; < 0 on error (sets errno).
  82 + */
  83 +LIB3270_EXPORT int lib3270_set_toggle(H3270 *session, LIB3270_TOGGLE ix, int value)
  84 +{
  85 + char v = value ? True : False;
  86 + struct lib3270_toggle * t;
  87 +
  88 + CHECK_SESSION_HANDLE(session);
  89 +
  90 + if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT)
  91 + return -(errno = EINVAL);
  92 +
  93 + t = &session->toggle[ix];
  94 +
  95 + if(v == t->value)
  96 + return 0;
  97 +
  98 + t->value = v;
  99 +
  100 + toggle_notify(session,t,ix);
  101 + return 1;
  102 +}
  103 +
  104 +LIB3270_EXPORT int lib3270_toggle(H3270 *session, LIB3270_TOGGLE ix)
  105 +{
  106 + struct lib3270_toggle *t;
  107 +
  108 + CHECK_SESSION_HANDLE(session);
  109 +
  110 + if(ix < 0 || ix >= LIB3270_TOGGLE_COUNT)
  111 + return 0;
  112 +
  113 + t = &session->toggle[ix];
  114 +
  115 + t->value = t->value ? False : True;
  116 + toggle_notify(session,t,ix);
  117 +
  118 + return (int) t->value;
  119 +}
  120 +
... ...
src/core/toggles/init.c 0 → 100644
... ... @@ -0,0 +1,138 @@
  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. 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., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - 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 +
  31 +/**
  32 + * @file toggles/init.c
  33 + * @brief Initialize toggles.
  34 + */
  35 +
  36 +#include <errno.h>
  37 +#include <sys/types.h>
  38 +
  39 +#ifdef WIN32
  40 + #include <winsock2.h>
  41 + #include <windows.h>
  42 + #include <ws2tcpip.h>
  43 +#else
  44 + #include <sys/socket.h>
  45 +#endif // !WIN32
  46 +
  47 +#include <config.h>
  48 +#include <lib3270/toggle.h>
  49 +#include <lib3270-internals.h>
  50 +
  51 +#include "ansic.h"
  52 +#include "ctlrc.h"
  53 +#include "popupsc.h"
  54 +#include "screenc.h"
  55 +#include "trace_dsc.h"
  56 +#include "togglesc.h"
  57 +#include "utilc.h"
  58 +#include <lib3270/log.h>
  59 +
  60 +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
  61 +
  62 +static void toggle_altscreen(H3270 *session, struct lib3270_toggle *t, LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt))
  63 +{
  64 + if(!session->screen_alt)
  65 + set_viewsize(session,t->value ? 24 : session->max.rows,80);
  66 +}
  67 +
  68 +static void toggle_redraw(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt))
  69 +{
  70 + session->cbk.display(session);
  71 +}
  72 +
  73 +/**
  74 + * @brief No-op toggle.
  75 + */
  76 +static void toggle_nop(H3270 GNUC_UNUSED(*session), struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt))
  77 +{
  78 +}
  79 +
  80 +static void toggle_keepalive(H3270 *session, struct lib3270_toggle GNUC_UNUSED(*t), LIB3270_TOGGLE_TYPE GNUC_UNUSED(tt))
  81 +{
  82 + if(session->sock > 0)
  83 + {
  84 + // Update keep-alive option
  85 + int optval = t->value ? 1 : 0;
  86 +
  87 + if (setsockopt(session->sock, SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) < 0)
  88 + {
  89 + popup_a_sockerr(session, N_( "Can't %s network keep-alive" ), optval ? _( "enable" ) : _( "disable" ));
  90 + }
  91 + else
  92 + {
  93 + trace_dsn(session,"Network keep-alive is %s\n",optval ? "enabled" : "disabled" );
  94 + }
  95 +
  96 + }
  97 +}
  98 +
  99 +/**
  100 + * @brief Called from system initialization code to handle initial toggle settings.
  101 + */
  102 +void initialize_toggles(H3270 *session)
  103 +{
  104 + int f;
  105 +
  106 + for(f=0;f<LIB3270_TOGGLE_COUNT;f++)
  107 + session->toggle[f].upcall = toggle_nop;
  108 +
  109 + session->toggle[LIB3270_TOGGLE_RECTANGLE_SELECT].upcall = toggle_rectselect;
  110 + session->toggle[LIB3270_TOGGLE_MONOCASE].upcall = toggle_redraw;
  111 + session->toggle[LIB3270_TOGGLE_UNDERLINE].upcall = toggle_redraw;
  112 + session->toggle[LIB3270_TOGGLE_ALTSCREEN].upcall = toggle_altscreen;
  113 + session->toggle[LIB3270_TOGGLE_KEEP_ALIVE].upcall = toggle_keepalive;
  114 +
  115 + for(f=0;f<LIB3270_TOGGLE_COUNT;f++)
  116 + {
  117 + session->toggle[f].value = toggle_descriptor[f].def;
  118 + if(session->toggle[f].value)
  119 + session->toggle[f].upcall(session,&session->toggle[f],LIB3270_TOGGLE_TYPE_INITIAL);
  120 + }
  121 +
  122 +}
  123 +
  124 +/**
  125 + * @brief Called from system exit code to handle toggles.
  126 + */
  127 +void shutdown_toggles(H3270 *session)
  128 +{
  129 +#if defined(X3270_TRACE)
  130 + static const LIB3270_TOGGLE disable_on_shutdown[] = {LIB3270_TOGGLE_DS_TRACE, LIB3270_TOGGLE_EVENT_TRACE, LIB3270_TOGGLE_SCREEN_TRACE};
  131 +
  132 + size_t f;
  133 +
  134 + for(f=0;f< (sizeof(disable_on_shutdown)/sizeof(disable_on_shutdown[0])); f++)
  135 + lib3270_set_toggle(session,disable_on_shutdown[f],0);
  136 +
  137 +#endif
  138 +}
... ...
src/core/toggles/listener.c 0 → 100644
... ... @@ -0,0 +1,98 @@
  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. 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., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - 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 +
  31 +/**
  32 + * @file toggles/listener.c
  33 + * @brief This module handles toggle listeners.
  34 + */
  35 +
  36 +#include <config.h>
  37 +#include <errno.h>
  38 +#include <sys/types.h>
  39 +
  40 +#include <lib3270/toggle.h>
  41 +#include <lib3270-internals.h>
  42 +#include <lib3270/log.h>
  43 +
  44 +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
  45 +
  46 +LIB3270_EXPORT const void * lib3270_register_toggle_listener(H3270 *hSession, LIB3270_TOGGLE tx, void (*func)(H3270 *, LIB3270_TOGGLE, char, void *),void *data)
  47 +{
  48 + struct lib3270_toggle_callback *st;
  49 +
  50 + CHECK_SESSION_HANDLE(hSession);
  51 +
  52 + st = (struct lib3270_toggle_callback *) lib3270_malloc(sizeof(struct lib3270_toggle_callback));
  53 + st->func = func;
  54 + st->data = data;
  55 +
  56 + if (hSession->listeners.toggle.last[tx])
  57 + hSession->listeners.toggle.last[tx]->next = st;
  58 + else
  59 + hSession->listeners.toggle.callbacks[tx] = st;
  60 +
  61 + hSession->listeners.toggle.last[tx] = st;
  62 +
  63 + return (void *) st;
  64 +
  65 +}
  66 +
  67 +LIB3270_EXPORT int lib3270_unregister_toggle_listener(H3270 *hSession, LIB3270_TOGGLE tx, const void *id)
  68 +{
  69 + struct lib3270_toggle_callback *st;
  70 + struct lib3270_toggle_callback *prev = (struct lib3270_toggle_callback *) NULL;
  71 +
  72 + for (st = hSession->listeners.toggle.callbacks[tx]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next)
  73 + {
  74 + if (st == (struct lib3270_toggle_callback *)id)
  75 + break;
  76 +
  77 + prev = st;
  78 + }
  79 +
  80 + if (st == (struct lib3270_toggle_callback *)NULL)
  81 + {
  82 + lib3270_write_log(hSession,"lib3270","Invalid call to (%s): %p wasnt found in the list",__FUNCTION__,id);
  83 + return errno = ENOENT;
  84 + }
  85 +
  86 + if (prev != (struct lib3270_toggle_callback *) NULL)
  87 + prev->next = st->next;
  88 + else
  89 + hSession->listeners.toggle.callbacks[tx] = (struct lib3270_toggle_callback *) st->next;
  90 +
  91 + for(st = hSession->listeners.toggle.callbacks[tx]; st != (struct lib3270_toggle_callback *) NULL; st = (struct lib3270_toggle_callback *) st->next)
  92 + hSession->listeners.toggle.last[tx] = st;
  93 +
  94 + lib3270_free((void *) id);
  95 +
  96 + return 0;
  97 +
  98 +}
... ...
src/core/toggles/table.c 0 → 100644
... ... @@ -0,0 +1,342 @@
  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. 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., 51 Franklin
  19 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  20 + *
  21 + * Este programa está nomeado como - 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 +
  31 +/**
  32 + * @file toggles/init.c
  33 + * @brief Toggle description table.
  34 + */
  35 +
  36 +#include <config.h>
  37 +#include <lib3270/toggle.h>
  38 +#include <lib3270-internals.h>
  39 +#include "togglesc.h"
  40 +
  41 +/*---[ Implement ]------------------------------------------------------------------------------------------------------------*/
  42 +
  43 +const LIB3270_TOGGLE_ENTRY toggle_descriptor[LIB3270_TOGGLE_COUNT+1] =
  44 +{
  45 + {
  46 + "monocase",
  47 + False,
  48 + NULL, // Default keycode
  49 + NULL, // Icon name
  50 + N_( "Monocase" ),
  51 + N_( "Uppercase only" ),
  52 + N_( "If set, the terminal operates in uppercase-only mode" )
  53 + },
  54 + {
  55 + "cursorblink",
  56 + True,
  57 + NULL, // Default keycode
  58 + NULL, // Icon name
  59 + N_( "Blinking Cursor" ),
  60 + N_( "Blinking Cursor" ),
  61 + N_( "If set, the cursor blinks" )
  62 + },
  63 + {
  64 + "showtiming",
  65 + True,
  66 + NULL, // Default keycode
  67 + NULL, // Icon name
  68 + N_( "Show timer when processing" ),
  69 + N_( "Show timer when processing" ),
  70 + N_( "If set, the time taken by the host to process an AID is displayed on the status line" )
  71 + },
  72 + {
  73 + "cursorpos",
  74 + True,
  75 + NULL, // Default keycode
  76 + NULL, // Icon name
  77 + N_( "Track Cursor" ),
  78 + N_( "Track Cursor" ),
  79 + N_( "Display the cursor location in the OIA (the status line)" )
  80 + },
  81 + {
  82 + "dstrace",
  83 + False,
  84 + NULL, // Default keycode
  85 + NULL, // Icon name
  86 + N_( "Data Stream" ),
  87 + N_( "Trace Data Stream" ),
  88 + ""
  89 + },
  90 + {
  91 + "linewrap",
  92 + False,
  93 + NULL, // Default keycode
  94 + NULL, // Icon name
  95 + N_("Wrap around"),
  96 + N_("Wrap around"),
  97 + N_("If set, the NVT terminal emulator automatically assumes a NEWLINE character when it reaches the end of a line.")
  98 + },
  99 + {
  100 + "blankfill",
  101 + False,
  102 + NULL, // Default keycode
  103 + NULL, // Icon name
  104 + N_( "Blank Fill" ),
  105 + N_( "Blank Fill" ),
  106 + 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" )
  107 + },
  108 + {
  109 + "screentrace",
  110 + False,
  111 + NULL, // Default keycode
  112 + NULL, // Icon name
  113 + N_( "Screens" ),
  114 + N_( "Trace screen contents" ),
  115 + ""
  116 + },
  117 + {
  118 + "eventtrace",
  119 + False,
  120 + NULL, // Default keycode
  121 + NULL, // Icon name
  122 + N_( "Events" ),
  123 + N_( "Trace interface and application events" ),
  124 + ""
  125 + },
  126 + {
  127 + "marginedpaste",
  128 + False,
  129 + NULL, // Default keycode
  130 + NULL, // Icon name
  131 + N_( "Paste with left margin" ),
  132 + N_( "Paste with left margin" ),
  133 + 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" )
  134 + },
  135 + {
  136 + "rectselect",
  137 + False,
  138 + NULL, // Default keycode
  139 + NULL, // Icon name
  140 + N_( "Select by rectangles" ),
  141 + N_( "Select by rectangles" ),
  142 + N_( "If set, the terminal will always select rectangular areas of the screen. Otherwise, it selects continuous regions of the screen" )
  143 + },
  144 + {
  145 + "crosshair",
  146 + False,
  147 + "<alt>x", // Default keycode
  148 + NULL, // Icon name
  149 + N_( "Cross hair cursor" ),
  150 + N_( "Cross hair cursor" ),
  151 + 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" )
  152 + },
  153 + {
  154 + "fullscreen",
  155 + False,
  156 + "<alt>Home", // Default keycode
  157 + NULL, // Icon name
  158 + N_( "Full Screen" ),
  159 + N_( "Full Screen" ),
  160 + N_( "If set, asks to place the toplevel window in the fullscreen state" )
  161 + },
  162 + {
  163 + "reconnect",
  164 + False,
  165 + NULL, // Default keycode
  166 + NULL, // Icon name
  167 + N_( "Auto-Reconnect" ),
  168 + N_( "Auto-Reconnect" ),
  169 + N_( "Automatically reconnect to the host if it ever disconnects" )
  170 + },
  171 + {
  172 + "insert",
  173 + False,
  174 + NULL, // Default keycode
  175 + NULL, // Icon name
  176 + N_( "Insert" ),
  177 + N_( "Set insert mode" ),
  178 + ""
  179 + },
  180 + {
  181 + "smartpaste",
  182 + False,
  183 + NULL, // Default keycode
  184 + NULL, // Icon name
  185 + N_( "Smart paste" ),
  186 + N_( "Smart paste" ),
  187 + ""
  188 + },
  189 + {
  190 + "bold",
  191 + False,
  192 + NULL, // Default keycode
  193 + NULL, // Icon name
  194 + N_( "Bold" ),
  195 + N_( "Bold" ),
  196 + ""
  197 + },
  198 + {
  199 + "keepselected",
  200 + False,
  201 + NULL, // Default keycode
  202 + NULL, // Icon name
  203 + N_( "Keep selected" ),
  204 + N_( "Keep selected" ),
  205 + ""
  206 + },
  207 + {
  208 + "underline",
  209 + False,
  210 + NULL, // Default keycode
  211 + NULL, // Icon name
  212 + N_( "Underline" ),
  213 + N_( "Show Underline" ),
  214 + ""
  215 + },
  216 + {
  217 + "autoconnect",
  218 + False,
  219 + NULL, // Default keycode
  220 + NULL, // Icon name
  221 + N_( "Auto connect" ),
  222 + N_( "Connect on startup" ),
  223 + ""
  224 + },
  225 + {
  226 + "kpalternative",
  227 + False,
  228 + NULL, // Default keycode
  229 + NULL, // Icon name
  230 + N_( "Use +/- for field navigation" ),
  231 + N_( "Use +/- for field navigation" ),
  232 + N_( "Use the keys +/- from keypad to select editable fields" )
  233 + },
  234 + {
  235 + "beep",
  236 + True,
  237 + NULL, // Default keycode
  238 + NULL, // Icon name
  239 + N_( "Sound" ),
  240 + N_( "Alert sound" ),
  241 + N_( "Beep on errors" )
  242 + },
  243 + {
  244 + "fieldattr",
  245 + False,
  246 + NULL, // Default keycode
  247 + NULL, // Icon name
  248 + N_( "Show Field" ),
  249 + N_( "Show Field attributes" ),
  250 + ""
  251 + },
  252 + {
  253 + "altscreen",
  254 + True,
  255 + NULL, // Default keycode
  256 + NULL, // Icon name
  257 + N_( "Alternate screen" ),
  258 + N_( "Resize on alternate screen" ),
  259 + N_( "Auto resize on altscreen" )
  260 + },
  261 + {
  262 + "keepalive",
  263 + True,
  264 + NULL, // Default keycode
  265 + NULL, // Icon name
  266 + N_( "Network keep alive" ),
  267 + N_( "Network keep alive" ),
  268 + N_( "Enable network keep-alive with SO_KEEPALIVE" )
  269 + },
  270 + {
  271 + "nettrace",
  272 + False,
  273 + NULL, // Default keycode
  274 + NULL, // Icon name
  275 + N_( "Network data" ),
  276 + N_( "Trace network data flow" ),
  277 + N_( "Enable network in/out trace" )
  278 + },
  279 + {
  280 + "ssltrace",
  281 + False,
  282 + NULL, // Default keycode
  283 + NULL, // Icon name
  284 + N_( "SSL negotiation" ),
  285 + N_( "Trace SSL negotiation" ),
  286 + N_( "Enable security negotiation trace" )
  287 + },
  288 +
  289 + {
  290 + NULL,
  291 + 0,
  292 + NULL,
  293 + NULL,
  294 + NULL,
  295 + NULL,
  296 + NULL
  297 + }
  298 +
  299 +};
  300 +
  301 +LIB3270_EXPORT const char * lib3270_get_toggle_summary(LIB3270_TOGGLE ix)
  302 +{
  303 + if(ix < LIB3270_TOGGLE_COUNT)
  304 + return toggle_descriptor[ix].summary;
  305 + return "";
  306 +}
  307 +
  308 +LIB3270_EXPORT const char * lib3270_get_toggle_label(LIB3270_TOGGLE ix)
  309 +{
  310 + if(ix < LIB3270_TOGGLE_COUNT)
  311 + return toggle_descriptor[ix].label;
  312 + return "";
  313 +}
  314 +
  315 +
  316 +LIB3270_EXPORT const char * lib3270_get_toggle_description(LIB3270_TOGGLE ix)
  317 +{
  318 + if(ix < LIB3270_TOGGLE_COUNT)
  319 + return toggle_descriptor[ix].description;
  320 + return "";
  321 +}
  322 +
  323 +LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE ix)
  324 +{
  325 + if(ix < LIB3270_TOGGLE_COUNT)
  326 + return toggle_descriptor[ix].name;
  327 + return "";
  328 +}
  329 +
  330 +LIB3270_EXPORT LIB3270_TOGGLE lib3270_get_toggle_id(const char *name)
  331 +{
  332 + if(name)
  333 + {
  334 + int f;
  335 + for(f=0;f<LIB3270_TOGGLE_COUNT;f++)
  336 + {
  337 + if(!strcasecmp(name,toggle_descriptor[f].name))
  338 + return f;
  339 + }
  340 + }
  341 + return -1;
  342 +}
... ...
src/core/util.c
... ... @@ -682,7 +682,7 @@ LIB3270_EXPORT LIB3270_POINTER lib3270_get_pointer(H3270 *hSession, int baddr)
682 682 size_t f;
683 683 unsigned short id = lib3270_get_selection_flags(hSession,baddr) & 0x8f;
684 684  
685   - if(!lib3270_connected(hSession) || baddr < 0)
  685 + if(!lib3270_is_connected(hSession) || baddr < 0)
686 686 return LIB3270_POINTER_LOCKED;
687 687  
688 688 for(f = 0; f < (sizeof(ptr)/sizeof(ptr[0]));f++)
... ...
src/core/wait.c
... ... @@ -56,7 +56,7 @@ LIB3270_EXPORT int lib3270_wait_for_ready(H3270 *hSession, int seconds)
56 56 if(!lib3270_get_lock_status(hSession))
57 57 return 0;
58 58  
59   - if(!lib3270_connected(hSession))
  59 + if(!lib3270_is_connected(hSession))
60 60 return errno = ENOTCONN;
61 61  
62 62 lib3270_main_iterate(hSession,1);
... ... @@ -81,7 +81,7 @@ int lib3270_wait_for_string(H3270 *hSession, const char *key, int seconds)
81 81 if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession))
82 82 return errno = EPERM;
83 83  
84   - if(!lib3270_connected(hSession))
  84 + if(!lib3270_is_connected(hSession))
85 85 return errno = ENOTCONN;
86 86  
87 87 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
120 120 if(hSession->kybdlock && KYBDLOCK_IS_OERR(hSession))
121 121 return errno = EPERM;
122 122  
123   - if(!lib3270_connected(hSession))
  123 + if(!lib3270_is_connected(hSession))
124 124 return errno = ENOTCONN;
125 125  
126 126 if(lib3270_cmp_string_at_address(hSession, baddr, key, 0) == 0)
... ...
src/include/lib3270-internals.h
... ... @@ -164,7 +164,7 @@ struct toggle_name {
164 164 /// @brief State macros
165 165 #define PCONNECTED lib3270_pconnected(hSession)
166 166 #define HALF_CONNECTED lib3270_half_connected(hSession)
167   -#define CONNECTED lib3270_connected(hSession)
  167 +#define CONNECTED lib3270_is_connected(hSession)
168 168  
169 169 #define IN_NEITHER lib3270_in_neither(hSession)
170 170 #define IN_ANSI lib3270_in_ansi(hSession)
... ...
src/include/lib3270/toggle.h
... ... @@ -37,6 +37,17 @@
37 37 extern "C" {
38 38 #endif
39 39  
  40 + typedef struct _lib3270_toggle_entry
  41 + {
  42 + const char *name; ///< @brief Toggle name.
  43 + const char def; ///< @brief Default value.
  44 + const char *key; ///< @brief Default key (or NULL if no default).
  45 + const char *icon; ///< @brief Icon name (from https://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html)
  46 + const char *label; ///< @brief Button label (or NULL).
  47 + const char *summary; ///< @brief Short description (or NULL).
  48 + const char *description; ///< @brief Toggle description.
  49 + } LIB3270_TOGGLE_ENTRY;
  50 +
40 51 /**
41 52 * @brief get toggle state.
42 53 *
... ... @@ -56,6 +67,9 @@
56 67 * @param value New toggle state (non zero for true).
57 68 *
58 69 * @returns 0 if the toggle is already at the state, 1 if the toggle was changed; < 0 on error (sets errno).
  70 + *
  71 + * @retval -EINVAL Invalid toggle id.
  72 + *
59 73 */
60 74 LIB3270_EXPORT int lib3270_set_toggle(H3270 *h, LIB3270_TOGGLE ix, int value);
61 75  
... ... @@ -64,7 +78,7 @@
64 78 *
65 79 * @param name Toggle name.
66 80 *
67   - * @return Toggle ID or -1 if it's invalid.
  81 + * @return Toggle ID or negative if it's invalid.
68 82 *
69 83 */
70 84 LIB3270_EXPORT LIB3270_TOGGLE lib3270_get_toggle_id(const char *name);
... ...
src/include/togglesc.h
... ... @@ -32,5 +32,9 @@
32 32 * @brief Global declarations for toggles.c.
33 33 */
34 34  
  35 + #include <lib3270/toggle.h>
  36 +
35 37 LIB3270_INTERNAL void initialize_toggles(H3270 *session);
36 38 LIB3270_INTERNAL void shutdown_toggles(H3270 *session);
  39 + LIB3270_INTERNAL const LIB3270_TOGGLE_ENTRY toggle_descriptor[LIB3270_TOGGLE_COUNT+1];
  40 +
... ...
src/selection/actions.c
... ... @@ -74,7 +74,7 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr)
74 74  
75 75 CHECK_SESSION_HANDLE(session);
76 76  
77   - if(!lib3270_connected(session))
  77 + if(!lib3270_is_connected(session))
78 78 return;
79 79  
80 80 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)
91 91  
92 92 CHECK_SESSION_HANDLE(h);
93 93  
94   - if(!lib3270_connected(h))
  94 + if(!lib3270_is_connected(h))
95 95 return ENOTCONN;
96 96  
97 97 maxlen = (h->view.rows * h->view.cols);
... ...
src/selection/selection.c
... ... @@ -206,7 +206,7 @@ LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *hSession, int ba
206 206  
207 207 CHECK_SESSION_HANDLE(hSession);
208 208  
209   - if(!(lib3270_connected(hSession) && (hSession->text[baddr].attr & LIB3270_ATTR_SELECTED)))
  209 + if(!(lib3270_is_connected(hSession) && (hSession->text[baddr].attr & LIB3270_ATTR_SELECTED)))
210 210 return rc;
211 211  
212 212 row = baddr / hSession->view.cols;
... ... @@ -282,7 +282,7 @@ LIB3270_EXPORT char * lib3270_get_string_at_address(H3270 *h, int offset, int le
282 282  
283 283 CHECK_SESSION_HANDLE(h);
284 284  
285   - if(!lib3270_connected(h))
  285 + if(!lib3270_is_connected(h))
286 286 {
287 287 errno = ENOTCONN;
288 288 return NULL;
... ...