1 /* Handle lists of commands, their decoding and documentation, for GDB.
3 Copyright (C) 1986-2014 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21 #include "gdb_regex.h"
23 #include "completer.h"
25 #include "cli/cli-cmds.h"
26 #include "cli/cli-decode.h"
28 /* Prototypes for local functions. */
30 static void undef_cmd_error (const char *, const char *);
32 static struct cmd_list_element
*delete_cmd (const char *name
,
33 struct cmd_list_element
**list
,
34 struct cmd_list_element
**prehook
,
35 struct cmd_list_element
**prehookee
,
36 struct cmd_list_element
**posthook
,
37 struct cmd_list_element
**posthookee
);
39 static struct cmd_list_element
*find_cmd (const char *command
,
41 struct cmd_list_element
*clist
,
42 int ignore_help_classes
,
45 static void help_all (struct ui_file
*stream
);
47 /* Look up a command whose 'prefixlist' is KEY. Return the command if found,
48 otherwise return NULL. */
50 static struct cmd_list_element
*
51 lookup_cmd_for_prefixlist (struct cmd_list_element
**key
,
52 struct cmd_list_element
*list
)
54 struct cmd_list_element
*p
= NULL
;
56 for (p
= list
; p
!= NULL
; p
= p
->next
)
58 struct cmd_list_element
*q
;
60 if (p
->prefixlist
== NULL
)
62 else if (p
->prefixlist
== key
)
65 q
= lookup_cmd_for_prefixlist (key
, *(p
->prefixlist
));
74 set_cmd_prefix (struct cmd_list_element
*c
, struct cmd_list_element
**list
)
76 struct cmd_list_element
*p
;
78 /* Check to see if *LIST contains any element other than C. */
79 for (p
= *list
; p
!= NULL
; p
= p
->next
)
85 /* *SET_LIST only contains SET. */
86 p
= lookup_cmd_for_prefixlist (list
, setlist
);
88 c
->prefix
= p
? (p
->cmd_pointer
? p
->cmd_pointer
: p
) : p
;
91 c
->prefix
= p
->prefix
;
95 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
96 int recurse
, struct ui_file
*stream
);
99 /* Set the callback function for the specified command. For each both
100 the commands callback and func() are set. The latter set to a
101 bounce function (unless cfunc / sfunc is NULL that is). */
104 do_cfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
106 c
->function
.cfunc (args
, from_tty
); /* Ok. */
110 set_cmd_cfunc (struct cmd_list_element
*cmd
, cmd_cfunc_ftype
*cfunc
)
115 cmd
->func
= do_cfunc
;
116 cmd
->function
.cfunc
= cfunc
; /* Ok. */
120 do_sfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
122 c
->function
.sfunc (args
, from_tty
, c
); /* Ok. */
126 set_cmd_sfunc (struct cmd_list_element
*cmd
, cmd_sfunc_ftype
*sfunc
)
131 cmd
->func
= do_sfunc
;
132 cmd
->function
.sfunc
= sfunc
; /* Ok. */
136 cmd_cfunc_eq (struct cmd_list_element
*cmd
, cmd_cfunc_ftype
*cfunc
)
138 return cmd
->func
== do_cfunc
&& cmd
->function
.cfunc
== cfunc
;
142 set_cmd_context (struct cmd_list_element
*cmd
, void *context
)
144 cmd
->context
= context
;
148 get_cmd_context (struct cmd_list_element
*cmd
)
154 cmd_type (struct cmd_list_element
*cmd
)
160 set_cmd_completer (struct cmd_list_element
*cmd
, completer_ftype
*completer
)
162 cmd
->completer
= completer
; /* Ok. */
165 /* Add element named NAME.
166 Space for NAME and DOC must be allocated by the caller.
167 CLASS is the top level category into which commands are broken down
169 FUN should be the function to execute the command;
170 it will get a character string as argument, with leading
171 and trailing blanks already eliminated.
173 DOC is a documentation string for the command.
174 Its first line should be a complete sentence.
175 It should start with ? for a command that is an abbreviation
176 or with * for a command that most users don't need to know about.
178 Add this command to command list *LIST.
180 Returns a pointer to the added command (not necessarily the head
183 struct cmd_list_element
*
184 add_cmd (const char *name
, enum command_class
class, cmd_cfunc_ftype
*fun
,
185 const char *doc
, struct cmd_list_element
**list
)
187 struct cmd_list_element
*c
188 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
189 struct cmd_list_element
*p
, *iter
;
191 /* Turn each alias of the old command into an alias of the new
193 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
194 &c
->hook_post
, &c
->hookee_post
);
195 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
196 iter
->cmd_pointer
= c
;
198 c
->hook_pre
->hookee_pre
= c
;
200 c
->hookee_pre
->hook_pre
= c
;
202 c
->hook_post
->hookee_post
= c
;
204 c
->hookee_post
->hook_post
= c
;
206 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
214 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
224 set_cmd_cfunc (c
, fun
);
225 set_cmd_context (c
, NULL
);
227 c
->cmd_deprecated
= 0;
228 c
->deprecated_warn_user
= 0;
229 c
->malloced_replacement
= 0;
230 c
->doc_allocated
= 0;
231 c
->replacement
= NULL
;
232 c
->pre_show_hook
= NULL
;
234 c
->prefixlist
= NULL
;
235 c
->prefixname
= NULL
;
236 c
->allow_unknown
= 0;
239 set_cmd_completer (c
, make_symbol_completion_list_fn
);
241 c
->type
= not_set_cmd
;
243 c
->var_type
= var_boolean
;
245 c
->user_commands
= NULL
;
246 c
->cmd_pointer
= NULL
;
247 c
->alias_chain
= NULL
;
252 /* Deprecates a command CMD.
253 REPLACEMENT is the name of the command which should be used in
254 place of this command, or NULL if no such command exists.
256 This function does not check to see if command REPLACEMENT exists
257 since gdb may not have gotten around to adding REPLACEMENT when
258 this function is called.
260 Returns a pointer to the deprecated command. */
262 struct cmd_list_element
*
263 deprecate_cmd (struct cmd_list_element
*cmd
, const char *replacement
)
265 cmd
->cmd_deprecated
= 1;
266 cmd
->deprecated_warn_user
= 1;
268 if (replacement
!= NULL
)
269 cmd
->replacement
= replacement
;
271 cmd
->replacement
= NULL
;
276 struct cmd_list_element
*
277 add_alias_cmd (const char *name
, const char *oldname
, enum command_class
class,
278 int abbrev_flag
, struct cmd_list_element
**list
)
281 struct cmd_list_element
*old
;
282 struct cmd_list_element
*c
;
285 old
= lookup_cmd (&tmp
, *list
, "", 1, 1);
289 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
290 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
291 &prehook
, &prehookee
,
292 &posthook
, &posthookee
);
294 /* If this happens, it means a programmer error somewhere. */
295 gdb_assert (!aliases
&& !prehook
&& !prehookee
296 && !posthook
&& ! posthookee
);
300 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
302 /* If OLD->DOC can be freed, we should make another copy. */
303 if (old
->doc_allocated
)
305 c
->doc
= xstrdup (old
->doc
);
306 c
->doc_allocated
= 1;
308 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
310 c
->function
= old
->function
;
311 c
->prefixlist
= old
->prefixlist
;
312 c
->prefixname
= old
->prefixname
;
313 c
->allow_unknown
= old
->allow_unknown
;
314 c
->abbrev_flag
= abbrev_flag
;
315 c
->cmd_pointer
= old
;
316 c
->alias_chain
= old
->aliases
;
319 set_cmd_prefix (c
, list
);
323 /* Like add_cmd but adds an element for a command prefix: a name that
324 should be followed by a subcommand to be looked up in another
325 command list. PREFIXLIST should be the address of the variable
326 containing that list. */
328 struct cmd_list_element
*
329 add_prefix_cmd (const char *name
, enum command_class
class,
330 cmd_cfunc_ftype
*fun
,
331 const char *doc
, struct cmd_list_element
**prefixlist
,
332 const char *prefixname
, int allow_unknown
,
333 struct cmd_list_element
**list
)
335 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
336 struct cmd_list_element
*p
;
338 c
->prefixlist
= prefixlist
;
339 c
->prefixname
= prefixname
;
340 c
->allow_unknown
= allow_unknown
;
342 if (list
== &cmdlist
)
345 set_cmd_prefix (c
, list
);
347 /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
348 for (p
= *prefixlist
; p
!= NULL
; p
= p
->next
)
354 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
356 struct cmd_list_element
*
357 add_abbrev_prefix_cmd (const char *name
, enum command_class
class,
358 cmd_cfunc_ftype
*fun
, const char *doc
,
359 struct cmd_list_element
**prefixlist
,
360 const char *prefixname
,
361 int allow_unknown
, struct cmd_list_element
**list
)
363 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
365 c
->prefixlist
= prefixlist
;
366 c
->prefixname
= prefixname
;
367 c
->allow_unknown
= allow_unknown
;
372 /* This is an empty "cfunc". */
374 not_just_help_class_command (char *args
, int from_tty
)
378 /* This is an empty "sfunc". */
379 static void empty_sfunc (char *, int, struct cmd_list_element
*);
382 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
386 /* Add element named NAME to command list LIST (the list for set/show
387 or some sublist thereof).
388 TYPE is set_cmd or show_cmd.
389 CLASS is as in add_cmd.
390 VAR_TYPE is the kind of thing we are setting.
391 VAR is address of the variable being controlled by this command.
392 DOC is the documentation string. */
394 static struct cmd_list_element
*
395 add_set_or_show_cmd (const char *name
,
397 enum command_class
class,
401 struct cmd_list_element
**list
)
403 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
405 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
407 c
->var_type
= var_type
;
409 /* This needs to be something besides NULL so that this isn't
410 treated as a help class. */
411 set_cmd_sfunc (c
, empty_sfunc
);
415 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
416 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
417 setting. VAR is address of the variable being controlled by this
418 command. SET_FUNC and SHOW_FUNC are the callback functions (if
419 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
420 strings. PRINT the format string to print the value. SET_RESULT
421 and SHOW_RESULT, if not NULL, are set to the resulting command
425 add_setshow_cmd_full (const char *name
,
426 enum command_class
class,
427 var_types var_type
, void *var
,
428 const char *set_doc
, const char *show_doc
,
429 const char *help_doc
,
430 cmd_sfunc_ftype
*set_func
,
431 show_value_ftype
*show_func
,
432 struct cmd_list_element
**set_list
,
433 struct cmd_list_element
**show_list
,
434 struct cmd_list_element
**set_result
,
435 struct cmd_list_element
**show_result
)
437 struct cmd_list_element
*set
;
438 struct cmd_list_element
*show
;
442 if (help_doc
!= NULL
)
444 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
445 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
449 full_set_doc
= xstrdup (set_doc
);
450 full_show_doc
= xstrdup (show_doc
);
452 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
453 full_set_doc
, set_list
);
454 set
->doc_allocated
= 1;
456 if (set_func
!= NULL
)
457 set_cmd_sfunc (set
, set_func
);
459 set_cmd_prefix (set
, set_list
);
461 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
462 full_show_doc
, show_list
);
463 show
->doc_allocated
= 1;
464 show
->show_value_func
= show_func
;
466 if (set_result
!= NULL
)
468 if (show_result
!= NULL
)
472 /* Add element named NAME to command list LIST (the list for set or
473 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
474 of strings which may follow NAME. VAR is address of the variable
475 which will contain the matching string (from ENUMLIST). */
478 add_setshow_enum_cmd (const char *name
,
479 enum command_class
class,
480 const char *const *enumlist
,
483 const char *show_doc
,
484 const char *help_doc
,
485 cmd_sfunc_ftype
*set_func
,
486 show_value_ftype
*show_func
,
487 struct cmd_list_element
**set_list
,
488 struct cmd_list_element
**show_list
)
490 struct cmd_list_element
*c
;
492 add_setshow_cmd_full (name
, class, var_enum
, var
,
493 set_doc
, show_doc
, help_doc
,
500 const char * const auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
502 /* Add an auto-boolean command named NAME to both the set and show
503 command list lists. CLASS is as in add_cmd. VAR is address of the
504 variable which will contain the value. DOC is the documentation
505 string. FUNC is the corresponding callback. */
507 add_setshow_auto_boolean_cmd (const char *name
,
508 enum command_class
class,
509 enum auto_boolean
*var
,
510 const char *set_doc
, const char *show_doc
,
511 const char *help_doc
,
512 cmd_sfunc_ftype
*set_func
,
513 show_value_ftype
*show_func
,
514 struct cmd_list_element
**set_list
,
515 struct cmd_list_element
**show_list
)
517 struct cmd_list_element
*c
;
519 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
520 set_doc
, show_doc
, help_doc
,
524 c
->enums
= auto_boolean_enums
;
527 /* Add element named NAME to both the set and show command LISTs (the
528 list for set/show or some sublist thereof). CLASS is as in
529 add_cmd. VAR is address of the variable which will contain the
530 value. SET_DOC and SHOW_DOC are the documentation strings. */
532 add_setshow_boolean_cmd (const char *name
, enum command_class
class, int *var
,
533 const char *set_doc
, const char *show_doc
,
534 const char *help_doc
,
535 cmd_sfunc_ftype
*set_func
,
536 show_value_ftype
*show_func
,
537 struct cmd_list_element
**set_list
,
538 struct cmd_list_element
**show_list
)
540 static const char *boolean_enums
[] = { "on", "off", NULL
};
541 struct cmd_list_element
*c
;
543 add_setshow_cmd_full (name
, class, var_boolean
, var
,
544 set_doc
, show_doc
, help_doc
,
548 c
->enums
= boolean_enums
;
551 /* Add element named NAME to both the set and show command LISTs (the
552 list for set/show or some sublist thereof). */
554 add_setshow_filename_cmd (const char *name
, enum command_class
class,
556 const char *set_doc
, const char *show_doc
,
557 const char *help_doc
,
558 cmd_sfunc_ftype
*set_func
,
559 show_value_ftype
*show_func
,
560 struct cmd_list_element
**set_list
,
561 struct cmd_list_element
**show_list
)
563 struct cmd_list_element
*set_result
;
565 add_setshow_cmd_full (name
, class, var_filename
, var
,
566 set_doc
, show_doc
, help_doc
,
570 set_cmd_completer (set_result
, filename_completer
);
573 /* Add element named NAME to both the set and show command LISTs (the
574 list for set/show or some sublist thereof). */
576 add_setshow_string_cmd (const char *name
, enum command_class
class,
578 const char *set_doc
, const char *show_doc
,
579 const char *help_doc
,
580 cmd_sfunc_ftype
*set_func
,
581 show_value_ftype
*show_func
,
582 struct cmd_list_element
**set_list
,
583 struct cmd_list_element
**show_list
)
585 add_setshow_cmd_full (name
, class, var_string
, var
,
586 set_doc
, show_doc
, help_doc
,
592 /* Add element named NAME to both the set and show command LISTs (the
593 list for set/show or some sublist thereof). */
594 struct cmd_list_element
*
595 add_setshow_string_noescape_cmd (const char *name
, enum command_class
class,
597 const char *set_doc
, const char *show_doc
,
598 const char *help_doc
,
599 cmd_sfunc_ftype
*set_func
,
600 show_value_ftype
*show_func
,
601 struct cmd_list_element
**set_list
,
602 struct cmd_list_element
**show_list
)
604 struct cmd_list_element
*set_cmd
;
606 add_setshow_cmd_full (name
, class, var_string_noescape
, var
,
607 set_doc
, show_doc
, help_doc
,
614 /* Add element named NAME to both the set and show command LISTs (the
615 list for set/show or some sublist thereof). */
617 add_setshow_optional_filename_cmd (const char *name
, enum command_class
class,
619 const char *set_doc
, const char *show_doc
,
620 const char *help_doc
,
621 cmd_sfunc_ftype
*set_func
,
622 show_value_ftype
*show_func
,
623 struct cmd_list_element
**set_list
,
624 struct cmd_list_element
**show_list
)
626 struct cmd_list_element
*set_result
;
628 add_setshow_cmd_full (name
, class, var_optional_filename
, var
,
629 set_doc
, show_doc
, help_doc
,
634 set_cmd_completer (set_result
, filename_completer
);
638 /* Completes on literal "unlimited". Used by integer commands that
639 support a special "unlimited" value. */
641 static VEC (char_ptr
) *
642 integer_unlimited_completer (struct cmd_list_element
*ignore
,
643 const char *text
, const char *word
)
645 static const char * const keywords
[] =
651 return complete_on_enum (keywords
, text
, word
);
654 /* Add element named NAME to both the set and show command LISTs (the
655 list for set/show or some sublist thereof). CLASS is as in
656 add_cmd. VAR is address of the variable which will contain the
657 value. SET_DOC and SHOW_DOC are the documentation strings. This
658 function is only used in Python API. Please don't use it elsewhere. */
660 add_setshow_integer_cmd (const char *name
, enum command_class
class,
662 const char *set_doc
, const char *show_doc
,
663 const char *help_doc
,
664 cmd_sfunc_ftype
*set_func
,
665 show_value_ftype
*show_func
,
666 struct cmd_list_element
**set_list
,
667 struct cmd_list_element
**show_list
)
669 struct cmd_list_element
*set
;
671 add_setshow_cmd_full (name
, class, var_integer
, var
,
672 set_doc
, show_doc
, help_doc
,
677 set_cmd_completer (set
, integer_unlimited_completer
);
680 /* Add element named NAME to both the set and show command LISTs (the
681 list for set/show or some sublist thereof). CLASS is as in
682 add_cmd. VAR is address of the variable which will contain the
683 value. SET_DOC and SHOW_DOC are the documentation strings. */
685 add_setshow_uinteger_cmd (const char *name
, enum command_class
class,
687 const char *set_doc
, const char *show_doc
,
688 const char *help_doc
,
689 cmd_sfunc_ftype
*set_func
,
690 show_value_ftype
*show_func
,
691 struct cmd_list_element
**set_list
,
692 struct cmd_list_element
**show_list
)
694 struct cmd_list_element
*set
;
696 add_setshow_cmd_full (name
, class, var_uinteger
, var
,
697 set_doc
, show_doc
, help_doc
,
702 set_cmd_completer (set
, integer_unlimited_completer
);
705 /* Add element named NAME to both the set and show command LISTs (the
706 list for set/show or some sublist thereof). CLASS is as in
707 add_cmd. VAR is address of the variable which will contain the
708 value. SET_DOC and SHOW_DOC are the documentation strings. */
710 add_setshow_zinteger_cmd (const char *name
, enum command_class
class,
712 const char *set_doc
, const char *show_doc
,
713 const char *help_doc
,
714 cmd_sfunc_ftype
*set_func
,
715 show_value_ftype
*show_func
,
716 struct cmd_list_element
**set_list
,
717 struct cmd_list_element
**show_list
)
719 add_setshow_cmd_full (name
, class, var_zinteger
, var
,
720 set_doc
, show_doc
, help_doc
,
727 add_setshow_zuinteger_unlimited_cmd (const char *name
,
728 enum command_class
class,
731 const char *show_doc
,
732 const char *help_doc
,
733 cmd_sfunc_ftype
*set_func
,
734 show_value_ftype
*show_func
,
735 struct cmd_list_element
**set_list
,
736 struct cmd_list_element
**show_list
)
738 struct cmd_list_element
*set
;
740 add_setshow_cmd_full (name
, class, var_zuinteger_unlimited
, var
,
741 set_doc
, show_doc
, help_doc
,
746 set_cmd_completer (set
, integer_unlimited_completer
);
749 /* Add element named NAME to both the set and show command LISTs (the
750 list for set/show or some sublist thereof). CLASS is as in
751 add_cmd. VAR is address of the variable which will contain the
752 value. SET_DOC and SHOW_DOC are the documentation strings. */
754 add_setshow_zuinteger_cmd (const char *name
, enum command_class
class,
756 const char *set_doc
, const char *show_doc
,
757 const char *help_doc
,
758 cmd_sfunc_ftype
*set_func
,
759 show_value_ftype
*show_func
,
760 struct cmd_list_element
**set_list
,
761 struct cmd_list_element
**show_list
)
763 add_setshow_cmd_full (name
, class, var_zuinteger
, var
,
764 set_doc
, show_doc
, help_doc
,
770 /* Remove the command named NAME from the command list. Return the
771 list commands which were aliased to the deleted command. If the
772 command had no aliases, return NULL. The various *HOOKs are set to
773 the pre- and post-hook commands for the deleted command. If the
774 command does not have a hook, the corresponding out parameter is
777 static struct cmd_list_element
*
778 delete_cmd (const char *name
, struct cmd_list_element
**list
,
779 struct cmd_list_element
**prehook
,
780 struct cmd_list_element
**prehookee
,
781 struct cmd_list_element
**posthook
,
782 struct cmd_list_element
**posthookee
)
784 struct cmd_list_element
*iter
;
785 struct cmd_list_element
**previous_chain_ptr
;
786 struct cmd_list_element
*aliases
= NULL
;
792 previous_chain_ptr
= list
;
794 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
796 if (strcmp (iter
->name
, name
) == 0)
799 iter
->destroyer (iter
, iter
->context
);
800 if (iter
->hookee_pre
)
801 iter
->hookee_pre
->hook_pre
= 0;
802 *prehook
= iter
->hook_pre
;
803 *prehookee
= iter
->hookee_pre
;
804 if (iter
->hookee_post
)
805 iter
->hookee_post
->hook_post
= 0;
806 if (iter
->doc
&& iter
->doc_allocated
)
807 xfree ((char *) iter
->doc
);
808 *posthook
= iter
->hook_post
;
809 *posthookee
= iter
->hookee_post
;
811 /* Update the link. */
812 *previous_chain_ptr
= iter
->next
;
814 aliases
= iter
->aliases
;
816 /* If this command was an alias, remove it from the list of
818 if (iter
->cmd_pointer
)
820 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
821 struct cmd_list_element
*a
= *prevp
;
825 prevp
= &a
->alias_chain
;
828 *prevp
= iter
->alias_chain
;
833 /* We won't see another command with the same name. */
837 previous_chain_ptr
= &iter
->next
;
843 /* Shorthands to the commands above. */
845 /* Add an element to the list of info subcommands. */
847 struct cmd_list_element
*
848 add_info (const char *name
, cmd_cfunc_ftype
*fun
, const char *doc
)
850 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
853 /* Add an alias to the list of info subcommands. */
855 struct cmd_list_element
*
856 add_info_alias (const char *name
, const char *oldname
, int abbrev_flag
)
858 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
861 /* Add an element to the list of commands. */
863 struct cmd_list_element
*
864 add_com (const char *name
, enum command_class
class, cmd_cfunc_ftype
*fun
,
867 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
870 /* Add an alias or abbreviation command to the list of commands. */
872 struct cmd_list_element
*
873 add_com_alias (const char *name
, const char *oldname
, enum command_class
class,
876 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
879 /* Recursively walk the commandlist structures, and print out the
880 documentation of commands that match our regex in either their
881 name, or their documentation.
884 apropos_cmd (struct ui_file
*stream
,
885 struct cmd_list_element
*commandlist
,
886 struct re_pattern_buffer
*regex
, const char *prefix
)
888 struct cmd_list_element
*c
;
891 /* Walk through the commands. */
892 for (c
=commandlist
;c
;c
=c
->next
)
894 returnvalue
= -1; /* Needed to avoid double printing. */
897 /* Try to match against the name. */
898 returnvalue
= re_search (regex
, c
->name
, strlen(c
->name
),
899 0, strlen (c
->name
), NULL
);
900 if (returnvalue
>= 0)
902 print_help_for_command (c
, prefix
,
903 0 /* don't recurse */, stream
);
906 if (c
->doc
!= NULL
&& returnvalue
< 0)
908 /* Try to match against documentation. */
909 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
911 print_help_for_command (c
, prefix
,
912 0 /* don't recurse */, stream
);
915 /* Check if this command has subcommands and is not an
916 abbreviation. We skip listing subcommands of abbreviations
917 in order to avoid duplicates in the output. */
918 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
920 /* Recursively call ourselves on the subcommand list,
921 passing the right prefix in. */
922 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
927 /* This command really has to deal with two things:
928 1) I want documentation on *this string* (usually called by
931 2) I want documentation on *this list* (usually called by giving a
932 command that requires subcommands. Also called by saying just
935 I am going to split this into two seperate comamnds, help_cmd and
939 help_cmd (const char *command
, struct ui_file
*stream
)
941 struct cmd_list_element
*c
;
945 help_list (cmdlist
, "", all_classes
, stream
);
949 if (strcmp (command
, "all") == 0)
955 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
960 /* There are three cases here.
961 If c->prefixlist is nonzero, we have a prefix command.
962 Print its documentation, then list its subcommands.
964 If c->func is non NULL, we really have a command. Print its
965 documentation and return.
967 If c->func is NULL, we have a class name. Print its
968 documentation (as if it were a command) and then set class to the
969 number of this class so that the commands in the class will be
972 fputs_filtered (c
->doc
, stream
);
973 fputs_filtered ("\n", stream
);
975 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
977 fprintf_filtered (stream
, "\n");
979 /* If this is a prefix command, print it's subcommands. */
981 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
983 /* If this is a class name, print all of the commands in the class. */
985 help_list (cmdlist
, "", c
->class, stream
);
987 if (c
->hook_pre
|| c
->hook_post
)
988 fprintf_filtered (stream
,
989 "\nThis command has a hook (or hooks) defined:\n");
992 fprintf_filtered (stream
,
993 "\tThis command is run after : %s (pre hook)\n",
996 fprintf_filtered (stream
,
997 "\tThis command is run before : %s (post hook)\n",
1002 * Get a specific kind of help on a command list.
1005 * CMDTYPE is the prefix to use in the title string.
1006 * CLASS is the class with which to list the nodes of this list (see
1007 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1008 * everything, ALL_CLASSES for just classes, and non-negative for only things
1009 * in a specific class.
1010 * and STREAM is the output stream on which to print things.
1011 * If you call this routine with a class >= 0, it recurses.
1014 help_list (struct cmd_list_element
*list
, const char *cmdtype
,
1015 enum command_class
class, struct ui_file
*stream
)
1018 char *cmdtype1
, *cmdtype2
;
1020 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1022 len
= strlen (cmdtype
);
1023 cmdtype1
= (char *) alloca (len
+ 1);
1025 cmdtype2
= (char *) alloca (len
+ 4);
1030 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
1032 strncpy (cmdtype2
, cmdtype
, len
- 1);
1033 strcpy (cmdtype2
+ len
- 1, " sub");
1036 if (class == all_classes
)
1037 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
1039 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
1041 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
1043 if (class == all_classes
)
1045 fprintf_filtered (stream
, "\n\
1046 Type \"help%s\" followed by a class name for a list of commands in ",
1049 fprintf_filtered (stream
, "that class.");
1051 fprintf_filtered (stream
, "\n\
1052 Type \"help all\" for the list of all commands.");
1055 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
1056 cmdtype1
, cmdtype2
);
1058 fputs_filtered ("for ", stream
);
1060 fputs_filtered ("full ", stream
);
1062 fputs_filtered ("documentation.\n", stream
);
1063 fputs_filtered ("Type \"apropos word\" to search "
1064 "for commands related to \"word\".\n", stream
);
1065 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1070 help_all (struct ui_file
*stream
)
1072 struct cmd_list_element
*c
;
1073 int seen_unclassified
= 0;
1075 for (c
= cmdlist
; c
; c
= c
->next
)
1079 /* If this is a class name, print all of the commands in the
1082 if (c
->func
== NULL
)
1084 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
1085 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
1089 /* While it's expected that all commands are in some class,
1090 as a safety measure, we'll print commands outside of any
1091 class at the end. */
1093 for (c
= cmdlist
; c
; c
= c
->next
)
1098 if (c
->class == no_class
)
1100 if (!seen_unclassified
)
1102 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
1103 seen_unclassified
= 1;
1105 print_help_for_command (c
, "", 1, stream
);
1111 /* Print only the first line of STR on STREAM. */
1113 print_doc_line (struct ui_file
*stream
, const char *str
)
1115 static char *line_buffer
= 0;
1116 static int line_size
;
1122 line_buffer
= (char *) xmalloc (line_size
);
1125 /* Keep printing '.' or ',' not followed by a whitespace for embedded strings
1128 while (*p
&& *p
!= '\n'
1129 && ((*p
!= '.' && *p
!= ',') || (p
[1] && !isspace (p
[1]))))
1131 if (p
- str
> line_size
- 1)
1133 line_size
= p
- str
+ 1;
1134 xfree (line_buffer
);
1135 line_buffer
= (char *) xmalloc (line_size
);
1137 strncpy (line_buffer
, str
, p
- str
);
1138 line_buffer
[p
- str
] = '\0';
1139 if (islower (line_buffer
[0]))
1140 line_buffer
[0] = toupper (line_buffer
[0]);
1141 fputs_filtered (line_buffer
, stream
);
1144 /* Print one-line help for command C.
1145 If RECURSE is non-zero, also print one-line descriptions
1146 of all prefixed subcommands. */
1148 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
1149 int recurse
, struct ui_file
*stream
)
1151 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1152 print_doc_line (stream
, c
->doc
);
1153 fputs_filtered ("\n", stream
);
1156 && c
->prefixlist
!= 0
1157 && c
->abbrev_flag
== 0)
1158 /* Subcommands of a prefix command typically have 'all_commands'
1159 as class. If we pass CLASS to recursive invocation,
1160 most often we won't see anything. */
1161 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1165 * Implement a help command on command list LIST.
1166 * RECURSE should be non-zero if this should be done recursively on
1167 * all sublists of LIST.
1168 * PREFIX is the prefix to print before each command name.
1169 * STREAM is the stream upon which the output should be written.
1171 * A non-negative class number to list only commands in that
1173 * ALL_COMMANDS to list all commands in list.
1174 * ALL_CLASSES to list all classes in list.
1176 * Note that RECURSE will be active on *all* sublists, not just the
1177 * ones selected by the criteria above (ie. the selection mechanism
1178 * is at the low level, not the high-level).
1181 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1182 const char *prefix
, int recurse
, struct ui_file
*stream
)
1184 struct cmd_list_element
*c
;
1186 for (c
= list
; c
; c
= c
->next
)
1188 if (c
->abbrev_flag
== 0
1189 && (class == all_commands
1190 || (class == all_classes
&& c
->func
== NULL
)
1191 || (class == c
->class && c
->func
!= NULL
)))
1193 print_help_for_command (c
, prefix
, recurse
, stream
);
1195 else if (c
->abbrev_flag
== 0 && recurse
1196 && class == class_user
&& c
->prefixlist
!= NULL
)
1197 /* User-defined commands may be subcommands. */
1198 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
,
1204 /* Search the input clist for 'command'. Return the command if
1205 found (or NULL if not), and return the number of commands
1208 static struct cmd_list_element
*
1209 find_cmd (const char *command
, int len
, struct cmd_list_element
*clist
,
1210 int ignore_help_classes
, int *nfound
)
1212 struct cmd_list_element
*found
, *c
;
1214 found
= (struct cmd_list_element
*) NULL
;
1216 for (c
= clist
; c
; c
= c
->next
)
1217 if (!strncmp (command
, c
->name
, len
)
1218 && (!ignore_help_classes
|| c
->func
))
1222 if (c
->name
[len
] == '\0')
1232 find_command_name_length (const char *text
)
1234 const char *p
= text
;
1236 /* Treating underscores as part of command words is important
1237 so that "set args_foo()" doesn't get interpreted as
1238 "set args _foo()". */
1239 /* Some characters are only used for TUI specific commands.
1240 However, they are always allowed for the sake of consistency.
1242 The XDB compatibility characters are only allowed when using the
1243 right mode because they clash with other GDB commands -
1244 specifically '/' is used as a suffix for print, examine and
1247 Note that this is larger than the character set allowed when
1248 creating user-defined commands. */
1250 /* Recognize '!' as a single character command so that, e.g., "!ls"
1251 works as expected. */
1255 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1256 /* Characters used by TUI specific commands. */
1257 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$'
1258 /* Characters used for XDB compatibility. */
1259 || (xdb_commands
&& (*p
== '/' || *p
== '?')))
1265 /* Return TRUE if NAME is a valid user-defined command name.
1266 This is a stricter subset of all gdb commands,
1267 see find_command_name_length. */
1270 valid_user_defined_cmd_name_p (const char *name
)
1277 /* Alas "42" is a legitimate user-defined command.
1278 In the interests of not breaking anything we preserve that. */
1280 for (p
= name
; *p
!= '\0'; ++p
)
1293 /* This routine takes a line of TEXT and a CLIST in which to start the
1294 lookup. When it returns it will have incremented the text pointer past
1295 the section of text it matched, set *RESULT_LIST to point to the list in
1296 which the last word was matched, and will return a pointer to the cmd
1297 list element which the text matches. It will return NULL if no match at
1298 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1299 matches are possible; in this case *RESULT_LIST will be set to point to
1300 the list in which there are ambiguous choices (and *TEXT will be set to
1301 the ambiguous text string).
1303 If the located command was an abbreviation, this routine returns the base
1304 command of the abbreviation.
1306 It does no error reporting whatsoever; control will always return
1307 to the superior routine.
1309 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1310 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1311 if no prefix command was ever found. For example, in the case of "info a",
1312 "info" matches without ambiguity, but "a" could be "args" or "address", so
1313 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1314 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1315 list; it simply points to a specific command. In the case of an ambiguous
1316 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1317 "info t" can be "info types" or "info target"; upon return *TEXT has been
1318 advanced past "info ").
1320 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1321 affect the operation).
1323 This routine does *not* modify the text pointed to by TEXT.
1325 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1326 are actually help classes rather than commands (i.e. the function field of
1327 the struct cmd_list_element is NULL). */
1329 struct cmd_list_element
*
1330 lookup_cmd_1 (const char **text
, struct cmd_list_element
*clist
,
1331 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1334 int len
, tmp
, nfound
;
1335 struct cmd_list_element
*found
, *c
;
1336 const char *line
= *text
;
1338 while (**text
== ' ' || **text
== '\t')
1341 /* Identify the name of the command. */
1342 len
= find_command_name_length (*text
);
1344 /* If nothing but whitespace, return 0. */
1348 /* *text and p now bracket the first command word to lookup (and
1349 it's length is len). We copy this into a local temporary. */
1352 command
= (char *) alloca (len
+ 1);
1353 memcpy (command
, *text
, len
);
1354 command
[len
] = '\0';
1359 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1361 /* We didn't find the command in the entered case, so lower case it
1362 and search again. */
1363 if (!found
|| nfound
== 0)
1365 for (tmp
= 0; tmp
< len
; tmp
++)
1367 char x
= command
[tmp
];
1369 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1371 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1374 /* If nothing matches, we have a simple failure. */
1380 if (result_list
!= NULL
)
1381 /* Will be modified in calling routine
1382 if we know what the prefix command is. */
1384 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1387 /* We've matched something on this list. Move text pointer forward. */
1391 if (found
->cmd_pointer
)
1393 /* We drop the alias (abbreviation) in favor of the command it
1394 is pointing to. If the alias is deprecated, though, we need to
1395 warn the user about it before we drop it. Note that while we
1396 are warning about the alias, we may also warn about the command
1397 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1400 if (found
->deprecated_warn_user
)
1401 deprecated_cmd_warning (line
);
1402 found
= found
->cmd_pointer
;
1404 /* If we found a prefix command, keep looking. */
1406 if (found
->prefixlist
)
1408 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1409 ignore_help_classes
);
1412 /* Didn't find anything; this is as far as we got. */
1413 if (result_list
!= NULL
)
1414 *result_list
= clist
;
1417 else if (c
== CMD_LIST_AMBIGUOUS
)
1419 /* We've gotten this far properly, but the next step is
1420 ambiguous. We need to set the result list to the best
1421 we've found (if an inferior hasn't already set it). */
1422 if (result_list
!= NULL
)
1424 /* This used to say *result_list = *found->prefixlist.
1425 If that was correct, need to modify the documentation
1426 at the top of this function to clarify what is
1427 supposed to be going on. */
1428 *result_list
= found
;
1439 if (result_list
!= NULL
)
1440 *result_list
= clist
;
1445 /* All this hair to move the space to the front of cmdtype */
1448 undef_cmd_error (const char *cmdtype
, const char *q
)
1450 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1453 *cmdtype
? " " : "",
1454 (int) strlen (cmdtype
) - 1,
1458 /* Look up the contents of *LINE as a command in the command list LIST.
1459 LIST is a chain of struct cmd_list_element's.
1460 If it is found, return the struct cmd_list_element for that command
1461 and update *LINE to point after the command name, at the first argument.
1462 If not found, call error if ALLOW_UNKNOWN is zero
1463 otherwise (or if error returns) return zero.
1464 Call error if specified command is ambiguous,
1465 unless ALLOW_UNKNOWN is negative.
1466 CMDTYPE precedes the word "command" in the error message.
1468 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1469 elements which are actually help classes rather than commands (i.e.
1470 the function field of the struct cmd_list_element is 0). */
1472 struct cmd_list_element
*
1473 lookup_cmd (const char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1474 int allow_unknown
, int ignore_help_classes
)
1476 struct cmd_list_element
*last_list
= 0;
1477 struct cmd_list_element
*c
;
1479 /* Note: Do not remove trailing whitespace here because this
1480 would be wrong for complete_command. Jim Kingdon */
1483 error (_("Lack of needed %scommand"), cmdtype
);
1485 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1492 int len
= find_command_name_length (*line
);
1494 q
= (char *) alloca (len
+ 1);
1495 strncpy (q
, *line
, len
);
1497 undef_cmd_error (cmdtype
, q
);
1502 else if (c
== CMD_LIST_AMBIGUOUS
)
1504 /* Ambigous. Local values should be off prefixlist or called
1506 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1508 const char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1509 struct cmd_list_element
*local_list
=
1510 (last_list
? *(last_list
->prefixlist
) : list
);
1512 if (local_allow_unknown
< 0)
1515 return last_list
; /* Found something. */
1517 return 0; /* Found nothing. */
1521 /* Report as error. */
1526 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1527 && (*line
)[amb_len
] != '\t');
1532 for (c
= local_list
; c
; c
= c
->next
)
1533 if (!strncmp (*line
, c
->name
, amb_len
))
1535 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1536 < (int) sizeof ambbuf
)
1538 if (strlen (ambbuf
))
1539 strcat (ambbuf
, ", ");
1540 strcat (ambbuf
, c
->name
);
1544 strcat (ambbuf
, "..");
1548 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1550 return 0; /* lint */
1555 if (c
->type
== set_cmd
&& **line
!= '\0' && !isspace (**line
))
1556 error (_("Argument must be preceded by space."));
1558 /* We've got something. It may still not be what the caller
1559 wants (if this command *needs* a subcommand). */
1560 while (**line
== ' ' || **line
== '\t')
1563 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1564 undef_cmd_error (c
->prefixname
, *line
);
1566 /* Seems to be what he wants. Return it. */
1572 /* We are here presumably because an alias or command in TEXT is
1573 deprecated and a warning message should be generated. This
1574 function decodes TEXT and potentially generates a warning message
1577 Example for 'set endian big' which has a fictitious alias 'seb'.
1579 If alias wasn't used in TEXT, and the command is deprecated:
1580 "warning: 'set endian big' is deprecated."
1582 If alias was used, and only the alias is deprecated:
1583 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1585 If alias was used and command is deprecated (regardless of whether
1586 the alias itself is deprecated:
1588 "warning: 'set endian big' (seb) is deprecated."
1590 After the message has been sent, clear the appropriate flags in the
1591 command and/or the alias so the user is no longer bothered.
1595 deprecated_cmd_warning (const char *text
)
1597 struct cmd_list_element
*alias
= NULL
;
1598 struct cmd_list_element
*prefix_cmd
= NULL
;
1599 struct cmd_list_element
*cmd
= NULL
;
1601 if (!lookup_cmd_composition (text
, &alias
, &prefix_cmd
, &cmd
))
1602 /* Return if text doesn't evaluate to a command. */
1605 if (!((alias
? alias
->deprecated_warn_user
: 0)
1606 || cmd
->deprecated_warn_user
) )
1607 /* Return if nothing is deprecated. */
1610 printf_filtered ("Warning:");
1612 if (alias
&& !cmd
->cmd_deprecated
)
1613 printf_filtered (" '%s', an alias for the", alias
->name
);
1615 printf_filtered (" command '");
1618 printf_filtered ("%s", prefix_cmd
->prefixname
);
1620 printf_filtered ("%s", cmd
->name
);
1622 if (alias
&& cmd
->cmd_deprecated
)
1623 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1625 printf_filtered ("' is deprecated.\n");
1628 /* If it is only the alias that is deprecated, we want to indicate
1629 the new alias, otherwise we'll indicate the new command. */
1631 if (alias
&& !cmd
->cmd_deprecated
)
1633 if (alias
->replacement
)
1634 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1636 printf_filtered ("No alternative known.\n\n");
1640 if (cmd
->replacement
)
1641 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1643 printf_filtered ("No alternative known.\n\n");
1646 /* We've warned you, now we'll keep quiet. */
1648 alias
->deprecated_warn_user
= 0;
1650 cmd
->deprecated_warn_user
= 0;
1654 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1655 Return 1 on success, 0 on failure.
1657 If LINE refers to an alias, *alias will point to that alias.
1659 If LINE is a postfix command (i.e. one that is preceded by a prefix
1660 command) set *prefix_cmd.
1662 Set *cmd to point to the command LINE indicates.
1664 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1665 exist, they are NULL when we return.
1669 lookup_cmd_composition (const char *text
,
1670 struct cmd_list_element
**alias
,
1671 struct cmd_list_element
**prefix_cmd
,
1672 struct cmd_list_element
**cmd
)
1675 int len
, tmp
, nfound
;
1676 struct cmd_list_element
*cur_list
;
1677 struct cmd_list_element
*prev_cmd
;
1687 /* Go through as many command lists as we need to,
1688 to find the command TEXT refers to. */
1692 while (*text
== ' ' || *text
== '\t')
1695 /* Identify the name of the command. */
1696 len
= find_command_name_length (text
);
1698 /* If nothing but whitespace, return. */
1702 /* Text is the start of the first command word to lookup (and
1703 it's length is len). We copy this into a local temporary. */
1705 command
= (char *) alloca (len
+ 1);
1706 memcpy (command
, text
, len
);
1707 command
[len
] = '\0';
1712 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1714 /* We didn't find the command in the entered case, so lower case
1715 it and search again.
1717 if (!*cmd
|| nfound
== 0)
1719 for (tmp
= 0; tmp
< len
; tmp
++)
1721 char x
= command
[tmp
];
1723 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1725 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1728 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1730 return 0; /* ambiguous */
1734 return 0; /* nothing found */
1737 if ((*cmd
)->cmd_pointer
)
1739 /* cmd was actually an alias, we note that an alias was
1740 used (by assigning *alais) and we set *cmd. */
1742 *cmd
= (*cmd
)->cmd_pointer
;
1744 *prefix_cmd
= prev_cmd
;
1746 if ((*cmd
)->prefixlist
)
1747 cur_list
= *(*cmd
)->prefixlist
;
1755 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1757 /* Return a vector of char pointers which point to the different
1758 possible completions in LIST of TEXT.
1760 WORD points in the same buffer as TEXT, and completions should be
1761 returned relative to this position. For example, suppose TEXT is
1762 "foo" and we want to complete to "foobar". If WORD is "oo", return
1763 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1766 complete_on_cmdlist (struct cmd_list_element
*list
,
1767 const char *text
, const char *word
,
1768 int ignore_help_classes
)
1770 struct cmd_list_element
*ptr
;
1771 VEC (char_ptr
) *matchlist
= NULL
;
1772 int textlen
= strlen (text
);
1774 int saw_deprecated_match
= 0;
1776 /* We do one or two passes. In the first pass, we skip deprecated
1777 commands. If we see no matching commands in the first pass, and
1778 if we did happen to see a matching deprecated command, we do
1779 another loop to collect those. */
1780 for (pass
= 0; matchlist
== 0 && pass
< 2; ++pass
)
1782 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1783 if (!strncmp (ptr
->name
, text
, textlen
)
1784 && !ptr
->abbrev_flag
1785 && (!ignore_help_classes
|| ptr
->func
1786 || ptr
->prefixlist
))
1792 if (ptr
->cmd_deprecated
)
1794 saw_deprecated_match
= 1;
1799 match
= (char *) xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1801 strcpy (match
, ptr
->name
);
1802 else if (word
> text
)
1804 /* Return some portion of ptr->name. */
1805 strcpy (match
, ptr
->name
+ (word
- text
));
1809 /* Return some of text plus ptr->name. */
1810 strncpy (match
, word
, text
- word
);
1811 match
[text
- word
] = '\0';
1812 strcat (match
, ptr
->name
);
1814 VEC_safe_push (char_ptr
, matchlist
, match
);
1816 /* If we saw no matching deprecated commands in the first pass,
1818 if (!saw_deprecated_match
)
1825 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1827 /* Return a vector of char pointers which point to the different
1828 possible completions in CMD of TEXT.
1830 WORD points in the same buffer as TEXT, and completions should be
1831 returned relative to this position. For example, suppose TEXT is "foo"
1832 and we want to complete to "foobar". If WORD is "oo", return
1833 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1836 complete_on_enum (const char *const *enumlist
,
1837 const char *text
, const char *word
)
1839 VEC (char_ptr
) *matchlist
= NULL
;
1840 int textlen
= strlen (text
);
1844 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1845 if (strncmp (name
, text
, textlen
) == 0)
1849 match
= (char *) xmalloc (strlen (word
) + strlen (name
) + 1);
1851 strcpy (match
, name
);
1852 else if (word
> text
)
1854 /* Return some portion of name. */
1855 strcpy (match
, name
+ (word
- text
));
1859 /* Return some of text plus name. */
1860 strncpy (match
, word
, text
- word
);
1861 match
[text
- word
] = '\0';
1862 strcat (match
, name
);
1864 VEC_safe_push (char_ptr
, matchlist
, match
);
1871 /* Check function pointer. */
1873 cmd_func_p (struct cmd_list_element
*cmd
)
1875 return (cmd
->func
!= NULL
);
1879 /* Call the command function. */
1881 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1883 if (cmd_func_p (cmd
))
1884 (*cmd
->func
) (cmd
, args
, from_tty
);
1886 error (_("Invalid command"));