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 cmd_type (struct cmd_list_element
*cmd
)
122 set_cmd_completer (struct cmd_list_element
*cmd
,
123 char **(*completer
) (struct cmd_list_element
*self
,
124 char *text
, char *word
))
126 cmd
->completer
= completer
; /* Ok. */
130 /* Add element named NAME.
131 CLASS is the top level category into which commands are broken down
133 FUN should be the function to execute the command;
134 it will get a character string as argument, with leading
135 and trailing blanks already eliminated.
137 DOC is a documentation string for the command.
138 Its first line should be a complete sentence.
139 It should start with ? for a command that is an abbreviation
140 or with * for a command that most users don't need to know about.
142 Add this command to command list *LIST.
144 Returns a pointer to the added command (not necessarily the head
147 struct cmd_list_element
*
148 add_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
149 char *doc
, struct cmd_list_element
**list
)
151 struct cmd_list_element
*c
152 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
153 struct cmd_list_element
*p
, *iter
;
155 /* Turn each alias of the old command into an alias of the new
157 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
158 &c
->hook_post
, &c
->hookee_post
);
159 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
160 iter
->cmd_pointer
= c
;
162 c
->hook_pre
->hookee_pre
= c
;
164 c
->hookee_pre
->hook_pre
= c
;
166 c
->hook_post
->hookee_post
= c
;
168 c
->hookee_post
->hook_post
= c
;
170 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
178 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
188 set_cmd_cfunc (c
, fun
);
189 set_cmd_context (c
, NULL
);
192 c
->replacement
= NULL
;
193 c
->pre_show_hook
= NULL
;
195 c
->prefixlist
= NULL
;
196 c
->prefixname
= NULL
;
197 c
->allow_unknown
= 0;
199 set_cmd_completer (c
, make_symbol_completion_list_fn
);
201 c
->type
= not_set_cmd
;
203 c
->var_type
= var_boolean
;
205 c
->user_commands
= NULL
;
206 c
->cmd_pointer
= NULL
;
207 c
->alias_chain
= NULL
;
212 /* Deprecates a command CMD.
213 REPLACEMENT is the name of the command which should be used in place
214 of this command, or NULL if no such command exists.
216 This function does not check to see if command REPLACEMENT exists
217 since gdb may not have gotten around to adding REPLACEMENT when this
220 Returns a pointer to the deprecated command. */
222 struct cmd_list_element
*
223 deprecate_cmd (struct cmd_list_element
*cmd
, char *replacement
)
225 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
227 if (replacement
!= NULL
)
228 cmd
->replacement
= replacement
;
230 cmd
->replacement
= NULL
;
235 struct cmd_list_element
*
236 add_alias_cmd (char *name
, char *oldname
, enum command_class
class,
237 int abbrev_flag
, struct cmd_list_element
**list
)
239 /* Must do this since lookup_cmd tries to side-effect its first arg */
241 struct cmd_list_element
*old
;
242 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
);
253 /* If this happens, it means a programmer error somewhere. */
254 gdb_assert (!aliases
&& !prehook
&& prehookee
255 && !posthook
&& ! posthookee
);
259 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
260 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
262 c
->function
= old
->function
;
263 c
->prefixlist
= old
->prefixlist
;
264 c
->prefixname
= old
->prefixname
;
265 c
->allow_unknown
= old
->allow_unknown
;
266 c
->abbrev_flag
= abbrev_flag
;
267 c
->cmd_pointer
= old
;
268 c
->alias_chain
= old
->aliases
;
273 /* Like add_cmd but adds an element for a command prefix:
274 a name that should be followed by a subcommand to be looked up
275 in another command list. PREFIXLIST should be the address
276 of the variable containing that list. */
278 struct cmd_list_element
*
279 add_prefix_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
280 char *doc
, struct cmd_list_element
**prefixlist
,
281 char *prefixname
, int allow_unknown
,
282 struct cmd_list_element
**list
)
284 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
285 c
->prefixlist
= prefixlist
;
286 c
->prefixname
= prefixname
;
287 c
->allow_unknown
= allow_unknown
;
291 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
293 struct cmd_list_element
*
294 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
295 void (*fun
) (char *, int), char *doc
,
296 struct cmd_list_element
**prefixlist
, char *prefixname
,
297 int allow_unknown
, struct cmd_list_element
**list
)
299 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
300 c
->prefixlist
= prefixlist
;
301 c
->prefixname
= prefixname
;
302 c
->allow_unknown
= allow_unknown
;
307 /* This is an empty "cfunc". */
309 not_just_help_class_command (char *args
, int from_tty
)
313 /* This is an empty "sfunc". */
314 static void empty_sfunc (char *, int, struct cmd_list_element
*);
317 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
321 /* Add element named NAME to command list LIST (the list for set/show
322 or some sublist thereof).
323 TYPE is set_cmd or show_cmd.
324 CLASS is as in add_cmd.
325 VAR_TYPE is the kind of thing we are setting.
326 VAR is address of the variable being controlled by this command.
327 DOC is the documentation string. */
329 static struct cmd_list_element
*
330 add_set_or_show_cmd (char *name
,
332 enum command_class
class,
336 struct cmd_list_element
**list
)
338 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
339 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
341 c
->var_type
= var_type
;
343 /* This needs to be something besides NULL so that this isn't
344 treated as a help class. */
345 set_cmd_sfunc (c
, empty_sfunc
);
349 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
350 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
351 setting. VAR is address of the variable being controlled by this
352 command. SET_FUNC and SHOW_FUNC are the callback functions (if
353 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
354 strings. PRINT the format string to print the value. SET_RESULT
355 and SHOW_RESULT, if not NULL, are set to the resulting command
359 add_setshow_cmd_full (char *name
,
360 enum command_class
class,
361 var_types var_type
, void *var
,
362 const char *set_doc
, const char *show_doc
,
363 const char *help_doc
,
364 cmd_sfunc_ftype
*set_func
,
365 show_value_ftype
*show_func
,
366 struct cmd_list_element
**set_list
,
367 struct cmd_list_element
**show_list
,
368 struct cmd_list_element
**set_result
,
369 struct cmd_list_element
**show_result
)
371 struct cmd_list_element
*set
;
372 struct cmd_list_element
*show
;
376 if (help_doc
!= NULL
)
378 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
379 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
383 full_set_doc
= xstrdup (set_doc
);
384 full_show_doc
= xstrdup (show_doc
);
386 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
387 full_set_doc
, set_list
);
388 if (set_func
!= NULL
)
389 set_cmd_sfunc (set
, set_func
);
390 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
391 full_show_doc
, show_list
);
392 show
->show_value_func
= show_func
;
394 if (set_result
!= NULL
)
396 if (show_result
!= NULL
)
400 struct cmd_list_element
*
401 deprecated_add_set_cmd (char *name
,
402 enum command_class
class,
406 struct cmd_list_element
**list
)
408 return add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
, doc
, list
);
411 /* Add element named NAME to command list LIST (the list for set or
412 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
413 of strings which may follow NAME. VAR is address of the variable
414 which will contain the matching string (from ENUMLIST). */
417 add_setshow_enum_cmd (char *name
,
418 enum command_class
class,
419 const char *enumlist
[],
422 const char *show_doc
,
423 const char *help_doc
,
424 cmd_sfunc_ftype
*set_func
,
425 show_value_ftype
*show_func
,
426 struct cmd_list_element
**set_list
,
427 struct cmd_list_element
**show_list
)
429 struct cmd_list_element
*c
;
430 add_setshow_cmd_full (name
, class, var_enum
, var
,
431 set_doc
, show_doc
, help_doc
,
438 /* Add an auto-boolean command named NAME to both the set and show
439 command list lists. CLASS is as in add_cmd. VAR is address of the
440 variable which will contain the value. DOC is the documentation
441 string. FUNC is the corresponding callback. */
443 add_setshow_auto_boolean_cmd (char *name
,
444 enum command_class
class,
445 enum auto_boolean
*var
,
446 const char *set_doc
, const char *show_doc
,
447 const char *help_doc
,
448 cmd_sfunc_ftype
*set_func
,
449 show_value_ftype
*show_func
,
450 struct cmd_list_element
**set_list
,
451 struct cmd_list_element
**show_list
)
453 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
454 struct cmd_list_element
*c
;
455 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
456 set_doc
, show_doc
, help_doc
,
460 c
->enums
= auto_boolean_enums
;
463 /* Add element named NAME to both the set and show command LISTs (the
464 list for set/show or some sublist thereof). CLASS is as in
465 add_cmd. VAR is address of the variable which will contain the
466 value. SET_DOC and SHOW_DOC are the documentation strings. */
468 add_setshow_boolean_cmd (char *name
, enum command_class
class, int *var
,
469 const char *set_doc
, const char *show_doc
,
470 const char *help_doc
,
471 cmd_sfunc_ftype
*set_func
,
472 show_value_ftype
*show_func
,
473 struct cmd_list_element
**set_list
,
474 struct cmd_list_element
**show_list
)
476 static const char *boolean_enums
[] = { "on", "off", NULL
};
477 struct cmd_list_element
*c
;
478 add_setshow_cmd_full (name
, class, var_boolean
, var
,
479 set_doc
, show_doc
, help_doc
,
483 c
->enums
= boolean_enums
;
486 /* Add element named NAME to both the set and show command LISTs (the
487 list for set/show or some sublist thereof). */
489 add_setshow_filename_cmd (char *name
, enum command_class
class,
491 const char *set_doc
, const char *show_doc
,
492 const char *help_doc
,
493 cmd_sfunc_ftype
*set_func
,
494 show_value_ftype
*show_func
,
495 struct cmd_list_element
**set_list
,
496 struct cmd_list_element
**show_list
)
498 struct cmd_list_element
*set_result
;
499 add_setshow_cmd_full (name
, class, var_filename
, var
,
500 set_doc
, show_doc
, help_doc
,
504 set_cmd_completer (set_result
, filename_completer
);
507 /* Add element named NAME to both the set and show command LISTs (the
508 list for set/show or some sublist thereof). */
510 add_setshow_string_cmd (char *name
, enum command_class
class,
512 const char *set_doc
, const char *show_doc
,
513 const char *help_doc
,
514 cmd_sfunc_ftype
*set_func
,
515 show_value_ftype
*show_func
,
516 struct cmd_list_element
**set_list
,
517 struct cmd_list_element
**show_list
)
519 add_setshow_cmd_full (name
, class, var_string
, var
,
520 set_doc
, show_doc
, help_doc
,
526 /* Add element named NAME to both the set and show command LISTs (the
527 list for set/show or some sublist thereof). */
529 add_setshow_string_noescape_cmd (char *name
, enum command_class
class,
531 const char *set_doc
, const char *show_doc
,
532 const char *help_doc
,
533 cmd_sfunc_ftype
*set_func
,
534 show_value_ftype
*show_func
,
535 struct cmd_list_element
**set_list
,
536 struct cmd_list_element
**show_list
)
538 add_setshow_cmd_full (name
, class, var_string_noescape
, var
,
539 set_doc
, show_doc
, help_doc
,
545 /* Add element named NAME to both the set and show command LISTs (the
546 list for set/show or some sublist thereof). */
548 add_setshow_optional_filename_cmd (char *name
, enum command_class
class,
550 const char *set_doc
, const char *show_doc
,
551 const char *help_doc
,
552 cmd_sfunc_ftype
*set_func
,
553 show_value_ftype
*show_func
,
554 struct cmd_list_element
**set_list
,
555 struct cmd_list_element
**show_list
)
557 struct cmd_list_element
*set_result
;
559 add_setshow_cmd_full (name
, class, var_optional_filename
, var
,
560 set_doc
, show_doc
, help_doc
,
565 set_cmd_completer (set_result
, filename_completer
);
569 /* Add element named NAME to both the set and show command LISTs (the
570 list for set/show or some sublist thereof). CLASS is as in
571 add_cmd. VAR is address of the variable which will contain the
572 value. SET_DOC and SHOW_DOC are the documentation strings. */
574 add_setshow_integer_cmd (char *name
, enum command_class
class,
576 const char *set_doc
, const char *show_doc
,
577 const char *help_doc
,
578 cmd_sfunc_ftype
*set_func
,
579 show_value_ftype
*show_func
,
580 struct cmd_list_element
**set_list
,
581 struct cmd_list_element
**show_list
)
583 add_setshow_cmd_full (name
, class, var_integer
, var
,
584 set_doc
, show_doc
, help_doc
,
590 /* Add element named NAME to both the set and show command LISTs (the
591 list for set/show or some sublist thereof). CLASS is as in
592 add_cmd. VAR is address of the variable which will contain the
593 value. SET_DOC and SHOW_DOC are the documentation strings. */
595 add_setshow_uinteger_cmd (char *name
, enum command_class
class,
597 const char *set_doc
, const char *show_doc
,
598 const char *help_doc
,
599 cmd_sfunc_ftype
*set_func
,
600 show_value_ftype
*show_func
,
601 struct cmd_list_element
**set_list
,
602 struct cmd_list_element
**show_list
)
604 add_setshow_cmd_full (name
, class, var_uinteger
, var
,
605 set_doc
, show_doc
, help_doc
,
611 /* Add element named NAME to both the set and show command LISTs (the
612 list for set/show or some sublist thereof). CLASS is as in
613 add_cmd. VAR is address of the variable which will contain the
614 value. SET_DOC and SHOW_DOC are the documentation strings. */
616 add_setshow_zinteger_cmd (char *name
, enum command_class
class,
618 const char *set_doc
, const char *show_doc
,
619 const char *help_doc
,
620 cmd_sfunc_ftype
*set_func
,
621 show_value_ftype
*show_func
,
622 struct cmd_list_element
**set_list
,
623 struct cmd_list_element
**show_list
)
625 add_setshow_cmd_full (name
, class, var_zinteger
, var
,
626 set_doc
, show_doc
, help_doc
,
632 /* Add element named NAME to both the set and show command LISTs (the
633 list for set/show or some sublist thereof). CLASS is as in
634 add_cmd. VAR is address of the variable which will contain the
635 value. SET_DOC and SHOW_DOC are the documentation strings. */
637 add_setshow_zuinteger_cmd (char *name
, enum command_class
class,
639 const char *set_doc
, const char *show_doc
,
640 const char *help_doc
,
641 cmd_sfunc_ftype
*set_func
,
642 show_value_ftype
*show_func
,
643 struct cmd_list_element
**set_list
,
644 struct cmd_list_element
**show_list
)
646 add_setshow_cmd_full (name
, class, var_zuinteger
, var
,
647 set_doc
, show_doc
, help_doc
,
653 /* Remove the command named NAME from the command list. Return the
654 list commands which were aliased to the deleted command. If the
655 command had no aliases, return NULL. The various *HOOKs are set to
656 the pre- and post-hook commands for the deleted command. If the
657 command does not have a hook, the corresponding out parameter is
660 static struct cmd_list_element
*
661 delete_cmd (char *name
, struct cmd_list_element
**list
,
662 struct cmd_list_element
**prehook
,
663 struct cmd_list_element
**prehookee
,
664 struct cmd_list_element
**posthook
,
665 struct cmd_list_element
**posthookee
)
667 struct cmd_list_element
*iter
;
668 struct cmd_list_element
**previous_chain_ptr
;
669 struct cmd_list_element
*aliases
= NULL
;
675 previous_chain_ptr
= list
;
677 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
679 if (strcmp (iter
->name
, name
) == 0)
682 iter
->destroyer (iter
, iter
->context
);
683 if (iter
->hookee_pre
)
684 iter
->hookee_pre
->hook_pre
= 0;
685 *prehook
= iter
->hook_pre
;
686 *prehookee
= iter
->hookee_pre
;
687 if (iter
->hookee_post
)
688 iter
->hookee_post
->hook_post
= 0;
689 *posthook
= iter
->hook_post
;
690 *posthookee
= iter
->hookee_post
;
692 /* Update the link. */
693 *previous_chain_ptr
= iter
->next
;
695 aliases
= iter
->aliases
;
697 /* If this command was an alias, remove it from the list of
699 if (iter
->cmd_pointer
)
701 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
702 struct cmd_list_element
*a
= *prevp
;
706 prevp
= &a
->alias_chain
;
709 *prevp
= iter
->alias_chain
;
714 /* We won't see another command with the same name. */
718 previous_chain_ptr
= &iter
->next
;
724 /* Shorthands to the commands above. */
726 /* Add an element to the list of info subcommands. */
728 struct cmd_list_element
*
729 add_info (char *name
, void (*fun
) (char *, int), char *doc
)
731 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
734 /* Add an alias to the list of info subcommands. */
736 struct cmd_list_element
*
737 add_info_alias (char *name
, char *oldname
, int abbrev_flag
)
739 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
742 /* Add an element to the list of commands. */
744 struct cmd_list_element
*
745 add_com (char *name
, enum command_class
class, void (*fun
) (char *, int),
748 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
751 /* Add an alias or abbreviation command to the list of commands. */
753 struct cmd_list_element
*
754 add_com_alias (char *name
, char *oldname
, enum command_class
class,
757 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
760 /* Recursively walk the commandlist structures, and print out the
761 documentation of commands that match our regex in either their
762 name, or their documentation.
765 apropos_cmd (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
766 struct re_pattern_buffer
*regex
, char *prefix
)
768 struct cmd_list_element
*c
;
769 int returnvalue
=1; /*Needed to avoid double printing*/
770 /* Walk through the commands */
771 for (c
=commandlist
;c
;c
=c
->next
)
775 /* Try to match against the name*/
776 returnvalue
=re_search(regex
,c
->name
,strlen(c
->name
),0,strlen(c
->name
),NULL
);
777 if (returnvalue
>= 0)
779 print_help_for_command (c
, prefix
,
780 0 /* don't recurse */, stream
);
783 if (c
->doc
!= NULL
&& returnvalue
!= 0)
785 /* Try to match against documentation */
786 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
788 print_help_for_command (c
, prefix
,
789 0 /* don't recurse */, stream
);
792 /* Check if this command has subcommands */
793 if (c
->prefixlist
!= NULL
)
795 /* Recursively call ourselves on the subcommand list,
796 passing the right prefix in.
798 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
803 /* This command really has to deal with two things:
804 * 1) I want documentation on *this string* (usually called by
805 * "help commandname").
806 * 2) I want documentation on *this list* (usually called by
807 * giving a command that requires subcommands. Also called by saying
810 * I am going to split this into two seperate comamnds, help_cmd and
815 help_cmd (char *command
, struct ui_file
*stream
)
817 struct cmd_list_element
*c
;
818 extern struct cmd_list_element
*cmdlist
;
822 help_list (cmdlist
, "", all_classes
, stream
);
826 if (strcmp (command
, "all") == 0)
832 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
837 /* There are three cases here.
838 If c->prefixlist is nonzero, we have a prefix command.
839 Print its documentation, then list its subcommands.
841 If c->func is non NULL, we really have a command. Print its
842 documentation and return.
844 If c->func is NULL, we have a class name. Print its
845 documentation (as if it were a command) and then set class to the
846 number of this class so that the commands in the class will be
849 fputs_filtered (c
->doc
, stream
);
850 fputs_filtered ("\n", stream
);
852 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
854 fprintf_filtered (stream
, "\n");
856 /* If this is a prefix command, print it's subcommands */
858 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
860 /* If this is a class name, print all of the commands in the class */
862 help_list (cmdlist
, "", c
->class, stream
);
864 if (c
->hook_pre
|| c
->hook_post
)
865 fprintf_filtered (stream
,
866 "\nThis command has a hook (or hooks) defined:\n");
869 fprintf_filtered (stream
,
870 "\tThis command is run after : %s (pre hook)\n",
873 fprintf_filtered (stream
,
874 "\tThis command is run before : %s (post hook)\n",
879 * Get a specific kind of help on a command list.
882 * CMDTYPE is the prefix to use in the title string.
883 * CLASS is the class with which to list the nodes of this list (see
884 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
885 * everything, ALL_CLASSES for just classes, and non-negative for only things
886 * in a specific class.
887 * and STREAM is the output stream on which to print things.
888 * If you call this routine with a class >= 0, it recurses.
891 help_list (struct cmd_list_element
*list
, char *cmdtype
,
892 enum command_class
class, struct ui_file
*stream
)
895 char *cmdtype1
, *cmdtype2
;
897 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
898 len
= strlen (cmdtype
);
899 cmdtype1
= (char *) alloca (len
+ 1);
901 cmdtype2
= (char *) alloca (len
+ 4);
906 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
908 strncpy (cmdtype2
, cmdtype
, len
- 1);
909 strcpy (cmdtype2
+ len
- 1, " sub");
912 if (class == all_classes
)
913 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
915 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
917 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
919 if (class == all_classes
)
921 fprintf_filtered (stream
, "\n\
922 Type \"help%s\" followed by a class name for a list of commands in ",
925 fprintf_filtered (stream
, "that class.");
927 fprintf_filtered (stream
, "\n\
928 Type \"help all\" for the list of all commands.");
931 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
934 fputs_filtered ("for ", stream
);
936 fputs_filtered ("full ", stream
);
938 fputs_filtered ("documentation.\n", stream
);
939 fputs_filtered ("Type \"apropos word\" to search "
940 "for commands related to \"word\".\n", stream
);
941 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
946 help_all (struct ui_file
*stream
)
948 struct cmd_list_element
*c
;
949 extern struct cmd_list_element
*cmdlist
;
950 int seen_unclassified
= 0;
952 for (c
= cmdlist
; c
; c
= c
->next
)
956 /* If this is a class name, print all of the commands in the class */
960 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
961 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
965 /* While it's expected that all commands are in some class,
966 as a safety measure, we'll print commands outside of any
969 for (c
= cmdlist
; c
; c
= c
->next
)
974 if (c
->class == no_class
)
976 if (!seen_unclassified
)
978 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
979 seen_unclassified
= 1;
981 print_help_for_command (c
, "", 1, stream
);
987 /* Print only the first line of STR on STREAM. */
989 print_doc_line (struct ui_file
*stream
, char *str
)
991 static char *line_buffer
= 0;
992 static int line_size
;
998 line_buffer
= (char *) xmalloc (line_size
);
1002 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
1004 if (p
- str
> line_size
- 1)
1006 line_size
= p
- str
+ 1;
1007 xfree (line_buffer
);
1008 line_buffer
= (char *) xmalloc (line_size
);
1010 strncpy (line_buffer
, str
, p
- str
);
1011 line_buffer
[p
- str
] = '\0';
1012 if (islower (line_buffer
[0]))
1013 line_buffer
[0] = toupper (line_buffer
[0]);
1014 ui_out_text (uiout
, line_buffer
);
1017 /* Print one-line help for command C.
1018 If RECURSE is non-zero, also print one-line descriptions
1019 of all prefixed subcommands. */
1021 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
1022 struct ui_file
*stream
)
1024 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1025 print_doc_line (stream
, c
->doc
);
1026 fputs_filtered ("\n", stream
);
1029 && c
->prefixlist
!= 0
1030 && c
->abbrev_flag
== 0)
1031 /* Subcommands of a prefix command typically have 'all_commands'
1032 as class. If we pass CLASS to recursive invocation,
1033 most often we won't see anything. */
1034 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1038 * Implement a help command on command list LIST.
1039 * RECURSE should be non-zero if this should be done recursively on
1040 * all sublists of LIST.
1041 * PREFIX is the prefix to print before each command name.
1042 * STREAM is the stream upon which the output should be written.
1044 * A non-negative class number to list only commands in that
1046 * ALL_COMMANDS to list all commands in list.
1047 * ALL_CLASSES to list all classes in list.
1049 * Note that RECURSE will be active on *all* sublists, not just the
1050 * ones selected by the criteria above (ie. the selection mechanism
1051 * is at the low level, not the high-level).
1054 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1055 char *prefix
, int recurse
, struct ui_file
*stream
)
1057 struct cmd_list_element
*c
;
1059 for (c
= list
; c
; c
= c
->next
)
1061 if (c
->abbrev_flag
== 0 &&
1062 (class == all_commands
1063 || (class == all_classes
&& c
->func
== NULL
)
1064 || (class == c
->class && c
->func
!= NULL
)))
1066 print_help_for_command (c
, prefix
, recurse
, stream
);
1068 else if (c
->abbrev_flag
== 0 && recurse
1069 && class == class_user
&& c
->prefixlist
!= NULL
)
1070 /* User-defined commands may be subcommands. */
1071 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, recurse
, stream
);
1076 /* Search the input clist for 'command'. Return the command if
1077 found (or NULL if not), and return the number of commands
1080 static struct cmd_list_element
*
1081 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
1082 int ignore_help_classes
, int *nfound
)
1084 struct cmd_list_element
*found
, *c
;
1086 found
= (struct cmd_list_element
*) NULL
;
1088 for (c
= clist
; c
; c
= c
->next
)
1089 if (!strncmp (command
, c
->name
, len
)
1090 && (!ignore_help_classes
|| c
->func
))
1094 if (c
->name
[len
] == '\0')
1104 find_command_name_length (const char *text
)
1106 const char *p
= text
;
1108 /* Treating underscores as part of command words is important
1109 so that "set args_foo()" doesn't get interpreted as
1110 "set args _foo()". */
1111 /* Some characters are only used for TUI specific commands. However, they
1112 are always allowed for the sake of consistency.
1113 The XDB compatibility characters are only allowed when using the right
1114 mode because they clash with other GDB commands - specifically '/' is
1115 used as a suffix for print, examine and display.
1116 Note that this is larger than the character set allowed when creating
1117 user-defined commands. */
1118 while (isalnum (*p
) || *p
== '-' || *p
== '_' ||
1119 /* Characters used by TUI specific commands. */
1120 *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$' ||
1121 /* Characters used for XDB compatibility. */
1122 (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')))
1128 /* This routine takes a line of TEXT and a CLIST in which to start the
1129 lookup. When it returns it will have incremented the text pointer past
1130 the section of text it matched, set *RESULT_LIST to point to the list in
1131 which the last word was matched, and will return a pointer to the cmd
1132 list element which the text matches. It will return NULL if no match at
1133 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1134 matches are possible; in this case *RESULT_LIST will be set to point to
1135 the list in which there are ambiguous choices (and *TEXT will be set to
1136 the ambiguous text string).
1138 If the located command was an abbreviation, this routine returns the base
1139 command of the abbreviation.
1141 It does no error reporting whatsoever; control will always return
1142 to the superior routine.
1144 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1145 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1146 if no prefix command was ever found. For example, in the case of "info a",
1147 "info" matches without ambiguity, but "a" could be "args" or "address", so
1148 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1149 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1150 list; it simply points to a specific command. In the case of an ambiguous
1151 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1152 "info t" can be "info types" or "info target"; upon return *TEXT has been
1153 advanced past "info ").
1155 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1156 affect the operation).
1158 This routine does *not* modify the text pointed to by TEXT.
1160 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1161 are actually help classes rather than commands (i.e. the function field of
1162 the struct cmd_list_element is NULL). */
1164 struct cmd_list_element
*
1165 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
1166 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1169 int len
, tmp
, nfound
;
1170 struct cmd_list_element
*found
, *c
;
1173 while (**text
== ' ' || **text
== '\t')
1176 /* Identify the name of the command. */
1177 len
= find_command_name_length (*text
);
1179 /* If nothing but whitespace, return 0. */
1183 /* *text and p now bracket the first command word to lookup (and
1184 it's length is len). We copy this into a local temporary */
1187 command
= (char *) alloca (len
+ 1);
1188 memcpy (command
, *text
, len
);
1189 command
[len
] = '\0';
1194 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1197 ** We didn't find the command in the entered case, so lower case it
1198 ** and search again.
1200 if (!found
|| nfound
== 0)
1202 for (tmp
= 0; tmp
< len
; tmp
++)
1204 char x
= command
[tmp
];
1205 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1207 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1210 /* If nothing matches, we have a simple failure. */
1216 if (result_list
!= NULL
)
1217 /* Will be modified in calling routine
1218 if we know what the prefix command is. */
1220 return (struct cmd_list_element
*) -1; /* Ambiguous. */
1223 /* We've matched something on this list. Move text pointer forward. */
1227 if (found
->cmd_pointer
)
1229 /* We drop the alias (abbreviation) in favor of the command it is
1230 pointing to. If the alias is deprecated, though, we need to
1231 warn the user about it before we drop it. Note that while we
1232 are warning about the alias, we may also warn about the command
1233 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1236 if (found
->flags
& DEPRECATED_WARN_USER
)
1237 deprecated_cmd_warning (&line
);
1238 found
= found
->cmd_pointer
;
1240 /* If we found a prefix command, keep looking. */
1242 if (found
->prefixlist
)
1244 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1245 ignore_help_classes
);
1248 /* Didn't find anything; this is as far as we got. */
1249 if (result_list
!= NULL
)
1250 *result_list
= clist
;
1253 else if (c
== (struct cmd_list_element
*) -1)
1255 /* We've gotten this far properly, but the next step
1256 is ambiguous. We need to set the result list to the best
1257 we've found (if an inferior hasn't already set it). */
1258 if (result_list
!= NULL
)
1260 /* This used to say *result_list = *found->prefixlist
1261 If that was correct, need to modify the documentation
1262 at the top of this function to clarify what is supposed
1264 *result_list
= found
;
1275 if (result_list
!= NULL
)
1276 *result_list
= clist
;
1281 /* All this hair to move the space to the front of cmdtype */
1284 undef_cmd_error (char *cmdtype
, char *q
)
1286 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1289 *cmdtype
? " " : "",
1290 (int) strlen (cmdtype
) - 1,
1294 /* Look up the contents of *LINE as a command in the command list LIST.
1295 LIST is a chain of struct cmd_list_element's.
1296 If it is found, return the struct cmd_list_element for that command
1297 and update *LINE to point after the command name, at the first argument.
1298 If not found, call error if ALLOW_UNKNOWN is zero
1299 otherwise (or if error returns) return zero.
1300 Call error if specified command is ambiguous,
1301 unless ALLOW_UNKNOWN is negative.
1302 CMDTYPE precedes the word "command" in the error message.
1304 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1305 elements which are actually help classes rather than commands (i.e.
1306 the function field of the struct cmd_list_element is 0). */
1308 struct cmd_list_element
*
1309 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1310 int allow_unknown
, int ignore_help_classes
)
1312 struct cmd_list_element
*last_list
= 0;
1313 struct cmd_list_element
*c
;
1315 /* Note: Do not remove trailing whitespace here because this
1316 would be wrong for complete_command. Jim Kingdon */
1319 error (_("Lack of needed %scommand"), cmdtype
);
1321 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1328 int len
= find_command_name_length (*line
);
1330 q
= (char *) alloca (len
+ 1);
1331 strncpy (q
, *line
, len
);
1333 undef_cmd_error (cmdtype
, q
);
1338 else if (c
== (struct cmd_list_element
*) -1)
1340 /* Ambigous. Local values should be off prefixlist or called
1342 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1344 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1345 struct cmd_list_element
*local_list
=
1346 (last_list
? *(last_list
->prefixlist
) : list
);
1348 if (local_allow_unknown
< 0)
1351 return last_list
; /* Found something. */
1353 return 0; /* Found nothing. */
1357 /* Report as error. */
1362 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1363 && (*line
)[amb_len
] != '\t');
1368 for (c
= local_list
; c
; c
= c
->next
)
1369 if (!strncmp (*line
, c
->name
, amb_len
))
1371 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
1373 if (strlen (ambbuf
))
1374 strcat (ambbuf
, ", ");
1375 strcat (ambbuf
, c
->name
);
1379 strcat (ambbuf
, "..");
1383 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1385 return 0; /* lint */
1390 /* We've got something. It may still not be what the caller
1391 wants (if this command *needs* a subcommand). */
1392 while (**line
== ' ' || **line
== '\t')
1395 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1396 undef_cmd_error (c
->prefixname
, *line
);
1398 /* Seems to be what he wants. Return it. */
1404 /* We are here presumably because an alias or command in *TEXT is
1405 deprecated and a warning message should be generated. This function
1406 decodes *TEXT and potentially generates a warning message as outlined
1409 Example for 'set endian big' which has a fictitious alias 'seb'.
1411 If alias wasn't used in *TEXT, and the command is deprecated:
1412 "warning: 'set endian big' is deprecated."
1414 If alias was used, and only the alias is deprecated:
1415 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1417 If alias was used and command is deprecated (regardless of whether the
1418 alias itself is deprecated:
1420 "warning: 'set endian big' (seb) is deprecated."
1422 After the message has been sent, clear the appropriate flags in the
1423 command and/or the alias so the user is no longer bothered.
1427 deprecated_cmd_warning (char **text
)
1429 struct cmd_list_element
*alias
= NULL
;
1430 struct cmd_list_element
*prefix_cmd
= NULL
;
1431 struct cmd_list_element
*cmd
= NULL
;
1432 struct cmd_list_element
*c
;
1435 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1436 /* return if text doesn't evaluate to a command */
1439 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1440 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1441 /* return if nothing is deprecated */
1444 printf_filtered ("Warning:");
1446 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1447 printf_filtered (" '%s', an alias for the", alias
->name
);
1449 printf_filtered (" command '");
1452 printf_filtered ("%s", prefix_cmd
->prefixname
);
1454 printf_filtered ("%s", cmd
->name
);
1456 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1457 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1459 printf_filtered ("' is deprecated.\n");
1462 /* if it is only the alias that is deprecated, we want to indicate the
1463 new alias, otherwise we'll indicate the new command */
1465 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1467 if (alias
->replacement
)
1468 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1470 printf_filtered ("No alternative known.\n\n");
1474 if (cmd
->replacement
)
1475 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1477 printf_filtered ("No alternative known.\n\n");
1480 /* We've warned you, now we'll keep quiet */
1482 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1484 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1489 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1490 Return 1 on success, 0 on failure.
1492 If LINE refers to an alias, *alias will point to that alias.
1494 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1495 command) set *prefix_cmd.
1497 Set *cmd to point to the command LINE indicates.
1499 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1500 exist, they are NULL when we return.
1504 lookup_cmd_composition (char *text
,
1505 struct cmd_list_element
**alias
,
1506 struct cmd_list_element
**prefix_cmd
,
1507 struct cmd_list_element
**cmd
)
1510 int len
, tmp
, nfound
;
1511 struct cmd_list_element
*cur_list
;
1512 struct cmd_list_element
*prev_cmd
;
1521 /* Go through as many command lists as we need to
1522 to find the command TEXT refers to. */
1526 while (*text
== ' ' || *text
== '\t')
1529 /* Identify the name of the command. */
1530 len
= find_command_name_length (text
);
1532 /* If nothing but whitespace, return. */
1536 /* text is the start of the first command word to lookup (and
1537 it's length is len). We copy this into a local temporary */
1539 command
= (char *) alloca (len
+ 1);
1540 memcpy (command
, text
, len
);
1541 command
[len
] = '\0';
1546 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1548 /* We didn't find the command in the entered case, so lower case it
1551 if (!*cmd
|| nfound
== 0)
1553 for (tmp
= 0; tmp
< len
; tmp
++)
1555 char x
= command
[tmp
];
1556 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1558 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1561 if (*cmd
== (struct cmd_list_element
*) -1)
1563 return 0; /* ambiguous */
1567 return 0; /* nothing found */
1570 if ((*cmd
)->cmd_pointer
)
1572 /* cmd was actually an alias, we note that an alias was used
1573 (by assigning *alais) and we set *cmd.
1576 *cmd
= (*cmd
)->cmd_pointer
;
1578 *prefix_cmd
= prev_cmd
;
1580 if ((*cmd
)->prefixlist
)
1581 cur_list
= *(*cmd
)->prefixlist
;
1589 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1591 /* Return a vector of char pointers which point to the different
1592 possible completions in LIST of TEXT.
1594 WORD points in the same buffer as TEXT, and completions should be
1595 returned relative to this position. For example, suppose TEXT is "foo"
1596 and we want to complete to "foobar". If WORD is "oo", return
1597 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1600 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1602 struct cmd_list_element
*ptr
;
1604 int sizeof_matchlist
;
1606 int textlen
= strlen (text
);
1608 sizeof_matchlist
= 10;
1609 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1612 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1613 if (!strncmp (ptr
->name
, text
, textlen
)
1614 && !ptr
->abbrev_flag
1616 || ptr
->prefixlist
))
1618 if (matches
== sizeof_matchlist
)
1620 sizeof_matchlist
*= 2;
1621 matchlist
= (char **) xrealloc ((char *) matchlist
,
1623 * sizeof (char *)));
1626 matchlist
[matches
] = (char *)
1627 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1629 strcpy (matchlist
[matches
], ptr
->name
);
1630 else if (word
> text
)
1632 /* Return some portion of ptr->name. */
1633 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1637 /* Return some of text plus ptr->name. */
1638 strncpy (matchlist
[matches
], word
, text
- word
);
1639 matchlist
[matches
][text
- word
] = '\0';
1640 strcat (matchlist
[matches
], ptr
->name
);
1652 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1653 * sizeof (char *)));
1654 matchlist
[matches
] = (char *) 0;
1660 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1662 /* Return a vector of char pointers which point to the different
1663 possible completions in CMD of TEXT.
1665 WORD points in the same buffer as TEXT, and completions should be
1666 returned relative to this position. For example, suppose TEXT is "foo"
1667 and we want to complete to "foobar". If WORD is "oo", return
1668 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1671 complete_on_enum (const char *enumlist
[],
1676 int sizeof_matchlist
;
1678 int textlen
= strlen (text
);
1682 sizeof_matchlist
= 10;
1683 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1686 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1687 if (strncmp (name
, text
, textlen
) == 0)
1689 if (matches
== sizeof_matchlist
)
1691 sizeof_matchlist
*= 2;
1692 matchlist
= (char **) xrealloc ((char *) matchlist
,
1694 * sizeof (char *)));
1697 matchlist
[matches
] = (char *)
1698 xmalloc (strlen (word
) + strlen (name
) + 1);
1700 strcpy (matchlist
[matches
], name
);
1701 else if (word
> text
)
1703 /* Return some portion of name. */
1704 strcpy (matchlist
[matches
], name
+ (word
- text
));
1708 /* Return some of text plus name. */
1709 strncpy (matchlist
[matches
], word
, text
- word
);
1710 matchlist
[matches
][text
- word
] = '\0';
1711 strcat (matchlist
[matches
], name
);
1723 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1724 * sizeof (char *)));
1725 matchlist
[matches
] = (char *) 0;
1732 /* check function pointer */
1734 cmd_func_p (struct cmd_list_element
*cmd
)
1736 return (cmd
->func
!= NULL
);
1740 /* call the command function */
1742 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1744 if (cmd_func_p (cmd
))
1745 (*cmd
->func
) (cmd
, args
, from_tty
);
1747 error (_("Invalid command"));