7 typedef union keytab keytab
;
10 enum {ACTION
, EXTENDED
} type
;
17 keytab
*extended
[256];
21 keytab
*base
[256] = { NULL256
};
24 * Bind a key sequence to an action.
26 void bind_key (char *sequence
, int len
, keyact action
) {
27 keytab
*(*table
)[256];
32 k
= (unsigned char) *sequence
++;
35 * We must create an EXTENDED entry.
37 (*table
)[k
] = malloc(sizeof(base
[0]->e
));
38 (*table
)[k
]->type
= EXTENDED
;
40 (*table
)[k
]->e
.extended
[i
] = NULL
;
41 } else if ( (*table
)[k
]->type
== ACTION
) {
43 * A subsequence is already bound: fail.
47 table
= &(*table
)[k
]->e
.extended
;
49 k
= (unsigned char) *sequence
;
52 * We can bind the key.
54 (*table
)[k
] = malloc(sizeof(base
[0]->a
));
55 (*table
)[k
]->type
= ACTION
;
56 (*table
)[k
]->a
.action
= action
;
61 * Format an ASCII code into a printable description of the key stroke.
63 static void strkey (char *s
, int k
) {
64 k
&= 255; /* force unsigned */
67 else if (k
<32 || k
==127)
68 sprintf(s
, " ^%c", k
^ 64);
72 sprintf(s
, " <0x%2X>", k
);
76 * Get and process a key stroke.
78 void proc_key (void) {
81 #if defined(unix) && !defined(GO32)
86 last_char
= display_getkey();
87 #if defined(unix) && !defined(GO32)
90 strcpy(message
, "Unknown key sequence");
91 strkey(message
+strlen(message
), last_char
);
92 kt
= base
[(unsigned char) last_char
];
95 while (display_input_to_flush())
96 strkey(message
+strlen(message
), display_getkey());
100 while (kt
->type
== EXTENDED
) {
101 #if defined(unix) && !defined(GO32)
106 last_char
= display_getkey();
107 #if defined(unix) && !defined(GO32)
110 strkey(message
+strlen(message
), last_char
);
111 kt
= kt
->e
.extended
[(unsigned char) last_char
];
114 while (display_input_to_flush())
115 strkey(message
+strlen(message
), display_getkey());
119 message
[0] = '\0'; /* clear the "unknown" message */