MCPcopy Create free account
hub / github.com/NetHack/NetHack / parse_function_key

Function parse_function_key

sys/vms/vmstty.c:295–366  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

293/* Ultimate return value is (index into smg_keypad_codes[] + 256). */
294
295static short
296parse_function_key(int c)
297{
298 struct _rd_iosb iosb;
299 unsigned long sts;
300 char seq_buf[15 + 1]; /* plenty room for escape sequence + slop */
301 short result = ESC; /* translate to <escape> by default */
302
303 /*
304 * Read whatever we can from type-ahead buffer (1 second timeout).
305 * If the user typed an actual <escape> to deliberately abort
306 * something, he or she should be able to tolerate the necessary
307 * restriction of a negligible pause before typing anything else.
308 * We might already have [at least some of] an escape sequence from a
309 * previous read, particularly if user holds down the arrow keys...
310 */
311 if (inc > 0)
312 strncpy(seq_buf, inp, inc);
313 if (inc < (int) (sizeof seq_buf) - 1) {
314 sts = sys$qiow(0, tt_chan, QIO_FUNC | IO$M_TIMED, &iosb,
315 (void (*) ()) 0, 0, seq_buf + inc,
316 sizeof seq_buf - 1 - inc, 1, 0, 0, 0);
317 if (vms_ok(sts))
318 sts = iosb.status;
319 } else
320 sts = SS$_NORMAL;
321 if (vms_ok(sts) || sts == SS$_TIMEOUT) {
322 int cnt = iosb.trm_offset + iosb.trm_siz + inc;
323 char *p = seq_buf;
324
325 if (c == ESC) /* check for 7-bit vt100/ANSI, or vt52 */
326 if (*p == '[' || *p == 'O')
327 c = META(CTRL(*p++)), cnt--;
328 else if (strchr(arrow_or_PF, *p))
329 c = SS3; /*CSI*/
330 if (cnt > 0 && (c == SS3 || (c == CSI && strchr(arrow_or_PF, *p)))) {
331 char *q = strchr(smg_keypad_codes, *p);
332
333 if (q)
334 result = 256 + (q - smg_keypad_codes);
335 p++, --cnt; /* one more char consumed */
336 } else if (cnt > 1 && c == CSI) {
337 static short /* "CSI nn ~" -> F_keys[nn] */
338 F_keys[35] = {
339 ESC, /*(filler)*/
340 311, 312, 313, 314, 315, 316, /* E1-E6 */
341 ESC, ESC, ESC, ESC, /*(more filler)*/
342 281, 282, 283, 284, 285, ESC, /* F1-F5 */
343 286, 287, 288, 289, 290, ESC, /* F6-F10*/
344 291, 292, 293, 294, ESC, /*F11-F14*/
345 295, 296, ESC, /*<help>,<do>, aka F15,F16*/
346 297, 298, 299, 300 /*F17-F20*/
347 }; /* note: there are several missing nn in CSI nn ~ values */
348 int nn;
349 char *q;
350
351 *(p + cnt) = '\0'; /* terminate string */
352 q = strchr(p, '~');

Callers 1

vms_getcharFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected