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
) (struct cmd_list_element
*self
,
136 char *text
, char *word
))
138 cmd
->completer
= completer
; /* Ok. */
142 /* Add element named NAME.
143 CLASS is the top level category into which commands are broken down
145 FUN should be the function to execute the command;
146 it will get a character string as argument, with leading
147 and trailing blanks already eliminated.
149 DOC is a documentation string for the command.
150 Its first line should be a complete sentence.
151 It should start with ? for a command that is an abbreviation
152 or with * for a command that most users don't need to know about.
154 Add this command to command list *LIST.
156 Returns a pointer to the added command (not necessarily the head
159 struct cmd_list_element
*
160 add_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
161 char *doc
, struct cmd_list_element
**list
)
163 struct cmd_list_element
*c
164 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
165 struct cmd_list_element
*p
, *iter
;
167 /* Turn each alias of the old command into an alias of the new
169 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
170 &c
->hook_post
, &c
->hookee_post
);
171 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
172 iter
->cmd_pointer
= c
;
174 c
->hook_pre
->hookee_pre
= c
;
176 c
->hookee_pre
->hook_pre
= c
;
178 c
->hook_post
->hookee_post
= c
;
180 c
->hookee_post
->hook_post
= c
;
182 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
190 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
200 set_cmd_cfunc (c
, fun
);
201 set_cmd_context (c
, NULL
);
204 c
->replacement
= NULL
;
205 c
->pre_show_hook
= NULL
;
207 c
->prefixlist
= NULL
;
208 c
->prefixname
= NULL
;
209 c
->allow_unknown
= 0;
211 set_cmd_completer (c
, make_symbol_completion_list_fn
);
213 c
->type
= not_set_cmd
;
215 c
->var_type
= var_boolean
;
217 c
->user_commands
= NULL
;
218 c
->cmd_pointer
= NULL
;
219 c
->alias_chain
= NULL
;
224 /* Deprecates a command CMD.
225 REPLACEMENT is the name of the command which should be used in place
226 of this command, or NULL if no such command exists.
228 This function does not check to see if command REPLACEMENT exists
229 since gdb may not have gotten around to adding REPLACEMENT when this
232 Returns a pointer to the deprecated command. */
234 struct cmd_list_element
*
235 deprecate_cmd (struct cmd_list_element
*cmd
, char *replacement
)
237 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
239 if (replacement
!= NULL
)
240 cmd
->replacement
= replacement
;
242 cmd
->replacement
= NULL
;
247 struct cmd_list_element
*
248 add_alias_cmd (char *name
, char *oldname
, enum command_class
class,
249 int abbrev_flag
, struct cmd_list_element
**list
)
251 /* Must do this since lookup_cmd tries to side-effect its first arg */
253 struct cmd_list_element
*old
;
254 struct cmd_list_element
*c
;
255 copied_name
= (char *) alloca (strlen (oldname
) + 1);
256 strcpy (copied_name
, oldname
);
257 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
261 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
262 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
263 &prehook
, &prehookee
,
264 &posthook
, &posthookee
);
265 /* If this happens, it means a programmer error somewhere. */
266 gdb_assert (!aliases
&& !prehook
&& prehookee
267 && !posthook
&& ! posthookee
);
271 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
272 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
274 c
->function
= old
->function
;
275 c
->prefixlist
= old
->prefixlist
;
276 c
->prefixname
= old
->prefixname
;
277 c
->allow_unknown
= old
->allow_unknown
;
278 c
->abbrev_flag
= abbrev_flag
;
279 c
->cmd_pointer
= old
;
280 c
->alias_chain
= old
->aliases
;
285 /* Like add_cmd but adds an element for a command prefix:
286 a name that should be followed by a subcommand to be looked up
287 in another command list. PREFIXLIST should be the address
288 of the variable containing that list. */
290 struct cmd_list_element
*
291 add_prefix_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
292 char *doc
, struct cmd_list_element
**prefixlist
,
293 char *prefixname
, int allow_unknown
,
294 struct cmd_list_element
**list
)
296 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
297 c
->prefixlist
= prefixlist
;
298 c
->prefixname
= prefixname
;
299 c
->allow_unknown
= allow_unknown
;
303 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
305 struct cmd_list_element
*
306 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
307 void (*fun
) (char *, int), char *doc
,
308 struct cmd_list_element
**prefixlist
, char *prefixname
,
309 int allow_unknown
, struct cmd_list_element
**list
)
311 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
312 c
->prefixlist
= prefixlist
;
313 c
->prefixname
= prefixname
;
314 c
->allow_unknown
= allow_unknown
;
319 /* This is an empty "cfunc". */
321 not_just_help_class_command (char *args
, int from_tty
)
325 /* This is an empty "sfunc". */
326 static void empty_sfunc (char *, int, struct cmd_list_element
*);
329 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
333 /* Add element named NAME to command list LIST (the list for set/show
334 or some sublist thereof).
335 TYPE is set_cmd or show_cmd.
336 CLASS is as in add_cmd.
337 VAR_TYPE is the kind of thing we are setting.
338 VAR is address of the variable being controlled by this command.
339 DOC is the documentation string. */
341 static struct cmd_list_element
*
342 add_set_or_show_cmd (char *name
,
344 enum command_class
class,
348 struct cmd_list_element
**list
)
350 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
351 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
353 c
->var_type
= var_type
;
355 /* This needs to be something besides NULL so that this isn't
356 treated as a help class. */
357 set_cmd_sfunc (c
, empty_sfunc
);
361 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
362 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
363 setting. VAR is address of the variable being controlled by this
364 command. SET_FUNC and SHOW_FUNC are the callback functions (if
365 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
366 strings. PRINT the format string to print the value. SET_RESULT
367 and SHOW_RESULT, if not NULL, are set to the resulting command
371 add_setshow_cmd_full (char *name
,
372 enum command_class
class,
373 var_types var_type
, void *var
,
374 const char *set_doc
, const char *show_doc
,
375 const char *help_doc
,
376 cmd_sfunc_ftype
*set_func
,
377 show_value_ftype
*show_func
,
378 struct cmd_list_element
**set_list
,
379 struct cmd_list_element
**show_list
,
380 struct cmd_list_element
**set_result
,
381 struct cmd_list_element
**show_result
)
383 struct cmd_list_element
*set
;
384 struct cmd_list_element
*show
;
388 if (help_doc
!= NULL
)
390 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
391 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
395 full_set_doc
= xstrdup (set_doc
);
396 full_show_doc
= xstrdup (show_doc
);
398 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
399 full_set_doc
, set_list
);
400 if (set_func
!= NULL
)
401 set_cmd_sfunc (set
, set_func
);
402 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
403 full_show_doc
, show_list
);
404 show
->show_value_func
= show_func
;
406 if (set_result
!= NULL
)
408 if (show_result
!= NULL
)
412 struct cmd_list_element
*
413 deprecated_add_set_cmd (char *name
,
414 enum command_class
class,
418 struct cmd_list_element
**list
)
420 return add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
, doc
, list
);
423 /* Add element named NAME to command list LIST (the list for set or
424 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
425 of strings which may follow NAME. VAR is address of the variable
426 which will contain the matching string (from ENUMLIST). */
429 add_setshow_enum_cmd (char *name
,
430 enum command_class
class,
431 const char *enumlist
[],
434 const char *show_doc
,
435 const char *help_doc
,
436 cmd_sfunc_ftype
*set_func
,
437 show_value_ftype
*show_func
,
438 struct cmd_list_element
**set_list
,
439 struct cmd_list_element
**show_list
)
441 struct cmd_list_element
*c
;
442 add_setshow_cmd_full (name
, class, var_enum
, var
,
443 set_doc
, show_doc
, help_doc
,
450 /* Add an auto-boolean command named NAME to both the set and show
451 command list lists. CLASS is as in add_cmd. VAR is address of the
452 variable which will contain the value. DOC is the documentation
453 string. FUNC is the corresponding callback. */
455 add_setshow_auto_boolean_cmd (char *name
,
456 enum command_class
class,
457 enum auto_boolean
*var
,
458 const char *set_doc
, const char *show_doc
,
459 const char *help_doc
,
460 cmd_sfunc_ftype
*set_func
,
461 show_value_ftype
*show_func
,
462 struct cmd_list_element
**set_list
,
463 struct cmd_list_element
**show_list
)
465 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
466 struct cmd_list_element
*c
;
467 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
468 set_doc
, show_doc
, help_doc
,
472 c
->enums
= auto_boolean_enums
;
475 /* Add element named NAME to both the set and show command LISTs (the
476 list for set/show or some sublist thereof). CLASS is as in
477 add_cmd. VAR is address of the variable which will contain the
478 value. SET_DOC and SHOW_DOC are the documentation strings. */
480 add_setshow_boolean_cmd (char *name
, enum command_class
class, int *var
,
481 const char *set_doc
, const char *show_doc
,
482 const char *help_doc
,
483 cmd_sfunc_ftype
*set_func
,
484 show_value_ftype
*show_func
,
485 struct cmd_list_element
**set_list
,
486 struct cmd_list_element
**show_list
)
488 static const char *boolean_enums
[] = { "on", "off", NULL
};
489 struct cmd_list_element
*c
;
490 add_setshow_cmd_full (name
, class, var_boolean
, var
,
491 set_doc
, show_doc
, help_doc
,
495 c
->enums
= boolean_enums
;
498 /* Add element named NAME to both the set and show command LISTs (the
499 list for set/show or some sublist thereof). */
501 add_setshow_filename_cmd (char *name
, enum command_class
class,
503 const char *set_doc
, const char *show_doc
,
504 const char *help_doc
,
505 cmd_sfunc_ftype
*set_func
,
506 show_value_ftype
*show_func
,
507 struct cmd_list_element
**set_list
,
508 struct cmd_list_element
**show_list
)
510 struct cmd_list_element
*set_result
;
511 add_setshow_cmd_full (name
, class, var_filename
, var
,
512 set_doc
, show_doc
, help_doc
,
516 set_cmd_completer (set_result
, filename_completer
);
519 /* Add element named NAME to both the set and show command LISTs (the
520 list for set/show or some sublist thereof). */
522 add_setshow_string_cmd (char *name
, enum command_class
class,
524 const char *set_doc
, const char *show_doc
,
525 const char *help_doc
,
526 cmd_sfunc_ftype
*set_func
,
527 show_value_ftype
*show_func
,
528 struct cmd_list_element
**set_list
,
529 struct cmd_list_element
**show_list
)
531 add_setshow_cmd_full (name
, class, var_string
, var
,
532 set_doc
, show_doc
, help_doc
,
538 /* Add element named NAME to both the set and show command LISTs (the
539 list for set/show or some sublist thereof). */
541 add_setshow_string_noescape_cmd (char *name
, enum command_class
class,
543 const char *set_doc
, const char *show_doc
,
544 const char *help_doc
,
545 cmd_sfunc_ftype
*set_func
,
546 show_value_ftype
*show_func
,
547 struct cmd_list_element
**set_list
,
548 struct cmd_list_element
**show_list
)
550 add_setshow_cmd_full (name
, class, var_string_noescape
, var
,
551 set_doc
, show_doc
, help_doc
,
557 /* Add element named NAME to both the set and show command LISTs (the
558 list for set/show or some sublist thereof). */
560 add_setshow_optional_filename_cmd (char *name
, enum command_class
class,
562 const char *set_doc
, const char *show_doc
,
563 const char *help_doc
,
564 cmd_sfunc_ftype
*set_func
,
565 show_value_ftype
*show_func
,
566 struct cmd_list_element
**set_list
,
567 struct cmd_list_element
**show_list
)
569 struct cmd_list_element
*set_result
;
571 add_setshow_cmd_full (name
, class, var_optional_filename
, var
,
572 set_doc
, show_doc
, help_doc
,
577 set_cmd_completer (set_result
, filename_completer
);
581 /* Add element named NAME to both the set and show command LISTs (the
582 list for set/show or some sublist thereof). CLASS is as in
583 add_cmd. VAR is address of the variable which will contain the
584 value. SET_DOC and SHOW_DOC are the documentation strings. */
586 add_setshow_integer_cmd (char *name
, enum command_class
class,
588 const char *set_doc
, const char *show_doc
,
589 const char *help_doc
,
590 cmd_sfunc_ftype
*set_func
,
591 show_value_ftype
*show_func
,
592 struct cmd_list_element
**set_list
,
593 struct cmd_list_element
**show_list
)
595 add_setshow_cmd_full (name
, class, var_integer
, var
,
596 set_doc
, show_doc
, help_doc
,
602 /* Add element named NAME to both the set and show command LISTs (the
603 list for set/show or some sublist thereof). CLASS is as in
604 add_cmd. VAR is address of the variable which will contain the
605 value. SET_DOC and SHOW_DOC are the documentation strings. */
607 add_setshow_uinteger_cmd (char *name
, enum command_class
class,
609 const char *set_doc
, const char *show_doc
,
610 const char *help_doc
,
611 cmd_sfunc_ftype
*set_func
,
612 show_value_ftype
*show_func
,
613 struct cmd_list_element
**set_list
,
614 struct cmd_list_element
**show_list
)
616 add_setshow_cmd_full (name
, class, var_uinteger
, var
,
617 set_doc
, show_doc
, help_doc
,
623 /* Add element named NAME to both the set and show command LISTs (the
624 list for set/show or some sublist thereof). CLASS is as in
625 add_cmd. VAR is address of the variable which will contain the
626 value. SET_DOC and SHOW_DOC are the documentation strings. */
628 add_setshow_zinteger_cmd (char *name
, enum command_class
class,
630 const char *set_doc
, const char *show_doc
,
631 const char *help_doc
,
632 cmd_sfunc_ftype
*set_func
,
633 show_value_ftype
*show_func
,
634 struct cmd_list_element
**set_list
,
635 struct cmd_list_element
**show_list
)
637 add_setshow_cmd_full (name
, class, var_zinteger
, var
,
638 set_doc
, show_doc
, help_doc
,
644 /* Add element named NAME to both the set and show command LISTs (the
645 list for set/show or some sublist thereof). CLASS is as in
646 add_cmd. VAR is address of the variable which will contain the
647 value. SET_DOC and SHOW_DOC are the documentation strings. */
649 add_setshow_zuinteger_cmd (char *name
, enum command_class
class,
651 const char *set_doc
, const char *show_doc
,
652 const char *help_doc
,
653 cmd_sfunc_ftype
*set_func
,
654 show_value_ftype
*show_func
,
655 struct cmd_list_element
**set_list
,
656 struct cmd_list_element
**show_list
)
658 add_setshow_cmd_full (name
, class, var_zuinteger
, var
,
659 set_doc
, show_doc
, help_doc
,
665 /* Remove the command named NAME from the command list. Return the
666 list commands which were aliased to the deleted command. If the
667 command had no aliases, return NULL. The various *HOOKs are set to
668 the pre- and post-hook commands for the deleted command. If the
669 command does not have a hook, the corresponding out parameter is
672 static struct cmd_list_element
*
673 delete_cmd (char *name
, struct cmd_list_element
**list
,
674 struct cmd_list_element
**prehook
,
675 struct cmd_list_element
**prehookee
,
676 struct cmd_list_element
**posthook
,
677 struct cmd_list_element
**posthookee
)
679 struct cmd_list_element
*iter
;
680 struct cmd_list_element
**previous_chain_ptr
;
681 struct cmd_list_element
*aliases
= NULL
;
687 previous_chain_ptr
= list
;
689 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
691 if (strcmp (iter
->name
, name
) == 0)
694 iter
->destroyer (iter
, iter
->context
);
695 if (iter
->hookee_pre
)
696 iter
->hookee_pre
->hook_pre
= 0;
697 *prehook
= iter
->hook_pre
;
698 *prehookee
= iter
->hookee_pre
;
699 if (iter
->hookee_post
)
700 iter
->hookee_post
->hook_post
= 0;
701 *posthook
= iter
->hook_post
;
702 *posthookee
= iter
->hookee_post
;
704 /* Update the link. */
705 *previous_chain_ptr
= iter
->next
;
707 aliases
= iter
->aliases
;
709 /* If this command was an alias, remove it from the list of
711 if (iter
->cmd_pointer
)
713 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
714 struct cmd_list_element
*a
= *prevp
;
718 prevp
= &a
->alias_chain
;
721 *prevp
= iter
->alias_chain
;
726 /* We won't see another command with the same name. */
730 previous_chain_ptr
= &iter
->next
;
736 /* Shorthands to the commands above. */
738 /* Add an element to the list of info subcommands. */
740 struct cmd_list_element
*
741 add_info (char *name
, void (*fun
) (char *, int), char *doc
)
743 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
746 /* Add an alias to the list of info subcommands. */
748 struct cmd_list_element
*
749 add_info_alias (char *name
, char *oldname
, int abbrev_flag
)
751 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
754 /* Add an element to the list of commands. */
756 struct cmd_list_element
*
757 add_com (char *name
, enum command_class
class, void (*fun
) (char *, int),
760 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
763 /* Add an alias or abbreviation command to the list of commands. */
765 struct cmd_list_element
*
766 add_com_alias (char *name
, char *oldname
, enum command_class
class,
769 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
772 /* Recursively walk the commandlist structures, and print out the
773 documentation of commands that match our regex in either their
774 name, or their documentation.
777 apropos_cmd (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
778 struct re_pattern_buffer
*regex
, char *prefix
)
780 struct cmd_list_element
*c
;
781 int returnvalue
=1; /*Needed to avoid double printing*/
782 /* Walk through the commands */
783 for (c
=commandlist
;c
;c
=c
->next
)
787 /* Try to match against the name*/
788 returnvalue
=re_search(regex
,c
->name
,strlen(c
->name
),0,strlen(c
->name
),NULL
);
789 if (returnvalue
>= 0)
791 print_help_for_command (c
, prefix
,
792 0 /* don't recurse */, stream
);
795 if (c
->doc
!= NULL
&& returnvalue
!= 0)
797 /* Try to match against documentation */
798 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
800 print_help_for_command (c
, prefix
,
801 0 /* don't recurse */, stream
);
804 /* Check if this command has subcommands */
805 if (c
->prefixlist
!= NULL
)
807 /* Recursively call ourselves on the subcommand list,
808 passing the right prefix in.
810 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
815 /* This command really has to deal with two things:
816 * 1) I want documentation on *this string* (usually called by
817 * "help commandname").
818 * 2) I want documentation on *this list* (usually called by
819 * giving a command that requires subcommands. Also called by saying
822 * I am going to split this into two seperate comamnds, help_cmd and
827 help_cmd (char *command
, struct ui_file
*stream
)
829 struct cmd_list_element
*c
;
830 extern struct cmd_list_element
*cmdlist
;
834 help_list (cmdlist
, "", all_classes
, stream
);
838 if (strcmp (command
, "all") == 0)
844 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
849 /* There are three cases here.
850 If c->prefixlist is nonzero, we have a prefix command.
851 Print its documentation, then list its subcommands.
853 If c->func is non NULL, we really have a command. Print its
854 documentation and return.
856 If c->func is NULL, we have a class name. Print its
857 documentation (as if it were a command) and then set class to the
858 number of this class so that the commands in the class will be
861 fputs_filtered (c
->doc
, stream
);
862 fputs_filtered ("\n", stream
);
864 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
866 fprintf_filtered (stream
, "\n");
868 /* If this is a prefix command, print it's subcommands */
870 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
872 /* If this is a class name, print all of the commands in the class */
874 help_list (cmdlist
, "", c
->class, stream
);
876 if (c
->hook_pre
|| c
->hook_post
)
877 fprintf_filtered (stream
,
878 "\nThis command has a hook (or hooks) defined:\n");
881 fprintf_filtered (stream
,
882 "\tThis command is run after : %s (pre hook)\n",
885 fprintf_filtered (stream
,
886 "\tThis command is run before : %s (post hook)\n",
891 * Get a specific kind of help on a command list.
894 * CMDTYPE is the prefix to use in the title string.
895 * CLASS is the class with which to list the nodes of this list (see
896 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
897 * everything, ALL_CLASSES for just classes, and non-negative for only things
898 * in a specific class.
899 * and STREAM is the output stream on which to print things.
900 * If you call this routine with a class >= 0, it recurses.
903 help_list (struct cmd_list_element
*list
, char *cmdtype
,
904 enum command_class
class, struct ui_file
*stream
)
907 char *cmdtype1
, *cmdtype2
;
909 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
910 len
= strlen (cmdtype
);
911 cmdtype1
= (char *) alloca (len
+ 1);
913 cmdtype2
= (char *) alloca (len
+ 4);
918 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
920 strncpy (cmdtype2
, cmdtype
, len
- 1);
921 strcpy (cmdtype2
+ len
- 1, " sub");
924 if (class == all_classes
)
925 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
927 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
929 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
931 if (class == all_classes
)
933 fprintf_filtered (stream
, "\n\
934 Type \"help%s\" followed by a class name for a list of commands in ",
937 fprintf_filtered (stream
, "that class.");
939 fprintf_filtered (stream
, "\n\
940 Type \"help all\" for the list of all commands.");
943 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
946 fputs_filtered ("for ", stream
);
948 fputs_filtered ("full ", stream
);
950 fputs_filtered ("documentation.\n", stream
);
951 fputs_filtered ("Type \"apropos word\" to search "
952 "for commands related to \"word\".\n", stream
);
953 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
958 help_all (struct ui_file
*stream
)
960 struct cmd_list_element
*c
;
961 extern struct cmd_list_element
*cmdlist
;
962 int seen_unclassified
= 0;
964 for (c
= cmdlist
; c
; c
= c
->next
)
968 /* If this is a class name, print all of the commands in the class */
972 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
973 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
977 /* While it's expected that all commands are in some class,
978 as a safety measure, we'll print commands outside of any
981 for (c
= cmdlist
; c
; c
= c
->next
)
986 if (c
->class == no_class
)
988 if (!seen_unclassified
)
990 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
991 seen_unclassified
= 1;
993 print_help_for_command (c
, "", 1, stream
);
999 /* Print only the first line of STR on STREAM. */
1001 print_doc_line (struct ui_file
*stream
, char *str
)
1003 static char *line_buffer
= 0;
1004 static int line_size
;
1010 line_buffer
= (char *) xmalloc (line_size
);
1014 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
1016 if (p
- str
> line_size
- 1)
1018 line_size
= p
- str
+ 1;
1019 xfree (line_buffer
);
1020 line_buffer
= (char *) xmalloc (line_size
);
1022 strncpy (line_buffer
, str
, p
- str
);
1023 line_buffer
[p
- str
] = '\0';
1024 if (islower (line_buffer
[0]))
1025 line_buffer
[0] = toupper (line_buffer
[0]);
1026 ui_out_text (uiout
, line_buffer
);
1029 /* Print one-line help for command C.
1030 If RECURSE is non-zero, also print one-line descriptions
1031 of all prefixed subcommands. */
1033 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
1034 struct ui_file
*stream
)
1036 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1037 print_doc_line (stream
, c
->doc
);
1038 fputs_filtered ("\n", stream
);
1041 && c
->prefixlist
!= 0
1042 && c
->abbrev_flag
== 0)
1043 /* Subcommands of a prefix command typically have 'all_commands'
1044 as class. If we pass CLASS to recursive invocation,
1045 most often we won't see anything. */
1046 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1050 * Implement a help command on command list LIST.
1051 * RECURSE should be non-zero if this should be done recursively on
1052 * all sublists of LIST.
1053 * PREFIX is the prefix to print before each command name.
1054 * STREAM is the stream upon which the output should be written.
1056 * A non-negative class number to list only commands in that
1058 * ALL_COMMANDS to list all commands in list.
1059 * ALL_CLASSES to list all classes in list.
1061 * Note that RECURSE will be active on *all* sublists, not just the
1062 * ones selected by the criteria above (ie. the selection mechanism
1063 * is at the low level, not the high-level).
1066 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1067 char *prefix
, int recurse
, struct ui_file
*stream
)
1069 struct cmd_list_element
*c
;
1071 for (c
= list
; c
; c
= c
->next
)
1073 if (c
->abbrev_flag
== 0 &&
1074 (class == all_commands
1075 || (class == all_classes
&& c
->func
== NULL
)
1076 || (class == c
->class && c
->func
!= NULL
)))
1078 print_help_for_command (c
, prefix
, recurse
, stream
);
1080 else if (c
->abbrev_flag
== 0 && recurse
1081 && class == class_user
&& c
->prefixlist
!= NULL
)
1082 /* User-defined commands may be subcommands. */
1083 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, recurse
, stream
);
1088 /* Search the input clist for 'command'. Return the command if
1089 found (or NULL if not), and return the number of commands
1092 static struct cmd_list_element
*
1093 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
1094 int ignore_help_classes
, int *nfound
)
1096 struct cmd_list_element
*found
, *c
;
1098 found
= (struct cmd_list_element
*) NULL
;
1100 for (c
= clist
; c
; c
= c
->next
)
1101 if (!strncmp (command
, c
->name
, len
)
1102 && (!ignore_help_classes
|| c
->func
))
1106 if (c
->name
[len
] == '\0')
1116 find_command_name_length (const char *text
)
1118 const char *p
= text
;
1120 /* Treating underscores as part of command words is important
1121 so that "set args_foo()" doesn't get interpreted as
1122 "set args _foo()". */
1123 /* Some characters are only used for TUI specific commands. However, they
1124 are always allowed for the sake of consistency.
1125 The XDB compatibility characters are only allowed when using the right
1126 mode because they clash with other GDB commands - specifically '/' is
1127 used as a suffix for print, examine and display.
1128 Note that this is larger than the character set allowed when creating
1129 user-defined commands. */
1130 while (isalnum (*p
) || *p
== '-' || *p
== '_' ||
1131 /* Characters used by TUI specific commands. */
1132 *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$' ||
1133 /* Characters used for XDB compatibility. */
1134 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')))
1140 /* This routine takes a line of TEXT and a CLIST in which to start the
1141 lookup. When it returns it will have incremented the text pointer past
1142 the section of text it matched, set *RESULT_LIST to point to the list in
1143 which the last word was matched, and will return a pointer to the cmd
1144 list element which the text matches. It will return NULL if no match at
1145 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1146 matches are possible; in this case *RESULT_LIST will be set to point to
1147 the list in which there are ambiguous choices (and *TEXT will be set to
1148 the ambiguous text string).
1150 If the located command was an abbreviation, this routine returns the base
1151 command of the abbreviation.
1153 It does no error reporting whatsoever; control will always return
1154 to the superior routine.
1156 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1157 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1158 if no prefix command was ever found. For example, in the case of "info a",
1159 "info" matches without ambiguity, but "a" could be "args" or "address", so
1160 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1161 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1162 list; it simply points to a specific command. In the case of an ambiguous
1163 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1164 "info t" can be "info types" or "info target"; upon return *TEXT has been
1165 advanced past "info ").
1167 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1168 affect the operation).
1170 This routine does *not* modify the text pointed to by TEXT.
1172 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1173 are actually help classes rather than commands (i.e. the function field of
1174 the struct cmd_list_element is NULL). */
1176 struct cmd_list_element
*
1177 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
1178 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1181 int len
, tmp
, nfound
;
1182 struct cmd_list_element
*found
, *c
;
1185 while (**text
== ' ' || **text
== '\t')
1188 /* Identify the name of the command. */
1189 len
= find_command_name_length (*text
);
1191 /* If nothing but whitespace, return 0. */
1195 /* *text and p now bracket the first command word to lookup (and
1196 it's length is len). We copy this into a local temporary */
1199 command
= (char *) alloca (len
+ 1);
1200 memcpy (command
, *text
, len
);
1201 command
[len
] = '\0';
1206 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1209 ** We didn't find the command in the entered case, so lower case it
1210 ** and search again.
1212 if (!found
|| nfound
== 0)
1214 for (tmp
= 0; tmp
< len
; tmp
++)
1216 char x
= command
[tmp
];
1217 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1219 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1222 /* If nothing matches, we have a simple failure. */
1228 if (result_list
!= NULL
)
1229 /* Will be modified in calling routine
1230 if we know what the prefix command is. */
1232 return (struct cmd_list_element
*) -1; /* Ambiguous. */
1235 /* We've matched something on this list. Move text pointer forward. */
1239 if (found
->cmd_pointer
)
1241 /* We drop the alias (abbreviation) in favor of the command it is
1242 pointing to. If the alias is deprecated, though, we need to
1243 warn the user about it before we drop it. Note that while we
1244 are warning about the alias, we may also warn about the command
1245 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1248 if (found
->flags
& DEPRECATED_WARN_USER
)
1249 deprecated_cmd_warning (&line
);
1250 found
= found
->cmd_pointer
;
1252 /* If we found a prefix command, keep looking. */
1254 if (found
->prefixlist
)
1256 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1257 ignore_help_classes
);
1260 /* Didn't find anything; this is as far as we got. */
1261 if (result_list
!= NULL
)
1262 *result_list
= clist
;
1265 else if (c
== (struct cmd_list_element
*) -1)
1267 /* We've gotten this far properly, but the next step
1268 is ambiguous. We need to set the result list to the best
1269 we've found (if an inferior hasn't already set it). */
1270 if (result_list
!= NULL
)
1272 /* This used to say *result_list = *found->prefixlist
1273 If that was correct, need to modify the documentation
1274 at the top of this function to clarify what is supposed
1276 *result_list
= found
;
1287 if (result_list
!= NULL
)
1288 *result_list
= clist
;
1293 /* All this hair to move the space to the front of cmdtype */
1296 undef_cmd_error (char *cmdtype
, char *q
)
1298 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1301 *cmdtype
? " " : "",
1302 (int) strlen (cmdtype
) - 1,
1306 /* Look up the contents of *LINE as a command in the command list LIST.
1307 LIST is a chain of struct cmd_list_element's.
1308 If it is found, return the struct cmd_list_element for that command
1309 and update *LINE to point after the command name, at the first argument.
1310 If not found, call error if ALLOW_UNKNOWN is zero
1311 otherwise (or if error returns) return zero.
1312 Call error if specified command is ambiguous,
1313 unless ALLOW_UNKNOWN is negative.
1314 CMDTYPE precedes the word "command" in the error message.
1316 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1317 elements which are actually help classes rather than commands (i.e.
1318 the function field of the struct cmd_list_element is 0). */
1320 struct cmd_list_element
*
1321 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1322 int allow_unknown
, int ignore_help_classes
)
1324 struct cmd_list_element
*last_list
= 0;
1325 struct cmd_list_element
*c
;
1327 /* Note: Do not remove trailing whitespace here because this
1328 would be wrong for complete_command. Jim Kingdon */
1331 error (_("Lack of needed %scommand"), cmdtype
);
1333 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1340 int len
= find_command_name_length (*line
);
1342 q
= (char *) alloca (len
+ 1);
1343 strncpy (q
, *line
, len
);
1345 undef_cmd_error (cmdtype
, q
);
1350 else if (c
== (struct cmd_list_element
*) -1)
1352 /* Ambigous. Local values should be off prefixlist or called
1354 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1356 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1357 struct cmd_list_element
*local_list
=
1358 (last_list
? *(last_list
->prefixlist
) : list
);
1360 if (local_allow_unknown
< 0)
1363 return last_list
; /* Found something. */
1365 return 0; /* Found nothing. */
1369 /* Report as error. */
1374 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1375 && (*line
)[amb_len
] != '\t');
1380 for (c
= local_list
; c
; c
= c
->next
)
1381 if (!strncmp (*line
, c
->name
, amb_len
))
1383 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
1385 if (strlen (ambbuf
))
1386 strcat (ambbuf
, ", ");
1387 strcat (ambbuf
, c
->name
);
1391 strcat (ambbuf
, "..");
1395 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1397 return 0; /* lint */
1402 /* We've got something. It may still not be what the caller
1403 wants (if this command *needs* a subcommand). */
1404 while (**line
== ' ' || **line
== '\t')
1407 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1408 undef_cmd_error (c
->prefixname
, *line
);
1410 /* Seems to be what he wants. Return it. */
1416 /* We are here presumably because an alias or command in *TEXT is
1417 deprecated and a warning message should be generated. This function
1418 decodes *TEXT and potentially generates a warning message as outlined
1421 Example for 'set endian big' which has a fictitious alias 'seb'.
1423 If alias wasn't used in *TEXT, and the command is deprecated:
1424 "warning: 'set endian big' is deprecated."
1426 If alias was used, and only the alias is deprecated:
1427 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1429 If alias was used and command is deprecated (regardless of whether the
1430 alias itself is deprecated:
1432 "warning: 'set endian big' (seb) is deprecated."
1434 After the message has been sent, clear the appropriate flags in the
1435 command and/or the alias so the user is no longer bothered.
1439 deprecated_cmd_warning (char **text
)
1441 struct cmd_list_element
*alias
= NULL
;
1442 struct cmd_list_element
*prefix_cmd
= NULL
;
1443 struct cmd_list_element
*cmd
= NULL
;
1444 struct cmd_list_element
*c
;
1447 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1448 /* return if text doesn't evaluate to a command */
1451 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1452 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1453 /* return if nothing is deprecated */
1456 printf_filtered ("Warning:");
1458 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1459 printf_filtered (" '%s', an alias for the", alias
->name
);
1461 printf_filtered (" command '");
1464 printf_filtered ("%s", prefix_cmd
->prefixname
);
1466 printf_filtered ("%s", cmd
->name
);
1468 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1469 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1471 printf_filtered ("' is deprecated.\n");
1474 /* if it is only the alias that is deprecated, we want to indicate the
1475 new alias, otherwise we'll indicate the new command */
1477 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1479 if (alias
->replacement
)
1480 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1482 printf_filtered ("No alternative known.\n\n");
1486 if (cmd
->replacement
)
1487 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1489 printf_filtered ("No alternative known.\n\n");
1492 /* We've warned you, now we'll keep quiet */
1494 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1496 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1501 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1502 Return 1 on success, 0 on failure.
1504 If LINE refers to an alias, *alias will point to that alias.
1506 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1507 command) set *prefix_cmd.
1509 Set *cmd to point to the command LINE indicates.
1511 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1512 exist, they are NULL when we return.
1516 lookup_cmd_composition (char *text
,
1517 struct cmd_list_element
**alias
,
1518 struct cmd_list_element
**prefix_cmd
,
1519 struct cmd_list_element
**cmd
)
1522 int len
, tmp
, nfound
;
1523 struct cmd_list_element
*cur_list
;
1524 struct cmd_list_element
*prev_cmd
;
1533 /* Go through as many command lists as we need to
1534 to find the command TEXT refers to. */
1538 while (*text
== ' ' || *text
== '\t')
1541 /* Identify the name of the command. */
1542 len
= find_command_name_length (text
);
1544 /* If nothing but whitespace, return. */
1548 /* text is the start of the first command word to lookup (and
1549 it's length is len). We copy this into a local temporary */
1551 command
= (char *) alloca (len
+ 1);
1552 memcpy (command
, text
, len
);
1553 command
[len
] = '\0';
1558 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1560 /* We didn't find the command in the entered case, so lower case it
1563 if (!*cmd
|| nfound
== 0)
1565 for (tmp
= 0; tmp
< len
; tmp
++)
1567 char x
= command
[tmp
];
1568 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1570 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1573 if (*cmd
== (struct cmd_list_element
*) -1)
1575 return 0; /* ambiguous */
1579 return 0; /* nothing found */
1582 if ((*cmd
)->cmd_pointer
)
1584 /* cmd was actually an alias, we note that an alias was used
1585 (by assigning *alais) and we set *cmd.
1588 *cmd
= (*cmd
)->cmd_pointer
;
1590 *prefix_cmd
= prev_cmd
;
1592 if ((*cmd
)->prefixlist
)
1593 cur_list
= *(*cmd
)->prefixlist
;
1601 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1603 /* Return a vector of char pointers which point to the different
1604 possible completions in LIST of TEXT.
1606 WORD points in the same buffer as TEXT, and completions should be
1607 returned relative to this position. For example, suppose TEXT is "foo"
1608 and we want to complete to "foobar". If WORD is "oo", return
1609 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1612 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1614 struct cmd_list_element
*ptr
;
1616 int sizeof_matchlist
;
1618 int textlen
= strlen (text
);
1620 sizeof_matchlist
= 10;
1621 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1624 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1625 if (!strncmp (ptr
->name
, text
, textlen
)
1626 && !ptr
->abbrev_flag
1628 || ptr
->prefixlist
))
1630 if (matches
== sizeof_matchlist
)
1632 sizeof_matchlist
*= 2;
1633 matchlist
= (char **) xrealloc ((char *) matchlist
,
1635 * sizeof (char *)));
1638 matchlist
[matches
] = (char *)
1639 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1641 strcpy (matchlist
[matches
], ptr
->name
);
1642 else if (word
> text
)
1644 /* Return some portion of ptr->name. */
1645 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1649 /* Return some of text plus ptr->name. */
1650 strncpy (matchlist
[matches
], word
, text
- word
);
1651 matchlist
[matches
][text
- word
] = '\0';
1652 strcat (matchlist
[matches
], ptr
->name
);
1664 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1665 * sizeof (char *)));
1666 matchlist
[matches
] = (char *) 0;
1672 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1674 /* Return a vector of char pointers which point to the different
1675 possible completions in CMD of TEXT.
1677 WORD points in the same buffer as TEXT, and completions should be
1678 returned relative to this position. For example, suppose TEXT is "foo"
1679 and we want to complete to "foobar". If WORD is "oo", return
1680 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1683 complete_on_enum (const char *enumlist
[],
1688 int sizeof_matchlist
;
1690 int textlen
= strlen (text
);
1694 sizeof_matchlist
= 10;
1695 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1698 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1699 if (strncmp (name
, text
, textlen
) == 0)
1701 if (matches
== sizeof_matchlist
)
1703 sizeof_matchlist
*= 2;
1704 matchlist
= (char **) xrealloc ((char *) matchlist
,
1706 * sizeof (char *)));
1709 matchlist
[matches
] = (char *)
1710 xmalloc (strlen (word
) + strlen (name
) + 1);
1712 strcpy (matchlist
[matches
], name
);
1713 else if (word
> text
)
1715 /* Return some portion of name. */
1716 strcpy (matchlist
[matches
], name
+ (word
- text
));
1720 /* Return some of text plus name. */
1721 strncpy (matchlist
[matches
], word
, text
- word
);
1722 matchlist
[matches
][text
- word
] = '\0';
1723 strcat (matchlist
[matches
], name
);
1735 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1736 * sizeof (char *)));
1737 matchlist
[matches
] = (char *) 0;
1744 /* check function pointer */
1746 cmd_func_p (struct cmd_list_element
*cmd
)
1748 return (cmd
->func
!= NULL
);
1752 /* call the command function */
1754 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1756 if (cmd_func_p (cmd
))
1757 (*cmd
->func
) (cmd
, args
, from_tty
);
1759 error (_("Invalid command"));