forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli-decode.c
1926 lines (1631 loc) · 54.1 KB
/
cli-decode.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
/* Handle lists of commands, their decoding and documentation, for GDB.
Copyright (C) 1986-2016 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "defs.h"
#include "symtab.h"
#include <ctype.h>
#include "gdb_regex.h"
#include "completer.h"
#include "ui-out.h"
#include "cli/cli-cmds.h"
#include "cli/cli-decode.h"
/* Prototypes for local functions. */
static void undef_cmd_error (const char *, const char *);
static struct cmd_list_element *delete_cmd (const char *name,
struct cmd_list_element **list,
struct cmd_list_element **prehook,
struct cmd_list_element **prehookee,
struct cmd_list_element **posthook,
struct cmd_list_element **posthookee);
static struct cmd_list_element *find_cmd (const char *command,
int len,
struct cmd_list_element *clist,
int ignore_help_classes,
int *nfound);
static void help_all (struct ui_file *stream);
/* Look up a command whose 'prefixlist' is KEY. Return the command if found,
otherwise return NULL. */
static struct cmd_list_element *
lookup_cmd_for_prefixlist (struct cmd_list_element **key,
struct cmd_list_element *list)
{
struct cmd_list_element *p = NULL;
for (p = list; p != NULL; p = p->next)
{
struct cmd_list_element *q;
if (p->prefixlist == NULL)
continue;
else if (p->prefixlist == key)
return p;
q = lookup_cmd_for_prefixlist (key, *(p->prefixlist));
if (q != NULL)
return q;
}
return NULL;
}
static void
set_cmd_prefix (struct cmd_list_element *c, struct cmd_list_element **list)
{
struct cmd_list_element *p;
/* Check to see if *LIST contains any element other than C. */
for (p = *list; p != NULL; p = p->next)
if (p != c)
break;
if (p == NULL)
{
/* *SET_LIST only contains SET. */
p = lookup_cmd_for_prefixlist (list, setlist);
c->prefix = p ? (p->cmd_pointer ? p->cmd_pointer : p) : p;
}
else
c->prefix = p->prefix;
}
static void
print_help_for_command (struct cmd_list_element *c, const char *prefix,
int recurse, struct ui_file *stream);
/* Set the callback function for the specified command. For each both
the commands callback and func() are set. The latter set to a
bounce function (unless cfunc / sfunc is NULL that is). */
static void
do_cfunc (struct cmd_list_element *c, char *args, int from_tty)
{
c->function.cfunc (args, from_tty); /* Ok. */
}
void
set_cmd_cfunc (struct cmd_list_element *cmd, cmd_cfunc_ftype *cfunc)
{
if (cfunc == NULL)
cmd->func = NULL;
else
cmd->func = do_cfunc;
cmd->function.cfunc = cfunc; /* Ok. */
}
static void
do_sfunc (struct cmd_list_element *c, char *args, int from_tty)
{
c->function.sfunc (args, from_tty, c); /* Ok. */
}
void
set_cmd_sfunc (struct cmd_list_element *cmd, cmd_sfunc_ftype *sfunc)
{
if (sfunc == NULL)
cmd->func = NULL;
else
cmd->func = do_sfunc;
cmd->function.sfunc = sfunc; /* Ok. */
}
int
cmd_cfunc_eq (struct cmd_list_element *cmd, cmd_cfunc_ftype *cfunc)
{
return cmd->func == do_cfunc && cmd->function.cfunc == cfunc;
}
void
set_cmd_context (struct cmd_list_element *cmd, void *context)
{
cmd->context = context;
}
void *
get_cmd_context (struct cmd_list_element *cmd)
{
return cmd->context;
}
enum cmd_types
cmd_type (struct cmd_list_element *cmd)
{
return cmd->type;
}
void
set_cmd_completer (struct cmd_list_element *cmd, completer_ftype *completer)
{
cmd->completer = completer; /* Ok. */
}
/* See definition in commands.h. */
void
set_cmd_completer_handle_brkchars (struct cmd_list_element *cmd,
completer_ftype_void *completer_handle_brkchars)
{
cmd->completer_handle_brkchars = completer_handle_brkchars;
}
/* Add element named NAME.
Space for NAME and DOC must be allocated by the caller.
CLASS is the top level category into which commands are broken down
for "help" purposes.
FUN should be the function to execute the command;
it will get a character string as argument, with leading
and trailing blanks already eliminated.
DOC is a documentation string for the command.
Its first line should be a complete sentence.
It should start with ? for a command that is an abbreviation
or with * for a command that most users don't need to know about.
Add this command to command list *LIST.
Returns a pointer to the added command (not necessarily the head
of *LIST). */
struct cmd_list_element *
add_cmd (const char *name, enum command_class theclass, cmd_cfunc_ftype *fun,
const char *doc, struct cmd_list_element **list)
{
struct cmd_list_element *c = XNEW (struct cmd_list_element);
struct cmd_list_element *p, *iter;
/* Turn each alias of the old command into an alias of the new
command. */
c->aliases = delete_cmd (name, list, &c->hook_pre, &c->hookee_pre,
&c->hook_post, &c->hookee_post);
for (iter = c->aliases; iter; iter = iter->alias_chain)
iter->cmd_pointer = c;
if (c->hook_pre)
c->hook_pre->hookee_pre = c;
if (c->hookee_pre)
c->hookee_pre->hook_pre = c;
if (c->hook_post)
c->hook_post->hookee_post = c;
if (c->hookee_post)
c->hookee_post->hook_post = c;
if (*list == NULL || strcmp ((*list)->name, name) >= 0)
{
c->next = *list;
*list = c;
}
else
{
p = *list;
while (p->next && strcmp (p->next->name, name) <= 0)
{
p = p->next;
}
c->next = p->next;
p->next = c;
}
c->name = name;
c->theclass = theclass;
set_cmd_cfunc (c, fun);
set_cmd_context (c, NULL);
c->doc = doc;
c->cmd_deprecated = 0;
c->deprecated_warn_user = 0;
c->malloced_replacement = 0;
c->doc_allocated = 0;
c->replacement = NULL;
c->pre_show_hook = NULL;
c->hook_in = 0;
c->prefixlist = NULL;
c->prefixname = NULL;
c->allow_unknown = 0;
c->prefix = NULL;
c->abbrev_flag = 0;
set_cmd_completer (c, make_symbol_completion_list_fn);
c->completer_handle_brkchars = NULL;
c->destroyer = NULL;
c->type = not_set_cmd;
c->var = NULL;
c->var_type = var_boolean;
c->enums = NULL;
c->user_commands = NULL;
c->cmd_pointer = NULL;
c->alias_chain = NULL;
c->suppress_notification = NULL;
return c;
}
/* Deprecates a command CMD.
REPLACEMENT is the name of the command which should be used in
place of this command, or NULL if no such command exists.
This function does not check to see if command REPLACEMENT exists
since gdb may not have gotten around to adding REPLACEMENT when
this function is called.
Returns a pointer to the deprecated command. */
struct cmd_list_element *
deprecate_cmd (struct cmd_list_element *cmd, const char *replacement)
{
cmd->cmd_deprecated = 1;
cmd->deprecated_warn_user = 1;
if (replacement != NULL)
cmd->replacement = replacement;
else
cmd->replacement = NULL;
return cmd;
}
struct cmd_list_element *
add_alias_cmd (const char *name, const char *oldname, enum command_class theclass,
int abbrev_flag, struct cmd_list_element **list)
{
const char *tmp;
struct cmd_list_element *old;
struct cmd_list_element *c;
tmp = oldname;
old = lookup_cmd (&tmp, *list, "", 1, 1);
if (old == 0)
{
struct cmd_list_element *prehook, *prehookee, *posthook, *posthookee;
struct cmd_list_element *aliases = delete_cmd (name, list,
&prehook, &prehookee,
&posthook, &posthookee);
/* If this happens, it means a programmer error somewhere. */
gdb_assert (!aliases && !prehook && !prehookee
&& !posthook && ! posthookee);
return 0;
}
c = add_cmd (name, theclass, NULL, old->doc, list);
/* If OLD->DOC can be freed, we should make another copy. */
if (old->doc_allocated)
{
c->doc = xstrdup (old->doc);
c->doc_allocated = 1;
}
/* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
c->func = old->func;
c->function = old->function;
c->prefixlist = old->prefixlist;
c->prefixname = old->prefixname;
c->allow_unknown = old->allow_unknown;
c->abbrev_flag = abbrev_flag;
c->cmd_pointer = old;
c->alias_chain = old->aliases;
old->aliases = c;
set_cmd_prefix (c, list);
return c;
}
/* Like add_cmd but adds an element for a command prefix: a name that
should be followed by a subcommand to be looked up in another
command list. PREFIXLIST should be the address of the variable
containing that list. */
struct cmd_list_element *
add_prefix_cmd (const char *name, enum command_class theclass,
cmd_cfunc_ftype *fun,
const char *doc, struct cmd_list_element **prefixlist,
const char *prefixname, int allow_unknown,
struct cmd_list_element **list)
{
struct cmd_list_element *c = add_cmd (name, theclass, fun, doc, list);
struct cmd_list_element *p;
c->prefixlist = prefixlist;
c->prefixname = prefixname;
c->allow_unknown = allow_unknown;
if (list == &cmdlist)
c->prefix = NULL;
else
set_cmd_prefix (c, list);
/* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
for (p = *prefixlist; p != NULL; p = p->next)
p->prefix = c;
return c;
}
/* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
struct cmd_list_element *
add_abbrev_prefix_cmd (const char *name, enum command_class theclass,
cmd_cfunc_ftype *fun, const char *doc,
struct cmd_list_element **prefixlist,
const char *prefixname,
int allow_unknown, struct cmd_list_element **list)
{
struct cmd_list_element *c = add_cmd (name, theclass, fun, doc, list);
c->prefixlist = prefixlist;
c->prefixname = prefixname;
c->allow_unknown = allow_unknown;
c->abbrev_flag = 1;
return c;
}
/* This is an empty "cfunc". */
void
not_just_help_class_command (char *args, int from_tty)
{
}
/* This is an empty "sfunc". */
static void empty_sfunc (char *, int, struct cmd_list_element *);
static void
empty_sfunc (char *args, int from_tty, struct cmd_list_element *c)
{
}
/* Add element named NAME to command list LIST (the list for set/show
or some sublist thereof).
TYPE is set_cmd or show_cmd.
CLASS is as in add_cmd.
VAR_TYPE is the kind of thing we are setting.
VAR is address of the variable being controlled by this command.
DOC is the documentation string. */
static struct cmd_list_element *
add_set_or_show_cmd (const char *name,
enum cmd_types type,
enum command_class theclass,
var_types var_type,
void *var,
const char *doc,
struct cmd_list_element **list)
{
struct cmd_list_element *c = add_cmd (name, theclass, NULL, doc, list);
gdb_assert (type == set_cmd || type == show_cmd);
c->type = type;
c->var_type = var_type;
c->var = var;
/* This needs to be something besides NULL so that this isn't
treated as a help class. */
set_cmd_sfunc (c, empty_sfunc);
return c;
}
/* Add element named NAME to both the command SET_LIST and SHOW_LIST.
CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
setting. VAR is address of the variable being controlled by this
command. SET_FUNC and SHOW_FUNC are the callback functions (if
non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
strings. PRINT the format string to print the value. SET_RESULT
and SHOW_RESULT, if not NULL, are set to the resulting command
structures. */
static void
add_setshow_cmd_full (const char *name,
enum command_class theclass,
var_types var_type, void *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list,
struct cmd_list_element **set_result,
struct cmd_list_element **show_result)
{
struct cmd_list_element *set;
struct cmd_list_element *show;
char *full_set_doc;
char *full_show_doc;
if (help_doc != NULL)
{
full_set_doc = xstrprintf ("%s\n%s", set_doc, help_doc);
full_show_doc = xstrprintf ("%s\n%s", show_doc, help_doc);
}
else
{
full_set_doc = xstrdup (set_doc);
full_show_doc = xstrdup (show_doc);
}
set = add_set_or_show_cmd (name, set_cmd, theclass, var_type, var,
full_set_doc, set_list);
set->doc_allocated = 1;
if (set_func != NULL)
set_cmd_sfunc (set, set_func);
set_cmd_prefix (set, set_list);
show = add_set_or_show_cmd (name, show_cmd, theclass, var_type, var,
full_show_doc, show_list);
show->doc_allocated = 1;
show->show_value_func = show_func;
if (set_result != NULL)
*set_result = set;
if (show_result != NULL)
*show_result = show;
}
/* Add element named NAME to command list LIST (the list for set or
some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
of strings which may follow NAME. VAR is address of the variable
which will contain the matching string (from ENUMLIST). */
void
add_setshow_enum_cmd (const char *name,
enum command_class theclass,
const char *const *enumlist,
const char **var,
const char *set_doc,
const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *c;
add_setshow_cmd_full (name, theclass, var_enum, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
&c, NULL);
c->enums = enumlist;
}
const char * const auto_boolean_enums[] = { "on", "off", "auto", NULL };
/* Add an auto-boolean command named NAME to both the set and show
command list lists. CLASS is as in add_cmd. VAR is address of the
variable which will contain the value. DOC is the documentation
string. FUNC is the corresponding callback. */
void
add_setshow_auto_boolean_cmd (const char *name,
enum command_class theclass,
enum auto_boolean *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *c;
add_setshow_cmd_full (name, theclass, var_auto_boolean, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
&c, NULL);
c->enums = auto_boolean_enums;
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). CLASS is as in
add_cmd. VAR is address of the variable which will contain the
value. SET_DOC and SHOW_DOC are the documentation strings. */
void
add_setshow_boolean_cmd (const char *name, enum command_class theclass, int *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
static const char *boolean_enums[] = { "on", "off", NULL };
struct cmd_list_element *c;
add_setshow_cmd_full (name, theclass, var_boolean, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
&c, NULL);
c->enums = boolean_enums;
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). */
void
add_setshow_filename_cmd (const char *name, enum command_class theclass,
char **var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *set_result;
add_setshow_cmd_full (name, theclass, var_filename, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
&set_result, NULL);
set_cmd_completer (set_result, filename_completer);
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). */
void
add_setshow_string_cmd (const char *name, enum command_class theclass,
char **var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
add_setshow_cmd_full (name, theclass, var_string, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
NULL, NULL);
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). */
struct cmd_list_element *
add_setshow_string_noescape_cmd (const char *name, enum command_class theclass,
char **var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *set_cmd;
add_setshow_cmd_full (name, theclass, var_string_noescape, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
&set_cmd, NULL);
return set_cmd;
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). */
void
add_setshow_optional_filename_cmd (const char *name, enum command_class theclass,
char **var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *set_result;
add_setshow_cmd_full (name, theclass, var_optional_filename, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
&set_result, NULL);
set_cmd_completer (set_result, filename_completer);
}
/* Completes on literal "unlimited". Used by integer commands that
support a special "unlimited" value. */
static VEC (char_ptr) *
integer_unlimited_completer (struct cmd_list_element *ignore,
const char *text, const char *word)
{
static const char * const keywords[] =
{
"unlimited",
NULL,
};
return complete_on_enum (keywords, text, word);
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). CLASS is as in
add_cmd. VAR is address of the variable which will contain the
value. SET_DOC and SHOW_DOC are the documentation strings. This
function is only used in Python API. Please don't use it elsewhere. */
void
add_setshow_integer_cmd (const char *name, enum command_class theclass,
int *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *set;
add_setshow_cmd_full (name, theclass, var_integer, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
&set, NULL);
set_cmd_completer (set, integer_unlimited_completer);
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). CLASS is as in
add_cmd. VAR is address of the variable which will contain the
value. SET_DOC and SHOW_DOC are the documentation strings. */
void
add_setshow_uinteger_cmd (const char *name, enum command_class theclass,
unsigned int *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *set;
add_setshow_cmd_full (name, theclass, var_uinteger, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
&set, NULL);
set_cmd_completer (set, integer_unlimited_completer);
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). CLASS is as in
add_cmd. VAR is address of the variable which will contain the
value. SET_DOC and SHOW_DOC are the documentation strings. */
void
add_setshow_zinteger_cmd (const char *name, enum command_class theclass,
int *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
add_setshow_cmd_full (name, theclass, var_zinteger, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
NULL, NULL);
}
void
add_setshow_zuinteger_unlimited_cmd (const char *name,
enum command_class theclass,
int *var,
const char *set_doc,
const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
struct cmd_list_element *set;
add_setshow_cmd_full (name, theclass, var_zuinteger_unlimited, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
&set, NULL);
set_cmd_completer (set, integer_unlimited_completer);
}
/* Add element named NAME to both the set and show command LISTs (the
list for set/show or some sublist thereof). CLASS is as in
add_cmd. VAR is address of the variable which will contain the
value. SET_DOC and SHOW_DOC are the documentation strings. */
void
add_setshow_zuinteger_cmd (const char *name, enum command_class theclass,
unsigned int *var,
const char *set_doc, const char *show_doc,
const char *help_doc,
cmd_sfunc_ftype *set_func,
show_value_ftype *show_func,
struct cmd_list_element **set_list,
struct cmd_list_element **show_list)
{
add_setshow_cmd_full (name, theclass, var_zuinteger, var,
set_doc, show_doc, help_doc,
set_func, show_func,
set_list, show_list,
NULL, NULL);
}
/* Remove the command named NAME from the command list. Return the
list commands which were aliased to the deleted command. If the
command had no aliases, return NULL. The various *HOOKs are set to
the pre- and post-hook commands for the deleted command. If the
command does not have a hook, the corresponding out parameter is
set to NULL. */
static struct cmd_list_element *
delete_cmd (const char *name, struct cmd_list_element **list,
struct cmd_list_element **prehook,
struct cmd_list_element **prehookee,
struct cmd_list_element **posthook,
struct cmd_list_element **posthookee)
{
struct cmd_list_element *iter;
struct cmd_list_element **previous_chain_ptr;
struct cmd_list_element *aliases = NULL;
*prehook = NULL;
*prehookee = NULL;
*posthook = NULL;
*posthookee = NULL;
previous_chain_ptr = list;
for (iter = *previous_chain_ptr; iter; iter = *previous_chain_ptr)
{
if (strcmp (iter->name, name) == 0)
{
if (iter->destroyer)
iter->destroyer (iter, iter->context);
if (iter->hookee_pre)
iter->hookee_pre->hook_pre = 0;
*prehook = iter->hook_pre;
*prehookee = iter->hookee_pre;
if (iter->hookee_post)
iter->hookee_post->hook_post = 0;
if (iter->doc && iter->doc_allocated)
xfree ((char *) iter->doc);
*posthook = iter->hook_post;
*posthookee = iter->hookee_post;
/* Update the link. */
*previous_chain_ptr = iter->next;
aliases = iter->aliases;
/* If this command was an alias, remove it from the list of
aliases. */
if (iter->cmd_pointer)
{
struct cmd_list_element **prevp = &iter->cmd_pointer->aliases;
struct cmd_list_element *a = *prevp;
while (a != iter)
{
prevp = &a->alias_chain;
a = *prevp;
}
*prevp = iter->alias_chain;
}
xfree (iter);
/* We won't see another command with the same name. */
break;
}
else
previous_chain_ptr = &iter->next;
}
return aliases;
}
/* Shorthands to the commands above. */
/* Add an element to the list of info subcommands. */
struct cmd_list_element *
add_info (const char *name, cmd_cfunc_ftype *fun, const char *doc)
{
return add_cmd (name, class_info, fun, doc, &infolist);
}
/* Add an alias to the list of info subcommands. */
struct cmd_list_element *
add_info_alias (const char *name, const char *oldname, int abbrev_flag)
{
return add_alias_cmd (name, oldname, class_run, abbrev_flag, &infolist);
}
/* Add an element to the list of commands. */
struct cmd_list_element *
add_com (const char *name, enum command_class theclass, cmd_cfunc_ftype *fun,
const char *doc)
{
return add_cmd (name, theclass, fun, doc, &cmdlist);
}
/* Add an alias or abbreviation command to the list of commands. */
struct cmd_list_element *
add_com_alias (const char *name, const char *oldname, enum command_class theclass,
int abbrev_flag)
{
return add_alias_cmd (name, oldname, theclass, abbrev_flag, &cmdlist);
}
/* Add an element with a suppress notification to the list of commands. */
struct cmd_list_element *
add_com_suppress_notification (const char *name, enum command_class theclass,
cmd_cfunc_ftype *fun, const char *doc,
int *suppress_notification)
{
struct cmd_list_element *element;
element = add_cmd (name, theclass, fun, doc, &cmdlist);
element->suppress_notification = suppress_notification;
return element;
}
/* Recursively walk the commandlist structures, and print out the
documentation of commands that match our regex in either their
name, or their documentation.
*/
void
apropos_cmd (struct ui_file *stream,
struct cmd_list_element *commandlist,
struct re_pattern_buffer *regex, const char *prefix)
{
struct cmd_list_element *c;
int returnvalue;
/* Walk through the commands. */
for (c=commandlist;c;c=c->next)
{
returnvalue = -1; /* Needed to avoid double printing. */
if (c->name != NULL)
{
/* Try to match against the name. */
returnvalue = re_search (regex, c->name, strlen(c->name),
0, strlen (c->name), NULL);
if (returnvalue >= 0)
{
print_help_for_command (c, prefix,
0 /* don't recurse */, stream);
}
}
if (c->doc != NULL && returnvalue < 0)
{
/* Try to match against documentation. */
if (re_search(regex,c->doc,strlen(c->doc),0,strlen(c->doc),NULL) >=0)
{
print_help_for_command (c, prefix,
0 /* don't recurse */, stream);
}
}
/* Check if this command has subcommands and is not an
abbreviation. We skip listing subcommands of abbreviations
in order to avoid duplicates in the output. */
if (c->prefixlist != NULL && !c->abbrev_flag)
{
/* Recursively call ourselves on the subcommand list,
passing the right prefix in. */
apropos_cmd (stream,*c->prefixlist,regex,c->prefixname);
}
}
}
/* This command really has to deal with two things:
1) I want documentation on *this string* (usually called by
"help commandname").
2) I want documentation on *this list* (usually called by giving a
command that requires subcommands. Also called by saying just
"help".)
I am going to split this into two seperate comamnds, help_cmd and
help_list. */
void
help_cmd (const char *command, struct ui_file *stream)
{
struct cmd_list_element *c;
if (!command)
{
help_list (cmdlist, "", all_classes, stream);
return;
}
if (strcmp (command, "all") == 0)
{
help_all (stream);
return;
}
c = lookup_cmd (&command, cmdlist, "", 0, 0);
if (c == 0)
return;
/* There are three cases here.
If c->prefixlist is nonzero, we have a prefix command.
Print its documentation, then list its subcommands.
If c->func is non NULL, we really have a command. Print its
documentation and return.
If c->func is NULL, we have a class name. Print its
documentation (as if it were a command) and then set class to the
number of this class so that the commands in the class will be
listed. */
fputs_filtered (c->doc, stream);
fputs_filtered ("\n", stream);
if (c->prefixlist == 0 && c->func != NULL)
return;