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"
22 #include "completer.h"
24 #include "cli/cli-cmds.h"
25 #include "cli/cli-decode.h"
27 /* Prototypes for local functions. */
29 static void undef_cmd_error (const char *, const char *);
31 static struct cmd_list_element
*delete_cmd (const char *name
,
32 struct cmd_list_element
**list
,
33 struct cmd_list_element
**prehook
,
34 struct cmd_list_element
**prehookee
,
35 struct cmd_list_element
**posthook
,
36 struct cmd_list_element
**posthookee
);
38 static struct cmd_list_element
*find_cmd (const char *command
,
40 struct cmd_list_element
*clist
,
41 int ignore_help_classes
,
44 static void help_all (struct ui_file
*stream
);
46 /* Look up a command whose 'prefixlist' is KEY. Return the command if found,
47 otherwise return NULL. */
49 static struct cmd_list_element
*
50 lookup_cmd_for_prefixlist (struct cmd_list_element
**key
,
51 struct cmd_list_element
*list
)
53 struct cmd_list_element
*p
= NULL
;
55 for (p
= list
; p
!= NULL
; p
= p
->next
)
57 struct cmd_list_element
*q
;
59 if (p
->prefixlist
== NULL
)
61 else if (p
->prefixlist
== key
)
64 q
= lookup_cmd_for_prefixlist (key
, *(p
->prefixlist
));
73 set_cmd_prefix (struct cmd_list_element
*c
, struct cmd_list_element
**list
)
75 struct cmd_list_element
*p
;
77 /* Check to see if *LIST contains any element other than C. */
78 for (p
= *list
; p
!= NULL
; p
= p
->next
)
84 /* *SET_LIST only contains SET. */
85 p
= lookup_cmd_for_prefixlist (list
, setlist
);
87 c
->prefix
= p
? (p
->cmd_pointer
? p
->cmd_pointer
: p
) : p
;
90 c
->prefix
= p
->prefix
;
94 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
95 int recurse
, struct ui_file
*stream
);
98 /* Set the callback function for the specified command. For each both
99 the commands callback and func() are set. The latter set to a
100 bounce function (unless cfunc / sfunc is NULL that is). */
103 do_cfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
105 c
->function
.cfunc (args
, from_tty
); /* Ok. */
109 set_cmd_cfunc (struct cmd_list_element
*cmd
, cmd_cfunc_ftype
*cfunc
)
114 cmd
->func
= do_cfunc
;
115 cmd
->function
.cfunc
= cfunc
; /* Ok. */
119 do_sfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
121 c
->function
.sfunc (args
, from_tty
, c
); /* Ok. */
125 set_cmd_sfunc (struct cmd_list_element
*cmd
, cmd_sfunc_ftype
*sfunc
)
130 cmd
->func
= do_sfunc
;
131 cmd
->function
.sfunc
= sfunc
; /* Ok. */
135 cmd_cfunc_eq (struct cmd_list_element
*cmd
, cmd_cfunc_ftype
*cfunc
)
137 return cmd
->func
== do_cfunc
&& cmd
->function
.cfunc
== cfunc
;
141 set_cmd_context (struct cmd_list_element
*cmd
, void *context
)
143 cmd
->context
= context
;
147 get_cmd_context (struct cmd_list_element
*cmd
)
153 cmd_type (struct cmd_list_element
*cmd
)
159 set_cmd_completer (struct cmd_list_element
*cmd
, completer_ftype
*completer
)
161 cmd
->completer
= completer
; /* Ok. */
164 /* Add element named NAME.
165 Space for NAME and DOC must be allocated by the caller.
166 CLASS is the top level category into which commands are broken down
168 FUN should be the function to execute the command;
169 it will get a character string as argument, with leading
170 and trailing blanks already eliminated.
172 DOC is a documentation string for the command.
173 Its first line should be a complete sentence.
174 It should start with ? for a command that is an abbreviation
175 or with * for a command that most users don't need to know about.
177 Add this command to command list *LIST.
179 Returns a pointer to the added command (not necessarily the head
182 struct cmd_list_element
*
183 add_cmd (const char *name
, enum command_class
class, cmd_cfunc_ftype
*fun
,
184 const char *doc
, struct cmd_list_element
**list
)
186 struct cmd_list_element
*c
187 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
188 struct cmd_list_element
*p
, *iter
;
190 /* Turn each alias of the old command into an alias of the new
192 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
193 &c
->hook_post
, &c
->hookee_post
);
194 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
195 iter
->cmd_pointer
= c
;
197 c
->hook_pre
->hookee_pre
= c
;
199 c
->hookee_pre
->hook_pre
= c
;
201 c
->hook_post
->hookee_post
= c
;
203 c
->hookee_post
->hook_post
= c
;
205 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
213 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
223 set_cmd_cfunc (c
, fun
);
224 set_cmd_context (c
, NULL
);
226 c
->cmd_deprecated
= 0;
227 c
->deprecated_warn_user
= 0;
228 c
->malloced_replacement
= 0;
229 c
->doc_allocated
= 0;
230 c
->replacement
= NULL
;
231 c
->pre_show_hook
= NULL
;
233 c
->prefixlist
= NULL
;
234 c
->prefixname
= NULL
;
235 c
->allow_unknown
= 0;
238 set_cmd_completer (c
, make_symbol_completion_list_fn
);
240 c
->type
= not_set_cmd
;
242 c
->var_type
= var_boolean
;
244 c
->user_commands
= NULL
;
245 c
->cmd_pointer
= NULL
;
246 c
->alias_chain
= NULL
;
251 /* Deprecates a command CMD.
252 REPLACEMENT is the name of the command which should be used in
253 place of this command, or NULL if no such command exists.
255 This function does not check to see if command REPLACEMENT exists
256 since gdb may not have gotten around to adding REPLACEMENT when
257 this function is called.
259 Returns a pointer to the deprecated command. */
261 struct cmd_list_element
*
262 deprecate_cmd (struct cmd_list_element
*cmd
, const char *replacement
)
264 cmd
->cmd_deprecated
= 1;
265 cmd
->deprecated_warn_user
= 1;
267 if (replacement
!= NULL
)
268 cmd
->replacement
= replacement
;
270 cmd
->replacement
= NULL
;
275 struct cmd_list_element
*
276 add_alias_cmd (const char *name
, const char *oldname
, enum command_class
class,
277 int abbrev_flag
, struct cmd_list_element
**list
)
280 struct cmd_list_element
*old
;
281 struct cmd_list_element
*c
;
284 old
= lookup_cmd (&tmp
, *list
, "", 1, 1);
288 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
289 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
290 &prehook
, &prehookee
,
291 &posthook
, &posthookee
);
293 /* If this happens, it means a programmer error somewhere. */
294 gdb_assert (!aliases
&& !prehook
&& !prehookee
295 && !posthook
&& ! posthookee
);
299 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
301 /* If OLD->DOC can be freed, we should make another copy. */
302 if (old
->doc_allocated
)
304 c
->doc
= xstrdup (old
->doc
);
305 c
->doc_allocated
= 1;
307 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
309 c
->function
= old
->function
;
310 c
->prefixlist
= old
->prefixlist
;
311 c
->prefixname
= old
->prefixname
;
312 c
->allow_unknown
= old
->allow_unknown
;
313 c
->abbrev_flag
= abbrev_flag
;
314 c
->cmd_pointer
= old
;
315 c
->alias_chain
= old
->aliases
;
318 set_cmd_prefix (c
, list
);
322 /* Like add_cmd but adds an element for a command prefix: a name that
323 should be followed by a subcommand to be looked up in another
324 command list. PREFIXLIST should be the address of the variable
325 containing that list. */
327 struct cmd_list_element
*
328 add_prefix_cmd (const char *name
, enum command_class
class,
329 cmd_cfunc_ftype
*fun
,
330 const char *doc
, struct cmd_list_element
**prefixlist
,
331 const char *prefixname
, int allow_unknown
,
332 struct cmd_list_element
**list
)
334 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
335 struct cmd_list_element
*p
;
337 c
->prefixlist
= prefixlist
;
338 c
->prefixname
= prefixname
;
339 c
->allow_unknown
= allow_unknown
;
341 if (list
== &cmdlist
)
344 set_cmd_prefix (c
, list
);
346 /* Update the field 'prefix' of each cmd_list_element in *PREFIXLIST. */
347 for (p
= *prefixlist
; p
!= NULL
; p
= p
->next
)
353 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
355 struct cmd_list_element
*
356 add_abbrev_prefix_cmd (const char *name
, enum command_class
class,
357 cmd_cfunc_ftype
*fun
, const char *doc
,
358 struct cmd_list_element
**prefixlist
,
359 const char *prefixname
,
360 int allow_unknown
, struct cmd_list_element
**list
)
362 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
364 c
->prefixlist
= prefixlist
;
365 c
->prefixname
= prefixname
;
366 c
->allow_unknown
= allow_unknown
;
371 /* This is an empty "cfunc". */
373 not_just_help_class_command (char *args
, int from_tty
)
377 /* This is an empty "sfunc". */
378 static void empty_sfunc (char *, int, struct cmd_list_element
*);
381 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
385 /* Add element named NAME to command list LIST (the list for set/show
386 or some sublist thereof).
387 TYPE is set_cmd or show_cmd.
388 CLASS is as in add_cmd.
389 VAR_TYPE is the kind of thing we are setting.
390 VAR is address of the variable being controlled by this command.
391 DOC is the documentation string. */
393 static struct cmd_list_element
*
394 add_set_or_show_cmd (const char *name
,
396 enum command_class
class,
400 struct cmd_list_element
**list
)
402 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
404 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
406 c
->var_type
= var_type
;
408 /* This needs to be something besides NULL so that this isn't
409 treated as a help class. */
410 set_cmd_sfunc (c
, empty_sfunc
);
414 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
415 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
416 setting. VAR is address of the variable being controlled by this
417 command. SET_FUNC and SHOW_FUNC are the callback functions (if
418 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
419 strings. PRINT the format string to print the value. SET_RESULT
420 and SHOW_RESULT, if not NULL, are set to the resulting command
424 add_setshow_cmd_full (const char *name
,
425 enum command_class
class,
426 var_types var_type
, void *var
,
427 const char *set_doc
, const char *show_doc
,
428 const char *help_doc
,
429 cmd_sfunc_ftype
*set_func
,
430 show_value_ftype
*show_func
,
431 struct cmd_list_element
**set_list
,
432 struct cmd_list_element
**show_list
,
433 struct cmd_list_element
**set_result
,
434 struct cmd_list_element
**show_result
)
436 struct cmd_list_element
*set
;
437 struct cmd_list_element
*show
;
441 if (help_doc
!= NULL
)
443 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
444 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
448 full_set_doc
= xstrdup (set_doc
);
449 full_show_doc
= xstrdup (show_doc
);
451 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
452 full_set_doc
, set_list
);
453 set
->doc_allocated
= 1;
455 if (set_func
!= NULL
)
456 set_cmd_sfunc (set
, set_func
);
458 set_cmd_prefix (set
, set_list
);
460 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
461 full_show_doc
, show_list
);
462 show
->doc_allocated
= 1;
463 show
->show_value_func
= show_func
;
465 if (set_result
!= NULL
)
467 if (show_result
!= NULL
)
471 /* Add element named NAME to command list LIST (the list for set or
472 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
473 of strings which may follow NAME. VAR is address of the variable
474 which will contain the matching string (from ENUMLIST). */
477 add_setshow_enum_cmd (const char *name
,
478 enum command_class
class,
479 const char *const *enumlist
,
482 const char *show_doc
,
483 const char *help_doc
,
484 cmd_sfunc_ftype
*set_func
,
485 show_value_ftype
*show_func
,
486 struct cmd_list_element
**set_list
,
487 struct cmd_list_element
**show_list
)
489 struct cmd_list_element
*c
;
491 add_setshow_cmd_full (name
, class, var_enum
, var
,
492 set_doc
, show_doc
, help_doc
,
499 const char * const auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
501 /* Add an auto-boolean command named NAME to both the set and show
502 command list lists. CLASS is as in add_cmd. VAR is address of the
503 variable which will contain the value. DOC is the documentation
504 string. FUNC is the corresponding callback. */
506 add_setshow_auto_boolean_cmd (const char *name
,
507 enum command_class
class,
508 enum auto_boolean
*var
,
509 const char *set_doc
, const char *show_doc
,
510 const char *help_doc
,
511 cmd_sfunc_ftype
*set_func
,
512 show_value_ftype
*show_func
,
513 struct cmd_list_element
**set_list
,
514 struct cmd_list_element
**show_list
)
516 struct cmd_list_element
*c
;
518 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
519 set_doc
, show_doc
, help_doc
,
523 c
->enums
= auto_boolean_enums
;
526 /* Add element named NAME to both the set and show command LISTs (the
527 list for set/show or some sublist thereof). CLASS is as in
528 add_cmd. VAR is address of the variable which will contain the
529 value. SET_DOC and SHOW_DOC are the documentation strings. */
531 add_setshow_boolean_cmd (const char *name
, enum command_class
class, int *var
,
532 const char *set_doc
, const char *show_doc
,
533 const char *help_doc
,
534 cmd_sfunc_ftype
*set_func
,
535 show_value_ftype
*show_func
,
536 struct cmd_list_element
**set_list
,
537 struct cmd_list_element
**show_list
)
539 static const char *boolean_enums
[] = { "on", "off", NULL
};
540 struct cmd_list_element
*c
;
542 add_setshow_cmd_full (name
, class, var_boolean
, var
,
543 set_doc
, show_doc
, help_doc
,
547 c
->enums
= boolean_enums
;
550 /* Add element named NAME to both the set and show command LISTs (the
551 list for set/show or some sublist thereof). */
553 add_setshow_filename_cmd (const char *name
, enum command_class
class,
555 const char *set_doc
, const char *show_doc
,
556 const char *help_doc
,
557 cmd_sfunc_ftype
*set_func
,
558 show_value_ftype
*show_func
,
559 struct cmd_list_element
**set_list
,
560 struct cmd_list_element
**show_list
)
562 struct cmd_list_element
*set_result
;
564 add_setshow_cmd_full (name
, class, var_filename
, var
,
565 set_doc
, show_doc
, help_doc
,
569 set_cmd_completer (set_result
, filename_completer
);
572 /* Add element named NAME to both the set and show command LISTs (the
573 list for set/show or some sublist thereof). */
575 add_setshow_string_cmd (const char *name
, enum command_class
class,
577 const char *set_doc
, const char *show_doc
,
578 const char *help_doc
,
579 cmd_sfunc_ftype
*set_func
,
580 show_value_ftype
*show_func
,
581 struct cmd_list_element
**set_list
,
582 struct cmd_list_element
**show_list
)
584 add_setshow_cmd_full (name
, class, var_string
, var
,
585 set_doc
, show_doc
, help_doc
,
591 /* Add element named NAME to both the set and show command LISTs (the
592 list for set/show or some sublist thereof). */
593 struct cmd_list_element
*
594 add_setshow_string_noescape_cmd (const char *name
, enum command_class
class,
596 const char *set_doc
, const char *show_doc
,
597 const char *help_doc
,
598 cmd_sfunc_ftype
*set_func
,
599 show_value_ftype
*show_func
,
600 struct cmd_list_element
**set_list
,
601 struct cmd_list_element
**show_list
)
603 struct cmd_list_element
*set_cmd
;
605 add_setshow_cmd_full (name
, class, var_string_noescape
, var
,
606 set_doc
, show_doc
, help_doc
,
613 /* Add element named NAME to both the set and show command LISTs (the
614 list for set/show or some sublist thereof). */
616 add_setshow_optional_filename_cmd (const char *name
, enum command_class
class,
618 const char *set_doc
, const char *show_doc
,
619 const char *help_doc
,
620 cmd_sfunc_ftype
*set_func
,
621 show_value_ftype
*show_func
,
622 struct cmd_list_element
**set_list
,
623 struct cmd_list_element
**show_list
)
625 struct cmd_list_element
*set_result
;
627 add_setshow_cmd_full (name
, class, var_optional_filename
, var
,
628 set_doc
, show_doc
, help_doc
,
633 set_cmd_completer (set_result
, filename_completer
);
637 /* Completes on literal "unlimited". Used by integer commands that
638 support a special "unlimited" value. */
640 static VEC (char_ptr
) *
641 integer_unlimited_completer (struct cmd_list_element
*ignore
,
642 const char *text
, const char *word
)
644 static const char * const keywords
[] =
650 return complete_on_enum (keywords
, text
, word
);
653 /* Add element named NAME to both the set and show command LISTs (the
654 list for set/show or some sublist thereof). CLASS is as in
655 add_cmd. VAR is address of the variable which will contain the
656 value. SET_DOC and SHOW_DOC are the documentation strings. This
657 function is only used in Python API. Please don't use it elsewhere. */
659 add_setshow_integer_cmd (const char *name
, enum command_class
class,
661 const char *set_doc
, const char *show_doc
,
662 const char *help_doc
,
663 cmd_sfunc_ftype
*set_func
,
664 show_value_ftype
*show_func
,
665 struct cmd_list_element
**set_list
,
666 struct cmd_list_element
**show_list
)
668 struct cmd_list_element
*set
;
670 add_setshow_cmd_full (name
, class, var_integer
, var
,
671 set_doc
, show_doc
, help_doc
,
676 set_cmd_completer (set
, integer_unlimited_completer
);
679 /* Add element named NAME to both the set and show command LISTs (the
680 list for set/show or some sublist thereof). CLASS is as in
681 add_cmd. VAR is address of the variable which will contain the
682 value. SET_DOC and SHOW_DOC are the documentation strings. */
684 add_setshow_uinteger_cmd (const char *name
, enum command_class
class,
686 const char *set_doc
, const char *show_doc
,
687 const char *help_doc
,
688 cmd_sfunc_ftype
*set_func
,
689 show_value_ftype
*show_func
,
690 struct cmd_list_element
**set_list
,
691 struct cmd_list_element
**show_list
)
693 struct cmd_list_element
*set
;
695 add_setshow_cmd_full (name
, class, var_uinteger
, var
,
696 set_doc
, show_doc
, help_doc
,
701 set_cmd_completer (set
, integer_unlimited_completer
);
704 /* Add element named NAME to both the set and show command LISTs (the
705 list for set/show or some sublist thereof). CLASS is as in
706 add_cmd. VAR is address of the variable which will contain the
707 value. SET_DOC and SHOW_DOC are the documentation strings. */
709 add_setshow_zinteger_cmd (const char *name
, enum command_class
class,
711 const char *set_doc
, const char *show_doc
,
712 const char *help_doc
,
713 cmd_sfunc_ftype
*set_func
,
714 show_value_ftype
*show_func
,
715 struct cmd_list_element
**set_list
,
716 struct cmd_list_element
**show_list
)
718 add_setshow_cmd_full (name
, class, var_zinteger
, var
,
719 set_doc
, show_doc
, help_doc
,
726 add_setshow_zuinteger_unlimited_cmd (const char *name
,
727 enum command_class
class,
730 const char *show_doc
,
731 const char *help_doc
,
732 cmd_sfunc_ftype
*set_func
,
733 show_value_ftype
*show_func
,
734 struct cmd_list_element
**set_list
,
735 struct cmd_list_element
**show_list
)
737 struct cmd_list_element
*set
;
739 add_setshow_cmd_full (name
, class, var_zuinteger_unlimited
, var
,
740 set_doc
, show_doc
, help_doc
,
745 set_cmd_completer (set
, integer_unlimited_completer
);
748 /* Add element named NAME to both the set and show command LISTs (the
749 list for set/show or some sublist thereof). CLASS is as in
750 add_cmd. VAR is address of the variable which will contain the
751 value. SET_DOC and SHOW_DOC are the documentation strings. */
753 add_setshow_zuinteger_cmd (const char *name
, enum command_class
class,
755 const char *set_doc
, const char *show_doc
,
756 const char *help_doc
,
757 cmd_sfunc_ftype
*set_func
,
758 show_value_ftype
*show_func
,
759 struct cmd_list_element
**set_list
,
760 struct cmd_list_element
**show_list
)
762 add_setshow_cmd_full (name
, class, var_zuinteger
, var
,
763 set_doc
, show_doc
, help_doc
,
769 /* Remove the command named NAME from the command list. Return the
770 list commands which were aliased to the deleted command. If the
771 command had no aliases, return NULL. The various *HOOKs are set to
772 the pre- and post-hook commands for the deleted command. If the
773 command does not have a hook, the corresponding out parameter is
776 static struct cmd_list_element
*
777 delete_cmd (const char *name
, struct cmd_list_element
**list
,
778 struct cmd_list_element
**prehook
,
779 struct cmd_list_element
**prehookee
,
780 struct cmd_list_element
**posthook
,
781 struct cmd_list_element
**posthookee
)
783 struct cmd_list_element
*iter
;
784 struct cmd_list_element
**previous_chain_ptr
;
785 struct cmd_list_element
*aliases
= NULL
;
791 previous_chain_ptr
= list
;
793 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
795 if (strcmp (iter
->name
, name
) == 0)
798 iter
->destroyer (iter
, iter
->context
);
799 if (iter
->hookee_pre
)
800 iter
->hookee_pre
->hook_pre
= 0;
801 *prehook
= iter
->hook_pre
;
802 *prehookee
= iter
->hookee_pre
;
803 if (iter
->hookee_post
)
804 iter
->hookee_post
->hook_post
= 0;
805 if (iter
->doc
&& iter
->doc_allocated
)
806 xfree ((char *) iter
->doc
);
807 *posthook
= iter
->hook_post
;
808 *posthookee
= iter
->hookee_post
;
810 /* Update the link. */
811 *previous_chain_ptr
= iter
->next
;
813 aliases
= iter
->aliases
;
815 /* If this command was an alias, remove it from the list of
817 if (iter
->cmd_pointer
)
819 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
820 struct cmd_list_element
*a
= *prevp
;
824 prevp
= &a
->alias_chain
;
827 *prevp
= iter
->alias_chain
;
832 /* We won't see another command with the same name. */
836 previous_chain_ptr
= &iter
->next
;
842 /* Shorthands to the commands above. */
844 /* Add an element to the list of info subcommands. */
846 struct cmd_list_element
*
847 add_info (const char *name
, cmd_cfunc_ftype
*fun
, const char *doc
)
849 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
852 /* Add an alias to the list of info subcommands. */
854 struct cmd_list_element
*
855 add_info_alias (const char *name
, const char *oldname
, int abbrev_flag
)
857 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
860 /* Add an element to the list of commands. */
862 struct cmd_list_element
*
863 add_com (const char *name
, enum command_class
class, cmd_cfunc_ftype
*fun
,
866 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
869 /* Add an alias or abbreviation command to the list of commands. */
871 struct cmd_list_element
*
872 add_com_alias (const char *name
, const char *oldname
, enum command_class
class,
875 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
878 /* Recursively walk the commandlist structures, and print out the
879 documentation of commands that match our regex in either their
880 name, or their documentation.
883 apropos_cmd (struct ui_file
*stream
,
884 struct cmd_list_element
*commandlist
,
885 struct re_pattern_buffer
*regex
, const char *prefix
)
887 struct cmd_list_element
*c
;
890 /* Walk through the commands. */
891 for (c
=commandlist
;c
;c
=c
->next
)
893 returnvalue
= -1; /* Needed to avoid double printing. */
896 /* Try to match against the name. */
897 returnvalue
= re_search (regex
, c
->name
, strlen(c
->name
),
898 0, strlen (c
->name
), NULL
);
899 if (returnvalue
>= 0)
901 print_help_for_command (c
, prefix
,
902 0 /* don't recurse */, stream
);
905 if (c
->doc
!= NULL
&& returnvalue
< 0)
907 /* Try to match against documentation. */
908 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
910 print_help_for_command (c
, prefix
,
911 0 /* don't recurse */, stream
);
914 /* Check if this command has subcommands and is not an
915 abbreviation. We skip listing subcommands of abbreviations
916 in order to avoid duplicates in the output. */
917 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
919 /* Recursively call ourselves on the subcommand list,
920 passing the right prefix in. */
921 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
926 /* This command really has to deal with two things:
927 1) I want documentation on *this string* (usually called by
930 2) I want documentation on *this list* (usually called by giving a
931 command that requires subcommands. Also called by saying just
934 I am going to split this into two seperate comamnds, help_cmd and
938 help_cmd (const char *command
, struct ui_file
*stream
)
940 struct cmd_list_element
*c
;
944 help_list (cmdlist
, "", all_classes
, stream
);
948 if (strcmp (command
, "all") == 0)
954 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
959 /* There are three cases here.
960 If c->prefixlist is nonzero, we have a prefix command.
961 Print its documentation, then list its subcommands.
963 If c->func is non NULL, we really have a command. Print its
964 documentation and return.
966 If c->func is NULL, we have a class name. Print its
967 documentation (as if it were a command) and then set class to the
968 number of this class so that the commands in the class will be
971 fputs_filtered (c
->doc
, stream
);
972 fputs_filtered ("\n", stream
);
974 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
976 fprintf_filtered (stream
, "\n");
978 /* If this is a prefix command, print it's subcommands. */
980 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
982 /* If this is a class name, print all of the commands in the class. */
984 help_list (cmdlist
, "", c
->class, stream
);
986 if (c
->hook_pre
|| c
->hook_post
)
987 fprintf_filtered (stream
,
988 "\nThis command has a hook (or hooks) defined:\n");
991 fprintf_filtered (stream
,
992 "\tThis command is run after : %s (pre hook)\n",
995 fprintf_filtered (stream
,
996 "\tThis command is run before : %s (post hook)\n",
1001 * Get a specific kind of help on a command list.
1004 * CMDTYPE is the prefix to use in the title string.
1005 * CLASS is the class with which to list the nodes of this list (see
1006 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
1007 * everything, ALL_CLASSES for just classes, and non-negative for only things
1008 * in a specific class.
1009 * and STREAM is the output stream on which to print things.
1010 * If you call this routine with a class >= 0, it recurses.
1013 help_list (struct cmd_list_element
*list
, const char *cmdtype
,
1014 enum command_class
class, struct ui_file
*stream
)
1017 char *cmdtype1
, *cmdtype2
;
1019 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
1021 len
= strlen (cmdtype
);
1022 cmdtype1
= (char *) alloca (len
+ 1);
1024 cmdtype2
= (char *) alloca (len
+ 4);
1029 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
1031 strncpy (cmdtype2
, cmdtype
, len
- 1);
1032 strcpy (cmdtype2
+ len
- 1, " sub");
1035 if (class == all_classes
)
1036 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
1038 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
1040 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
1042 if (class == all_classes
)
1044 fprintf_filtered (stream
, "\n\
1045 Type \"help%s\" followed by a class name for a list of commands in ",
1048 fprintf_filtered (stream
, "that class.");
1050 fprintf_filtered (stream
, "\n\
1051 Type \"help all\" for the list of all commands.");
1054 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
1055 cmdtype1
, cmdtype2
);
1057 fputs_filtered ("for ", stream
);
1059 fputs_filtered ("full ", stream
);
1061 fputs_filtered ("documentation.\n", stream
);
1062 fputs_filtered ("Type \"apropos word\" to search "
1063 "for commands related to \"word\".\n", stream
);
1064 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
1069 help_all (struct ui_file
*stream
)
1071 struct cmd_list_element
*c
;
1072 int seen_unclassified
= 0;
1074 for (c
= cmdlist
; c
; c
= c
->next
)
1078 /* If this is a class name, print all of the commands in the
1081 if (c
->func
== NULL
)
1083 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
1084 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
1088 /* While it's expected that all commands are in some class,
1089 as a safety measure, we'll print commands outside of any
1090 class at the end. */
1092 for (c
= cmdlist
; c
; c
= c
->next
)
1097 if (c
->class == no_class
)
1099 if (!seen_unclassified
)
1101 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
1102 seen_unclassified
= 1;
1104 print_help_for_command (c
, "", 1, stream
);
1110 /* Print only the first line of STR on STREAM. */
1112 print_doc_line (struct ui_file
*stream
, const char *str
)
1114 static char *line_buffer
= 0;
1115 static int line_size
;
1121 line_buffer
= (char *) xmalloc (line_size
);
1124 /* Keep printing '.' or ',' not followed by a whitespace for embedded strings
1127 while (*p
&& *p
!= '\n'
1128 && ((*p
!= '.' && *p
!= ',') || (p
[1] && !isspace (p
[1]))))
1130 if (p
- str
> line_size
- 1)
1132 line_size
= p
- str
+ 1;
1133 xfree (line_buffer
);
1134 line_buffer
= (char *) xmalloc (line_size
);
1136 strncpy (line_buffer
, str
, p
- str
);
1137 line_buffer
[p
- str
] = '\0';
1138 if (islower (line_buffer
[0]))
1139 line_buffer
[0] = toupper (line_buffer
[0]);
1140 fputs_filtered (line_buffer
, stream
);
1143 /* Print one-line help for command C.
1144 If RECURSE is non-zero, also print one-line descriptions
1145 of all prefixed subcommands. */
1147 print_help_for_command (struct cmd_list_element
*c
, const char *prefix
,
1148 int recurse
, struct ui_file
*stream
)
1150 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1151 print_doc_line (stream
, c
->doc
);
1152 fputs_filtered ("\n", stream
);
1155 && c
->prefixlist
!= 0
1156 && c
->abbrev_flag
== 0)
1157 /* Subcommands of a prefix command typically have 'all_commands'
1158 as class. If we pass CLASS to recursive invocation,
1159 most often we won't see anything. */
1160 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1164 * Implement a help command on command list LIST.
1165 * RECURSE should be non-zero if this should be done recursively on
1166 * all sublists of LIST.
1167 * PREFIX is the prefix to print before each command name.
1168 * STREAM is the stream upon which the output should be written.
1170 * A non-negative class number to list only commands in that
1172 * ALL_COMMANDS to list all commands in list.
1173 * ALL_CLASSES to list all classes in list.
1175 * Note that RECURSE will be active on *all* sublists, not just the
1176 * ones selected by the criteria above (ie. the selection mechanism
1177 * is at the low level, not the high-level).
1180 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1181 const char *prefix
, int recurse
, struct ui_file
*stream
)
1183 struct cmd_list_element
*c
;
1185 for (c
= list
; c
; c
= c
->next
)
1187 if (c
->abbrev_flag
== 0
1188 && (class == all_commands
1189 || (class == all_classes
&& c
->func
== NULL
)
1190 || (class == c
->class && c
->func
!= NULL
)))
1192 print_help_for_command (c
, prefix
, recurse
, stream
);
1194 else if (c
->abbrev_flag
== 0 && recurse
1195 && class == class_user
&& c
->prefixlist
!= NULL
)
1196 /* User-defined commands may be subcommands. */
1197 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
,
1203 /* Search the input clist for 'command'. Return the command if
1204 found (or NULL if not), and return the number of commands
1207 static struct cmd_list_element
*
1208 find_cmd (const char *command
, int len
, struct cmd_list_element
*clist
,
1209 int ignore_help_classes
, int *nfound
)
1211 struct cmd_list_element
*found
, *c
;
1213 found
= (struct cmd_list_element
*) NULL
;
1215 for (c
= clist
; c
; c
= c
->next
)
1216 if (!strncmp (command
, c
->name
, len
)
1217 && (!ignore_help_classes
|| c
->func
))
1221 if (c
->name
[len
] == '\0')
1231 find_command_name_length (const char *text
)
1233 const char *p
= text
;
1235 /* Treating underscores as part of command words is important
1236 so that "set args_foo()" doesn't get interpreted as
1237 "set args _foo()". */
1238 /* Some characters are only used for TUI specific commands.
1239 However, they are always allowed for the sake of consistency.
1241 The XDB compatibility characters are only allowed when using the
1242 right mode because they clash with other GDB commands -
1243 specifically '/' is used as a suffix for print, examine and
1246 Note that this is larger than the character set allowed when
1247 creating user-defined commands. */
1249 /* Recognize '!' as a single character command so that, e.g., "!ls"
1250 works as expected. */
1254 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1255 /* Characters used by TUI specific commands. */
1256 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$'
1257 /* Characters used for XDB compatibility. */
1258 || (xdb_commands
&& (*p
== '/' || *p
== '?')))
1264 /* Return TRUE if NAME is a valid user-defined command name.
1265 This is a stricter subset of all gdb commands,
1266 see find_command_name_length. */
1269 valid_user_defined_cmd_name_p (const char *name
)
1276 /* Alas "42" is a legitimate user-defined command.
1277 In the interests of not breaking anything we preserve that. */
1279 for (p
= name
; *p
!= '\0'; ++p
)
1292 /* This routine takes a line of TEXT and a CLIST in which to start the
1293 lookup. When it returns it will have incremented the text pointer past
1294 the section of text it matched, set *RESULT_LIST to point to the list in
1295 which the last word was matched, and will return a pointer to the cmd
1296 list element which the text matches. It will return NULL if no match at
1297 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1298 matches are possible; in this case *RESULT_LIST will be set to point to
1299 the list in which there are ambiguous choices (and *TEXT will be set to
1300 the ambiguous text string).
1302 If the located command was an abbreviation, this routine returns the base
1303 command of the abbreviation.
1305 It does no error reporting whatsoever; control will always return
1306 to the superior routine.
1308 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1309 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1310 if no prefix command was ever found. For example, in the case of "info a",
1311 "info" matches without ambiguity, but "a" could be "args" or "address", so
1312 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1313 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1314 list; it simply points to a specific command. In the case of an ambiguous
1315 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1316 "info t" can be "info types" or "info target"; upon return *TEXT has been
1317 advanced past "info ").
1319 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1320 affect the operation).
1322 This routine does *not* modify the text pointed to by TEXT.
1324 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1325 are actually help classes rather than commands (i.e. the function field of
1326 the struct cmd_list_element is NULL). */
1328 struct cmd_list_element
*
1329 lookup_cmd_1 (const char **text
, struct cmd_list_element
*clist
,
1330 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1333 int len
, tmp
, nfound
;
1334 struct cmd_list_element
*found
, *c
;
1335 const char *line
= *text
;
1337 while (**text
== ' ' || **text
== '\t')
1340 /* Identify the name of the command. */
1341 len
= find_command_name_length (*text
);
1343 /* If nothing but whitespace, return 0. */
1347 /* *text and p now bracket the first command word to lookup (and
1348 it's length is len). We copy this into a local temporary. */
1351 command
= (char *) alloca (len
+ 1);
1352 memcpy (command
, *text
, len
);
1353 command
[len
] = '\0';
1358 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1360 /* We didn't find the command in the entered case, so lower case it
1361 and search again. */
1362 if (!found
|| nfound
== 0)
1364 for (tmp
= 0; tmp
< len
; tmp
++)
1366 char x
= command
[tmp
];
1368 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1370 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1373 /* If nothing matches, we have a simple failure. */
1379 if (result_list
!= NULL
)
1380 /* Will be modified in calling routine
1381 if we know what the prefix command is. */
1383 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1386 /* We've matched something on this list. Move text pointer forward. */
1390 if (found
->cmd_pointer
)
1392 /* We drop the alias (abbreviation) in favor of the command it
1393 is pointing to. If the alias is deprecated, though, we need to
1394 warn the user about it before we drop it. Note that while we
1395 are warning about the alias, we may also warn about the command
1396 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1399 if (found
->deprecated_warn_user
)
1400 deprecated_cmd_warning (line
);
1401 found
= found
->cmd_pointer
;
1403 /* If we found a prefix command, keep looking. */
1405 if (found
->prefixlist
)
1407 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1408 ignore_help_classes
);
1411 /* Didn't find anything; this is as far as we got. */
1412 if (result_list
!= NULL
)
1413 *result_list
= clist
;
1416 else if (c
== CMD_LIST_AMBIGUOUS
)
1418 /* We've gotten this far properly, but the next step is
1419 ambiguous. We need to set the result list to the best
1420 we've found (if an inferior hasn't already set it). */
1421 if (result_list
!= NULL
)
1423 /* This used to say *result_list = *found->prefixlist.
1424 If that was correct, need to modify the documentation
1425 at the top of this function to clarify what is
1426 supposed to be going on. */
1427 *result_list
= found
;
1438 if (result_list
!= NULL
)
1439 *result_list
= clist
;
1444 /* All this hair to move the space to the front of cmdtype */
1447 undef_cmd_error (const char *cmdtype
, const char *q
)
1449 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1452 *cmdtype
? " " : "",
1453 (int) strlen (cmdtype
) - 1,
1457 /* Look up the contents of *LINE as a command in the command list LIST.
1458 LIST is a chain of struct cmd_list_element's.
1459 If it is found, return the struct cmd_list_element for that command
1460 and update *LINE to point after the command name, at the first argument.
1461 If not found, call error if ALLOW_UNKNOWN is zero
1462 otherwise (or if error returns) return zero.
1463 Call error if specified command is ambiguous,
1464 unless ALLOW_UNKNOWN is negative.
1465 CMDTYPE precedes the word "command" in the error message.
1467 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1468 elements which are actually help classes rather than commands (i.e.
1469 the function field of the struct cmd_list_element is 0). */
1471 struct cmd_list_element
*
1472 lookup_cmd (const char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1473 int allow_unknown
, int ignore_help_classes
)
1475 struct cmd_list_element
*last_list
= 0;
1476 struct cmd_list_element
*c
;
1478 /* Note: Do not remove trailing whitespace here because this
1479 would be wrong for complete_command. Jim Kingdon */
1482 error (_("Lack of needed %scommand"), cmdtype
);
1484 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1491 int len
= find_command_name_length (*line
);
1493 q
= (char *) alloca (len
+ 1);
1494 strncpy (q
, *line
, len
);
1496 undef_cmd_error (cmdtype
, q
);
1501 else if (c
== CMD_LIST_AMBIGUOUS
)
1503 /* Ambigous. Local values should be off prefixlist or called
1505 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1507 const char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1508 struct cmd_list_element
*local_list
=
1509 (last_list
? *(last_list
->prefixlist
) : list
);
1511 if (local_allow_unknown
< 0)
1514 return last_list
; /* Found something. */
1516 return 0; /* Found nothing. */
1520 /* Report as error. */
1525 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1526 && (*line
)[amb_len
] != '\t');
1531 for (c
= local_list
; c
; c
= c
->next
)
1532 if (!strncmp (*line
, c
->name
, amb_len
))
1534 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1535 < (int) sizeof ambbuf
)
1537 if (strlen (ambbuf
))
1538 strcat (ambbuf
, ", ");
1539 strcat (ambbuf
, c
->name
);
1543 strcat (ambbuf
, "..");
1547 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1549 return 0; /* lint */
1554 if (c
->type
== set_cmd
&& **line
!= '\0' && !isspace (**line
))
1555 error (_("Argument must be preceded by space."));
1557 /* We've got something. It may still not be what the caller
1558 wants (if this command *needs* a subcommand). */
1559 while (**line
== ' ' || **line
== '\t')
1562 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1563 undef_cmd_error (c
->prefixname
, *line
);
1565 /* Seems to be what he wants. Return it. */
1571 /* We are here presumably because an alias or command in TEXT is
1572 deprecated and a warning message should be generated. This
1573 function decodes TEXT and potentially generates a warning message
1576 Example for 'set endian big' which has a fictitious alias 'seb'.
1578 If alias wasn't used in TEXT, and the command is deprecated:
1579 "warning: 'set endian big' is deprecated."
1581 If alias was used, and only the alias is deprecated:
1582 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1584 If alias was used and command is deprecated (regardless of whether
1585 the alias itself is deprecated:
1587 "warning: 'set endian big' (seb) is deprecated."
1589 After the message has been sent, clear the appropriate flags in the
1590 command and/or the alias so the user is no longer bothered.
1594 deprecated_cmd_warning (const char *text
)
1596 struct cmd_list_element
*alias
= NULL
;
1597 struct cmd_list_element
*prefix_cmd
= NULL
;
1598 struct cmd_list_element
*cmd
= NULL
;
1600 if (!lookup_cmd_composition (text
, &alias
, &prefix_cmd
, &cmd
))
1601 /* Return if text doesn't evaluate to a command. */
1604 if (!((alias
? alias
->deprecated_warn_user
: 0)
1605 || cmd
->deprecated_warn_user
) )
1606 /* Return if nothing is deprecated. */
1609 printf_filtered ("Warning:");
1611 if (alias
&& !cmd
->cmd_deprecated
)
1612 printf_filtered (" '%s', an alias for the", alias
->name
);
1614 printf_filtered (" command '");
1617 printf_filtered ("%s", prefix_cmd
->prefixname
);
1619 printf_filtered ("%s", cmd
->name
);
1621 if (alias
&& cmd
->cmd_deprecated
)
1622 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1624 printf_filtered ("' is deprecated.\n");
1627 /* If it is only the alias that is deprecated, we want to indicate
1628 the new alias, otherwise we'll indicate the new command. */
1630 if (alias
&& !cmd
->cmd_deprecated
)
1632 if (alias
->replacement
)
1633 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1635 printf_filtered ("No alternative known.\n\n");
1639 if (cmd
->replacement
)
1640 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1642 printf_filtered ("No alternative known.\n\n");
1645 /* We've warned you, now we'll keep quiet. */
1647 alias
->deprecated_warn_user
= 0;
1649 cmd
->deprecated_warn_user
= 0;
1653 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1654 Return 1 on success, 0 on failure.
1656 If LINE refers to an alias, *alias will point to that alias.
1658 If LINE is a postfix command (i.e. one that is preceded by a prefix
1659 command) set *prefix_cmd.
1661 Set *cmd to point to the command LINE indicates.
1663 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1664 exist, they are NULL when we return.
1668 lookup_cmd_composition (const char *text
,
1669 struct cmd_list_element
**alias
,
1670 struct cmd_list_element
**prefix_cmd
,
1671 struct cmd_list_element
**cmd
)
1674 int len
, tmp
, nfound
;
1675 struct cmd_list_element
*cur_list
;
1676 struct cmd_list_element
*prev_cmd
;
1686 /* Go through as many command lists as we need to,
1687 to find the command TEXT refers to. */
1691 while (*text
== ' ' || *text
== '\t')
1694 /* Identify the name of the command. */
1695 len
= find_command_name_length (text
);
1697 /* If nothing but whitespace, return. */
1701 /* Text is the start of the first command word to lookup (and
1702 it's length is len). We copy this into a local temporary. */
1704 command
= (char *) alloca (len
+ 1);
1705 memcpy (command
, text
, len
);
1706 command
[len
] = '\0';
1711 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1713 /* We didn't find the command in the entered case, so lower case
1714 it and search again.
1716 if (!*cmd
|| nfound
== 0)
1718 for (tmp
= 0; tmp
< len
; tmp
++)
1720 char x
= command
[tmp
];
1722 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1724 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1727 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1729 return 0; /* ambiguous */
1733 return 0; /* nothing found */
1736 if ((*cmd
)->cmd_pointer
)
1738 /* cmd was actually an alias, we note that an alias was
1739 used (by assigning *alais) and we set *cmd. */
1741 *cmd
= (*cmd
)->cmd_pointer
;
1743 *prefix_cmd
= prev_cmd
;
1745 if ((*cmd
)->prefixlist
)
1746 cur_list
= *(*cmd
)->prefixlist
;
1754 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1756 /* Return a vector of char pointers which point to the different
1757 possible completions in LIST of TEXT.
1759 WORD points in the same buffer as TEXT, and completions should be
1760 returned relative to this position. For example, suppose TEXT is
1761 "foo" and we want to complete to "foobar". If WORD is "oo", return
1762 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1765 complete_on_cmdlist (struct cmd_list_element
*list
,
1766 const char *text
, const char *word
,
1767 int ignore_help_classes
)
1769 struct cmd_list_element
*ptr
;
1770 VEC (char_ptr
) *matchlist
= NULL
;
1771 int textlen
= strlen (text
);
1773 int saw_deprecated_match
= 0;
1775 /* We do one or two passes. In the first pass, we skip deprecated
1776 commands. If we see no matching commands in the first pass, and
1777 if we did happen to see a matching deprecated command, we do
1778 another loop to collect those. */
1779 for (pass
= 0; matchlist
== 0 && pass
< 2; ++pass
)
1781 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1782 if (!strncmp (ptr
->name
, text
, textlen
)
1783 && !ptr
->abbrev_flag
1784 && (!ignore_help_classes
|| ptr
->func
1785 || ptr
->prefixlist
))
1791 if (ptr
->cmd_deprecated
)
1793 saw_deprecated_match
= 1;
1798 match
= (char *) xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1800 strcpy (match
, ptr
->name
);
1801 else if (word
> text
)
1803 /* Return some portion of ptr->name. */
1804 strcpy (match
, ptr
->name
+ (word
- text
));
1808 /* Return some of text plus ptr->name. */
1809 strncpy (match
, word
, text
- word
);
1810 match
[text
- word
] = '\0';
1811 strcat (match
, ptr
->name
);
1813 VEC_safe_push (char_ptr
, matchlist
, match
);
1815 /* If we saw no matching deprecated commands in the first pass,
1817 if (!saw_deprecated_match
)
1824 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1826 /* Return a vector of char pointers which point to the different
1827 possible completions in CMD of TEXT.
1829 WORD points in the same buffer as TEXT, and completions should be
1830 returned relative to this position. For example, suppose TEXT is "foo"
1831 and we want to complete to "foobar". If WORD is "oo", return
1832 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1835 complete_on_enum (const char *const *enumlist
,
1836 const char *text
, const char *word
)
1838 VEC (char_ptr
) *matchlist
= NULL
;
1839 int textlen
= strlen (text
);
1843 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1844 if (strncmp (name
, text
, textlen
) == 0)
1848 match
= (char *) xmalloc (strlen (word
) + strlen (name
) + 1);
1850 strcpy (match
, name
);
1851 else if (word
> text
)
1853 /* Return some portion of name. */
1854 strcpy (match
, name
+ (word
- text
));
1858 /* Return some of text plus name. */
1859 strncpy (match
, word
, text
- word
);
1860 match
[text
- word
] = '\0';
1861 strcat (match
, name
);
1863 VEC_safe_push (char_ptr
, matchlist
, match
);
1870 /* Check function pointer. */
1872 cmd_func_p (struct cmd_list_element
*cmd
)
1874 return (cmd
->func
!= NULL
);
1878 /* Call the command function. */
1880 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1882 if (cmd_func_p (cmd
))
1883 (*cmd
->func
) (cmd
, args
, from_tty
);
1885 error (_("Invalid command"));