1 /* Handle lists of commands, their decoding and documentation, for GDB.
3 Copyright (c) 1986, 1989, 1990, 1991, 1998, 2000, 2001, 2002, 2004, 2007,
4 2008, 2009 Free 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 set_cmd_no_selected_thread_ok (struct cmd_list_element
*cmd
)
118 cmd
->flags
|= CMD_NO_SELECTED_THREAD_OK
;
122 get_cmd_no_selected_thread_ok (struct cmd_list_element
*cmd
)
124 return cmd
->flags
& CMD_NO_SELECTED_THREAD_OK
;
128 cmd_type (struct cmd_list_element
*cmd
)
134 set_cmd_completer (struct cmd_list_element
*cmd
,
135 char **(*completer
) (char *text
, char *word
))
137 cmd
->completer
= completer
; /* Ok. */
141 /* Add element named NAME.
142 CLASS is the top level category into which commands are broken down
144 FUN should be the function to execute the command;
145 it will get a character string as argument, with leading
146 and trailing blanks already eliminated.
148 DOC is a documentation string for the command.
149 Its first line should be a complete sentence.
150 It should start with ? for a command that is an abbreviation
151 or with * for a command that most users don't need to know about.
153 Add this command to command list *LIST.
155 Returns a pointer to the added command (not necessarily the head
158 struct cmd_list_element
*
159 add_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
160 char *doc
, struct cmd_list_element
**list
)
162 struct cmd_list_element
*c
163 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
164 struct cmd_list_element
*p
, *iter
;
166 /* Turn each alias of the old command into an alias of the new
168 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
169 &c
->hook_post
, &c
->hookee_post
);
170 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
171 iter
->cmd_pointer
= c
;
173 c
->hook_pre
->hookee_pre
= c
;
175 c
->hookee_pre
->hook_pre
= c
;
177 c
->hook_post
->hookee_post
= c
;
179 c
->hookee_post
->hook_post
= c
;
181 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
189 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
199 set_cmd_cfunc (c
, fun
);
200 set_cmd_context (c
, NULL
);
203 c
->replacement
= NULL
;
204 c
->pre_show_hook
= NULL
;
206 c
->prefixlist
= NULL
;
207 c
->prefixname
= NULL
;
208 c
->allow_unknown
= 0;
210 set_cmd_completer (c
, make_symbol_completion_list
);
211 c
->type
= not_set_cmd
;
213 c
->var_type
= var_boolean
;
215 c
->user_commands
= NULL
;
216 c
->cmd_pointer
= NULL
;
217 c
->alias_chain
= NULL
;
222 /* Deprecates a command CMD.
223 REPLACEMENT is the name of the command which should be used in place
224 of this command, or NULL if no such command exists.
226 This function does not check to see if command REPLACEMENT exists
227 since gdb may not have gotten around to adding REPLACEMENT when this
230 Returns a pointer to the deprecated command. */
232 struct cmd_list_element
*
233 deprecate_cmd (struct cmd_list_element
*cmd
, char *replacement
)
235 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
237 if (replacement
!= NULL
)
238 cmd
->replacement
= replacement
;
240 cmd
->replacement
= NULL
;
245 struct cmd_list_element
*
246 add_alias_cmd (char *name
, char *oldname
, enum command_class
class,
247 int abbrev_flag
, struct cmd_list_element
**list
)
249 /* Must do this since lookup_cmd tries to side-effect its first arg */
251 struct cmd_list_element
*old
;
252 struct cmd_list_element
*c
;
253 copied_name
= (char *) alloca (strlen (oldname
) + 1);
254 strcpy (copied_name
, oldname
);
255 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
259 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
260 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
261 &prehook
, &prehookee
,
262 &posthook
, &posthookee
);
263 /* If this happens, it means a programmer error somewhere. */
264 gdb_assert (!aliases
&& !prehook
&& prehookee
265 && !posthook
&& ! posthookee
);
269 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
270 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
272 c
->function
= old
->function
;
273 c
->prefixlist
= old
->prefixlist
;
274 c
->prefixname
= old
->prefixname
;
275 c
->allow_unknown
= old
->allow_unknown
;
276 c
->abbrev_flag
= abbrev_flag
;
277 c
->cmd_pointer
= old
;
278 c
->alias_chain
= old
->aliases
;
283 /* Like add_cmd but adds an element for a command prefix:
284 a name that should be followed by a subcommand to be looked up
285 in another command list. PREFIXLIST should be the address
286 of the variable containing that list. */
288 struct cmd_list_element
*
289 add_prefix_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
290 char *doc
, struct cmd_list_element
**prefixlist
,
291 char *prefixname
, int allow_unknown
,
292 struct cmd_list_element
**list
)
294 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
295 c
->prefixlist
= prefixlist
;
296 c
->prefixname
= prefixname
;
297 c
->allow_unknown
= allow_unknown
;
301 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
303 struct cmd_list_element
*
304 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
305 void (*fun
) (char *, int), char *doc
,
306 struct cmd_list_element
**prefixlist
, char *prefixname
,
307 int allow_unknown
, struct cmd_list_element
**list
)
309 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
310 c
->prefixlist
= prefixlist
;
311 c
->prefixname
= prefixname
;
312 c
->allow_unknown
= allow_unknown
;
317 /* This is an empty "cfunc". */
319 not_just_help_class_command (char *args
, int from_tty
)
323 /* This is an empty "sfunc". */
324 static void empty_sfunc (char *, int, struct cmd_list_element
*);
327 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
331 /* Add element named NAME to command list LIST (the list for set/show
332 or some sublist thereof).
333 TYPE is set_cmd or show_cmd.
334 CLASS is as in add_cmd.
335 VAR_TYPE is the kind of thing we are setting.
336 VAR is address of the variable being controlled by this command.
337 DOC is the documentation string. */
339 static struct cmd_list_element
*
340 add_set_or_show_cmd (char *name
,
342 enum command_class
class,
346 struct cmd_list_element
**list
)
348 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
349 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
351 c
->var_type
= var_type
;
353 /* This needs to be something besides NULL so that this isn't
354 treated as a help class. */
355 set_cmd_sfunc (c
, empty_sfunc
);
359 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
360 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
361 setting. VAR is address of the variable being controlled by this
362 command. SET_FUNC and SHOW_FUNC are the callback functions (if
363 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
364 strings. PRINT the format string to print the value. SET_RESULT
365 and SHOW_RESULT, if not NULL, are set to the resulting command
369 add_setshow_cmd_full (char *name
,
370 enum command_class
class,
371 var_types var_type
, void *var
,
372 const char *set_doc
, const char *show_doc
,
373 const char *help_doc
,
374 cmd_sfunc_ftype
*set_func
,
375 show_value_ftype
*show_func
,
376 struct cmd_list_element
**set_list
,
377 struct cmd_list_element
**show_list
,
378 struct cmd_list_element
**set_result
,
379 struct cmd_list_element
**show_result
)
381 struct cmd_list_element
*set
;
382 struct cmd_list_element
*show
;
386 if (help_doc
!= NULL
)
388 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
389 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
393 full_set_doc
= xstrdup (set_doc
);
394 full_show_doc
= xstrdup (show_doc
);
396 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
397 full_set_doc
, set_list
);
398 if (set_func
!= NULL
)
399 set_cmd_sfunc (set
, set_func
);
400 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
401 full_show_doc
, show_list
);
402 show
->show_value_func
= show_func
;
404 if (set_result
!= NULL
)
406 if (show_result
!= NULL
)
410 struct cmd_list_element
*
411 deprecated_add_set_cmd (char *name
,
412 enum command_class
class,
416 struct cmd_list_element
**list
)
418 return add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
, doc
, list
);
421 /* Add element named NAME to command list LIST (the list for set or
422 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
423 of strings which may follow NAME. VAR is address of the variable
424 which will contain the matching string (from ENUMLIST). */
427 add_setshow_enum_cmd (char *name
,
428 enum command_class
class,
429 const char *enumlist
[],
432 const char *show_doc
,
433 const char *help_doc
,
434 cmd_sfunc_ftype
*set_func
,
435 show_value_ftype
*show_func
,
436 struct cmd_list_element
**set_list
,
437 struct cmd_list_element
**show_list
)
439 struct cmd_list_element
*c
;
440 add_setshow_cmd_full (name
, class, var_enum
, var
,
441 set_doc
, show_doc
, help_doc
,
448 /* Add an auto-boolean command named NAME to both the set and show
449 command list lists. CLASS is as in add_cmd. VAR is address of the
450 variable which will contain the value. DOC is the documentation
451 string. FUNC is the corresponding callback. */
453 add_setshow_auto_boolean_cmd (char *name
,
454 enum command_class
class,
455 enum auto_boolean
*var
,
456 const char *set_doc
, const char *show_doc
,
457 const char *help_doc
,
458 cmd_sfunc_ftype
*set_func
,
459 show_value_ftype
*show_func
,
460 struct cmd_list_element
**set_list
,
461 struct cmd_list_element
**show_list
)
463 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
464 struct cmd_list_element
*c
;
465 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
466 set_doc
, show_doc
, help_doc
,
470 c
->enums
= auto_boolean_enums
;
473 /* Add element named NAME to both the set and show command LISTs (the
474 list for set/show or some sublist thereof). CLASS is as in
475 add_cmd. VAR is address of the variable which will contain the
476 value. SET_DOC and SHOW_DOC are the documentation strings. */
478 add_setshow_boolean_cmd (char *name
, enum command_class
class, int *var
,
479 const char *set_doc
, const char *show_doc
,
480 const char *help_doc
,
481 cmd_sfunc_ftype
*set_func
,
482 show_value_ftype
*show_func
,
483 struct cmd_list_element
**set_list
,
484 struct cmd_list_element
**show_list
)
486 static const char *boolean_enums
[] = { "on", "off", NULL
};
487 struct cmd_list_element
*c
;
488 add_setshow_cmd_full (name
, class, var_boolean
, var
,
489 set_doc
, show_doc
, help_doc
,
493 c
->enums
= boolean_enums
;
496 /* Add element named NAME to both the set and show command LISTs (the
497 list for set/show or some sublist thereof). */
499 add_setshow_filename_cmd (char *name
, enum command_class
class,
501 const char *set_doc
, const char *show_doc
,
502 const char *help_doc
,
503 cmd_sfunc_ftype
*set_func
,
504 show_value_ftype
*show_func
,
505 struct cmd_list_element
**set_list
,
506 struct cmd_list_element
**show_list
)
508 struct cmd_list_element
*set_result
;
509 add_setshow_cmd_full (name
, class, var_filename
, var
,
510 set_doc
, show_doc
, help_doc
,
514 set_cmd_completer (set_result
, filename_completer
);
517 /* Add element named NAME to both the set and show command LISTs (the
518 list for set/show or some sublist thereof). */
520 add_setshow_string_cmd (char *name
, enum command_class
class,
522 const char *set_doc
, const char *show_doc
,
523 const char *help_doc
,
524 cmd_sfunc_ftype
*set_func
,
525 show_value_ftype
*show_func
,
526 struct cmd_list_element
**set_list
,
527 struct cmd_list_element
**show_list
)
529 add_setshow_cmd_full (name
, class, var_string
, var
,
530 set_doc
, show_doc
, help_doc
,
536 /* Add element named NAME to both the set and show command LISTs (the
537 list for set/show or some sublist thereof). */
539 add_setshow_string_noescape_cmd (char *name
, enum command_class
class,
541 const char *set_doc
, const char *show_doc
,
542 const char *help_doc
,
543 cmd_sfunc_ftype
*set_func
,
544 show_value_ftype
*show_func
,
545 struct cmd_list_element
**set_list
,
546 struct cmd_list_element
**show_list
)
548 add_setshow_cmd_full (name
, class, var_string_noescape
, var
,
549 set_doc
, show_doc
, help_doc
,
555 /* Add element named NAME to both the set and show command LISTs (the
556 list for set/show or some sublist thereof). */
558 add_setshow_optional_filename_cmd (char *name
, enum command_class
class,
560 const char *set_doc
, const char *show_doc
,
561 const char *help_doc
,
562 cmd_sfunc_ftype
*set_func
,
563 show_value_ftype
*show_func
,
564 struct cmd_list_element
**set_list
,
565 struct cmd_list_element
**show_list
)
567 struct cmd_list_element
*set_result
;
569 add_setshow_cmd_full (name
, class, var_optional_filename
, var
,
570 set_doc
, show_doc
, help_doc
,
575 set_cmd_completer (set_result
, filename_completer
);
579 /* Add element named NAME to both the set and show command LISTs (the
580 list for set/show or some sublist thereof). CLASS is as in
581 add_cmd. VAR is address of the variable which will contain the
582 value. SET_DOC and SHOW_DOC are the documentation strings. */
584 add_setshow_integer_cmd (char *name
, enum command_class
class,
586 const char *set_doc
, const char *show_doc
,
587 const char *help_doc
,
588 cmd_sfunc_ftype
*set_func
,
589 show_value_ftype
*show_func
,
590 struct cmd_list_element
**set_list
,
591 struct cmd_list_element
**show_list
)
593 add_setshow_cmd_full (name
, class, var_integer
, var
,
594 set_doc
, show_doc
, help_doc
,
600 /* Add element named NAME to both the set and show command LISTs (the
601 list for set/show or some sublist thereof). CLASS is as in
602 add_cmd. VAR is address of the variable which will contain the
603 value. SET_DOC and SHOW_DOC are the documentation strings. */
605 add_setshow_uinteger_cmd (char *name
, enum command_class
class,
607 const char *set_doc
, const char *show_doc
,
608 const char *help_doc
,
609 cmd_sfunc_ftype
*set_func
,
610 show_value_ftype
*show_func
,
611 struct cmd_list_element
**set_list
,
612 struct cmd_list_element
**show_list
)
614 add_setshow_cmd_full (name
, class, var_uinteger
, var
,
615 set_doc
, show_doc
, help_doc
,
621 /* Add element named NAME to both the set and show command LISTs (the
622 list for set/show or some sublist thereof). CLASS is as in
623 add_cmd. VAR is address of the variable which will contain the
624 value. SET_DOC and SHOW_DOC are the documentation strings. */
626 add_setshow_zinteger_cmd (char *name
, enum command_class
class,
628 const char *set_doc
, const char *show_doc
,
629 const char *help_doc
,
630 cmd_sfunc_ftype
*set_func
,
631 show_value_ftype
*show_func
,
632 struct cmd_list_element
**set_list
,
633 struct cmd_list_element
**show_list
)
635 add_setshow_cmd_full (name
, class, var_zinteger
, var
,
636 set_doc
, show_doc
, help_doc
,
642 /* Add element named NAME to both the set and show command LISTs (the
643 list for set/show or some sublist thereof). CLASS is as in
644 add_cmd. VAR is address of the variable which will contain the
645 value. SET_DOC and SHOW_DOC are the documentation strings. */
647 add_setshow_zuinteger_cmd (char *name
, enum command_class
class,
649 const char *set_doc
, const char *show_doc
,
650 const char *help_doc
,
651 cmd_sfunc_ftype
*set_func
,
652 show_value_ftype
*show_func
,
653 struct cmd_list_element
**set_list
,
654 struct cmd_list_element
**show_list
)
656 add_setshow_cmd_full (name
, class, var_zuinteger
, var
,
657 set_doc
, show_doc
, help_doc
,
663 /* Remove the command named NAME from the command list. Return the
664 list commands which were aliased to the deleted command. If the
665 command had no aliases, return NULL. The various *HOOKs are set to
666 the pre- and post-hook commands for the deleted command. If the
667 command does not have a hook, the corresponding out parameter is
670 static struct cmd_list_element
*
671 delete_cmd (char *name
, struct cmd_list_element
**list
,
672 struct cmd_list_element
**prehook
,
673 struct cmd_list_element
**prehookee
,
674 struct cmd_list_element
**posthook
,
675 struct cmd_list_element
**posthookee
)
677 struct cmd_list_element
*iter
;
678 struct cmd_list_element
**previous_chain_ptr
;
679 struct cmd_list_element
*aliases
= NULL
;
685 previous_chain_ptr
= list
;
687 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
689 if (strcmp (iter
->name
, name
) == 0)
691 if (iter
->hookee_pre
)
692 iter
->hookee_pre
->hook_pre
= 0;
693 *prehook
= iter
->hook_pre
;
694 *prehookee
= iter
->hookee_pre
;
695 if (iter
->hookee_post
)
696 iter
->hookee_post
->hook_post
= 0;
697 *posthook
= iter
->hook_post
;
698 *posthookee
= iter
->hookee_post
;
700 /* Update the link. */
701 *previous_chain_ptr
= iter
->next
;
703 aliases
= iter
->aliases
;
705 /* If this command was an alias, remove it from the list of
707 if (iter
->cmd_pointer
)
709 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
710 struct cmd_list_element
*a
= *prevp
;
714 prevp
= &a
->alias_chain
;
717 *prevp
= iter
->alias_chain
;
722 /* We won't see another command with the same name. */
726 previous_chain_ptr
= &iter
->next
;
732 /* Shorthands to the commands above. */
734 /* Add an element to the list of info subcommands. */
736 struct cmd_list_element
*
737 add_info (char *name
, void (*fun
) (char *, int), char *doc
)
739 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
742 /* Add an alias to the list of info subcommands. */
744 struct cmd_list_element
*
745 add_info_alias (char *name
, char *oldname
, int abbrev_flag
)
747 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
750 /* Add an element to the list of commands. */
752 struct cmd_list_element
*
753 add_com (char *name
, enum command_class
class, void (*fun
) (char *, int),
756 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
759 /* Add an alias or abbreviation command to the list of commands. */
761 struct cmd_list_element
*
762 add_com_alias (char *name
, char *oldname
, enum command_class
class,
765 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
768 /* Recursively walk the commandlist structures, and print out the
769 documentation of commands that match our regex in either their
770 name, or their documentation.
773 apropos_cmd (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
774 struct re_pattern_buffer
*regex
, char *prefix
)
776 struct cmd_list_element
*c
;
777 int returnvalue
=1; /*Needed to avoid double printing*/
778 /* Walk through the commands */
779 for (c
=commandlist
;c
;c
=c
->next
)
783 /* Try to match against the name*/
784 returnvalue
=re_search(regex
,c
->name
,strlen(c
->name
),0,strlen(c
->name
),NULL
);
785 if (returnvalue
>= 0)
787 print_help_for_command (c
, prefix
,
788 0 /* don't recurse */, stream
);
791 if (c
->doc
!= NULL
&& returnvalue
!= 0)
793 /* Try to match against documentation */
794 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
796 print_help_for_command (c
, prefix
,
797 0 /* don't recurse */, stream
);
800 /* Check if this command has subcommands */
801 if (c
->prefixlist
!= NULL
)
803 /* Recursively call ourselves on the subcommand list,
804 passing the right prefix in.
806 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
811 /* This command really has to deal with two things:
812 * 1) I want documentation on *this string* (usually called by
813 * "help commandname").
814 * 2) I want documentation on *this list* (usually called by
815 * giving a command that requires subcommands. Also called by saying
818 * I am going to split this into two seperate comamnds, help_cmd and
823 help_cmd (char *command
, struct ui_file
*stream
)
825 struct cmd_list_element
*c
;
826 extern struct cmd_list_element
*cmdlist
;
830 help_list (cmdlist
, "", all_classes
, stream
);
834 if (strcmp (command
, "all") == 0)
840 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
845 /* There are three cases here.
846 If c->prefixlist is nonzero, we have a prefix command.
847 Print its documentation, then list its subcommands.
849 If c->func is non NULL, we really have a command. Print its
850 documentation and return.
852 If c->func is NULL, we have a class name. Print its
853 documentation (as if it were a command) and then set class to the
854 number of this class so that the commands in the class will be
857 fputs_filtered (c
->doc
, stream
);
858 fputs_filtered ("\n", stream
);
860 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
862 fprintf_filtered (stream
, "\n");
864 /* If this is a prefix command, print it's subcommands */
866 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
868 /* If this is a class name, print all of the commands in the class */
870 help_list (cmdlist
, "", c
->class, stream
);
872 if (c
->hook_pre
|| c
->hook_post
)
873 fprintf_filtered (stream
,
874 "\nThis command has a hook (or hooks) defined:\n");
877 fprintf_filtered (stream
,
878 "\tThis command is run after : %s (pre hook)\n",
881 fprintf_filtered (stream
,
882 "\tThis command is run before : %s (post hook)\n",
887 * Get a specific kind of help on a command list.
890 * CMDTYPE is the prefix to use in the title string.
891 * CLASS is the class with which to list the nodes of this list (see
892 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
893 * everything, ALL_CLASSES for just classes, and non-negative for only things
894 * in a specific class.
895 * and STREAM is the output stream on which to print things.
896 * If you call this routine with a class >= 0, it recurses.
899 help_list (struct cmd_list_element
*list
, char *cmdtype
,
900 enum command_class
class, struct ui_file
*stream
)
903 char *cmdtype1
, *cmdtype2
;
905 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
906 len
= strlen (cmdtype
);
907 cmdtype1
= (char *) alloca (len
+ 1);
909 cmdtype2
= (char *) alloca (len
+ 4);
914 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
916 strncpy (cmdtype2
, cmdtype
, len
- 1);
917 strcpy (cmdtype2
+ len
- 1, " sub");
920 if (class == all_classes
)
921 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
923 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
925 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
927 if (class == all_classes
)
929 fprintf_filtered (stream
, "\n\
930 Type \"help%s\" followed by a class name for a list of commands in ",
933 fprintf_filtered (stream
, "that class.");
935 fprintf_filtered (stream
, "\n\
936 Type \"help all\" for the list of all commands.");
939 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
942 fputs_filtered ("for ", stream
);
944 fputs_filtered ("full ", stream
);
946 fputs_filtered ("documentation.\n", stream
);
947 fputs_filtered ("Type \"apropos word\" to search "
948 "for commands related to \"word\".\n", stream
);
949 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
954 help_all (struct ui_file
*stream
)
956 struct cmd_list_element
*c
;
957 extern struct cmd_list_element
*cmdlist
;
958 int seen_unclassified
= 0;
960 for (c
= cmdlist
; c
; c
= c
->next
)
964 /* If this is a class name, print all of the commands in the class */
968 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
969 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
973 /* While it's expected that all commands are in some class,
974 as a safety measure, we'll print commands outside of any
977 for (c
= cmdlist
; c
; c
= c
->next
)
982 if (c
->class == no_class
)
984 if (!seen_unclassified
)
986 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
987 seen_unclassified
= 1;
989 print_help_for_command (c
, "", 1, stream
);
995 /* Print only the first line of STR on STREAM. */
997 print_doc_line (struct ui_file
*stream
, char *str
)
999 static char *line_buffer
= 0;
1000 static int line_size
;
1006 line_buffer
= (char *) xmalloc (line_size
);
1010 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
1012 if (p
- str
> line_size
- 1)
1014 line_size
= p
- str
+ 1;
1015 xfree (line_buffer
);
1016 line_buffer
= (char *) xmalloc (line_size
);
1018 strncpy (line_buffer
, str
, p
- str
);
1019 line_buffer
[p
- str
] = '\0';
1020 if (islower (line_buffer
[0]))
1021 line_buffer
[0] = toupper (line_buffer
[0]);
1022 ui_out_text (uiout
, line_buffer
);
1025 /* Print one-line help for command C.
1026 If RECURSE is non-zero, also print one-line descriptions
1027 of all prefixed subcommands. */
1029 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
1030 struct ui_file
*stream
)
1032 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1033 print_doc_line (stream
, c
->doc
);
1034 fputs_filtered ("\n", stream
);
1037 && c
->prefixlist
!= 0
1038 && c
->abbrev_flag
== 0)
1039 /* Subcommands of a prefix command typically have 'all_commands'
1040 as class. If we pass CLASS to recursive invocation,
1041 most often we won't see anything. */
1042 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1046 * Implement a help command on command list LIST.
1047 * RECURSE should be non-zero if this should be done recursively on
1048 * all sublists of LIST.
1049 * PREFIX is the prefix to print before each command name.
1050 * STREAM is the stream upon which the output should be written.
1052 * A non-negative class number to list only commands in that
1054 * ALL_COMMANDS to list all commands in list.
1055 * ALL_CLASSES to list all classes in list.
1057 * Note that RECURSE will be active on *all* sublists, not just the
1058 * ones selected by the criteria above (ie. the selection mechanism
1059 * is at the low level, not the high-level).
1062 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1063 char *prefix
, int recurse
, struct ui_file
*stream
)
1065 struct cmd_list_element
*c
;
1067 for (c
= list
; c
; c
= c
->next
)
1069 if (c
->abbrev_flag
== 0 &&
1070 (class == all_commands
1071 || (class == all_classes
&& c
->func
== NULL
)
1072 || (class == c
->class && c
->func
!= NULL
)))
1074 print_help_for_command (c
, prefix
, recurse
, stream
);
1076 else if (c
->abbrev_flag
== 0 && recurse
1077 && class == class_user
&& c
->prefixlist
!= NULL
)
1078 /* User-defined commands may be subcommands. */
1079 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, recurse
, stream
);
1084 /* Search the input clist for 'command'. Return the command if
1085 found (or NULL if not), and return the number of commands
1088 static struct cmd_list_element
*
1089 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
1090 int ignore_help_classes
, int *nfound
)
1092 struct cmd_list_element
*found
, *c
;
1094 found
= (struct cmd_list_element
*) NULL
;
1096 for (c
= clist
; c
; c
= c
->next
)
1097 if (!strncmp (command
, c
->name
, len
)
1098 && (!ignore_help_classes
|| c
->func
))
1102 if (c
->name
[len
] == '\0')
1112 find_command_name_length (const char *text
)
1114 const char *p
= text
;
1116 /* Treating underscores as part of command words is important
1117 so that "set args_foo()" doesn't get interpreted as
1118 "set args _foo()". */
1119 /* Some characters are only used for TUI specific commands. However, they
1120 are always allowed for the sake of consistency.
1121 The XDB compatibility characters are only allowed when using the right
1122 mode because they clash with other GDB commands - specifically '/' is
1123 used as a suffix for print, examine and display.
1124 Note that this is larger than the character set allowed when creating
1125 user-defined commands. */
1126 while (isalnum (*p
) || *p
== '-' || *p
== '_' ||
1127 /* Characters used by TUI specific commands. */
1128 *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$' ||
1129 /* Characters used for XDB compatibility. */
1130 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')))
1136 /* This routine takes a line of TEXT and a CLIST in which to start the
1137 lookup. When it returns it will have incremented the text pointer past
1138 the section of text it matched, set *RESULT_LIST to point to the list in
1139 which the last word was matched, and will return a pointer to the cmd
1140 list element which the text matches. It will return NULL if no match at
1141 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1142 matches are possible; in this case *RESULT_LIST will be set to point to
1143 the list in which there are ambiguous choices (and *TEXT will be set to
1144 the ambiguous text string).
1146 If the located command was an abbreviation, this routine returns the base
1147 command of the abbreviation.
1149 It does no error reporting whatsoever; control will always return
1150 to the superior routine.
1152 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1153 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1154 if no prefix command was ever found. For example, in the case of "info a",
1155 "info" matches without ambiguity, but "a" could be "args" or "address", so
1156 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1157 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1158 list; it simply points to a specific command. In the case of an ambiguous
1159 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1160 "info t" can be "info types" or "info target"; upon return *TEXT has been
1161 advanced past "info ").
1163 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1164 affect the operation).
1166 This routine does *not* modify the text pointed to by TEXT.
1168 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1169 are actually help classes rather than commands (i.e. the function field of
1170 the struct cmd_list_element is NULL). */
1172 struct cmd_list_element
*
1173 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
1174 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1177 int len
, tmp
, nfound
;
1178 struct cmd_list_element
*found
, *c
;
1181 while (**text
== ' ' || **text
== '\t')
1184 /* Identify the name of the command. */
1185 len
= find_command_name_length (*text
);
1187 /* If nothing but whitespace, return 0. */
1191 /* *text and p now bracket the first command word to lookup (and
1192 it's length is len). We copy this into a local temporary */
1195 command
= (char *) alloca (len
+ 1);
1196 memcpy (command
, *text
, len
);
1197 command
[len
] = '\0';
1202 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1205 ** We didn't find the command in the entered case, so lower case it
1206 ** and search again.
1208 if (!found
|| nfound
== 0)
1210 for (tmp
= 0; tmp
< len
; tmp
++)
1212 char x
= command
[tmp
];
1213 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1215 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1218 /* If nothing matches, we have a simple failure. */
1224 if (result_list
!= NULL
)
1225 /* Will be modified in calling routine
1226 if we know what the prefix command is. */
1228 return (struct cmd_list_element
*) -1; /* Ambiguous. */
1231 /* We've matched something on this list. Move text pointer forward. */
1235 if (found
->cmd_pointer
)
1237 /* We drop the alias (abbreviation) in favor of the command it is
1238 pointing to. If the alias is deprecated, though, we need to
1239 warn the user about it before we drop it. Note that while we
1240 are warning about the alias, we may also warn about the command
1241 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1244 if (found
->flags
& DEPRECATED_WARN_USER
)
1245 deprecated_cmd_warning (&line
);
1246 found
= found
->cmd_pointer
;
1248 /* If we found a prefix command, keep looking. */
1250 if (found
->prefixlist
)
1252 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1253 ignore_help_classes
);
1256 /* Didn't find anything; this is as far as we got. */
1257 if (result_list
!= NULL
)
1258 *result_list
= clist
;
1261 else if (c
== (struct cmd_list_element
*) -1)
1263 /* We've gotten this far properly, but the next step
1264 is ambiguous. We need to set the result list to the best
1265 we've found (if an inferior hasn't already set it). */
1266 if (result_list
!= NULL
)
1268 /* This used to say *result_list = *found->prefixlist
1269 If that was correct, need to modify the documentation
1270 at the top of this function to clarify what is supposed
1272 *result_list
= found
;
1283 if (result_list
!= NULL
)
1284 *result_list
= clist
;
1289 /* All this hair to move the space to the front of cmdtype */
1292 undef_cmd_error (char *cmdtype
, char *q
)
1294 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1297 *cmdtype
? " " : "",
1298 (int) strlen (cmdtype
) - 1,
1302 /* Look up the contents of *LINE as a command in the command list LIST.
1303 LIST is a chain of struct cmd_list_element's.
1304 If it is found, return the struct cmd_list_element for that command
1305 and update *LINE to point after the command name, at the first argument.
1306 If not found, call error if ALLOW_UNKNOWN is zero
1307 otherwise (or if error returns) return zero.
1308 Call error if specified command is ambiguous,
1309 unless ALLOW_UNKNOWN is negative.
1310 CMDTYPE precedes the word "command" in the error message.
1312 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1313 elements which are actually help classes rather than commands (i.e.
1314 the function field of the struct cmd_list_element is 0). */
1316 struct cmd_list_element
*
1317 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1318 int allow_unknown
, int ignore_help_classes
)
1320 struct cmd_list_element
*last_list
= 0;
1321 struct cmd_list_element
*c
;
1323 /* Note: Do not remove trailing whitespace here because this
1324 would be wrong for complete_command. Jim Kingdon */
1327 error (_("Lack of needed %scommand"), cmdtype
);
1329 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1336 int len
= find_command_name_length (*line
);
1338 q
= (char *) alloca (len
+ 1);
1339 strncpy (q
, *line
, len
);
1341 undef_cmd_error (cmdtype
, q
);
1346 else if (c
== (struct cmd_list_element
*) -1)
1348 /* Ambigous. Local values should be off prefixlist or called
1350 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1352 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1353 struct cmd_list_element
*local_list
=
1354 (last_list
? *(last_list
->prefixlist
) : list
);
1356 if (local_allow_unknown
< 0)
1359 return last_list
; /* Found something. */
1361 return 0; /* Found nothing. */
1365 /* Report as error. */
1370 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1371 && (*line
)[amb_len
] != '\t');
1376 for (c
= local_list
; c
; c
= c
->next
)
1377 if (!strncmp (*line
, c
->name
, amb_len
))
1379 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
1381 if (strlen (ambbuf
))
1382 strcat (ambbuf
, ", ");
1383 strcat (ambbuf
, c
->name
);
1387 strcat (ambbuf
, "..");
1391 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1393 return 0; /* lint */
1398 /* We've got something. It may still not be what the caller
1399 wants (if this command *needs* a subcommand). */
1400 while (**line
== ' ' || **line
== '\t')
1403 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1404 undef_cmd_error (c
->prefixname
, *line
);
1406 /* Seems to be what he wants. Return it. */
1412 /* We are here presumably because an alias or command in *TEXT is
1413 deprecated and a warning message should be generated. This function
1414 decodes *TEXT and potentially generates a warning message as outlined
1417 Example for 'set endian big' which has a fictitious alias 'seb'.
1419 If alias wasn't used in *TEXT, and the command is deprecated:
1420 "warning: 'set endian big' is deprecated."
1422 If alias was used, and only the alias is deprecated:
1423 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1425 If alias was used and command is deprecated (regardless of whether the
1426 alias itself is deprecated:
1428 "warning: 'set endian big' (seb) is deprecated."
1430 After the message has been sent, clear the appropriate flags in the
1431 command and/or the alias so the user is no longer bothered.
1435 deprecated_cmd_warning (char **text
)
1437 struct cmd_list_element
*alias
= NULL
;
1438 struct cmd_list_element
*prefix_cmd
= NULL
;
1439 struct cmd_list_element
*cmd
= NULL
;
1440 struct cmd_list_element
*c
;
1443 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1444 /* return if text doesn't evaluate to a command */
1447 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1448 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1449 /* return if nothing is deprecated */
1452 printf_filtered ("Warning:");
1454 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1455 printf_filtered (" '%s', an alias for the", alias
->name
);
1457 printf_filtered (" command '");
1460 printf_filtered ("%s", prefix_cmd
->prefixname
);
1462 printf_filtered ("%s", cmd
->name
);
1464 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1465 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1467 printf_filtered ("' is deprecated.\n");
1470 /* if it is only the alias that is deprecated, we want to indicate the
1471 new alias, otherwise we'll indicate the new command */
1473 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1475 if (alias
->replacement
)
1476 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1478 printf_filtered ("No alternative known.\n\n");
1482 if (cmd
->replacement
)
1483 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1485 printf_filtered ("No alternative known.\n\n");
1488 /* We've warned you, now we'll keep quiet */
1490 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1492 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1497 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1498 Return 1 on success, 0 on failure.
1500 If LINE refers to an alias, *alias will point to that alias.
1502 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1503 command) set *prefix_cmd.
1505 Set *cmd to point to the command LINE indicates.
1507 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1508 exist, they are NULL when we return.
1512 lookup_cmd_composition (char *text
,
1513 struct cmd_list_element
**alias
,
1514 struct cmd_list_element
**prefix_cmd
,
1515 struct cmd_list_element
**cmd
)
1518 int len
, tmp
, nfound
;
1519 struct cmd_list_element
*cur_list
;
1520 struct cmd_list_element
*prev_cmd
;
1529 /* Go through as many command lists as we need to
1530 to find the command TEXT refers to. */
1534 while (*text
== ' ' || *text
== '\t')
1537 /* Identify the name of the command. */
1538 len
= find_command_name_length (text
);
1540 /* If nothing but whitespace, return. */
1544 /* text is the start of the first command word to lookup (and
1545 it's length is len). We copy this into a local temporary */
1547 command
= (char *) alloca (len
+ 1);
1548 memcpy (command
, text
, len
);
1549 command
[len
] = '\0';
1554 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1556 /* We didn't find the command in the entered case, so lower case it
1559 if (!*cmd
|| nfound
== 0)
1561 for (tmp
= 0; tmp
< len
; tmp
++)
1563 char x
= command
[tmp
];
1564 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1566 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1569 if (*cmd
== (struct cmd_list_element
*) -1)
1571 return 0; /* ambiguous */
1575 return 0; /* nothing found */
1578 if ((*cmd
)->cmd_pointer
)
1580 /* cmd was actually an alias, we note that an alias was used
1581 (by assigning *alais) and we set *cmd.
1584 *cmd
= (*cmd
)->cmd_pointer
;
1586 *prefix_cmd
= prev_cmd
;
1588 if ((*cmd
)->prefixlist
)
1589 cur_list
= *(*cmd
)->prefixlist
;
1597 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1599 /* Return a vector of char pointers which point to the different
1600 possible completions in LIST of TEXT.
1602 WORD points in the same buffer as TEXT, and completions should be
1603 returned relative to this position. For example, suppose TEXT is "foo"
1604 and we want to complete to "foobar". If WORD is "oo", return
1605 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1608 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1610 struct cmd_list_element
*ptr
;
1612 int sizeof_matchlist
;
1614 int textlen
= strlen (text
);
1616 sizeof_matchlist
= 10;
1617 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1620 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1621 if (!strncmp (ptr
->name
, text
, textlen
)
1622 && !ptr
->abbrev_flag
1624 || ptr
->prefixlist
))
1626 if (matches
== sizeof_matchlist
)
1628 sizeof_matchlist
*= 2;
1629 matchlist
= (char **) xrealloc ((char *) matchlist
,
1631 * sizeof (char *)));
1634 matchlist
[matches
] = (char *)
1635 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1637 strcpy (matchlist
[matches
], ptr
->name
);
1638 else if (word
> text
)
1640 /* Return some portion of ptr->name. */
1641 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1645 /* Return some of text plus ptr->name. */
1646 strncpy (matchlist
[matches
], word
, text
- word
);
1647 matchlist
[matches
][text
- word
] = '\0';
1648 strcat (matchlist
[matches
], ptr
->name
);
1660 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1661 * sizeof (char *)));
1662 matchlist
[matches
] = (char *) 0;
1668 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1670 /* Return a vector of char pointers which point to the different
1671 possible completions in CMD of TEXT.
1673 WORD points in the same buffer as TEXT, and completions should be
1674 returned relative to this position. For example, suppose TEXT is "foo"
1675 and we want to complete to "foobar". If WORD is "oo", return
1676 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1679 complete_on_enum (const char *enumlist
[],
1684 int sizeof_matchlist
;
1686 int textlen
= strlen (text
);
1690 sizeof_matchlist
= 10;
1691 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1694 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1695 if (strncmp (name
, text
, textlen
) == 0)
1697 if (matches
== sizeof_matchlist
)
1699 sizeof_matchlist
*= 2;
1700 matchlist
= (char **) xrealloc ((char *) matchlist
,
1702 * sizeof (char *)));
1705 matchlist
[matches
] = (char *)
1706 xmalloc (strlen (word
) + strlen (name
) + 1);
1708 strcpy (matchlist
[matches
], name
);
1709 else if (word
> text
)
1711 /* Return some portion of name. */
1712 strcpy (matchlist
[matches
], name
+ (word
- text
));
1716 /* Return some of text plus name. */
1717 strncpy (matchlist
[matches
], word
, text
- word
);
1718 matchlist
[matches
][text
- word
] = '\0';
1719 strcat (matchlist
[matches
], name
);
1731 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1732 * sizeof (char *)));
1733 matchlist
[matches
] = (char *) 0;
1740 /* check function pointer */
1742 cmd_func_p (struct cmd_list_element
*cmd
)
1744 return (cmd
->func
!= NULL
);
1748 /* call the command function */
1750 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1752 if (cmd_func_p (cmd
))
1753 (*cmd
->func
) (cmd
, args
, from_tty
);
1755 error (_("Invalid command"));