8
typedef union keytab keytab;
11
enum {ACTION, EXTENDED} type;
18
keytab *extended[256];
22
keytab *base[256] = { NULL256 };
25
* Bind a key sequence to an action.
27
void bind_key (char *sequence, int len, keyact action) {
28
keytab *(*table)[256];
33
k = (unsigned char) *sequence++;
36
* We must create an EXTENDED entry.
38
(*table)[k] = malloc(sizeof(base[0]->e));
39
(*table)[k]->type = EXTENDED;
41
(*table)[k]->e.extended[i] = NULL;
42
} else if ( (*table)[k]->type == ACTION ) {
44
* A subsequence is already bound: fail.
48
table = &(*table)[k]->e.extended;
50
k = (unsigned char) *sequence;
53
* We can bind the key.
55
(*table)[k] = malloc(sizeof(base[0]->a));
56
(*table)[k]->type = ACTION;
57
(*table)[k]->a.action = action;
62
* Format an ASCII code into a printable description of the key stroke.
64
static void strkey (char *s, int k) {
65
k &= 255; /* force unsigned */
68
else if (k<32 || k==127)
69
sprintf(s, " ^%c", k ^ 64);
73
sprintf(s, " <0x%2X>", k);
77
* Get and process a key stroke.
79
void proc_key (void) {
82
#if defined(unix) && !defined(GO32)
87
last_char = display_getkey();
88
#if defined(unix) && !defined(GO32)
91
strcpy(message, "Unknown key sequence");
92
strkey(message+strlen(message), last_char);
93
kt = base[(unsigned char) last_char];
96
while (display_input_to_flush())
97
strkey(message+strlen(message), display_getkey());
101
while (kt->type == EXTENDED) {
102
#if defined(unix) && !defined(GO32)
107
last_char = display_getkey();
108
#if defined(unix) && !defined(GO32)
111
strkey(message+strlen(message), last_char);
112
kt = kt->e.extended[(unsigned char) last_char];
115
while (display_input_to_flush())
116
strkey(message+strlen(message), display_getkey());
120
message[0] = '\0'; /* clear the "unknown" message */