-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbind.c
3661 lines (3216 loc) · 79.9 KB
/
bind.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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* This file is for functions having to do with key bindings,
* descriptions, help commands and startup file.
*
* written 11-feb-86 by Daniel Lawrence
*
* $Id: bind.c,v 1.384 2025/01/26 17:07:24 tom Exp $
*/
#include "estruct.h"
#include "edef.h"
#include "nefunc.h"
#include "nefsms.h"
#include "nename.h"
#define BI_DATA NBST_DATA
#include "btree.h"
#define SHORT_CMD_LEN 4 /* command names longer than this are preferred
over those shorter. e.g. display "quit"
instead of "q" if possible */
extern const int nametbl_size;
#define Strcmp(s,d) cs_strcmp(case_insensitive, s, d)
#define StrNcmp(s,d,len) cs_strncmp(case_insensitive, s, d, len)
#if OPT_REBIND
#define isSpecialCmd(k) \
( (k == &f_cntl_a_func)\
||(k == &f_cntl_x_func)\
||(k == &f_poundc_func)\
||(k == &f_reptc_func)\
||(k == &f_esc_func)\
)
static int key_to_bind(const CMDFUNC * kcmd);
static int update_binding_list(BUFFER *bp);
static void makebindlist(LIST_ARGS);
static void makebindkeyslist(LIST_ARGS);
#endif /* OPT_REBIND */
#if OPT_NAMEBST
static int kbd_complete_bst(unsigned flags, int c, char *buf, size_t *pos);
#else
#define kbd_complete_bst(params) \
kbd_complete(params, \
(const char *)&nametbl[0], sizeof(nametbl[0]))
#endif /* OPT_NAMEBST */
#if OPT_EVAL || OPT_REBIND
static int fnc2ntab(NTAB * result, const CMDFUNC * cfp);
static int prc2kcod(const char *kk);
#endif
BINDINGS dft_bindings =
{
BINDINGLIST_BufName
,asciitbl
,kbindtbl
#if OPT_REBIND
,kbindtbl
#endif
};
static const CMDFUNC *ins_table[N_chars];
BINDINGS ins_bindings =
{
INS_BINDINGS_BufName
,ins_table
,kbindtbl
#if OPT_REBIND
,kbindtbl
#endif
};
static const CMDFUNC *cmd_table[N_chars];
BINDINGS cmd_bindings =
{
CMD_BINDINGS_BufName
,cmd_table
,kbindtbl
#if OPT_REBIND
,kbindtbl
#endif
};
static const CMDFUNC *sel_table[N_chars];
BINDINGS sel_bindings =
{
SEL_BINDINGS_BufName
,sel_table
,kbindtbl
#if OPT_REBIND
,kbindtbl
#endif
};
static struct {
const char *name;
BINDINGS *binding;
} bindings_by_name[] = {
{
"command", &cmd_bindings
},
{
"default", &dft_bindings
},
{
"insert", &ins_bindings
},
{
"select", &sel_bindings
},
};
static UINT which_current;
#if OPT_REBIND
static BINDINGS *bindings_to_describe = &dft_bindings;
#endif
static void kbd_puts(const char *s);
/*----------------------------------------------------------------------------*/
BINDINGS *
vl_get_binding(const char *name)
{
BINDINGS *result = NULL;
unsigned n;
for (n = 0; n < TABLESIZE(bindings_by_name); ++n) {
if (!strncmp(bindings_by_name[n].name, name, strlen(name))) {
result = bindings_by_name[n].binding;
break;
}
}
return result;
}
/*----------------------------------------------------------------------------*/
#if OPT_NAMEBST
static void
old_namebst(BI_NODE * a)
{
beginDisplay();
if (!(a->value.n_flags & NBST_READONLY)) {
CMDFUNC *cmd = TYPECAST(CMDFUNC, a->value.n_cmd);
if (cmd != NULL) {
if ((cmd->c_flags & CMD_TYPE) != CMD_FUNC) {
#if OPT_ONLINEHELP
if (cmd->c_help)
free(TYPECAST(char, cmd->c_help));
#endif
#if OPT_MACRO_ARGS
if (cmd->c_args) {
int n;
for (n = 0; cmd->c_args[n].pi_text != NULL; ++n) {
free(cmd->c_args[n].pi_text);
}
free(cmd->c_args);
}
#endif
free(cmd);
free(TYPECAST(char, BI_KEY(a)));
}
} else {
free(TYPECAST(char, BI_KEY(a)));
}
}
free(a);
endofDisplay();
}
static BI_NODE *
new_namebst(BI_DATA * a)
{
BI_NODE *p;
beginDisplay();
if ((p = typecalloc(BI_NODE)) != NULL) {
p->value = *a;
if (!(a->n_flags & NBST_READONLY)) {
if ((BI_KEY(p) = strmalloc(a->bi_key)) == NULL) {
old_namebst(p);
p = NULL;
}
}
}
endofDisplay();
return p;
}
static void
dpy_namebst(BI_NODE * a GCC_UNUSED, int level GCC_UNUSED)
{
#if OPT_TRACE
TRACE(("[%d]%s%p -> %s%s (%d)\n",
level, alloc_indent(level, '.'),
(void *) a,
(a->value.n_flags & NBST_READONLY)
? "*"
: "",
BI_KEY(a), a->balance));
#endif
}
static void
xcg_namebst(BI_NODE * a, BI_NODE * b)
{
BI_DATA temp = a->value;
a->value = b->value;
b->value = temp;
}
#define BI_DATA0 {{NULL}, 0, {NULL,NULL,0}}
#define BI_TREE0 0, 0, BI_DATA0
static BI_TREE namebst =
{new_namebst, old_namebst, dpy_namebst, xcg_namebst, BI_TREE0};
static BI_TREE glbsbst =
{new_namebst, old_namebst, dpy_namebst, xcg_namebst, BI_TREE0};
static BI_TREE redefns =
{new_namebst, old_namebst, dpy_namebst, xcg_namebst, BI_TREE0};
/*----------------------------------------------------------------------------*/
/*
* Name-completion for global commands uses a different table (a subset) from
* the normal command-table. Provide a way to select that table.
*/
static BI_TREE *
bst_pointer(UINT which)
{
BI_TREE *result;
if (which == GLOBOK) {
result = &glbsbst;
} else {
result = &namebst;
}
return result;
}
static BI_TREE *
bst_current(void)
{
return bst_pointer(which_current);
}
#endif /* OPT_NAMEBST */
/*----------------------------------------------------------------------------*/
int
no_such_function(const char *fnp)
{
mlforce("[No such function \"%s\"]", NONNULL(fnp));
return FALSE;
}
/* give me some help!!!! bring up a buffer and read the help file into it */
/* ARGSUSED */
int
vl_help(int f GCC_UNUSED, int n GCC_UNUSED)
{
BUFFER *bp; /* buffer pointer to help */
char *hname;
int alreadypopped;
TRACE((T_CALLED "vl_help()\n"));
/* first check if we are already here */
bp = bfind(HELP_BufName, BFSCRTCH);
if (bp == NULL)
returnCode(FALSE);
if (bp->b_active == FALSE) { /* never been used */
hname = cfg_locate(helpfile, LOCATE_HELP);
if (!hname) {
mlforce("[Sorry, can't find the help information]");
(void) zotbuf(bp);
returnCode(FALSE);
}
alreadypopped = (bp->b_nwnd != 0);
/* and read the stuff in */
if (readin(hname, 0, bp, TRUE) != TRUE ||
popupbuff(bp) == FALSE) {
(void) zotbuf(bp);
returnCode(FALSE);
}
set_bname(bp, HELP_BufName);
set_rdonly(bp, hname, MDVIEW);
set_local_b_val(bp, MDIGNCASE, TRUE); /* easy to search, */
b_set_scratch(bp);
b_set_recentlychanged(bp);
if (!alreadypopped)
shrinkwrap();
}
if (!swbuffer(bp))
returnCode(FALSE);
if (help_at >= 0) {
if (!vl_gotoline(help_at))
returnCode(FALSE);
mlwrite("[Type '1G' to return to start of help information]");
help_at = -1; /* until zotbuf is called, we let normal
DOT tracking keep our position */
}
returnCode(TRUE);
}
/*
* translate a 10-bit key-binding to the table-pointer
*/
static KBIND *
kcode2kbind(const BINDINGS * bs, int code)
{
KBIND *kbp;
TRACE((T_CALLED "kcode2kbind(%s, %#x)\n", bs->bufname, code));
#if OPT_REBIND
for (kbp = bs->kb_extra; kbp != bs->kb_special; kbp = kbp->k_link) {
if (kbp->k_code == code) {
TRACE(("...found in extra-bindings\n"));
returnPtr(kbp);
}
}
#endif
for (kbp = bs->kb_special; kbp->k_cmd; kbp++) {
if (kbp->k_code == code) {
TRACE(("...found in special-bindings\n"));
returnPtr(kbp);
}
}
returnPtr(NULL);
}
#if OPT_REBIND
#if OPT_TERMCHRS
/* NOTE: this table and the corresponding initializations should be
* generated by 'mktbls'. In any case, the table must be sorted to use
* name-completion on it.
*/
static const struct {
const char *name;
int *value;
char how_to;
} TermChrs[] = {
/* *INDENT-OFF* */
{"backspace", &backspc, 's'},
{"interrupt", &intrc, 's'},
{"line-kill", &killc, 's'},
{"mini-edit", &editc, 's'},
{"name-complete", &name_cmpl, 0},
{"quote-next", "ec, 0},
{"start-output", &startc, 's'},
{"stop-output", &stopc, 's'},
{"suspend", &suspc, 's'},
{"test-completions", &test_cmpl, 0},
{"word-kill", &wkillc, 's'},
{NULL, NULL, 0}
/* *INDENT-ON* */
};
/*----------------------------------------------------------------------------*/
/* list the current chrs into the current buffer */
/* ARGSUSED */
static void
makechrslist(int dum1 GCC_UNUSED, void *ptr GCC_UNUSED)
{
int i;
char temp[NLINE];
bprintf("--- Terminal Character Settings ");
bpadc('-', term.cols - DOT.o);
bputc('\n');
for (i = 0; TermChrs[i].name != NULL; i++) {
bprintf("\n%s = %s",
TermChrs[i].name,
kcod2prc(*(TermChrs[i].value), temp));
}
}
/*
* Find a special-character definition, given the name
*/
static int
chr_lookup(const char *name)
{
int j;
if (name != NULL) {
for (j = 0; TermChrs[j].name != NULL; j++)
if (!strcmp(name, TermChrs[j].name))
return j;
}
return -1;
}
/*
* The 'chr_complete()' and 'chr_eol()' functions are invoked from
* 'kbd_reply()' to setup the mode-name completion and query displays.
*/
static int
chr_complete(DONE_ARGS)
{
return kbd_complete(PASS_DONE_ARGS, (const char *) &TermChrs[0],
sizeof(TermChrs[0]));
}
static int
/*ARGSUSED*/
chr_eol(EOL_ARGS)
{
(void) buffer;
(void) cpos;
(void) eolchar;
return isSpace(c);
}
#if OPT_UPBUFF
/* ARGSUSED */
static int
update_termchrs(BUFFER *bp GCC_UNUSED)
{
return show_termchrs(FALSE, 1);
}
#endif
/* ARGSUSED */
int
set_termchrs(int f GCC_UNUSED, int n GCC_UNUSED)
{
int s, j;
static TBUFF *name;
int c;
/* get the table-entry */
tb_scopy(&name, "");
if ((s = kbd_reply("Terminal setting: ", &name, chr_eol,
' ', 0, chr_complete)) == TRUE
&& (j = chr_lookup(tb_values(name))) >= 0) {
switch (TermChrs[j].how_to) {
case 's':
default:
c = key_to_bind((CMDFUNC *) 0);
if (c < 0)
return (FALSE);
*(TermChrs[j].value) = c;
break;
}
update_scratch(TERMINALCHARS_BufName, update_termchrs);
}
return s;
}
/* ARGSUSED */
int
show_termchrs(int f GCC_UNUSED, int n GCC_UNUSED)
{
return liststuff(TERMINALCHARS_BufName, FALSE, makechrslist, 0, (void *) 0);
}
#endif /* OPT_TERMCHRS */
static int
mac_token2kcod(int check)
{
static TBUFF *tok;
char *value;
int c;
if ((value = mac_unquotedarg(&tok)) == NULL) {
c = -1;
} else {
c = prc2kcod(value);
if (c < 0 && check)
mlforce("[Illegal key-sequence \"%s\"]", value);
}
return c;
}
/*
* Prompt-for and return the key-code to bind.
*/
static int
key_to_bind(const CMDFUNC * kcmd)
{
char outseq[NLINE]; /* output buffer for keystroke sequence */
int c;
mlprompt("...to keyboard sequence (type it exactly): ");
/* if running a command line, get a token rather than keystrokes */
if (clexec) {
c = mac_token2kcod(FALSE);
} else {
/* perhaps we only want a single key, not a sequence */
/* (see more comments below) */
if (isSpecialCmd(kcmd)) {
c = keystroke();
} else {
c = kbd_seq();
}
}
if (c >= 0) {
/* change it to something we can print as well */
outseq[0] = EOS;
if (vl_msgs)
kbd_puts(kcod2prc(c, outseq));
hst_append_s(outseq, FALSE, TRUE);
} else {
mlforce("[Not a proper key-sequence]");
}
return c;
}
static int
free_KBIND(KBIND ** oldp, KBIND * newp)
{
*oldp = newp->k_link;
beginDisplay();
free(newp);
endofDisplay();
return TRUE;
}
static int
unbindchar(BINDINGS * bs, int c)
{
KBIND *kbp; /* pointer into the command table */
KBIND *skbp; /* saved pointer into the command table */
/* if it's a simple character, it will be in the normal[] array */
if (is8Bits(c)) {
if (bs->kb_normal[CharOf(c)]) {
bs->kb_normal[CharOf(c)] = NULL;
return TRUE;
}
return FALSE;
}
/* check first entry in kb_extra table */
kbp = skbp = bs->kb_extra;
if (kbp->k_code == c) {
return free_KBIND(&(bs->kb_extra), kbp);
}
/* check kb_extra codes */
while (kbp != bs->kb_special) {
if (kbp->k_code == c) {
/* relink previous */
return free_KBIND(&(skbp->k_link), kbp);
}
skbp = kbp;
kbp = kbp->k_link;
}
/* nope, check special codes */
for (skbp = NULL; kbp->k_cmd; kbp++) {
if (!skbp && kbp->k_code == c)
skbp = kbp;
}
/* not found */
if (!skbp)
return FALSE;
--kbp; /* backup to the last legit entry */
if (skbp != kbp) {
/* copy the last entry to the current one */
skbp->k_code = kbp->k_code;
skbp->k_cmd = kbp->k_cmd;
}
/* null out the last one */
kbp->k_code = 0;
kbp->k_cmd = NULL;
return TRUE;
}
/*
* removes a key from the table of bindings
*/
static int
unbind_any_key(BINDINGS * bs)
{
int c; /* command key to unbind */
char outseq[NLINE]; /* output buffer for keystroke sequence */
/* prompt the user to type in a key to unbind */
mlprompt("Unbind this key sequence: ");
/* get the command sequence to unbind */
if (clexec) {
if ((c = mac_token2kcod(TRUE)) < 0)
return FALSE;
} else {
c = kbd_seq();
if (c < 0) {
mlforce("[Not a bindable key-sequence]");
return (FALSE);
}
}
if (vl_msgs)
kbd_puts(kcod2prc(c, outseq));
if (unbindchar(bs, c) == FALSE) {
mlforce("[Key not bound]");
return (FALSE);
}
update_scratch(bs->bufname, update_binding_list);
return (TRUE);
}
/* ARGSUSED */
int
unbindkey(int f GCC_UNUSED, int n GCC_UNUSED)
{
return unbind_any_key(&dft_bindings);
}
/* ARGSUSED */
int
unbind_i_key(int f GCC_UNUSED, int n GCC_UNUSED)
{
return unbind_any_key(&ins_bindings);
}
/* ARGSUSED */
int
unbind_c_key(int f GCC_UNUSED, int n GCC_UNUSED)
{
return unbind_any_key(&cmd_bindings);
}
/* ARGSUSED */
int
unbind_s_key(int f GCC_UNUSED, int n GCC_UNUSED)
{
return unbind_any_key(&sel_bindings);
}
/*
* Prefix-keys can be only bound to one value. This procedure tests the
* argument 'kcmd' to see if it is a prefix key, and if so, unbinds the
* key, and sets the corresponding global variable to the new value.
* The calling procedure will then do the binding per se.
*/
static void
reset_prefix(int c, const CMDFUNC * kcmd, BINDINGS * bs)
{
if (isSpecialCmd(kcmd)) {
int j;
/* search for an existing binding for the prefix key */
if ((j = fnc2kcod(kcmd)) >= 0)
(void) unbindchar(bs, j);
/* reset the appropriate global prefix variable */
if (kcmd == &f_cntl_a_func)
cntl_a = c;
if (kcmd == &f_cntl_x_func)
cntl_x = c;
if (kcmd == &f_poundc_func)
poundc = c;
if (kcmd == &f_reptc_func)
reptc = c;
if (kcmd == &f_esc_func)
esc_c = c;
}
}
/*
* Bind a command-function pointer to a given key-code (saving the old
* value of the function-pointer via an pointer given by the caller).
*/
static int
install_bind(int c, const CMDFUNC * kcmd, BINDINGS * bs)
{
KBIND *kbp; /* pointer into a binding table */
TRACE(("install_bind(%#x, %s(%s), %s)\n",
c, TRACE_CMDFUNC(kcmd), TRACE_BINDINGS(bs)));
if (c < 0)
return FALSE; /* not a legal key-code */
/* if the function is a prefix key, i.e. we're changing the definition
of a prefix key, then they typed a dummy function name, which
has been translated into a dummy function pointer */
reset_prefix(-1, kcod2fnc(bs, c), bs);
reset_prefix(c, kcmd, bs);
if (is8Bits(c)) {
bs->kb_normal[CharOf(c)] = TYPECAST(CMDFUNC, kcmd);
} else if ((kbp = kcode2kbind(bs, c)) != NULL) { /* change it in place */
kbp->k_cmd = kcmd;
} else {
beginDisplay();
kbp = typealloc(KBIND);
endofDisplay();
if (kbp == NULL) {
return no_memory("Key-Binding");
}
kbp->k_link = bs->kb_extra;
kbp->k_code = c; /* add keycode */
kbp->k_cmd = kcmd; /* and func pointer */
bs->kb_extra = kbp;
}
update_scratch(bs->bufname, update_binding_list);
return (TRUE);
}
/* ARGSUSED */
static int
bind_any_key(BINDINGS * bs)
{
const CMDFUNC *kcmd;
char cmd[NLINE];
char *fnp;
/* prompt the user to type in a key to bind */
/* and get the function name to bind it to */
fnp = kbd_engl("Bind function whose full name is: ", cmd, 0);
if (fnp == NULL || (kcmd = engl2fnc(fnp)) == NULL) {
return no_such_function(fnp);
}
return install_bind(key_to_bind(kcmd), kcmd, bs);
}
/*
* bindkey: add a new key to the key binding table
*/
/* ARGSUSED */
int
bindkey(int f GCC_UNUSED, int n GCC_UNUSED)
{
return bind_any_key(&dft_bindings);
}
/* ARGSUSED */
int
bind_i_key(int f GCC_UNUSED, int n GCC_UNUSED)
{
return bind_any_key(&ins_bindings);
}
/* ARGSUSED */
int
bind_c_key(int f GCC_UNUSED, int n GCC_UNUSED)
{
return bind_any_key(&cmd_bindings);
}
/* ARGSUSED */
int
bind_s_key(int f GCC_UNUSED, int n GCC_UNUSED)
{
return bind_any_key(&sel_bindings);
}
/* describe bindings bring up a fake buffer and list the key bindings
into it with view mode */
/* remember whether we last did "apropos" or "describe-bindings" */
static char *last_lookup_string;
static CMDFLAGS last_whichcmds;
static int last_whichmode;
static int append_to_binding_list;
/* ARGSUSED */
static int
update_binding_list(BUFFER *bp GCC_UNUSED)
{
return liststuff(bindings_to_describe->bufname, append_to_binding_list,
makebindlist, (int) last_whichcmds, (void *) last_lookup_string);
}
static int
describe_any_bindings(char *lookup, CMDFLAGS whichcmd)
{
last_lookup_string = lookup;
last_whichcmds = whichcmd;
return update_binding_list((BUFFER *) 0);
}
/* ARGSUSED */
int
desbind(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_any_bindings((char *) 0, (CMDFLAGS) 0);
}
/* ARGSUSED */
static int
update_bindkeys_list(BUFFER *bp GCC_UNUSED)
{
return liststuff(bindings_to_describe->bufname, append_to_binding_list,
makebindkeyslist, (int) last_whichcmds, (void *) last_lookup_string);
}
static int
describe_all_bindings(char *lookup, CMDFLAGS whichcmd, int mode)
{
last_lookup_string = lookup;
last_whichcmds = whichcmd;
last_whichmode = mode;
return update_bindkeys_list((BUFFER *) 0);
}
/* ARGSUSED */
int
desall_bind(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_all_bindings((char *) 0, (CMDFLAGS) 0, (f ? n : -1));
}
static int
describe_all_keys_bindings(BINDINGS * bs, int mode)
{
int code;
bindings_to_describe = bs;
code = describe_all_bindings((char *) 0, (CMDFLAGS) 0, mode);
bindings_to_describe = &dft_bindings;
return code;
}
int
desall_i_bind(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_all_keys_bindings(&ins_bindings, (f ? n : -1));
}
int
desall_c_bind(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_all_keys_bindings(&cmd_bindings, (f ? n : -1));
}
int
desall_s_bind(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_all_keys_bindings(&sel_bindings, (f ? n : -1));
}
static int
describe_alternate_bindings(BINDINGS * bs)
{
int code;
bindings_to_describe = bs;
code = describe_any_bindings((char *) 0, (CMDFLAGS) 0);
bindings_to_describe = &dft_bindings;
return code;
}
int
des_i_bind(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_alternate_bindings(&ins_bindings);
}
int
des_c_bind(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_alternate_bindings(&cmd_bindings);
}
int
des_s_bind(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_alternate_bindings(&sel_bindings);
}
/* ARGSUSED */
int
desmotions(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_any_bindings((char *) 0, MOTION);
}
/* ARGSUSED */
int
desopers(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_any_bindings((char *) 0, OPER);
}
/* ARGSUSED */
int
desglobals(int f GCC_UNUSED, int n GCC_UNUSED)
{
return describe_any_bindings((char *) 0, GLOBOK);
}
/* lookup function by substring */
/* ARGSUSED */
int
dessubstr(int f GCC_UNUSED, int n GCC_UNUSED)
{
int s;
static char substring[NSTRING];
s = mlreply("Apropos string: ", substring, (UINT) sizeof(substring));
if (s != TRUE)
return (s);
return describe_any_bindings(substring, (CMDFLAGS) 0);
}
static char described_cmd[NLINE + 1]; /* string to match cmd names to */
/* lookup up function by name */
/* ARGSUSED */
int
desfunc(int f GCC_UNUSED, int n GCC_UNUSED)
{
int s;
char *fnp;
/* force an exact match by ourstrstr() later on from makefuncdesc() */
described_cmd[0] = '^';
fnp = kbd_engl("Describe function whose full name is: ",
described_cmd + 1, 0);
if (fnp == NULL || engl2fnc(fnp) == NULL) {
s = no_such_function(fnp);
} else {
append_to_binding_list = TRUE;
s = describe_any_bindings(described_cmd, (CMDFLAGS) 0);
append_to_binding_list = FALSE;
}
return s;
}
/* FIXME: this table should be generated from cmdtbl, but excluding the
* mouse and text pseudo-keys. Note that the table isn't really
* sorted alphabetically, so it would be hard to generate in a nice way.
*/
static void
make_key_names(int iarg GCC_UNUSED, void *varg GCC_UNUSED)
{
static const struct {
int code;
const char *name;
} table[] = {
/* *INDENT-OFF* */
{ KEY_Up, "KEY_Up" },
{ KEY_Down, "KEY_Down" },
{ KEY_Right, "KEY_Right" },
{ KEY_Left, "KEY_Left" },
{ 0, NULL },
{ KEY_Delete, "KEY_Delete" },
{ KEY_End, "KEY_End" },
{ KEY_Find, "KEY_Find" },
{ KEY_Help, "KEY_Help" },
{ KEY_Home, "KEY_Home" },
{ KEY_Insert, "KEY_Insert" },
{ KEY_Menu, "KEY_Menu" },
{ KEY_Next, "KEY_Next" },
{ KEY_Prior, "KEY_Prior" },
{ KEY_Select, "KEY_Select" },
{ KEY_BackTab, "KEY_BackTab" },
{ 0, NULL },
{ KEY_F1, "KEY_F1" },
{ KEY_F2, "KEY_F2" },
{ KEY_F3, "KEY_F3" },
{ KEY_F4, "KEY_F4" },
{ KEY_F5, "KEY_F5" },
{ KEY_F6, "KEY_F6" },
{ KEY_F7, "KEY_F7" },
{ KEY_F8, "KEY_F8" },
{ KEY_F9, "KEY_F9" },
{ KEY_F10, "KEY_F10" },
{ KEY_F11, "KEY_F11" },
{ KEY_F12, "KEY_F12" },
{ KEY_F13, "KEY_F13" },