1 /* Handle lists of commands, their decoding and documentation, for GDB.
3 Copyright (c) 1986, 1989-1991, 1998, 2000-2002, 2004, 2007-2012 Free
4 Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "gdb_regex.h"
23 #include "gdb_string.h"
24 #include "completer.h"
27 #include "cli/cli-cmds.h"
28 #include "cli/cli-decode.h"
31 #include "tui/tui.h" /* For tui_active et al. */
34 #include "gdb_assert.h"
36 /* Prototypes for local functions. */
38 static void undef_cmd_error (char *, char *);
40 static struct cmd_list_element
*delete_cmd (char *name
,
41 struct cmd_list_element
**list
,
42 struct cmd_list_element
**prehook
,
43 struct cmd_list_element
**prehookee
,
44 struct cmd_list_element
**posthook
,
45 struct cmd_list_element
**posthookee
);
47 static struct cmd_list_element
*find_cmd (char *command
,
49 struct cmd_list_element
*clist
,
50 int ignore_help_classes
,
53 static void help_all (struct ui_file
*stream
);
56 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
57 struct ui_file
*stream
);
60 /* Set the callback function for the specified command. For each both
61 the commands callback and func() are set. The latter set to a
62 bounce function (unless cfunc / sfunc is NULL that is). */
65 do_cfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
67 c
->function
.cfunc (args
, from_tty
); /* Ok. */
71 set_cmd_cfunc (struct cmd_list_element
*cmd
, cmd_cfunc_ftype
*cfunc
)
77 cmd
->function
.cfunc
= cfunc
; /* Ok. */
81 do_sfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
83 c
->function
.sfunc (args
, from_tty
, c
); /* Ok. */
87 set_cmd_sfunc (struct cmd_list_element
*cmd
, cmd_sfunc_ftype
*sfunc
)
93 cmd
->function
.sfunc
= sfunc
; /* Ok. */
97 cmd_cfunc_eq (struct cmd_list_element
*cmd
,
98 void (*cfunc
) (char *args
, int from_tty
))
100 return cmd
->func
== do_cfunc
&& cmd
->function
.cfunc
== cfunc
;
104 set_cmd_context (struct cmd_list_element
*cmd
, void *context
)
106 cmd
->context
= context
;
110 get_cmd_context (struct cmd_list_element
*cmd
)
116 cmd_type (struct cmd_list_element
*cmd
)
122 set_cmd_completer (struct cmd_list_element
*cmd
, completer_ftype
*completer
)
124 cmd
->completer
= completer
; /* Ok. */
127 /* Add element named NAME.
128 Space for NAME and DOC must be allocated by the caller.
129 CLASS is the top level category into which commands are broken down
131 FUN should be the function to execute the command;
132 it will get a character string as argument, with leading
133 and trailing blanks already eliminated.
135 DOC is a documentation string for the command.
136 Its first line should be a complete sentence.
137 It should start with ? for a command that is an abbreviation
138 or with * for a command that most users don't need to know about.
140 Add this command to command list *LIST.
142 Returns a pointer to the added command (not necessarily the head
145 struct cmd_list_element
*
146 add_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
147 char *doc
, struct cmd_list_element
**list
)
149 struct cmd_list_element
*c
150 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
151 struct cmd_list_element
*p
, *iter
;
153 /* Turn each alias of the old command into an alias of the new
155 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
156 &c
->hook_post
, &c
->hookee_post
);
157 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
158 iter
->cmd_pointer
= c
;
160 c
->hook_pre
->hookee_pre
= c
;
162 c
->hookee_pre
->hook_pre
= c
;
164 c
->hook_post
->hookee_post
= c
;
166 c
->hookee_post
->hook_post
= c
;
168 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
176 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
186 set_cmd_cfunc (c
, fun
);
187 set_cmd_context (c
, NULL
);
190 c
->replacement
= NULL
;
191 c
->pre_show_hook
= NULL
;
193 c
->prefixlist
= NULL
;
194 c
->prefixname
= NULL
;
195 c
->allow_unknown
= 0;
197 set_cmd_completer (c
, make_symbol_completion_list_fn
);
199 c
->type
= not_set_cmd
;
201 c
->var_type
= var_boolean
;
203 c
->user_commands
= NULL
;
204 c
->cmd_pointer
= NULL
;
205 c
->alias_chain
= NULL
;
210 /* Deprecates a command CMD.
211 REPLACEMENT is the name of the command which should be used in
212 place of this command, or NULL if no such command exists.
214 This function does not check to see if command REPLACEMENT exists
215 since gdb may not have gotten around to adding REPLACEMENT when
216 this function is called.
218 Returns a pointer to the deprecated command. */
220 struct cmd_list_element
*
221 deprecate_cmd (struct cmd_list_element
*cmd
, char *replacement
)
223 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
225 if (replacement
!= NULL
)
226 cmd
->replacement
= replacement
;
228 cmd
->replacement
= NULL
;
233 struct cmd_list_element
*
234 add_alias_cmd (char *name
, char *oldname
, enum command_class
class,
235 int abbrev_flag
, struct cmd_list_element
**list
)
237 /* Must do this since lookup_cmd tries to side-effect its first
240 struct cmd_list_element
*old
;
241 struct cmd_list_element
*c
;
243 copied_name
= (char *) alloca (strlen (oldname
) + 1);
244 strcpy (copied_name
, oldname
);
245 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
249 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
250 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
251 &prehook
, &prehookee
,
252 &posthook
, &posthookee
);
254 /* If this happens, it means a programmer error somewhere. */
255 gdb_assert (!aliases
&& !prehook
&& !prehookee
256 && !posthook
&& ! posthookee
);
260 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
261 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
263 c
->function
= old
->function
;
264 c
->prefixlist
= old
->prefixlist
;
265 c
->prefixname
= old
->prefixname
;
266 c
->allow_unknown
= old
->allow_unknown
;
267 c
->abbrev_flag
= abbrev_flag
;
268 c
->cmd_pointer
= old
;
269 c
->alias_chain
= old
->aliases
;
274 /* Like add_cmd but adds an element for a command prefix: a name that
275 should be followed by a subcommand to be looked up in another
276 command list. PREFIXLIST should be the address of the variable
277 containing that list. */
279 struct cmd_list_element
*
280 add_prefix_cmd (char *name
, enum command_class
class,
281 void (*fun
) (char *, int),
282 char *doc
, struct cmd_list_element
**prefixlist
,
283 char *prefixname
, int allow_unknown
,
284 struct cmd_list_element
**list
)
286 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
288 c
->prefixlist
= prefixlist
;
289 c
->prefixname
= prefixname
;
290 c
->allow_unknown
= allow_unknown
;
294 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
296 struct cmd_list_element
*
297 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
298 void (*fun
) (char *, int), char *doc
,
299 struct cmd_list_element
**prefixlist
, char *prefixname
,
300 int allow_unknown
, struct cmd_list_element
**list
)
302 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
304 c
->prefixlist
= prefixlist
;
305 c
->prefixname
= prefixname
;
306 c
->allow_unknown
= allow_unknown
;
311 /* This is an empty "cfunc". */
313 not_just_help_class_command (char *args
, int from_tty
)
317 /* This is an empty "sfunc". */
318 static void empty_sfunc (char *, int, struct cmd_list_element
*);
321 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
325 /* Add element named NAME to command list LIST (the list for set/show
326 or some sublist thereof).
327 TYPE is set_cmd or show_cmd.
328 CLASS is as in add_cmd.
329 VAR_TYPE is the kind of thing we are setting.
330 VAR is address of the variable being controlled by this command.
331 DOC is the documentation string. */
333 static struct cmd_list_element
*
334 add_set_or_show_cmd (char *name
,
336 enum command_class
class,
340 struct cmd_list_element
**list
)
342 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
344 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
346 c
->var_type
= var_type
;
348 /* This needs to be something besides NULL so that this isn't
349 treated as a help class. */
350 set_cmd_sfunc (c
, empty_sfunc
);
354 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
355 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
356 setting. VAR is address of the variable being controlled by this
357 command. SET_FUNC and SHOW_FUNC are the callback functions (if
358 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
359 strings. PRINT the format string to print the value. SET_RESULT
360 and SHOW_RESULT, if not NULL, are set to the resulting command
364 add_setshow_cmd_full (char *name
,
365 enum command_class
class,
366 var_types var_type
, void *var
,
367 const char *set_doc
, const char *show_doc
,
368 const char *help_doc
,
369 cmd_sfunc_ftype
*set_func
,
370 show_value_ftype
*show_func
,
371 struct cmd_list_element
**set_list
,
372 struct cmd_list_element
**show_list
,
373 struct cmd_list_element
**set_result
,
374 struct cmd_list_element
**show_result
)
376 struct cmd_list_element
*set
;
377 struct cmd_list_element
*show
;
381 if (help_doc
!= NULL
)
383 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
384 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
388 full_set_doc
= xstrdup (set_doc
);
389 full_show_doc
= xstrdup (show_doc
);
391 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
392 full_set_doc
, set_list
);
393 if (set_func
!= NULL
)
394 set_cmd_sfunc (set
, set_func
);
395 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
396 full_show_doc
, show_list
);
397 show
->show_value_func
= show_func
;
399 if (set_result
!= NULL
)
401 if (show_result
!= NULL
)
405 /* Add element named NAME to command list LIST (the list for set or
406 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
407 of strings which may follow NAME. VAR is address of the variable
408 which will contain the matching string (from ENUMLIST). */
411 add_setshow_enum_cmd (char *name
,
412 enum command_class
class,
413 const char *const *enumlist
,
416 const char *show_doc
,
417 const char *help_doc
,
418 cmd_sfunc_ftype
*set_func
,
419 show_value_ftype
*show_func
,
420 struct cmd_list_element
**set_list
,
421 struct cmd_list_element
**show_list
)
423 struct cmd_list_element
*c
;
425 add_setshow_cmd_full (name
, class, var_enum
, var
,
426 set_doc
, show_doc
, help_doc
,
433 /* Add an auto-boolean command named NAME to both the set and show
434 command list lists. CLASS is as in add_cmd. VAR is address of the
435 variable which will contain the value. DOC is the documentation
436 string. FUNC is the corresponding callback. */
438 add_setshow_auto_boolean_cmd (char *name
,
439 enum command_class
class,
440 enum auto_boolean
*var
,
441 const char *set_doc
, const char *show_doc
,
442 const char *help_doc
,
443 cmd_sfunc_ftype
*set_func
,
444 show_value_ftype
*show_func
,
445 struct cmd_list_element
**set_list
,
446 struct cmd_list_element
**show_list
)
448 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
449 struct cmd_list_element
*c
;
451 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
452 set_doc
, show_doc
, help_doc
,
456 c
->enums
= auto_boolean_enums
;
459 /* Add element named NAME to both the set and show command LISTs (the
460 list for set/show or some sublist thereof). CLASS is as in
461 add_cmd. VAR is address of the variable which will contain the
462 value. SET_DOC and SHOW_DOC are the documentation strings. */
464 add_setshow_boolean_cmd (char *name
, enum command_class
class, int *var
,
465 const char *set_doc
, const char *show_doc
,
466 const char *help_doc
,
467 cmd_sfunc_ftype
*set_func
,
468 show_value_ftype
*show_func
,
469 struct cmd_list_element
**set_list
,
470 struct cmd_list_element
**show_list
)
472 static const char *boolean_enums
[] = { "on", "off", NULL
};
473 struct cmd_list_element
*c
;
475 add_setshow_cmd_full (name
, class, var_boolean
, var
,
476 set_doc
, show_doc
, help_doc
,
480 c
->enums
= boolean_enums
;
483 /* Add element named NAME to both the set and show command LISTs (the
484 list for set/show or some sublist thereof). */
486 add_setshow_filename_cmd (char *name
, enum command_class
class,
488 const char *set_doc
, const char *show_doc
,
489 const char *help_doc
,
490 cmd_sfunc_ftype
*set_func
,
491 show_value_ftype
*show_func
,
492 struct cmd_list_element
**set_list
,
493 struct cmd_list_element
**show_list
)
495 struct cmd_list_element
*set_result
;
497 add_setshow_cmd_full (name
, class, var_filename
, var
,
498 set_doc
, show_doc
, help_doc
,
502 set_cmd_completer (set_result
, filename_completer
);
505 /* Add element named NAME to both the set and show command LISTs (the
506 list for set/show or some sublist thereof). */
508 add_setshow_string_cmd (char *name
, enum command_class
class,
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 add_setshow_cmd_full (name
, class, var_string
, var
,
518 set_doc
, show_doc
, help_doc
,
524 /* Add element named NAME to both the set and show command LISTs (the
525 list for set/show or some sublist thereof). */
527 add_setshow_string_noescape_cmd (char *name
, enum command_class
class,
529 const char *set_doc
, const char *show_doc
,
530 const char *help_doc
,
531 cmd_sfunc_ftype
*set_func
,
532 show_value_ftype
*show_func
,
533 struct cmd_list_element
**set_list
,
534 struct cmd_list_element
**show_list
)
536 add_setshow_cmd_full (name
, class, var_string_noescape
, var
,
537 set_doc
, show_doc
, help_doc
,
543 /* Add element named NAME to both the set and show command LISTs (the
544 list for set/show or some sublist thereof). */
546 add_setshow_optional_filename_cmd (char *name
, enum command_class
class,
548 const char *set_doc
, const char *show_doc
,
549 const char *help_doc
,
550 cmd_sfunc_ftype
*set_func
,
551 show_value_ftype
*show_func
,
552 struct cmd_list_element
**set_list
,
553 struct cmd_list_element
**show_list
)
555 struct cmd_list_element
*set_result
;
557 add_setshow_cmd_full (name
, class, var_optional_filename
, var
,
558 set_doc
, show_doc
, help_doc
,
563 set_cmd_completer (set_result
, filename_completer
);
567 /* Add element named NAME to both the set and show command LISTs (the
568 list for set/show or some sublist thereof). CLASS is as in
569 add_cmd. VAR is address of the variable which will contain the
570 value. SET_DOC and SHOW_DOC are the documentation strings. */
572 add_setshow_integer_cmd (char *name
, enum command_class
class,
574 const char *set_doc
, const char *show_doc
,
575 const char *help_doc
,
576 cmd_sfunc_ftype
*set_func
,
577 show_value_ftype
*show_func
,
578 struct cmd_list_element
**set_list
,
579 struct cmd_list_element
**show_list
)
581 add_setshow_cmd_full (name
, class, var_integer
, var
,
582 set_doc
, show_doc
, help_doc
,
588 /* Add element named NAME to both the set and show command LISTs (the
589 list for set/show or some sublist thereof). CLASS is as in
590 add_cmd. VAR is address of the variable which will contain the
591 value. SET_DOC and SHOW_DOC are the documentation strings. */
593 add_setshow_uinteger_cmd (char *name
, enum command_class
class,
595 const char *set_doc
, const char *show_doc
,
596 const char *help_doc
,
597 cmd_sfunc_ftype
*set_func
,
598 show_value_ftype
*show_func
,
599 struct cmd_list_element
**set_list
,
600 struct cmd_list_element
**show_list
)
602 add_setshow_cmd_full (name
, class, var_uinteger
, var
,
603 set_doc
, show_doc
, help_doc
,
609 /* Add element named NAME to both the set and show command LISTs (the
610 list for set/show or some sublist thereof). CLASS is as in
611 add_cmd. VAR is address of the variable which will contain the
612 value. SET_DOC and SHOW_DOC are the documentation strings. */
614 add_setshow_zinteger_cmd (char *name
, enum command_class
class,
616 const char *set_doc
, const char *show_doc
,
617 const char *help_doc
,
618 cmd_sfunc_ftype
*set_func
,
619 show_value_ftype
*show_func
,
620 struct cmd_list_element
**set_list
,
621 struct cmd_list_element
**show_list
)
623 add_setshow_cmd_full (name
, class, var_zinteger
, var
,
624 set_doc
, show_doc
, help_doc
,
630 /* Add element named NAME to both the set and show command LISTs (the
631 list for set/show or some sublist thereof). CLASS is as in
632 add_cmd. VAR is address of the variable which will contain the
633 value. SET_DOC and SHOW_DOC are the documentation strings. */
635 add_setshow_zuinteger_cmd (char *name
, enum command_class
class,
637 const char *set_doc
, const char *show_doc
,
638 const char *help_doc
,
639 cmd_sfunc_ftype
*set_func
,
640 show_value_ftype
*show_func
,
641 struct cmd_list_element
**set_list
,
642 struct cmd_list_element
**show_list
)
644 add_setshow_cmd_full (name
, class, var_zuinteger
, var
,
645 set_doc
, show_doc
, help_doc
,
651 /* Remove the command named NAME from the command list. Return the
652 list commands which were aliased to the deleted command. If the
653 command had no aliases, return NULL. The various *HOOKs are set to
654 the pre- and post-hook commands for the deleted command. If the
655 command does not have a hook, the corresponding out parameter is
658 static struct cmd_list_element
*
659 delete_cmd (char *name
, struct cmd_list_element
**list
,
660 struct cmd_list_element
**prehook
,
661 struct cmd_list_element
**prehookee
,
662 struct cmd_list_element
**posthook
,
663 struct cmd_list_element
**posthookee
)
665 struct cmd_list_element
*iter
;
666 struct cmd_list_element
**previous_chain_ptr
;
667 struct cmd_list_element
*aliases
= NULL
;
673 previous_chain_ptr
= list
;
675 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
677 if (strcmp (iter
->name
, name
) == 0)
680 iter
->destroyer (iter
, iter
->context
);
681 if (iter
->hookee_pre
)
682 iter
->hookee_pre
->hook_pre
= 0;
683 *prehook
= iter
->hook_pre
;
684 *prehookee
= iter
->hookee_pre
;
685 if (iter
->hookee_post
)
686 iter
->hookee_post
->hook_post
= 0;
687 *posthook
= iter
->hook_post
;
688 *posthookee
= iter
->hookee_post
;
690 /* Update the link. */
691 *previous_chain_ptr
= iter
->next
;
693 aliases
= iter
->aliases
;
695 /* If this command was an alias, remove it from the list of
697 if (iter
->cmd_pointer
)
699 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
700 struct cmd_list_element
*a
= *prevp
;
704 prevp
= &a
->alias_chain
;
707 *prevp
= iter
->alias_chain
;
712 /* We won't see another command with the same name. */
716 previous_chain_ptr
= &iter
->next
;
722 /* Shorthands to the commands above. */
724 /* Add an element to the list of info subcommands. */
726 struct cmd_list_element
*
727 add_info (char *name
, void (*fun
) (char *, int), char *doc
)
729 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
732 /* Add an alias to the list of info subcommands. */
734 struct cmd_list_element
*
735 add_info_alias (char *name
, char *oldname
, int abbrev_flag
)
737 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
740 /* Add an element to the list of commands. */
742 struct cmd_list_element
*
743 add_com (char *name
, enum command_class
class, void (*fun
) (char *, int),
746 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
749 /* Add an alias or abbreviation command to the list of commands. */
751 struct cmd_list_element
*
752 add_com_alias (char *name
, char *oldname
, enum command_class
class,
755 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
758 /* Recursively walk the commandlist structures, and print out the
759 documentation of commands that match our regex in either their
760 name, or their documentation.
763 apropos_cmd (struct ui_file
*stream
,
764 struct cmd_list_element
*commandlist
,
765 struct re_pattern_buffer
*regex
, char *prefix
)
767 struct cmd_list_element
*c
;
770 /* Walk through the commands. */
771 for (c
=commandlist
;c
;c
=c
->next
)
773 returnvalue
= -1; /* Needed to avoid double printing. */
776 /* Try to match against the name. */
777 returnvalue
= re_search (regex
, c
->name
, strlen(c
->name
),
778 0, strlen (c
->name
), NULL
);
779 if (returnvalue
>= 0)
781 print_help_for_command (c
, prefix
,
782 0 /* don't recurse */, stream
);
785 if (c
->doc
!= NULL
&& returnvalue
< 0)
787 /* Try to match against documentation. */
788 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
790 print_help_for_command (c
, prefix
,
791 0 /* don't recurse */, stream
);
794 /* Check if this command has subcommands and is not an
795 abbreviation. We skip listing subcommands of abbreviations
796 in order to avoid duplicates in the output. */
797 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
799 /* Recursively call ourselves on the subcommand list,
800 passing the right prefix in. */
801 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
806 /* This command really has to deal with two things:
807 1) I want documentation on *this string* (usually called by
810 2) I want documentation on *this list* (usually called by giving a
811 command that requires subcommands. Also called by saying just
814 I am going to split this into two seperate comamnds, help_cmd and
818 help_cmd (char *command
, struct ui_file
*stream
)
820 struct cmd_list_element
*c
;
821 extern struct cmd_list_element
*cmdlist
;
825 help_list (cmdlist
, "", all_classes
, stream
);
829 if (strcmp (command
, "all") == 0)
835 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
840 /* There are three cases here.
841 If c->prefixlist is nonzero, we have a prefix command.
842 Print its documentation, then list its subcommands.
844 If c->func is non NULL, we really have a command. Print its
845 documentation and return.
847 If c->func is NULL, we have a class name. Print its
848 documentation (as if it were a command) and then set class to the
849 number of this class so that the commands in the class will be
852 fputs_filtered (c
->doc
, stream
);
853 fputs_filtered ("\n", stream
);
855 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
857 fprintf_filtered (stream
, "\n");
859 /* If this is a prefix command, print it's subcommands. */
861 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
863 /* If this is a class name, print all of the commands in the class. */
865 help_list (cmdlist
, "", c
->class, stream
);
867 if (c
->hook_pre
|| c
->hook_post
)
868 fprintf_filtered (stream
,
869 "\nThis command has a hook (or hooks) defined:\n");
872 fprintf_filtered (stream
,
873 "\tThis command is run after : %s (pre hook)\n",
876 fprintf_filtered (stream
,
877 "\tThis command is run before : %s (post hook)\n",
882 * Get a specific kind of help on a command list.
885 * CMDTYPE is the prefix to use in the title string.
886 * CLASS is the class with which to list the nodes of this list (see
887 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
888 * everything, ALL_CLASSES for just classes, and non-negative for only things
889 * in a specific class.
890 * and STREAM is the output stream on which to print things.
891 * If you call this routine with a class >= 0, it recurses.
894 help_list (struct cmd_list_element
*list
, char *cmdtype
,
895 enum command_class
class, struct ui_file
*stream
)
898 char *cmdtype1
, *cmdtype2
;
900 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
902 len
= strlen (cmdtype
);
903 cmdtype1
= (char *) alloca (len
+ 1);
905 cmdtype2
= (char *) alloca (len
+ 4);
910 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
912 strncpy (cmdtype2
, cmdtype
, len
- 1);
913 strcpy (cmdtype2
+ len
- 1, " sub");
916 if (class == all_classes
)
917 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
919 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
921 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
923 if (class == all_classes
)
925 fprintf_filtered (stream
, "\n\
926 Type \"help%s\" followed by a class name for a list of commands in ",
929 fprintf_filtered (stream
, "that class.");
931 fprintf_filtered (stream
, "\n\
932 Type \"help all\" for the list of all commands.");
935 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
938 fputs_filtered ("for ", stream
);
940 fputs_filtered ("full ", stream
);
942 fputs_filtered ("documentation.\n", stream
);
943 fputs_filtered ("Type \"apropos word\" to search "
944 "for commands related to \"word\".\n", stream
);
945 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
950 help_all (struct ui_file
*stream
)
952 struct cmd_list_element
*c
;
953 extern struct cmd_list_element
*cmdlist
;
954 int seen_unclassified
= 0;
956 for (c
= cmdlist
; c
; c
= c
->next
)
960 /* If this is a class name, print all of the commands in the
965 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
966 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
970 /* While it's expected that all commands are in some class,
971 as a safety measure, we'll print commands outside of any
974 for (c
= cmdlist
; c
; c
= c
->next
)
979 if (c
->class == no_class
)
981 if (!seen_unclassified
)
983 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
984 seen_unclassified
= 1;
986 print_help_for_command (c
, "", 1, stream
);
992 /* Print only the first line of STR on STREAM. */
994 print_doc_line (struct ui_file
*stream
, char *str
)
996 static char *line_buffer
= 0;
997 static int line_size
;
1003 line_buffer
= (char *) xmalloc (line_size
);
1007 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
1009 if (p
- str
> line_size
- 1)
1011 line_size
= p
- str
+ 1;
1012 xfree (line_buffer
);
1013 line_buffer
= (char *) xmalloc (line_size
);
1015 strncpy (line_buffer
, str
, p
- str
);
1016 line_buffer
[p
- str
] = '\0';
1017 if (islower (line_buffer
[0]))
1018 line_buffer
[0] = toupper (line_buffer
[0]);
1019 fputs_filtered (line_buffer
, stream
);
1022 /* Print one-line help for command C.
1023 If RECURSE is non-zero, also print one-line descriptions
1024 of all prefixed subcommands. */
1026 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
1027 struct ui_file
*stream
)
1029 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1030 print_doc_line (stream
, c
->doc
);
1031 fputs_filtered ("\n", stream
);
1034 && c
->prefixlist
!= 0
1035 && c
->abbrev_flag
== 0)
1036 /* Subcommands of a prefix command typically have 'all_commands'
1037 as class. If we pass CLASS to recursive invocation,
1038 most often we won't see anything. */
1039 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1043 * Implement a help command on command list LIST.
1044 * RECURSE should be non-zero if this should be done recursively on
1045 * all sublists of LIST.
1046 * PREFIX is the prefix to print before each command name.
1047 * STREAM is the stream upon which the output should be written.
1049 * A non-negative class number to list only commands in that
1051 * ALL_COMMANDS to list all commands in list.
1052 * ALL_CLASSES to list all classes in list.
1054 * Note that RECURSE will be active on *all* sublists, not just the
1055 * ones selected by the criteria above (ie. the selection mechanism
1056 * is at the low level, not the high-level).
1059 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1060 char *prefix
, int recurse
, struct ui_file
*stream
)
1062 struct cmd_list_element
*c
;
1064 for (c
= list
; c
; c
= c
->next
)
1066 if (c
->abbrev_flag
== 0
1067 && (class == all_commands
1068 || (class == all_classes
&& c
->func
== NULL
)
1069 || (class == c
->class && c
->func
!= NULL
)))
1071 print_help_for_command (c
, prefix
, recurse
, stream
);
1073 else if (c
->abbrev_flag
== 0 && recurse
1074 && class == class_user
&& c
->prefixlist
!= NULL
)
1075 /* User-defined commands may be subcommands. */
1076 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
,
1082 /* Search the input clist for 'command'. Return the command if
1083 found (or NULL if not), and return the number of commands
1086 static struct cmd_list_element
*
1087 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
1088 int ignore_help_classes
, int *nfound
)
1090 struct cmd_list_element
*found
, *c
;
1092 found
= (struct cmd_list_element
*) NULL
;
1094 for (c
= clist
; c
; c
= c
->next
)
1095 if (!strncmp (command
, c
->name
, len
)
1096 && (!ignore_help_classes
|| c
->func
))
1100 if (c
->name
[len
] == '\0')
1110 find_command_name_length (const char *text
)
1112 const char *p
= text
;
1114 /* Treating underscores as part of command words is important
1115 so that "set args_foo()" doesn't get interpreted as
1116 "set args _foo()". */
1117 /* Some characters are only used for TUI specific commands.
1118 However, they are always allowed for the sake of consistency.
1120 The XDB compatibility characters are only allowed when using the
1121 right mode because they clash with other GDB commands -
1122 specifically '/' is used as a suffix for print, examine and
1125 Note that this is larger than the character set allowed when
1126 creating user-defined commands. */
1128 /* Recognize '!' as a single character command so that, e.g., "!ls"
1129 works as expected. */
1133 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1134 /* Characters used by TUI specific commands. */
1135 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$'
1136 /* Characters used for XDB compatibility. */
1137 || (xdb_commands
&& (*p
== '/' || *p
== '?')))
1143 /* Return TRUE if NAME is a valid user-defined command name.
1144 This is a stricter subset of all gdb commands,
1145 see find_command_name_length. */
1148 valid_user_defined_cmd_name_p (const char *name
)
1155 /* Alas "42" is a legitimate user-defined command.
1156 In the interests of not breaking anything we preserve that. */
1158 for (p
= name
; *p
!= '\0'; ++p
)
1171 /* This routine takes a line of TEXT and a CLIST in which to start the
1172 lookup. When it returns it will have incremented the text pointer past
1173 the section of text it matched, set *RESULT_LIST to point to the list in
1174 which the last word was matched, and will return a pointer to the cmd
1175 list element which the text matches. It will return NULL if no match at
1176 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1177 matches are possible; in this case *RESULT_LIST will be set to point to
1178 the list in which there are ambiguous choices (and *TEXT will be set to
1179 the ambiguous text string).
1181 If the located command was an abbreviation, this routine returns the base
1182 command of the abbreviation.
1184 It does no error reporting whatsoever; control will always return
1185 to the superior routine.
1187 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1188 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1189 if no prefix command was ever found. For example, in the case of "info a",
1190 "info" matches without ambiguity, but "a" could be "args" or "address", so
1191 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1192 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1193 list; it simply points to a specific command. In the case of an ambiguous
1194 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1195 "info t" can be "info types" or "info target"; upon return *TEXT has been
1196 advanced past "info ").
1198 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1199 affect the operation).
1201 This routine does *not* modify the text pointed to by TEXT.
1203 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1204 are actually help classes rather than commands (i.e. the function field of
1205 the struct cmd_list_element is NULL). */
1207 struct cmd_list_element
*
1208 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
1209 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1212 int len
, tmp
, nfound
;
1213 struct cmd_list_element
*found
, *c
;
1216 while (**text
== ' ' || **text
== '\t')
1219 /* Identify the name of the command. */
1220 len
= find_command_name_length (*text
);
1222 /* If nothing but whitespace, return 0. */
1226 /* *text and p now bracket the first command word to lookup (and
1227 it's length is len). We copy this into a local temporary. */
1230 command
= (char *) alloca (len
+ 1);
1231 memcpy (command
, *text
, len
);
1232 command
[len
] = '\0';
1237 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1239 /* We didn't find the command in the entered case, so lower case it
1240 and search again. */
1241 if (!found
|| nfound
== 0)
1243 for (tmp
= 0; tmp
< len
; tmp
++)
1245 char x
= command
[tmp
];
1247 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1249 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1252 /* If nothing matches, we have a simple failure. */
1258 if (result_list
!= NULL
)
1259 /* Will be modified in calling routine
1260 if we know what the prefix command is. */
1262 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1265 /* We've matched something on this list. Move text pointer forward. */
1269 if (found
->cmd_pointer
)
1271 /* We drop the alias (abbreviation) in favor of the command it
1272 is pointing to. If the alias is deprecated, though, we need to
1273 warn the user about it before we drop it. Note that while we
1274 are warning about the alias, we may also warn about the command
1275 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1278 if (found
->flags
& DEPRECATED_WARN_USER
)
1279 deprecated_cmd_warning (&line
);
1280 found
= found
->cmd_pointer
;
1282 /* If we found a prefix command, keep looking. */
1284 if (found
->prefixlist
)
1286 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1287 ignore_help_classes
);
1290 /* Didn't find anything; this is as far as we got. */
1291 if (result_list
!= NULL
)
1292 *result_list
= clist
;
1295 else if (c
== CMD_LIST_AMBIGUOUS
)
1297 /* We've gotten this far properly, but the next step is
1298 ambiguous. We need to set the result list to the best
1299 we've found (if an inferior hasn't already set it). */
1300 if (result_list
!= NULL
)
1302 /* This used to say *result_list = *found->prefixlist.
1303 If that was correct, need to modify the documentation
1304 at the top of this function to clarify what is
1305 supposed to be going on. */
1306 *result_list
= found
;
1317 if (result_list
!= NULL
)
1318 *result_list
= clist
;
1323 /* All this hair to move the space to the front of cmdtype */
1326 undef_cmd_error (char *cmdtype
, char *q
)
1328 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1331 *cmdtype
? " " : "",
1332 (int) strlen (cmdtype
) - 1,
1336 /* Look up the contents of *LINE as a command in the command list LIST.
1337 LIST is a chain of struct cmd_list_element's.
1338 If it is found, return the struct cmd_list_element for that command
1339 and update *LINE to point after the command name, at the first argument.
1340 If not found, call error if ALLOW_UNKNOWN is zero
1341 otherwise (or if error returns) return zero.
1342 Call error if specified command is ambiguous,
1343 unless ALLOW_UNKNOWN is negative.
1344 CMDTYPE precedes the word "command" in the error message.
1346 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1347 elements which are actually help classes rather than commands (i.e.
1348 the function field of the struct cmd_list_element is 0). */
1350 struct cmd_list_element
*
1351 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1352 int allow_unknown
, int ignore_help_classes
)
1354 struct cmd_list_element
*last_list
= 0;
1355 struct cmd_list_element
*c
;
1357 /* Note: Do not remove trailing whitespace here because this
1358 would be wrong for complete_command. Jim Kingdon */
1361 error (_("Lack of needed %scommand"), cmdtype
);
1363 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1370 int len
= find_command_name_length (*line
);
1372 q
= (char *) alloca (len
+ 1);
1373 strncpy (q
, *line
, len
);
1375 undef_cmd_error (cmdtype
, q
);
1380 else if (c
== CMD_LIST_AMBIGUOUS
)
1382 /* Ambigous. Local values should be off prefixlist or called
1384 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1386 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1387 struct cmd_list_element
*local_list
=
1388 (last_list
? *(last_list
->prefixlist
) : list
);
1390 if (local_allow_unknown
< 0)
1393 return last_list
; /* Found something. */
1395 return 0; /* Found nothing. */
1399 /* Report as error. */
1404 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1405 && (*line
)[amb_len
] != '\t');
1410 for (c
= local_list
; c
; c
= c
->next
)
1411 if (!strncmp (*line
, c
->name
, amb_len
))
1413 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1414 < (int) sizeof ambbuf
)
1416 if (strlen (ambbuf
))
1417 strcat (ambbuf
, ", ");
1418 strcat (ambbuf
, c
->name
);
1422 strcat (ambbuf
, "..");
1426 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1428 return 0; /* lint */
1433 /* We've got something. It may still not be what the caller
1434 wants (if this command *needs* a subcommand). */
1435 while (**line
== ' ' || **line
== '\t')
1438 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1439 undef_cmd_error (c
->prefixname
, *line
);
1441 /* Seems to be what he wants. Return it. */
1447 /* We are here presumably because an alias or command in *TEXT is
1448 deprecated and a warning message should be generated. This
1449 function decodes *TEXT and potentially generates a warning message
1452 Example for 'set endian big' which has a fictitious alias 'seb'.
1454 If alias wasn't used in *TEXT, and the command is deprecated:
1455 "warning: 'set endian big' is deprecated."
1457 If alias was used, and only the alias is deprecated:
1458 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1460 If alias was used and command is deprecated (regardless of whether
1461 the alias itself is deprecated:
1463 "warning: 'set endian big' (seb) is deprecated."
1465 After the message has been sent, clear the appropriate flags in the
1466 command and/or the alias so the user is no longer bothered.
1470 deprecated_cmd_warning (char **text
)
1472 struct cmd_list_element
*alias
= NULL
;
1473 struct cmd_list_element
*prefix_cmd
= NULL
;
1474 struct cmd_list_element
*cmd
= NULL
;
1476 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1477 /* Return if text doesn't evaluate to a command. */
1480 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1481 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1482 /* Return if nothing is deprecated. */
1485 printf_filtered ("Warning:");
1487 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1488 printf_filtered (" '%s', an alias for the", alias
->name
);
1490 printf_filtered (" command '");
1493 printf_filtered ("%s", prefix_cmd
->prefixname
);
1495 printf_filtered ("%s", cmd
->name
);
1497 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1498 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1500 printf_filtered ("' is deprecated.\n");
1503 /* If it is only the alias that is deprecated, we want to indicate
1504 the new alias, otherwise we'll indicate the new command. */
1506 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1508 if (alias
->replacement
)
1509 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1511 printf_filtered ("No alternative known.\n\n");
1515 if (cmd
->replacement
)
1516 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1518 printf_filtered ("No alternative known.\n\n");
1521 /* We've warned you, now we'll keep quiet. */
1523 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1525 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1529 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1530 Return 1 on success, 0 on failure.
1532 If LINE refers to an alias, *alias will point to that alias.
1534 If LINE is a postfix command (i.e. one that is preceded by a prefix
1535 command) set *prefix_cmd.
1537 Set *cmd to point to the command LINE indicates.
1539 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1540 exist, they are NULL when we return.
1544 lookup_cmd_composition (char *text
,
1545 struct cmd_list_element
**alias
,
1546 struct cmd_list_element
**prefix_cmd
,
1547 struct cmd_list_element
**cmd
)
1550 int len
, tmp
, nfound
;
1551 struct cmd_list_element
*cur_list
;
1552 struct cmd_list_element
*prev_cmd
;
1562 /* Go through as many command lists as we need to,
1563 to find the command TEXT refers to. */
1567 while (*text
== ' ' || *text
== '\t')
1570 /* Identify the name of the command. */
1571 len
= find_command_name_length (text
);
1573 /* If nothing but whitespace, return. */
1577 /* Text is the start of the first command word to lookup (and
1578 it's length is len). We copy this into a local temporary. */
1580 command
= (char *) alloca (len
+ 1);
1581 memcpy (command
, text
, len
);
1582 command
[len
] = '\0';
1587 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1589 /* We didn't find the command in the entered case, so lower case
1590 it and search again.
1592 if (!*cmd
|| nfound
== 0)
1594 for (tmp
= 0; tmp
< len
; tmp
++)
1596 char x
= command
[tmp
];
1598 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1600 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1603 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1605 return 0; /* ambiguous */
1609 return 0; /* nothing found */
1612 if ((*cmd
)->cmd_pointer
)
1614 /* cmd was actually an alias, we note that an alias was
1615 used (by assigning *alais) and we set *cmd. */
1617 *cmd
= (*cmd
)->cmd_pointer
;
1619 *prefix_cmd
= prev_cmd
;
1621 if ((*cmd
)->prefixlist
)
1622 cur_list
= *(*cmd
)->prefixlist
;
1630 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1632 /* Return a vector of char pointers which point to the different
1633 possible completions in LIST of TEXT.
1635 WORD points in the same buffer as TEXT, and completions should be
1636 returned relative to this position. For example, suppose TEXT is
1637 "foo" and we want to complete to "foobar". If WORD is "oo", return
1638 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1641 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1643 struct cmd_list_element
*ptr
;
1644 VEC (char_ptr
) *matchlist
= NULL
;
1645 int textlen
= strlen (text
);
1647 int saw_deprecated_match
= 0;
1649 /* We do one or two passes. In the first pass, we skip deprecated
1650 commands. If we see no matching commands in the first pass, and
1651 if we did happen to see a matching deprecated command, we do
1652 another loop to collect those. */
1653 for (pass
= 0; matchlist
== 0 && pass
< 2; ++pass
)
1655 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1656 if (!strncmp (ptr
->name
, text
, textlen
)
1657 && !ptr
->abbrev_flag
1659 || ptr
->prefixlist
))
1665 if ((ptr
->flags
& CMD_DEPRECATED
) != 0)
1667 saw_deprecated_match
= 1;
1672 match
= (char *) xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1674 strcpy (match
, ptr
->name
);
1675 else if (word
> text
)
1677 /* Return some portion of ptr->name. */
1678 strcpy (match
, ptr
->name
+ (word
- text
));
1682 /* Return some of text plus ptr->name. */
1683 strncpy (match
, word
, text
- word
);
1684 match
[text
- word
] = '\0';
1685 strcat (match
, ptr
->name
);
1687 VEC_safe_push (char_ptr
, matchlist
, match
);
1689 /* If we saw no matching deprecated commands in the first pass,
1691 if (!saw_deprecated_match
)
1698 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1700 /* Return a vector of char pointers which point to the different
1701 possible completions in CMD of TEXT.
1703 WORD points in the same buffer as TEXT, and completions should be
1704 returned relative to this position. For example, suppose TEXT is "foo"
1705 and we want to complete to "foobar". If WORD is "oo", return
1706 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1709 complete_on_enum (const char *const *enumlist
,
1713 VEC (char_ptr
) *matchlist
= NULL
;
1714 int textlen
= strlen (text
);
1718 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1719 if (strncmp (name
, text
, textlen
) == 0)
1723 match
= (char *) xmalloc (strlen (word
) + strlen (name
) + 1);
1725 strcpy (match
, name
);
1726 else if (word
> text
)
1728 /* Return some portion of name. */
1729 strcpy (match
, name
+ (word
- text
));
1733 /* Return some of text plus name. */
1734 strncpy (match
, word
, text
- word
);
1735 match
[text
- word
] = '\0';
1736 strcat (match
, name
);
1738 VEC_safe_push (char_ptr
, matchlist
, match
);
1745 /* Check function pointer. */
1747 cmd_func_p (struct cmd_list_element
*cmd
)
1749 return (cmd
->func
!= NULL
);
1753 /* Call the command function. */
1755 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1757 if (cmd_func_p (cmd
))
1758 (*cmd
->func
) (cmd
, args
, from_tty
);
1760 error (_("Invalid command"));