Commit 8ffe1bd5202384dcb1a1178eb56f47c07a2f32f0
1 parent
378afd68
Exists in
master
and in
3 other branches
Fixing win32 warnings.
Showing
1 changed file
with
98 additions
and
70 deletions
Show diff stats
src/lib3270/kybd.c
... | ... | @@ -131,6 +131,7 @@ struct akeysym |
131 | 131 | #define ak_eq(k1, k2) (((k1).keysym == (k2).keysym) && \ |
132 | 132 | ((k1).keytype == (k2).keytype)) |
133 | 133 | |
134 | + | |
134 | 135 | struct ta |
135 | 136 | { |
136 | 137 | struct ta *next; |
... | ... | @@ -139,25 +140,29 @@ struct ta |
139 | 140 | { |
140 | 141 | TA_TYPE_DEFAULT, |
141 | 142 | TA_TYPE_KEY_AID, |
143 | + TA_TYPE_ACTION, | |
142 | 144 | TA_TYPE_USER |
143 | 145 | } type; |
144 | 146 | |
145 | - void (*fn)(H3270 *, const char *, const char *); | |
146 | - char *parm[2]; | |
147 | - unsigned char aid_code; | |
148 | -}; | |
147 | + union | |
148 | + { | |
149 | + unsigned char aid_code; | |
150 | + struct | |
151 | + { | |
152 | + void (*fn)(H3270 *, const char *, const char *); | |
153 | + char *parm[2]; | |
154 | + } def; | |
155 | + | |
156 | + int (*action)(H3270 *); | |
157 | + | |
158 | + } args; | |
149 | 159 | |
150 | -#if defined(DEBUG) | |
151 | - #define ENQUEUE_ACTION(x) enq_ta(hSession, (void (*)(H3270 *, const char *, const char *)) x, NULL, NULL, #x) | |
152 | -#else | |
153 | - #define ENQUEUE_ACTION(x) enq_ta(hSession, (void (*)(H3270 *, const char *, const char *)) x, NULL, NULL) | |
154 | -#endif // DEBUG | |
160 | +}; | |
155 | 161 | |
156 | 162 | static const char dxl[] = "0123456789abcdef"; |
157 | 163 | #define FROM_HEX(c) (strchr(dxl, tolower(c)) - dxl) |
158 | 164 | #define KYBDLOCK_IS_OERR(hSession) (hSession->kybdlock && !(hSession->kybdlock & ~KL_OERR_MASK)) |
159 | 165 | |
160 | - | |
161 | 166 | /* |
162 | 167 | * Check if the typeahead queue is available |
163 | 168 | */ |
... | ... | @@ -196,8 +201,8 @@ static int enq_chk(H3270 *hSession) |
196 | 201 | return 0; |
197 | 202 | } |
198 | 203 | |
199 | -/* | |
200 | - * Put a "Key-aid" on the typeahead queue | |
204 | +/** | |
205 | + * @brief Put a "Key-aid" on the typeahead queue | |
201 | 206 | */ |
202 | 207 | static void enq_key(H3270 *session, unsigned char aid_code) |
203 | 208 | { |
... | ... | @@ -207,9 +212,9 @@ static int enq_chk(H3270 *hSession) |
207 | 212 | return; |
208 | 213 | |
209 | 214 | ta = (struct ta *) lib3270_malloc(sizeof(*ta)); |
210 | - ta->next = (struct ta *) NULL; | |
211 | - ta->type = TA_TYPE_KEY_AID; | |
212 | - ta->aid_code = aid_code; | |
215 | + ta->next = (struct ta *) NULL; | |
216 | + ta->type = TA_TYPE_KEY_AID; | |
217 | + ta->args.aid_code = aid_code; | |
213 | 218 | |
214 | 219 | trace("Adding key %02x on queue",(int) aid_code); |
215 | 220 | |
... | ... | @@ -227,34 +232,28 @@ static int enq_chk(H3270 *hSession) |
227 | 232 | lib3270_trace_event(session," Key-aid queued (kybdlock 0x%x)\n", session->kybdlock); |
228 | 233 | } |
229 | 234 | |
230 | -/* | |
231 | - * Put an action on the typeahead queue. | |
235 | + | |
236 | + | |
237 | +/** | |
238 | + * @brief Put an action on the typeahead queue. | |
232 | 239 | */ |
233 | -#if defined(DEBUG) | |
234 | -static void enq_ta(H3270 *hSession, void (*fn)(H3270 *, const char *, const char *), const char *parm1, const char *parm2, const char *name) | |
235 | -#else | |
236 | 240 | static void enq_ta(H3270 *hSession, void (*fn)(H3270 *, const char *, const char *), const char *parm1, const char *parm2) |
237 | -#endif // DEBUG | |
238 | 241 | { |
239 | 242 | struct ta *ta; |
240 | 243 | |
241 | - CHECK_SESSION_HANDLE(hSession); | |
242 | - | |
243 | - trace("%s: %s",__FUNCTION__,name); | |
244 | - | |
245 | 244 | if(enq_chk(hSession)) |
246 | 245 | return; |
247 | 246 | |
248 | 247 | ta = (struct ta *) lib3270_malloc(sizeof(*ta)); |
249 | - ta->next = (struct ta *) NULL; | |
250 | - ta->type = TA_TYPE_DEFAULT; | |
251 | - ta->fn = fn; | |
248 | + ta->next = (struct ta *) NULL; | |
249 | + ta->type = TA_TYPE_DEFAULT; | |
250 | + ta->args.def.fn = fn; | |
252 | 251 | |
253 | 252 | if (parm1) |
254 | - ta->parm[0] = NewString(parm1); | |
253 | + ta->args.def.parm[0] = NewString(parm1); | |
255 | 254 | |
256 | 255 | if (parm2) |
257 | - ta->parm[1] = NewString(parm2); | |
256 | + ta->args.def.parm[1] = NewString(parm2); | |
258 | 257 | |
259 | 258 | if(hSession->ta_head) |
260 | 259 | { |
... | ... | @@ -270,8 +269,35 @@ static void enq_ta(H3270 *hSession, void (*fn)(H3270 *, const char *, const char |
270 | 269 | lib3270_trace_event(hSession," action queued (kybdlock 0x%x)\n", hSession->kybdlock); |
271 | 270 | } |
272 | 271 | |
273 | -/* | |
274 | - * Execute an action from the typeahead queue. | |
272 | +static void enq_action(H3270 *hSession, int (*fn)(H3270 *)) | |
273 | +{ | |
274 | + struct ta *ta; | |
275 | + | |
276 | + if(enq_chk(hSession)) | |
277 | + return; | |
278 | + | |
279 | + ta = (struct ta *) lib3270_malloc(sizeof(*ta)); | |
280 | + ta->next = (struct ta *) NULL; | |
281 | + ta->type = TA_TYPE_ACTION; | |
282 | + ta->args.action = fn; | |
283 | + | |
284 | + if(hSession->ta_head) | |
285 | + { | |
286 | + hSession->ta_tail->next = ta; | |
287 | + } | |
288 | + else | |
289 | + { | |
290 | + hSession->ta_head = ta; | |
291 | + status_typeahead(hSession,True); | |
292 | + } | |
293 | + hSession->ta_tail = ta; | |
294 | + | |
295 | + lib3270_trace_event(hSession," action queued (kybdlock 0x%x)\n", hSession->kybdlock); | |
296 | +} | |
297 | + | |
298 | + | |
299 | +/** | |
300 | + * @brief Execute an action from the typeahead queue. | |
275 | 301 | */ |
276 | 302 | int run_ta(H3270 *hSession) |
277 | 303 | { |
... | ... | @@ -289,14 +315,17 @@ int run_ta(H3270 *hSession) |
289 | 315 | switch(ta->type) |
290 | 316 | { |
291 | 317 | case TA_TYPE_DEFAULT: |
292 | - ta->fn(hSession,ta->parm[0],ta->parm[1]); | |
293 | - lib3270_free(ta->parm[0]); | |
294 | - lib3270_free(ta->parm[1]); | |
318 | + ta->args.def.fn(hSession,ta->args.def.parm[0],ta->args.def.parm[1]); | |
319 | + lib3270_free(ta->args.def.parm[0]); | |
320 | + lib3270_free(ta->args.def.parm[1]); | |
321 | + break; | |
322 | + | |
323 | + case TA_TYPE_ACTION: | |
324 | + ta->args.action(hSession); | |
295 | 325 | break; |
296 | 326 | |
297 | 327 | case TA_TYPE_KEY_AID: |
298 | -// trace("Sending enqueued key %02x",ta->aid_code); | |
299 | - key_AID(hSession,ta->aid_code); | |
328 | + key_AID(hSession,ta->args.aid_code); | |
300 | 329 | break; |
301 | 330 | |
302 | 331 | default: |
... | ... | @@ -309,9 +338,9 @@ int run_ta(H3270 *hSession) |
309 | 338 | return 1; |
310 | 339 | } |
311 | 340 | |
312 | -/* | |
313 | - * Flush the typeahead queue. | |
314 | - * Returns whether or not anything was flushed. | |
341 | +/** | |
342 | + * @brief Flush the typeahead queue. | |
343 | + * @return whether or not anything was flushed. | |
315 | 344 | */ |
316 | 345 | static int flush_ta(H3270 *hSession) |
317 | 346 | { |
... | ... | @@ -320,8 +349,11 @@ static int flush_ta(H3270 *hSession) |
320 | 349 | |
321 | 350 | for (ta = hSession->ta_head; ta != (struct ta *) NULL; ta = next) |
322 | 351 | { |
323 | - lib3270_free(ta->parm[0]); | |
324 | - lib3270_free(ta->parm[1]); | |
352 | + if(ta->type == TA_TYPE_DEFAULT) | |
353 | + { | |
354 | + lib3270_free(ta->args.def.parm[0]); | |
355 | + lib3270_free(ta->args.def.parm[1]); | |
356 | + } | |
325 | 357 | next = ta->next; |
326 | 358 | lib3270_free(ta); |
327 | 359 | any++; |
... | ... | @@ -740,11 +772,7 @@ static Boolean key_Character(H3270 *hSession, int code, Boolean with_ge, Boolean |
740 | 772 | |
741 | 773 | (void) sprintf(codename, "%d", code |(with_ge ? GE_WFLAG : 0) | (pasting ? PASTE_WFLAG : 0)); |
742 | 774 | |
743 | -#if defined(DEBUG) | |
744 | - enq_ta(hSession,key_Character_wrapper, codename, CN, "key_Character_wrapper"); | |
745 | -#else | |
746 | 775 | enq_ta(hSession,key_Character_wrapper, codename, CN); |
747 | -#endif // DEBUG | |
748 | 776 | |
749 | 777 | return False; |
750 | 778 | } |
... | ... | @@ -1031,7 +1059,7 @@ LIB3270_EXPORT int lib3270_nextfield(H3270 *hSession) |
1031 | 1059 | status_reset(hSession); |
1032 | 1060 | } else |
1033 | 1061 | { |
1034 | - ENQUEUE_ACTION(lib3270_nextfield); | |
1062 | + enq_action(hSession, lib3270_nextfield); | |
1035 | 1063 | return 0; |
1036 | 1064 | } |
1037 | 1065 | } |
... | ... | @@ -1079,7 +1107,7 @@ LIB3270_EXPORT int lib3270_previousfield(H3270 *hSession) |
1079 | 1107 | } |
1080 | 1108 | else |
1081 | 1109 | { |
1082 | - ENQUEUE_ACTION(lib3270_previousfield); | |
1110 | + enq_action(hSession, lib3270_previousfield); | |
1083 | 1111 | return 0; |
1084 | 1112 | } |
1085 | 1113 | } |
... | ... | @@ -1202,7 +1230,7 @@ LIB3270_EXPORT int lib3270_firstfield(H3270 *hSession) |
1202 | 1230 | |
1203 | 1231 | if (hSession->kybdlock) |
1204 | 1232 | { |
1205 | - ENQUEUE_ACTION(lib3270_firstfield); | |
1233 | + enq_action(hSession, lib3270_firstfield); | |
1206 | 1234 | return 0; |
1207 | 1235 | } |
1208 | 1236 | #if defined(X3270_ANSI) /*[*/ |
... | ... | @@ -1250,7 +1278,7 @@ LIB3270_EXPORT int lib3270_cursor_left(H3270 *hSession) |
1250 | 1278 | } |
1251 | 1279 | else |
1252 | 1280 | { |
1253 | - ENQUEUE_ACTION(lib3270_cursor_left); | |
1281 | + enq_action(hSession, lib3270_cursor_left); | |
1254 | 1282 | return 0; |
1255 | 1283 | } |
1256 | 1284 | } |
... | ... | @@ -1380,7 +1408,7 @@ LIB3270_EXPORT int lib3270_delete(H3270 *hSession) |
1380 | 1408 | |
1381 | 1409 | if (hSession->kybdlock) |
1382 | 1410 | { |
1383 | - ENQUEUE_ACTION(lib3270_delete); | |
1411 | + enq_action(hSession, lib3270_delete); | |
1384 | 1412 | return 0; |
1385 | 1413 | } |
1386 | 1414 | #if defined(X3270_ANSI) /*[*/ |
... | ... | @@ -1413,7 +1441,7 @@ LIB3270_EXPORT int lib3270_backspace(H3270 *hSession) |
1413 | 1441 | |
1414 | 1442 | if (hSession->kybdlock) |
1415 | 1443 | { |
1416 | - ENQUEUE_ACTION( lib3270_backspace ); | |
1444 | + enq_action(hSession, lib3270_backspace ); | |
1417 | 1445 | return 0; |
1418 | 1446 | } |
1419 | 1447 | #if defined(X3270_ANSI) /*[*/ |
... | ... | @@ -1508,7 +1536,7 @@ int lib3270_erase(H3270 *hSession) |
1508 | 1536 | |
1509 | 1537 | if (hSession->kybdlock) |
1510 | 1538 | { |
1511 | - ENQUEUE_ACTION(lib3270_erase); | |
1539 | + enq_action(hSession, lib3270_erase); | |
1512 | 1540 | return 0; |
1513 | 1541 | } |
1514 | 1542 | #if defined(X3270_ANSI) /*[*/ |
... | ... | @@ -1541,7 +1569,7 @@ LIB3270_EXPORT int lib3270_cursor_right(H3270 *hSession) |
1541 | 1569 | } |
1542 | 1570 | else |
1543 | 1571 | { |
1544 | - ENQUEUE_ACTION(lib3270_cursor_right); | |
1572 | + enq_action(hSession, lib3270_cursor_right); | |
1545 | 1573 | return 0; |
1546 | 1574 | } |
1547 | 1575 | } |
... | ... | @@ -1580,7 +1608,7 @@ LIB3270_EXPORT int lib3270_previousword(H3270 *hSession) |
1580 | 1608 | FAIL_IF_NOT_ONLINE(hSession); |
1581 | 1609 | |
1582 | 1610 | if (hSession->kybdlock) { |
1583 | - ENQUEUE_ACTION(lib3270_previousword); | |
1611 | + enq_action(hSession, lib3270_previousword); | |
1584 | 1612 | // enq_ta(PreviousWord_action, CN, CN); |
1585 | 1613 | return 0; |
1586 | 1614 | } |
... | ... | @@ -1703,7 +1731,7 @@ LIB3270_EXPORT int lib3270_nextword(H3270 *hSession) |
1703 | 1731 | FAIL_IF_NOT_ONLINE(hSession); |
1704 | 1732 | |
1705 | 1733 | if (hSession->kybdlock) { |
1706 | - ENQUEUE_ACTION( lib3270_nextword ); | |
1734 | + enq_action(hSession, lib3270_nextword ); | |
1707 | 1735 | // enq_ta(NextWord_action, CN, CN); |
1708 | 1736 | return 0; |
1709 | 1737 | } |
... | ... | @@ -1868,7 +1896,7 @@ LIB3270_EXPORT int lib3270_cursor_up(H3270 *hSession) |
1868 | 1896 | } |
1869 | 1897 | else |
1870 | 1898 | { |
1871 | - ENQUEUE_ACTION(lib3270_cursor_up); | |
1899 | + enq_action(hSession, lib3270_cursor_up); | |
1872 | 1900 | return 0; |
1873 | 1901 | } |
1874 | 1902 | } |
... | ... | @@ -1905,7 +1933,7 @@ LIB3270_EXPORT int lib3270_cursor_down(H3270 *hSession) |
1905 | 1933 | status_reset(hSession); |
1906 | 1934 | } else |
1907 | 1935 | { |
1908 | - ENQUEUE_ACTION(lib3270_cursor_down); | |
1936 | + enq_action(hSession, lib3270_cursor_down); | |
1909 | 1937 | // enq_ta(Down_action, CN, CN); |
1910 | 1938 | return 0; |
1911 | 1939 | } |
... | ... | @@ -1934,7 +1962,7 @@ LIB3270_EXPORT int lib3270_newline(H3270 *hSession) |
1934 | 1962 | |
1935 | 1963 | if (hSession->kybdlock) |
1936 | 1964 | { |
1937 | - ENQUEUE_ACTION(lib3270_newline); | |
1965 | + enq_action(hSession, lib3270_newline); | |
1938 | 1966 | return 0; |
1939 | 1967 | } |
1940 | 1968 | #if defined(X3270_ANSI) /*[*/ |
... | ... | @@ -1965,7 +1993,7 @@ LIB3270_EXPORT int lib3270_dup(H3270 *hSession) |
1965 | 1993 | |
1966 | 1994 | if (hSession->kybdlock) |
1967 | 1995 | { |
1968 | - ENQUEUE_ACTION(lib3270_dup); | |
1996 | + enq_action(hSession, lib3270_dup); | |
1969 | 1997 | return 0; |
1970 | 1998 | } |
1971 | 1999 | #if defined(X3270_ANSI) |
... | ... | @@ -1990,7 +2018,7 @@ LIB3270_EXPORT int lib3270_fieldmark(H3270 *hSession) |
1990 | 2018 | |
1991 | 2019 | if (hSession->kybdlock) |
1992 | 2020 | { |
1993 | - ENQUEUE_ACTION(lib3270_fieldmark); | |
2021 | + enq_action(hSession, lib3270_fieldmark); | |
1994 | 2022 | return 0; |
1995 | 2023 | } |
1996 | 2024 | #if defined(X3270_ANSI) |
... | ... | @@ -2021,7 +2049,7 @@ LIB3270_EXPORT int lib3270_enter(H3270 *hSession) |
2021 | 2049 | } |
2022 | 2050 | else if (hSession->kybdlock) |
2023 | 2051 | { |
2024 | - ENQUEUE_ACTION(lib3270_enter); | |
2052 | + enq_action(hSession, lib3270_enter); | |
2025 | 2053 | } |
2026 | 2054 | else |
2027 | 2055 | { |
... | ... | @@ -2052,7 +2080,7 @@ LIB3270_EXPORT int lib3270_sysreq(H3270 *hSession) |
2052 | 2080 | if (hSession->kybdlock & KL_OIA_MINUS) |
2053 | 2081 | return 0; |
2054 | 2082 | else if (hSession->kybdlock) |
2055 | - ENQUEUE_ACTION(lib3270_sysreq); | |
2083 | + enq_action(hSession, lib3270_sysreq); | |
2056 | 2084 | else |
2057 | 2085 | key_AID(hSession,AID_SYSREQ); |
2058 | 2086 | } |
... | ... | @@ -2069,7 +2097,7 @@ LIB3270_EXPORT int lib3270_clear(H3270 *hSession) |
2069 | 2097 | if (hSession->kybdlock & KL_OIA_MINUS) |
2070 | 2098 | return 0; |
2071 | 2099 | if (hSession->kybdlock && CONNECTED) { |
2072 | - ENQUEUE_ACTION(lib3270_clear); | |
2100 | + enq_action(hSession, lib3270_clear); | |
2073 | 2101 | return 0; |
2074 | 2102 | } |
2075 | 2103 | #if defined(X3270_ANSI) /*[*/ |
... | ... | @@ -2100,7 +2128,7 @@ LIB3270_EXPORT int lib3270_eraseeol(H3270 *hSession) |
2100 | 2128 | // reset_idle_timer(); |
2101 | 2129 | if (hSession->kybdlock) |
2102 | 2130 | { |
2103 | - ENQUEUE_ACTION(lib3270_eraseeol); | |
2131 | + enq_action(hSession, lib3270_eraseeol); | |
2104 | 2132 | return 0; |
2105 | 2133 | } |
2106 | 2134 | #if defined(X3270_ANSI) /*[*/ |
... | ... | @@ -2168,7 +2196,7 @@ LIB3270_EXPORT int lib3270_eraseeof(H3270 *hSession) |
2168 | 2196 | // reset_idle_timer(); |
2169 | 2197 | if (hSession->kybdlock) |
2170 | 2198 | { |
2171 | - ENQUEUE_ACTION(lib3270_eraseeof); | |
2199 | + enq_action(hSession, lib3270_eraseeof); | |
2172 | 2200 | return 0; |
2173 | 2201 | } |
2174 | 2202 | #if defined(X3270_ANSI) /*[*/ |
... | ... | @@ -2219,7 +2247,7 @@ LIB3270_EXPORT int lib3270_eraseinput(H3270 *hSession) |
2219 | 2247 | |
2220 | 2248 | // reset_idle_timer(); |
2221 | 2249 | if (hSession->kybdlock) { |
2222 | - ENQUEUE_ACTION( lib3270_eraseinput ); | |
2250 | + enq_action(hSession, lib3270_eraseinput ); | |
2223 | 2251 | return 0; |
2224 | 2252 | } |
2225 | 2253 | #if defined(X3270_ANSI) /*[*/ |
... | ... | @@ -2284,7 +2312,7 @@ LIB3270_EXPORT int lib3270_deleteword(H3270 *hSession) |
2284 | 2312 | |
2285 | 2313 | // reset_idle_timer(); |
2286 | 2314 | if (hSession->kybdlock) { |
2287 | - ENQUEUE_ACTION(lib3270_deleteword); | |
2315 | + enq_action(hSession, lib3270_deleteword); | |
2288 | 2316 | // enq_ta(DeleteWord_action, CN, CN); |
2289 | 2317 | return 0; |
2290 | 2318 | } |
... | ... | @@ -2353,7 +2381,7 @@ LIB3270_EXPORT int lib3270_deletefield(H3270 *hSession) |
2353 | 2381 | |
2354 | 2382 | // reset_idle_timer(); |
2355 | 2383 | if (hSession->kybdlock) { |
2356 | - ENQUEUE_ACTION(lib3270_deletefield); | |
2384 | + enq_action(hSession, lib3270_deletefield); | |
2357 | 2385 | // enq_ta(DeleteField_action, CN, CN); |
2358 | 2386 | return 0; |
2359 | 2387 | } |
... | ... | @@ -2399,7 +2427,7 @@ LIB3270_EXPORT int lib3270_fieldend(H3270 *hSession) |
2399 | 2427 | |
2400 | 2428 | if (hSession->kybdlock) |
2401 | 2429 | { |
2402 | - ENQUEUE_ACTION( lib3270_fieldend ); | |
2430 | + enq_action(hSession, lib3270_fieldend ); | |
2403 | 2431 | return 0; |
2404 | 2432 | } |
2405 | 2433 | ... | ... |