Commit ffeef60c3a3daed4b0464f4140978199844534fd

Authored by perry.werneck@gmail.com
1 parent 447c3f0d

Movendo fila de teclado para a estrutura de sessão

Showing 1 changed file with 27 additions and 502 deletions   Show diff stats
kybd.c
... ... @@ -35,6 +35,10 @@
35 35 * This module handles the keyboard for the 3270 emulator.
36 36 */
37 37  
  38 +struct ta;
  39 +
  40 +#define LIB3270_TA struct ta
  41 +
38 42 #include "globals.h"
39 43  
40 44 #ifndef ANDROID
... ... @@ -153,7 +157,7 @@ static int n_composites = 0;
153 157 #define ak_eq(k1, k2) (((k1).keysym == (k2).keysym) && \
154 158 ((k1).keytype == (k2).keytype))
155 159  
156   -static struct ta
  160 +struct ta
157 161 {
158 162 struct ta *next;
159 163  
... ... @@ -164,12 +168,15 @@ static struct ta
164 168 TA_TYPE_USER
165 169 } type;
166 170  
167   - H3270 * session;
168 171 void (*fn)(H3270 *, const char *, const char *);
169 172 char *parm[2];
170 173 unsigned char aid_code;
171   -} *ta_head = (struct ta *) NULL,
  174 +};
  175 +
  176 +/*
  177 +*ta_head = (struct ta *) NULL,
172 178 *ta_tail = (struct ta *) NULL;
  179 +*/
173 180  
174 181  
175 182 #if defined(DEBUG) || defined(ANDROID)
... ... @@ -238,16 +245,16 @@ static int enq_chk(H3270 *session)
238 245  
239 246 trace("Adding key %02x on queue",(int) aid_code);
240 247  
241   - if (ta_head)
  248 + if (session->ta_head)
242 249 {
243   - ta_tail->next = ta;
  250 + session->ta_tail->next = ta;
244 251 }
245 252 else
246 253 {
247   - ta_head = ta;
  254 + session->ta_head = ta;
248 255 status_typeahead(session,True);
249 256 }
250   - ta_tail = ta;
  257 + session->ta_tail = ta;
251 258  
252 259 trace_event(" Key-aid queued (kybdlock 0x%x)\n", session->kybdlock);
253 260 }
... ... @@ -271,7 +278,6 @@ static void enq_ta(H3270 *hSession, void (*fn)(H3270 *, const char *, const char
271 278 return;
272 279  
273 280 ta = (struct ta *) lib3270_malloc(sizeof(*ta));
274   - ta->session = hSession;
275 281 ta->next = (struct ta *) NULL;
276 282 ta->type = TA_TYPE_DEFAULT;
277 283 ta->fn = fn;
... ... @@ -282,16 +288,16 @@ static void enq_ta(H3270 *hSession, void (*fn)(H3270 *, const char *, const char
282 288 if (parm2)
283 289 ta->parm[1] = NewString(parm2);
284 290  
285   - if (ta_head)
  291 + if(hSession->ta_head)
286 292 {
287   - ta_tail->next = ta;
  293 + hSession->ta_tail->next = ta;
288 294 }
289 295 else
290 296 {
291   - ta_head = ta;
  297 + hSession->ta_head = ta;
292 298 status_typeahead(hSession,True);
293 299 }
294   - ta_tail = ta;
  300 + hSession->ta_tail = ta;
295 301  
296 302 trace_event(" action queued (kybdlock 0x%x)\n", h3270.kybdlock);
297 303 }
... ... @@ -303,30 +309,30 @@ Boolean run_ta(void)
303 309 {
304 310 struct ta *ta;
305 311  
306   - if (h3270.kybdlock || (ta = ta_head) == (struct ta *)NULL)
  312 + if (h3270.kybdlock || (ta = h3270.ta_head) == (struct ta *)NULL)
307 313 return False;
308 314  
309   - if ((ta_head = ta->next) == (struct ta *)NULL)
  315 + if ((h3270.ta_head = ta->next) == (struct ta *)NULL)
310 316 {
311   - ta_tail = (struct ta *)NULL;
  317 + h3270.ta_tail = (struct ta *)NULL;
312 318 status_typeahead(&h3270,False);
313 319 }
314 320  
315 321 switch(ta->type)
316 322 {
317 323 case TA_TYPE_DEFAULT:
318   - ta->fn(ta->session,ta->parm[0],ta->parm[1]);
  324 + ta->fn(&h3270,ta->parm[0],ta->parm[1]);
319 325 lib3270_free(ta->parm[0]);
320 326 lib3270_free(ta->parm[1]);
321 327 break;
322 328  
323 329 case TA_TYPE_KEY_AID:
324 330 trace("Sending enqueued key %02x",ta->aid_code);
325   - key_AID(ta->session,ta->aid_code);
  331 + key_AID(&h3270,ta->aid_code);
326 332 break;
327 333  
328 334 default:
329   - popup_an_error(ta->session, _( "Unexpected type %d in typeahead queue" ), ta->type);
  335 + popup_an_error(&h3270, _( "Unexpected type %d in typeahead queue" ), ta->type);
330 336  
331 337 }
332 338  
... ... @@ -339,13 +345,12 @@ Boolean run_ta(void)
339 345 * Flush the typeahead queue.
340 346 * Returns whether or not anything was flushed.
341 347 */
342   -static Boolean
343   -flush_ta(void)
  348 +static Boolean flush_ta(void)
344 349 {
345 350 struct ta *ta, *next;
346 351 Boolean any = False;
347 352  
348   - for (ta = ta_head; ta != (struct ta *) NULL; ta = next)
  353 + for (ta = h3270.ta_head; ta != (struct ta *) NULL; ta = next)
349 354 {
350 355 lib3270_free(ta->parm[0]);
351 356 lib3270_free(ta->parm[1]);
... ... @@ -353,7 +358,7 @@ flush_ta(void)
353 358 lib3270_free(ta);
354 359 any = True;
355 360 }
356   - ta_head = ta_tail = (struct ta *) NULL;
  361 + h3270.ta_head = h3270.ta_tail = (struct ta *) NULL;
357 362 status_typeahead(&h3270,False);
358 363 return any;
359 364 }
... ... @@ -1001,316 +1006,6 @@ static Boolean key_Character(int code, Boolean with_ge, Boolean pasting, Boolean
1001 1006 }
1002 1007  
1003 1008 /*
1004   -#if defined(X3270_DBCS)
1005   -static void
1006   -key_WCharacter_wrapper(Widget w unused, XEvent *event unused, String *params, Cardinal *num_params unused)
1007   -{
1008   - int code;
1009   - unsigned char codebuf[2];
1010   -
1011   - code = atoi(params[0]);
1012   - trace_event(" %s -> Key(0x%04x)\n",
1013   - ia_name[(int) ia_cause], code);
1014   - codebuf[0] = (code >> 8) & 0xff;
1015   - codebuf[1] = code & 0xff;
1016   - (void) key_WCharacter(codebuf, NULL);
1017   -}
1018   -
1019   -//
1020   -// Input a DBCS character.
1021   -// Returns True if a character was stored in the buffer, False otherwise.
1022   -//
1023   -Boolean key_WCharacter(unsigned char code[], Boolean *skipped)
1024   -{
1025   - int baddr;
1026   - register unsigned char fa;
1027   - int faddr;
1028   - enum dbcs_state d;
1029   - int xaddr;
1030   - Boolean done = False;
1031   - Boolean no_si = False;
1032   - extern unsigned char reply_mode; // XXX
1033   -
1034   - reset_idle_timer();
1035   -
1036   - if (kybdlock) {
1037   - char codename[64];
1038   -
1039   - (void) sprintf(codename, "%d", (code[0] << 8) | code[1]);
1040   - enq_ta(key_WCharacter_wrapper, codename, CN);
1041   - return False;
1042   - }
1043   -
1044   - if (skipped != NULL)
1045   - *skipped = False;
1046   -
1047   - // In DBCS mode?
1048   - if (!dbcs) {
1049   - trace_event("DBCS character received when not in DBCS mode, "
1050   - "ignoring.\n");
1051   - return True;
1052   - }
1053   -
1054   -#if defined(X3270_ANSI)
1055   - // In ANSI mode?
1056   - if (IN_ANSI) {
1057   - char mb[16];
1058   -
1059   - dbcs_to_mb(code[0], code[1], mb);
1060   - net_sends(mb);
1061   - return True;
1062   - }
1063   -#endif
1064   -
1065   - baddr = cursor_addr;
1066   - fa = get_field_attribute(baddr);
1067   - faddr = find_field_attribute(baddr);
1068   -
1069   - // Protected?
1070   - if (ea_buf[baddr].fa || FA_IS_PROTECTED(fa)) {
1071   - operator_error(KL_OERR_PROTECTED);
1072   - return False;
1073   - }
1074   -
1075   - // Numeric?
1076   - if (h3270.numeric_lock && FA_IS_NUMERIC(fa)) {
1077   - operator_error(KL_OERR_NUMERIC);
1078   - return False;
1079   - }
1080   -
1081   - //
1082   - // Figure our what to do based on the DBCS state of the buffer.
1083   - // Leaves baddr pointing to the next unmodified position.
1084   - //
1085   -retry:
1086   - switch (d = ctlr_dbcs_state(baddr)) {
1087   - case DBCS_RIGHT:
1088   - case DBCS_RIGHT_WRAP:
1089   - // Back up one position and process it as a LEFT.
1090   - DEC_BA(baddr);
1091   - // fall through...
1092   - case DBCS_LEFT:
1093   - case DBCS_LEFT_WRAP:
1094   - // Overwrite the existing character.
1095   - if (insert) {
1096   - if (!ins_prep(faddr, baddr, 2)) {
1097   - return False;
1098   - }
1099   - }
1100   - ctlr_add(baddr, code[0], ea_buf[baddr].cs);
1101   - INC_BA(baddr);
1102   - ctlr_add(baddr, code[1], ea_buf[baddr].cs);
1103   - INC_BA(baddr);
1104   - done = True;
1105   - break;
1106   - case DBCS_SB:
1107   - // Back up one position and process it as an SI.
1108   - DEC_BA(baddr);
1109   - // fall through...
1110   - case DBCS_SI:
1111   - // Extend the subfield to the right.
1112   - if (insert) {
1113   - if (!ins_prep(faddr, baddr, 2)) {
1114   - return False;
1115   - }
1116   - } else {
1117   - // Don't overwrite a field attribute or an SO.
1118   - xaddr = baddr;
1119   - INC_BA(xaddr); // C1
1120   - if (ea_buf[xaddr].fa)
1121   - break;
1122   - if (ea_buf[xaddr].cc == EBC_so)
1123   - no_si = True;
1124   - INC_BA(xaddr); // SI
1125   - if (ea_buf[xaddr].fa || ea_buf[xaddr].cc == EBC_so)
1126   - break;
1127   - }
1128   - ctlr_add(baddr, code[0], ea_buf[baddr].cs);
1129   - INC_BA(baddr);
1130   - ctlr_add(baddr, code[1], ea_buf[baddr].cs);
1131   - if (!no_si) {
1132   - INC_BA(baddr);
1133   - ctlr_add(baddr, EBC_si, ea_buf[baddr].cs);
1134   - }
1135   - done = True;
1136   - break;
1137   - case DBCS_DEAD:
1138   - break;
1139   - case DBCS_NONE:
1140   - if (ea_buf[faddr].ic) {
1141   - Boolean extend_left = FALSE;
1142   -
1143   - // Is there room?
1144   - if (insert) {
1145   - if (!ins_prep(faddr, baddr, 4)) {
1146   - return False;
1147   - }
1148   - } else {
1149   - xaddr = baddr; // baddr, SO
1150   - if (ea_buf[xaddr].cc == EBC_so) {
1151   - //
1152   - // (baddr), where we would have put the
1153   - // SO, is already an SO. Move to
1154   - // (baddr+1) and try again.
1155   - //
1156   -#if defined(DBCS_RIGHT_DEBUG)
1157   - printf("SO in position 0\n");
1158   -#endif
1159   - INC_BA(baddr);
1160   - goto retry;
1161   - }
1162   -
1163   - INC_BA(xaddr); // baddr+1, C0
1164   - if (ea_buf[xaddr].fa)
1165   - break;
1166   - if (ea_buf[xaddr].cc == EBC_so) {
1167   - enum dbcs_state e;
1168   -
1169   - //
1170   - // (baddr+1), where we would have put
1171   - // the left side of the DBCS, is a SO.
1172   - // If there's room, we can extend the
1173   - // subfield to the left. If not, we're
1174   - // stuck.
1175   - //
1176   - DEC_BA(xaddr);
1177   - DEC_BA(xaddr);
1178   - e = ctlr_dbcs_state(xaddr);
1179   - if (e == DBCS_NONE || e == DBCS_SB) {
1180   - extend_left = True;
1181   - no_si = True;
1182   -#if defined(DBCS_RIGHT_DEBUG)
1183   - printf("SO in position 1, "
1184   - "extend left\n");
1185   -#endif
1186   - } else {
1187   - //
1188   - // Won't actually happen,
1189   - // because this implies that
1190   - // the buffer addr at baddr
1191   - // is an SB.
1192   - //
1193   -#if defined(DBCS_RIGHT_DEBUG)
1194   - printf("SO in position 1, "
1195   - "no room on left, "
1196   - "fail\n");
1197   -#endif
1198   - break;
1199   - }
1200   - }
1201   -
1202   - INC_BA(xaddr); // baddr+2, C1
1203   - if (ea_buf[xaddr].fa)
1204   - break;
1205   - if (ea_buf[xaddr].cc == EBC_so) {
1206   - //
1207   - // (baddr+2), where we want to put the
1208   - // right half of the DBCS character, is
1209   - // a SO. This is a natural extension
1210   - // to the left -- just make sure we
1211   - // don't write an SI.
1212   - //
1213   - no_si = True;
1214   -#if defined(DBCS_RIGHT_DEBUG)
1215   - printf("SO in position 2, no SI\n");
1216   -#endif
1217   - }
1218   -
1219   - //
1220   - // Check the fourth position only if we're
1221   - // not doing an extend-left.
1222   - ///
1223   - if (!no_si) {
1224   - INC_BA(xaddr); // baddr+3, SI
1225   - if (ea_buf[xaddr].fa)
1226   - break;
1227   - if (ea_buf[xaddr].cc == EBC_so) {
1228   - //
1229   - // (baddr+3), where we want to
1230   - // put an
1231   - // SI, is an SO. Forget it.
1232   - //
1233   -#if defined(DBCS_RIGHT_DEBUG)
1234   - printf("SO in position 3, "
1235   - "retry right\n");
1236   - INC_BA(baddr);
1237   - goto retry;
1238   -#endif
1239   - break;
1240   - }
1241   - }
1242   - }
1243   - // Yes, add it.
1244   - if (extend_left)
1245   - DEC_BA(baddr);
1246   - ctlr_add(baddr, EBC_so, ea_buf[baddr].cs);
1247   - INC_BA(baddr);
1248   - ctlr_add(baddr, code[0], ea_buf[baddr].cs);
1249   - INC_BA(baddr);
1250   - ctlr_add(baddr, code[1], ea_buf[baddr].cs);
1251   - if (!no_si) {
1252   - INC_BA(baddr);
1253   - ctlr_add(baddr, EBC_si, ea_buf[baddr].cs);
1254   - }
1255   - done = True;
1256   - } else if (reply_mode == SF_SRM_CHAR) {
1257   - // Use the character attribute.
1258   - if (insert) {
1259   - if (!ins_prep(faddr, baddr, 2)) {
1260   - return False;
1261   - }
1262   - } else {
1263   - xaddr = baddr;
1264   - INC_BA(xaddr);
1265   - if (ea_buf[xaddr].fa)
1266   - break;
1267   - }
1268   - ctlr_add(baddr, code[0], CS_DBCS);
1269   - INC_BA(baddr);
1270   - ctlr_add(baddr, code[1], CS_DBCS);
1271   - INC_BA(baddr);
1272   - done = True;
1273   - }
1274   - break;
1275   - }
1276   -
1277   - if (done) {
1278   - // Implement blank fill mode.
1279   - if (lib3270_get_toggle(&h3270,LIB3270_TOGGLE_BLANK_FILL)) {
1280   - xaddr = faddr;
1281   - INC_BA(xaddr);
1282   - while (xaddr != baddr) {
1283   - if (ea_buf[xaddr].cc == EBC_null)
1284   - ctlr_add(xaddr, EBC_space, CS_BASE);
1285   - else
1286   - break;
1287   - INC_BA(xaddr);
1288   - }
1289   - }
1290   -
1291   - mdt_set(cursor_addr);
1292   -
1293   - // Implement auto-skip.
1294   - while (ea_buf[baddr].fa) {
1295   - if (skipped != NULL)
1296   - *skipped = True;
1297   - if (FA_IS_SKIP(ea_buf[baddr].fa))
1298   - baddr = next_unprotected(&h3270,baddr);
1299   - else
1300   - INC_BA(baddr);
1301   - }
1302   - cursor_move(baddr);
1303   - (void) ctlr_dbcs_postprocess();
1304   - return True;
1305   - } else {
1306   - operator_error(KL_OERR_DBCS);
1307   - return False;
1308   - }
1309   -}
1310   -#endif
1311   -*/
1312   -
1313   -/*
1314 1009 * Handle an ordinary character key, given an ASCII code.
1315 1010 */
1316 1011 void key_ACharacter(unsigned char c, enum keytype keytype, enum iaction cause,Boolean *skipped)
... ... @@ -1341,59 +1036,6 @@ void key_ACharacter(unsigned char c, enum keytype keytype, enum iaction cause,Bo
1341 1036 }
1342 1037 }
1343 1038  
1344   -
1345   -/*
1346   - * Simple toggles.
1347   - */
1348   -/*
1349   -#if defined(X3270_DISPLAY)
1350   -void
1351   -AltCursor_action(Widget w unused, XEvent *event, String *params,
1352   - Cardinal *num_params)
1353   -{
1354   - reset_idle_timer();
1355   - do_toggle(ALT_CURSOR);
1356   -}
1357   -#endif
1358   -*/
1359   -
1360   -/*
1361   -void
1362   -MonoCase_action(Widget w unused, XEvent *event, String *params,
1363   - Cardinal *num_params)
1364   -{
1365   - reset_idle_timer();
1366   - do_toggle(MONOCASE);
1367   -}
1368   -*/
1369   -
1370   -/*
1371   - * Flip the display left-to-right
1372   - */
1373   - /*
1374   -void
1375   -Flip_action(Widget w unused, XEvent *event, String *params,
1376   - Cardinal *num_params)
1377   -{
1378   -
1379   -// reset_idle_timer();
1380   -
1381   - screen_flip();
1382   -}
1383   -*/
1384   -
1385   -
1386   -/*
1387   - * Tab forward to next field.
1388   - */
1389   -/*
1390   -void
1391   -Tab_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params)
1392   -{
1393   - action_NextField();
1394   -}
1395   -*/
1396   -
1397 1039 LIB3270_ACTION( nextfield )
1398 1040 {
1399 1041  
... ... @@ -1612,13 +1254,6 @@ do_left(void)
1612 1254 cursor_move(&h3270,baddr);
1613 1255 }
1614 1256  
1615   -/*
1616   -void Left_action(Widget w unused, XEvent *event, String *params, Cardinal *num_params)
1617   -{
1618   - action_CursorLeft();
1619   -}
1620   -*/
1621   -
1622 1257 LIB3270_CURSOR_ACTION( left )
1623 1258 {
1624 1259 if (hSession->kybdlock)
... ... @@ -2323,116 +1958,6 @@ LIB3270_ACTION( clear )
2323 1958 return 0;
2324 1959 }
2325 1960  
2326   -
2327   -/*
2328   - * Cursor Select key (light pen simulator).
2329   - */
2330   - /*
2331   -static void
2332   -lightpen_select(int baddr)
2333   -{
2334   - int faddr;
2335   - register unsigned char fa;
2336   - int designator;
2337   -#if defined(X3270_DBCS)
2338   - int designator2;
2339   -#endif
2340   -
2341   - faddr = find_field_attribute(baddr);
2342   - fa = ea_buf[faddr].fa;
2343   - if (!FA_IS_SELECTABLE(fa)) {
2344   - lib3270_ring_bell();
2345   - return;
2346   - }
2347   - designator = faddr;
2348   - INC_BA(designator);
2349   -
2350   -#if defined(X3270_DBCS)
2351   - if (dbcs) {
2352   - if (ea_buf[baddr].cs == CS_DBCS) {
2353   - designator2 = designator;
2354   - INC_BA(designator2);
2355   - if ((ea_buf[designator].db != DBCS_LEFT &&
2356   - ea_buf[designator].db != DBCS_LEFT_WRAP) &&
2357   - (ea_buf[designator2].db != DBCS_RIGHT &&
2358   - ea_buf[designator2].db != DBCS_RIGHT_WRAP)) {
2359   - lib3270_ring_bell();
2360   - return;
2361   - }
2362   - if (ea_buf[designator].cc == 0x42 &&
2363   - ea_buf[designator2].cc == EBC_greater) {
2364   - ctlr_add(designator2, EBC_question, CS_DBCS);
2365   - mdt_clear(faddr);
2366   - } else if (ea_buf[designator].cc == 0x42 &&
2367   - ea_buf[designator2].cc == EBC_question) {
2368   - ctlr_add(designator2, EBC_greater, CS_DBCS);
2369   - mdt_clear(faddr);
2370   - } else if ((ea_buf[designator].cc == EBC_space &&
2371   - ea_buf[designator2].cc == EBC_space) ||
2372   - (ea_buf[designator].cc == EBC_null &&
2373   - ea_buf[designator2].cc == EBC_null)) {
2374   - ctlr_add(designator2, EBC_greater, CS_DBCS);
2375   - mdt_set(faddr);
2376   - key_AID(AID_SELECT);
2377   - } else if (ea_buf[designator].cc == 0x42 &&
2378   - ea_buf[designator2].cc == EBC_ampersand) {
2379   - mdt_set(faddr);
2380   - key_AID(AID_ENTER);
2381   - } else {
2382   - lib3270_ring_bell();
2383   - }
2384   - return;
2385   - }
2386   - }
2387   -#endif
2388   -
2389   - switch (ea_buf[designator].cc) {
2390   - case EBC_greater:
2391   - ctlr_add(designator, EBC_question, 0);
2392   - mdt_clear(faddr);
2393   - break;
2394   - case EBC_question:
2395   - ctlr_add(designator, EBC_greater, 0);
2396   - mdt_set(faddr);
2397   - break;
2398   - case EBC_space:
2399   - case EBC_null:
2400   - mdt_set(faddr);
2401   - key_AID(AID_SELECT);
2402   - break;
2403   - case EBC_ampersand:
2404   - mdt_set(faddr);
2405   - key_AID(AID_ENTER);
2406   - break;
2407   - default:
2408   - lib3270_ring_bell();
2409   - break;
2410   - }
2411   -}
2412   -*/
2413   -
2414   -/*
2415   - * Cursor Select key (light pen simulator) -- at the current cursor location.
2416   - */
2417   -/*
2418   -void
2419   -CursorSelect_action(Widget w unused, XEvent *event, String *params,
2420   - Cardinal *num_params)
2421   -{
2422   -// reset_idle_timer();
2423   - if (kybdlock) {
2424   - enq_ta(CursorSelect_action, CN, CN);
2425   - return;
2426   - }
2427   -
2428   -#if defined(X3270_ANSI)
2429   - if (IN_ANSI)
2430   - return;
2431   -#endif
2432   - lightpen_select(cursor_addr);
2433   -}
2434   -*/
2435   -
2436 1961 /**
2437 1962 * Erase End Of Line Key.
2438 1963 *
... ...