-
Notifications
You must be signed in to change notification settings - Fork 0
/
FTABLE.C
334 lines (255 loc) · 7.37 KB
/
FTABLE.C
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/* FTABLE.C -- Command Table Routines
Written March 1991 by Craig A. Finseth
Copyright 1991,2,3,4 by Craig A. Finseth
*/
#include "freyja.h"
/* command table conventions are:
base 0 RES_BASE
control-x 1 RES_CTX
meta 2 RES_ESC
function keys 3 RES_FUNC
*/
/* In help strings:
@ no command
^ self-insert
*/
void (*cmddisp[])() = { MNotImpl, MInsChar,
BBufUnmod,
CCharB, CCharBD, CCharF, CCharFD, CCharTran, CLineA, CLineAED, CLineB,
CLineE, CLineF, CLineFD, CScrnB, CScrnBOW, CScrnF, CScrnFOW,
DCal, DLeft, DNewDisplay, DNext, DPrev, DRight, DScreenRange,
DTogVisGray, DWindGrow, DWindOne, DWindSwap, DWindTog, DWindTwo,
DWindTwoO,
FBufBeg, FBufDel, FBufEnd, FBufList, FBufNext, FBufPrev, FBufPrint,
FCommand, FDIRED, FFileDelete, FFileFind, FFileIns, FFilePath,
FFileRead, FFileSave, FFileWrite, FPrintSel, FSaveAll, FToDIRED,
#if defined(SYSMGR)
JCopy, JCut, JPaste,
#else
MNotImpl, MNotImpl, MNotImpl,
#endif
KBegMac, KColon, KEndMac, KFromMac, KLoadMac,
MAbort, MAbout, MApropos,
#if defined(MSDOS)
MAttr,
#else
MNotImpl,
#endif
MCharAt, MCtrlX, MDate, MDescBind, MDescKey, MDoKey, MExit, MFont,
MIns8, MInsPgBk, MMacEval, MMakeDelete, MMenu, MMenuH, MMenuM, MMeta,
MQuote, MReplace, MReplaceQ, MSearchB, MSearchF, MTime, MTogPgLn,
MUArg,
RDelWhite, RHardToSoft, RIndent, RLower, RMarkSet, RMarkSwap, RMeta,
ROutdent, RPrint, RRegCopy, RRegDelete, RRegFill, RSave, RSoftToHard,
RTabify, RUntabify, RUpper, RYank,
#if !defined(NOCALC)
UCalc, UEnter, UPrintX,
#else
MNotImpl, MNotImpl, MNotImpl,
#endif
WCaseRotate, WIndDel, WIndNext, WIndThis, WInsNL, WInsNLA, WJoinGray,
WLineCenter,
#if !defined(NOCALC)
WNumB, WNumF, WNumMark,
#else
MNotImpl, MNotImpl, MNotImpl,
#endif
WParaB, WParaF, WParaFill, WParaMark, WPrintLine, WPrintMar,
WPrintPos, WSentB, WSentBD, WSentF, WSentFD, WSetFill, WSetLeft,
WSetRight, WSetTabs, WWordB, WWordBD, WWordCap, WWordF, WWordFD,
WWordLow, WWordTran, WWordUp };
static char descrbuf[SMALLBUFFSIZE];
void *Tab_GetCmd(KEYCODE key, int table);
char *Tab_Help(int restable, KEYCODE key);
int Tab_Proc(int restable, KEYCODE key);
/* ------------------------------------------------------------ */
/* Return the command's description. */
char *
TabDescr(KEYCODE key, int table)
{
if (key == KEYQUIT)
return((char *)Res_String(NULL, RES_MSGS, RES_QUITKEY));
if (key == KEYABORT)
return((char *)Res_String(NULL, RES_MSGS, RES_ABORTKEY));
if (key >= 256) table = 3;
switch (table) {
case 0:
if (key > 127 && c.g.meta_handle == 'M')
return(TabDescr(key & 0x7f, 2));
return(TPrintChar(key & 0x7F));
/* break; */
case 1:
key &= 0x7F;
xsprintf(descrbuf, "%s ", TPrintChar(ZCX));
strcat(descrbuf, TPrintChar(key));
return(descrbuf);
/* break; */
case 2:
key &= 0x7F;
xsprintf(descrbuf, "%s ", TPrintChar(ESC));
strcat(descrbuf, TPrintChar(key));
return(descrbuf);
/* break; */
case 3:
if (key >= 256) key &= 0xFF;
return((char *)Res_String(NULL, RES_KEYLABEL, key));
/* break; */
}
}
/* ------------------------------------------------------------ */
/* Invoke the specifed key from the specified table. */
void
TabDispatch(KEYCODE key, int table)
{
if (key == KEYQUIT) {
MExit();
return;
}
if (key == KEYABORT) {
MAbort();
return;
}
if (key >= 256) table = 3;
switch (table) {
case 0:
if (key > 127) {
if (c.g.meta_handle == 'M')
(* (void(*)()) Tab_Proc(RES_ESC, key & 0x7F)
)();
else if (c.g.meta_handle == 'I')
MInsChar();
else MNotImpl();
}
else (* (void(*)()) Tab_Proc(RES_BASE, key & 0x7F) )();
break;
case 1:
(* (void(*)()) Tab_Proc(RES_CTX, key & 0x7F) )();
break;
case 2:
(* (void(*)()) Tab_Proc(RES_ESC, key & 0x7F) )();
break;
case 3:
if (key >= 256) key &= 0xff;
(* (void(*)()) Tab_Proc(RES_FUNC, key) )();
break;
}
}
/* ------------------------------------------------------------ */
/* Return a pointer to the help string for the specified command. */
char *
TabHelp(KEYCODE key, int table)
{
if (key == KEYQUIT)
return((char *)Res_String(NULL, RES_MSGS, RES_QUITHELP));
if (key == KEYABORT)
return((char *)Res_String(NULL, RES_MSGS, RES_ABORTHELP));
if (key >= 256) table = 3;
switch (table) {
case 0:
if (key > 127) {
if (c.g.meta_handle == 'M')
return(Tab_Help(RES_ESC, key & 0x7F));
else if (c.g.meta_handle == 'I')
return("^");
else return("@");
}
return(Tab_Help(RES_BASE, key & 0x7F));
/* break; */
case 1:
return(Tab_Help(RES_CTX, key & 0x7F));
/* break; */
case 2:
return(Tab_Help(RES_ESC, key & 0x7F));
/* break; */
case 3:
if (key >= 256) key &= 0xff;
return(Tab_Help(RES_FUNC, key));
/* break; */
}
}
/* ------------------------------------------------------------ */
/* Return the next command table or 0 if not a prefix. */
int
TabTable(KEYCODE key, int table)
{
if (key == KEYQUIT) return(0);
if (key == KEYABORT) return(0);
if (key >= 256) return(3);
if (table == 0) {
if (key == ZCX) return(1);
else if (key == ESC) return(2);
else if (key >= 256) return(3);
}
return(0);
}
/* ------------------------------------------------------------ */
/* Return True if the command is a deletion (kill) command or False if
not. */
FLAG
TabIsDelete(KEYCODE key, int table)
{
void (*cmd)();
cmd = (void (*)())Tab_GetCmd(key, table);
return(cmd == CLineFD ||
cmd == CLineAED ||
cmd == MMakeDelete ||
cmd == RRegDelete ||
cmd == RRegCopy ||
cmd == WSentFD ||
cmd == WWordBD ||
cmd == WWordFD);
}
/* ------------------------------------------------------------ */
/* Return True if the command is a vertical motion command or False if
not. */
FLAG
TabIsVMove(KEYCODE key, int table)
{
void (*cmd)();
cmd = (void (*)())Tab_GetCmd(key, table);
return(cmd == CLineB || cmd == CLineF);
}
/* ------------------------------------------------------------ */
/* Return the number of function keys. */
int
TabNumFunc(void)
{
return(256);
}
/* ------------------------------------------------------------ */
/* Return the command implied by KEY and TABLE. */
void *
Tab_GetCmd(KEYCODE key, int table)
{
void (*cmd)();
if (key == KEYQUIT) return((void *)MExit);
if (key == KEYABORT) return((void *)MAbort);
if (key >= 256) table = 3;
switch (table) {
case 0: cmd = (void (*)())Tab_Proc(RES_BASE, key & 0x7f);break;
case 1: cmd = (void (*)())Tab_Proc(RES_CTX, key & 0x7f); break;
case 2: cmd = (void (*)())Tab_Proc(RES_ESC, key & 0x7f); break;
case 3: if (key >= 256) key &= 0xff;
cmd = (void (*)()) Tab_Proc(RES_FUNC, key);
break;
}
return((void *)cmd);
}
/* ------------------------------------------------------------ */
/* Get help for KEY from resource table RESTABLE. */
char *
Tab_Help(int restable, KEYCODE key)
{
return((char *)Res_String(NULL, RES_HELPSTR,
*((unsigned char *)Res_String(NULL, restable, 0) + key)));
}
/* ------------------------------------------------------------ */
/* Return the procedure that does the KEY from resource table
RESTABLE. */
int
Tab_Proc(int restable, KEYCODE key)
{
return((int)cmddisp[
*((unsigned char *)Res_String(NULL, restable, 0) + key) ]);
}
/* end of FTABLE.C -- Command Table Routines */