1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
include <ctype.h>
define CAN_ABORT NO
define ABORT '\003'
# K_GET -- Read a character, translating function keys
int procedure k_get ()
#--
include "screen.com"
int ch
int first
int k_cget(), k_lookup()
string abortmsg "Task aborted by ^C"
begin
if (keych != EOF) {
# Check for a pushed back character, returning it if found
ch = keych
keych = EOF
} else {
# Check character to see if it is the start of a control sequence
# If not, return the character without searching the table
first = k_cget ()
if (IS_PRINT(first))
ch = first
else if ((CAN_ABORT == YES) && (first == ABORT))
call error (1, abortmsg)
else
ch = k_lookup (first, Memi[keytab])
}
return (ch)
end
# K_LOOKUP -- Look up a function key sequence in a table
int procedure k_lookup (first, table)
int first # i: First character in the sequence
int table[4,ARB] # i: Table of function key sequences
#--
include "screen.com"
int key, new, old, link
int k_cget()
begin
# Search the table for the control sequence
link = 0
key = first
for (new = 1; new != 0; new = table[link,old]) {
old = new
if (link == 1)
key = k_cget ()
if (key == table[3,old])
link = 1
else
link = 2
}
# Return the control sequence tag if the sequence was found,
# otherwise return the first unrecognized key
if (link == 1)
key = table[4,old]
return (key)
end
# K_CGET -- Read a single character from the terminal
int procedure k_cget ()
#--
include "screen.com"
int ch
int and(), getci()
begin
ch = getci (ttyin, ch)
return (and (ch, 177B))
end
|