-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhelp.c
More file actions
349 lines (330 loc) · 7.83 KB
/
help.c
File metadata and controls
349 lines (330 loc) · 7.83 KB
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
/* $Id: help.c,v 1.6 2003/02/22 08:09:46 amura Exp $ */
/* Help functions for MicroGnuEmacs 2 */
#include "config.h" /* 90.12.20 by S.Yoshida */
#include "def.h"
#ifndef NO_HELP
#include "kbd.h"
#include "key.h"
#ifndef NO_MACRO
# include "macro.h"
#endif
/* 91.02.06 Move static declaration to here for some compiler. by S.Yoshida */
static int showall _PRO((char *, KEYMAP *));
static VOID findbind _PRO((PF, char *, KEYMAP *));
static VOID bindfound _PRO((VOID));
/*
* Read a key from the keyboard, and look it
* up in the keymap. Display the name of the function
* currently bound to the key.
*/
/*ARGSUSED*/
int
desckey(f, n)
int f, n;
{
register KEYMAP *curmap;
register PF funct;
register char *pep;
char prompt[80];
int c;
int m;
int i;
#ifndef NO_MACRO
if (inmacro)
return TRUE; /* ignore inside keyboard macro */
#endif
(VOID) strcpy(prompt, "Describe key briefly: ");
pep = prompt + strlen(prompt);
key.k_count = 0;
m = curbp->b_nmodes;
curmap = curbp->b_modes[m]->p_map;
#ifdef FEPCTRL /* 90.11.26 by K.Takano */
fepmode_off();
#endif
for (;;) {
for (;;) {
ewprintf("%s", prompt);
pep[-1] = ' ';
pep = keyname(pep, key.k_chars[key.k_count++] = c = getkey(FALSE));
if((funct = doscan(curmap, c)) != prefix) break;
*pep++ = '-';
*pep = '\0';
curmap = ele->k_prefmap;
}
if (funct != rescan)
break;
if (ISUPPER(key.k_chars[key.k_count-1])) {
funct = doscan(curmap, TOLOWER(key.k_chars[key.k_count-1]));
if (funct == prefix) {
*pep++ = '-';
*pep = '\0';
curmap = ele->k_prefmap;
continue;
}
if (funct != rescan)
break;
}
nextmode:
if (--m < 0)
break;
curmap = curbp->b_modes[m]->p_map;
for (i=0; i < key.k_count; i++) {
funct = doscan(curmap, key.k_chars[i]);
if (funct != prefix) {
if(i == key.k_count - 1 && funct != rescan) goto found;
funct = rescan;
goto nextmode;
}
curmap = ele->k_prefmap;
}
*pep++ = '-';
*pep = '\0';
}
found:
if (funct == rescan)
ewprintf("%k is not bound to any function");
else if((pep = function_name(funct)) != NULL)
ewprintf("%k runs the command %s", pep);
else
ewprintf("%k is bound to an unnamed function");
#ifdef KANJI /* code from Ng-1.3.1L+6 */
if (ISKANJI(c))
getkey(FALSE); /* eat up kanji 2nd byte */
#endif
return TRUE;
}
/*
* This function creates a table, listing all
* of the command keys and their current bindings, and stores
* the table in the *help* pop-up buffer. This
* lets MicroGnuEMACS produce it's own wall chart.
*/
static BUFFER *bp;
static char buf[80]; /* used by showall and findbind */
/*ARGSUSED*/
int
wallchart(f, n)
int f, n;
{
int m;
static char locbind[80] = "Local keybindings for mode ";
if ((bp = bfind("*help*", TRUE)) == NULL)
return FALSE;
#ifdef AUTOSAVE /* 96.12.24 by M.Suzuki */
bp->b_flag &= ~(BFCHG | BFACHG);/* Blow away old. */
#else
bp->b_flag &= ~BFCHG; /* Blow away old. */
#endif /* AUTOSAVE */
if (bclear(bp) != TRUE)
return FALSE; /* Clear it out. */
for (m=curbp->b_nmodes; m > 0; m--) {
(VOID) strcpy(&locbind[27], curbp->b_modes[m]->p_name);
(VOID) strcat(&locbind[27], ":");
if ((addline(bp, locbind) == FALSE) ||
(showall(buf, curbp->b_modes[m]->p_map) == FALSE) ||
(addline(bp, "") == FALSE))
return FALSE;
}
if ((addline(bp, "Global bindings:") == FALSE) ||
(showall(buf, map_table[0].p_map) == FALSE))
return FALSE;
return popbuftop(bp);
}
static int
showall(ind, map)
char *ind;
KEYMAP *map;
{
register MAP_ELEMENT *ele;
register int i;
PF functp;
char *cp;
char *cp2;
int last;
if (addline(bp, "") == FALSE)
return FALSE;
last = -1;
for (ele = &map->map_element[0];
ele < &map->map_element[map->map_num] ; ele++) {
if (map->map_default != rescan && ++last < ele->k_base) {
cp = keyname(ind, last);
if (last < ele->k_base - 1) {
(VOID) strcpy(cp, " .. ");
cp = keyname(cp + 4, ele->k_base - 1);
}
do {
*cp++ = ' ';
} while(cp < &buf[16]);
(VOID) strcpy(cp, function_name(map->map_default));
if (addline(bp, buf) == FALSE)
return FALSE;
}
last = ele->k_num;
for (i=ele->k_base; i <= last; i++) {
functp = ele->k_funcp[i - ele->k_base];
if (functp != rescan) {
if (functp != prefix)
cp2 = function_name(functp);
else
cp2 = map_name(ele->k_prefmap);
if (cp2 != NULL) {
cp = keyname(ind, i);
do {
*cp++ = ' ';
} while(cp < &buf[16]);
(VOID) strcpy(cp, cp2);
if (addline(bp, buf) == FALSE)
return FALSE;
}
}
}
}
for (ele = &map->map_element[0];
ele < &map->map_element[map->map_num]; ele++) {
if (ele->k_prefmap != NULL) {
for (i = ele->k_base;
ele->k_funcp[i - ele->k_base] != prefix; i++) {
if (i >= ele->k_num) /* damaged map */
return FALSE;
}
cp = keyname(ind, i);
*cp++ = ' ';
if (showall(cp, ele->k_prefmap) == FALSE)
return FALSE;
}
}
return TRUE;
}
int help_help _PRO((int, int));
int
help_help(f, n)
int f, n;
{
KEYMAP *kp;
PF funct;
if ((kp = name_map("help")) == NULL)
return FALSE;
ewprintf("a b c: ");
#ifdef FEPCTRL /* 90.11.26 by K.Takano */
fepmode_off();
#endif
do {
#ifdef KANJI /* code from Ng-1.3.1L+6 */
int c = getkey(FALSE);
if (ISKANJI(c)) {
getkey(FALSE);
return ABORT;
}
funct = doscan(kp, c);
#else
funct = doscan(kp, getkey(FALSE));
#endif
} while (funct==NULL || funct==help_help);
#ifndef NO_MACRO
if (macrodef && macrocount < MAXMACRO)
macro[macrocount-1].m_funct = funct;
#endif
return (*funct)(f, n);
}
static char buf2[128];
static char *buf2p;
/*ARGSUSED*/
int
apropos_command(f, n)
int f, n;
{
register char *cp1, *cp2;
char string[NINPUT];
FUNCTNAMES *fnp;
BUFFER *bp;
/* FALSE means we got a 0 character string, which is fine */
if (eread("apropos: ", string, sizeof(string), EFNEW) == ABORT)
return ABORT;
if ((bp = bfind("*help*", TRUE)) == NULL)
return FALSE;
bp->b_flag &= ~BFCHG; /* Blow away old. */
if (bclear(bp) == FALSE)
return FALSE;
for (fnp = &functnames[0]; fnp < &functnames[nfunct]; fnp++) {
for (cp1 = fnp->n_name; *cp1; cp1++) {
cp2 = string;
while (*cp2 && *cp1 == *cp2)
cp1++, cp2++;
if (!*cp2) {
(VOID) strcpy(buf2, fnp->n_name);
buf2p = &buf2[strlen(buf2)];
findbind(fnp->n_funct, buf, map_table[0].p_map);
if (addline(bp, buf2) == FALSE)
return FALSE;
break;
}
else
cp1 -= cp2 - string;
}
}
return popbuftop(bp);
}
static VOID
findbind(funct, ind, map)
PF funct;
char *ind;
KEYMAP *map;
{
register MAP_ELEMENT *ele;
register int i;
char *cp;
int last;
last = -1;
for (ele = &map->map_element[0];
ele < &map->map_element[map->map_num]; ele++) {
if (map->map_default == funct && ++last < ele->k_base) {
cp = keyname(ind, last);
if (last < ele->k_base - 1) {
(VOID) strcpy(cp, " .. ");
(VOID) keyname(cp + 4, ele->k_base - 1);
}
bindfound();
}
last = ele->k_num;
for (i=ele->k_base; i <= last; i++) {
if (funct == ele->k_funcp[i - ele->k_base]) {
if (funct == prefix) {
cp = map_name(ele->k_prefmap);
if (cp == NULL ||
strncmp(cp, buf2, strlen(cp)) != 0)
continue;
}
(VOID) keyname(ind, i);
bindfound();
}
}
}
for (ele = &map->map_element[0];
ele < &map->map_element[map->map_num]; ele++) {
if (ele->k_prefmap != NULL) {
for (i = ele->k_base;
ele->k_funcp[i - ele->k_base] != prefix; i++) {
if (i >= ele->k_num)
return; /* damaged */
}
cp = keyname(ind, i);
*cp++ = ' ';
findbind(funct, cp, ele->k_prefmap);
}
}
}
static VOID
bindfound() {
if (buf2p < &buf2[32]) {
do {
*buf2p++ = ' ';
} while(buf2p < &buf2[32]);
}
else {
*buf2p++ = ',';
*buf2p++ = ' ';
}
(VOID) strcpy(buf2p, buf);
buf2p += strlen(buf);
}
#endif