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, 2010, 2011 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. */
129 /* Add element named NAME.
130 Space for NAME and DOC must be allocated by the caller.
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
214 place 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
218 this function is called.
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
242 struct cmd_list_element
*old
;
243 struct cmd_list_element
*c
;
245 copied_name
= (char *) alloca (strlen (oldname
) + 1);
246 strcpy (copied_name
, oldname
);
247 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
251 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
252 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
253 &prehook
, &prehookee
,
254 &posthook
, &posthookee
);
256 /* If this happens, it means a programmer error somewhere. */
257 gdb_assert (!aliases
&& !prehook
&& !prehookee
258 && !posthook
&& ! posthookee
);
262 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
263 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
265 c
->function
= old
->function
;
266 c
->prefixlist
= old
->prefixlist
;
267 c
->prefixname
= old
->prefixname
;
268 c
->allow_unknown
= old
->allow_unknown
;
269 c
->abbrev_flag
= abbrev_flag
;
270 c
->cmd_pointer
= old
;
271 c
->alias_chain
= old
->aliases
;
276 /* Like add_cmd but adds an element for a command prefix: a name that
277 should be followed by a subcommand to be looked up in another
278 command list. PREFIXLIST should be the address of the variable
279 containing that list. */
281 struct cmd_list_element
*
282 add_prefix_cmd (char *name
, enum command_class
class,
283 void (*fun
) (char *, int),
284 char *doc
, struct cmd_list_element
**prefixlist
,
285 char *prefixname
, int allow_unknown
,
286 struct cmd_list_element
**list
)
288 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
290 c
->prefixlist
= prefixlist
;
291 c
->prefixname
= prefixname
;
292 c
->allow_unknown
= allow_unknown
;
296 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
298 struct cmd_list_element
*
299 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
300 void (*fun
) (char *, int), char *doc
,
301 struct cmd_list_element
**prefixlist
, char *prefixname
,
302 int allow_unknown
, struct cmd_list_element
**list
)
304 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
306 c
->prefixlist
= prefixlist
;
307 c
->prefixname
= prefixname
;
308 c
->allow_unknown
= allow_unknown
;
313 /* This is an empty "cfunc". */
315 not_just_help_class_command (char *args
, int from_tty
)
319 /* This is an empty "sfunc". */
320 static void empty_sfunc (char *, int, struct cmd_list_element
*);
323 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
327 /* Add element named NAME to command list LIST (the list for set/show
328 or some sublist thereof).
329 TYPE is set_cmd or show_cmd.
330 CLASS is as in add_cmd.
331 VAR_TYPE is the kind of thing we are setting.
332 VAR is address of the variable being controlled by this command.
333 DOC is the documentation string. */
335 static struct cmd_list_element
*
336 add_set_or_show_cmd (char *name
,
338 enum command_class
class,
342 struct cmd_list_element
**list
)
344 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
346 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
348 c
->var_type
= var_type
;
350 /* This needs to be something besides NULL so that this isn't
351 treated as a help class. */
352 set_cmd_sfunc (c
, empty_sfunc
);
356 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
357 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
358 setting. VAR is address of the variable being controlled by this
359 command. SET_FUNC and SHOW_FUNC are the callback functions (if
360 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
361 strings. PRINT the format string to print the value. SET_RESULT
362 and SHOW_RESULT, if not NULL, are set to the resulting command
366 add_setshow_cmd_full (char *name
,
367 enum command_class
class,
368 var_types var_type
, void *var
,
369 const char *set_doc
, const char *show_doc
,
370 const char *help_doc
,
371 cmd_sfunc_ftype
*set_func
,
372 show_value_ftype
*show_func
,
373 struct cmd_list_element
**set_list
,
374 struct cmd_list_element
**show_list
,
375 struct cmd_list_element
**set_result
,
376 struct cmd_list_element
**show_result
)
378 struct cmd_list_element
*set
;
379 struct cmd_list_element
*show
;
383 if (help_doc
!= NULL
)
385 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
386 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
390 full_set_doc
= xstrdup (set_doc
);
391 full_show_doc
= xstrdup (show_doc
);
393 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
394 full_set_doc
, set_list
);
395 if (set_func
!= NULL
)
396 set_cmd_sfunc (set
, set_func
);
397 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
398 full_show_doc
, show_list
);
399 show
->show_value_func
= show_func
;
401 if (set_result
!= NULL
)
403 if (show_result
!= NULL
)
407 /* Add element named NAME to command list LIST (the list for set or
408 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
409 of strings which may follow NAME. VAR is address of the variable
410 which will contain the matching string (from ENUMLIST). */
413 add_setshow_enum_cmd (char *name
,
414 enum command_class
class,
415 const char *enumlist
[],
418 const char *show_doc
,
419 const char *help_doc
,
420 cmd_sfunc_ftype
*set_func
,
421 show_value_ftype
*show_func
,
422 struct cmd_list_element
**set_list
,
423 struct cmd_list_element
**show_list
)
425 struct cmd_list_element
*c
;
427 add_setshow_cmd_full (name
, class, var_enum
, var
,
428 set_doc
, show_doc
, help_doc
,
435 /* Add an auto-boolean command named NAME to both the set and show
436 command list lists. CLASS is as in add_cmd. VAR is address of the
437 variable which will contain the value. DOC is the documentation
438 string. FUNC is the corresponding callback. */
440 add_setshow_auto_boolean_cmd (char *name
,
441 enum command_class
class,
442 enum auto_boolean
*var
,
443 const char *set_doc
, const char *show_doc
,
444 const char *help_doc
,
445 cmd_sfunc_ftype
*set_func
,
446 show_value_ftype
*show_func
,
447 struct cmd_list_element
**set_list
,
448 struct cmd_list_element
**show_list
)
450 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
451 struct cmd_list_element
*c
;
453 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
454 set_doc
, show_doc
, help_doc
,
458 c
->enums
= auto_boolean_enums
;
461 /* Add element named NAME to both the set and show command LISTs (the
462 list for set/show or some sublist thereof). CLASS is as in
463 add_cmd. VAR is address of the variable which will contain the
464 value. SET_DOC and SHOW_DOC are the documentation strings. */
466 add_setshow_boolean_cmd (char *name
, enum command_class
class, int *var
,
467 const char *set_doc
, const char *show_doc
,
468 const char *help_doc
,
469 cmd_sfunc_ftype
*set_func
,
470 show_value_ftype
*show_func
,
471 struct cmd_list_element
**set_list
,
472 struct cmd_list_element
**show_list
)
474 static const char *boolean_enums
[] = { "on", "off", NULL
};
475 struct cmd_list_element
*c
;
477 add_setshow_cmd_full (name
, class, var_boolean
, var
,
478 set_doc
, show_doc
, help_doc
,
482 c
->enums
= boolean_enums
;
485 /* Add element named NAME to both the set and show command LISTs (the
486 list for set/show or some sublist thereof). */
488 add_setshow_filename_cmd (char *name
, enum command_class
class,
490 const char *set_doc
, const char *show_doc
,
491 const char *help_doc
,
492 cmd_sfunc_ftype
*set_func
,
493 show_value_ftype
*show_func
,
494 struct cmd_list_element
**set_list
,
495 struct cmd_list_element
**show_list
)
497 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
,
766 struct cmd_list_element
*commandlist
,
767 struct re_pattern_buffer
*regex
, char *prefix
)
769 struct cmd_list_element
*c
;
772 /* Walk through the commands. */
773 for (c
=commandlist
;c
;c
=c
->next
)
775 returnvalue
= -1; /* Needed to avoid double printing. */
778 /* Try to match against the name. */
779 returnvalue
= re_search (regex
, c
->name
, strlen(c
->name
),
780 0, strlen (c
->name
), NULL
);
781 if (returnvalue
>= 0)
783 print_help_for_command (c
, prefix
,
784 0 /* don't recurse */, stream
);
787 if (c
->doc
!= NULL
&& returnvalue
< 0)
789 /* Try to match against documentation. */
790 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
792 print_help_for_command (c
, prefix
,
793 0 /* don't recurse */, stream
);
796 /* Check if this command has subcommands and is not an
797 abbreviation. We skip listing subcommands of abbreviations
798 in order to avoid duplicates in the output. */
799 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
801 /* Recursively call ourselves on the subcommand list,
802 passing the right prefix in. */
803 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
808 /* This command really has to deal with two things:
809 1) I want documentation on *this string* (usually called by
812 2) I want documentation on *this list* (usually called by giving a
813 command that requires subcommands. Also called by saying just
816 I am going to split this into two seperate comamnds, help_cmd and
820 help_cmd (char *command
, struct ui_file
*stream
)
822 struct cmd_list_element
*c
;
823 extern struct cmd_list_element
*cmdlist
;
827 help_list (cmdlist
, "", all_classes
, stream
);
831 if (strcmp (command
, "all") == 0)
837 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
842 /* There are three cases here.
843 If c->prefixlist is nonzero, we have a prefix command.
844 Print its documentation, then list its subcommands.
846 If c->func is non NULL, we really have a command. Print its
847 documentation and return.
849 If c->func is NULL, we have a class name. Print its
850 documentation (as if it were a command) and then set class to the
851 number of this class so that the commands in the class will be
854 fputs_filtered (c
->doc
, stream
);
855 fputs_filtered ("\n", stream
);
857 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
859 fprintf_filtered (stream
, "\n");
861 /* If this is a prefix command, print it's subcommands. */
863 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
865 /* If this is a class name, print all of the commands in the class. */
867 help_list (cmdlist
, "", c
->class, stream
);
869 if (c
->hook_pre
|| c
->hook_post
)
870 fprintf_filtered (stream
,
871 "\nThis command has a hook (or hooks) defined:\n");
874 fprintf_filtered (stream
,
875 "\tThis command is run after : %s (pre hook)\n",
878 fprintf_filtered (stream
,
879 "\tThis command is run before : %s (post hook)\n",
884 * Get a specific kind of help on a command list.
887 * CMDTYPE is the prefix to use in the title string.
888 * CLASS is the class with which to list the nodes of this list (see
889 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
890 * everything, ALL_CLASSES for just classes, and non-negative for only things
891 * in a specific class.
892 * and STREAM is the output stream on which to print things.
893 * If you call this routine with a class >= 0, it recurses.
896 help_list (struct cmd_list_element
*list
, char *cmdtype
,
897 enum command_class
class, struct ui_file
*stream
)
900 char *cmdtype1
, *cmdtype2
;
902 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
904 len
= strlen (cmdtype
);
905 cmdtype1
= (char *) alloca (len
+ 1);
907 cmdtype2
= (char *) alloca (len
+ 4);
912 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
914 strncpy (cmdtype2
, cmdtype
, len
- 1);
915 strcpy (cmdtype2
+ len
- 1, " sub");
918 if (class == all_classes
)
919 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
921 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
923 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
925 if (class == all_classes
)
927 fprintf_filtered (stream
, "\n\
928 Type \"help%s\" followed by a class name for a list of commands in ",
931 fprintf_filtered (stream
, "that class.");
933 fprintf_filtered (stream
, "\n\
934 Type \"help all\" for the list of all commands.");
937 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
940 fputs_filtered ("for ", stream
);
942 fputs_filtered ("full ", stream
);
944 fputs_filtered ("documentation.\n", stream
);
945 fputs_filtered ("Type \"apropos word\" to search "
946 "for commands related to \"word\".\n", stream
);
947 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
952 help_all (struct ui_file
*stream
)
954 struct cmd_list_element
*c
;
955 extern struct cmd_list_element
*cmdlist
;
956 int seen_unclassified
= 0;
958 for (c
= cmdlist
; c
; c
= c
->next
)
962 /* If this is a class name, print all of the commands in the
967 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
968 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
972 /* While it's expected that all commands are in some class,
973 as a safety measure, we'll print commands outside of any
976 for (c
= cmdlist
; c
; c
= c
->next
)
981 if (c
->class == no_class
)
983 if (!seen_unclassified
)
985 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
986 seen_unclassified
= 1;
988 print_help_for_command (c
, "", 1, stream
);
994 /* Print only the first line of STR on STREAM. */
996 print_doc_line (struct ui_file
*stream
, char *str
)
998 static char *line_buffer
= 0;
999 static int line_size
;
1005 line_buffer
= (char *) xmalloc (line_size
);
1009 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
1011 if (p
- str
> line_size
- 1)
1013 line_size
= p
- str
+ 1;
1014 xfree (line_buffer
);
1015 line_buffer
= (char *) xmalloc (line_size
);
1017 strncpy (line_buffer
, str
, p
- str
);
1018 line_buffer
[p
- str
] = '\0';
1019 if (islower (line_buffer
[0]))
1020 line_buffer
[0] = toupper (line_buffer
[0]);
1021 ui_out_text (current_uiout
, line_buffer
);
1024 /* Print one-line help for command C.
1025 If RECURSE is non-zero, also print one-line descriptions
1026 of all prefixed subcommands. */
1028 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
1029 struct ui_file
*stream
)
1031 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1032 print_doc_line (stream
, c
->doc
);
1033 fputs_filtered ("\n", stream
);
1036 && c
->prefixlist
!= 0
1037 && c
->abbrev_flag
== 0)
1038 /* Subcommands of a prefix command typically have 'all_commands'
1039 as class. If we pass CLASS to recursive invocation,
1040 most often we won't see anything. */
1041 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1045 * Implement a help command on command list LIST.
1046 * RECURSE should be non-zero if this should be done recursively on
1047 * all sublists of LIST.
1048 * PREFIX is the prefix to print before each command name.
1049 * STREAM is the stream upon which the output should be written.
1051 * A non-negative class number to list only commands in that
1053 * ALL_COMMANDS to list all commands in list.
1054 * ALL_CLASSES to list all classes in list.
1056 * Note that RECURSE will be active on *all* sublists, not just the
1057 * ones selected by the criteria above (ie. the selection mechanism
1058 * is at the low level, not the high-level).
1061 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1062 char *prefix
, int recurse
, struct ui_file
*stream
)
1064 struct cmd_list_element
*c
;
1066 for (c
= list
; c
; c
= c
->next
)
1068 if (c
->abbrev_flag
== 0
1069 && (class == all_commands
1070 || (class == all_classes
&& c
->func
== NULL
)
1071 || (class == c
->class && c
->func
!= NULL
)))
1073 print_help_for_command (c
, prefix
, recurse
, stream
);
1075 else if (c
->abbrev_flag
== 0 && recurse
1076 && class == class_user
&& c
->prefixlist
!= NULL
)
1077 /* User-defined commands may be subcommands. */
1078 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
,
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.
1120 However, they are always allowed for the sake of consistency.
1122 The XDB compatibility characters are only allowed when using the
1123 right mode because they clash with other GDB commands -
1124 specifically '/' is used as a suffix for print, examine and
1127 Note that this is larger than the character set allowed when
1128 creating user-defined commands. */
1130 /* Recognize '!' as a single character command so that, e.g., "!ls"
1131 works as expected. */
1135 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1136 /* Characters used by TUI specific commands. */
1137 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$'
1138 /* Characters used for XDB compatibility. */
1139 || (xdb_commands
&& (*p
== '/' || *p
== '?')))
1145 /* Return TRUE if NAME is a valid user-defined command name.
1146 This is a stricter subset of all gdb commands,
1147 see find_command_name_length. */
1150 valid_user_defined_cmd_name_p (const char *name
)
1157 /* Alas "42" is a legitimate user-defined command.
1158 In the interests of not breaking anything we preserve that. */
1160 for (p
= name
; *p
!= '\0'; ++p
)
1173 /* This routine takes a line of TEXT and a CLIST in which to start the
1174 lookup. When it returns it will have incremented the text pointer past
1175 the section of text it matched, set *RESULT_LIST to point to the list in
1176 which the last word was matched, and will return a pointer to the cmd
1177 list element which the text matches. It will return NULL if no match at
1178 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1179 matches are possible; in this case *RESULT_LIST will be set to point to
1180 the list in which there are ambiguous choices (and *TEXT will be set to
1181 the ambiguous text string).
1183 If the located command was an abbreviation, this routine returns the base
1184 command of the abbreviation.
1186 It does no error reporting whatsoever; control will always return
1187 to the superior routine.
1189 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1190 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1191 if no prefix command was ever found. For example, in the case of "info a",
1192 "info" matches without ambiguity, but "a" could be "args" or "address", so
1193 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1194 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1195 list; it simply points to a specific command. In the case of an ambiguous
1196 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1197 "info t" can be "info types" or "info target"; upon return *TEXT has been
1198 advanced past "info ").
1200 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1201 affect the operation).
1203 This routine does *not* modify the text pointed to by TEXT.
1205 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1206 are actually help classes rather than commands (i.e. the function field of
1207 the struct cmd_list_element is NULL). */
1209 struct cmd_list_element
*
1210 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
1211 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1214 int len
, tmp
, nfound
;
1215 struct cmd_list_element
*found
, *c
;
1218 while (**text
== ' ' || **text
== '\t')
1221 /* Identify the name of the command. */
1222 len
= find_command_name_length (*text
);
1224 /* If nothing but whitespace, return 0. */
1228 /* *text and p now bracket the first command word to lookup (and
1229 it's length is len). We copy this into a local temporary. */
1232 command
= (char *) alloca (len
+ 1);
1233 memcpy (command
, *text
, len
);
1234 command
[len
] = '\0';
1239 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1241 /* We didn't find the command in the entered case, so lower case it
1242 and search again. */
1243 if (!found
|| nfound
== 0)
1245 for (tmp
= 0; tmp
< len
; tmp
++)
1247 char x
= command
[tmp
];
1249 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1251 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1254 /* If nothing matches, we have a simple failure. */
1260 if (result_list
!= NULL
)
1261 /* Will be modified in calling routine
1262 if we know what the prefix command is. */
1264 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1267 /* We've matched something on this list. Move text pointer forward. */
1271 if (found
->cmd_pointer
)
1273 /* We drop the alias (abbreviation) in favor of the command it
1274 is pointing to. If the alias is deprecated, though, we need to
1275 warn the user about it before we drop it. Note that while we
1276 are warning about the alias, we may also warn about the command
1277 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1280 if (found
->flags
& DEPRECATED_WARN_USER
)
1281 deprecated_cmd_warning (&line
);
1282 found
= found
->cmd_pointer
;
1284 /* If we found a prefix command, keep looking. */
1286 if (found
->prefixlist
)
1288 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1289 ignore_help_classes
);
1292 /* Didn't find anything; this is as far as we got. */
1293 if (result_list
!= NULL
)
1294 *result_list
= clist
;
1297 else if (c
== CMD_LIST_AMBIGUOUS
)
1299 /* We've gotten this far properly, but the next step is
1300 ambiguous. We need to set the result list to the best
1301 we've found (if an inferior hasn't already set it). */
1302 if (result_list
!= NULL
)
1304 /* This used to say *result_list = *found->prefixlist.
1305 If that was correct, need to modify the documentation
1306 at the top of this function to clarify what is
1307 supposed to be going on. */
1308 *result_list
= found
;
1319 if (result_list
!= NULL
)
1320 *result_list
= clist
;
1325 /* All this hair to move the space to the front of cmdtype */
1328 undef_cmd_error (char *cmdtype
, char *q
)
1330 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1333 *cmdtype
? " " : "",
1334 (int) strlen (cmdtype
) - 1,
1338 /* Look up the contents of *LINE as a command in the command list LIST.
1339 LIST is a chain of struct cmd_list_element's.
1340 If it is found, return the struct cmd_list_element for that command
1341 and update *LINE to point after the command name, at the first argument.
1342 If not found, call error if ALLOW_UNKNOWN is zero
1343 otherwise (or if error returns) return zero.
1344 Call error if specified command is ambiguous,
1345 unless ALLOW_UNKNOWN is negative.
1346 CMDTYPE precedes the word "command" in the error message.
1348 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1349 elements which are actually help classes rather than commands (i.e.
1350 the function field of the struct cmd_list_element is 0). */
1352 struct cmd_list_element
*
1353 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1354 int allow_unknown
, int ignore_help_classes
)
1356 struct cmd_list_element
*last_list
= 0;
1357 struct cmd_list_element
*c
;
1359 /* Note: Do not remove trailing whitespace here because this
1360 would be wrong for complete_command. Jim Kingdon */
1363 error (_("Lack of needed %scommand"), cmdtype
);
1365 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1372 int len
= find_command_name_length (*line
);
1374 q
= (char *) alloca (len
+ 1);
1375 strncpy (q
, *line
, len
);
1377 undef_cmd_error (cmdtype
, q
);
1382 else if (c
== CMD_LIST_AMBIGUOUS
)
1384 /* Ambigous. Local values should be off prefixlist or called
1386 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1388 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1389 struct cmd_list_element
*local_list
=
1390 (last_list
? *(last_list
->prefixlist
) : list
);
1392 if (local_allow_unknown
< 0)
1395 return last_list
; /* Found something. */
1397 return 0; /* Found nothing. */
1401 /* Report as error. */
1406 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1407 && (*line
)[amb_len
] != '\t');
1412 for (c
= local_list
; c
; c
= c
->next
)
1413 if (!strncmp (*line
, c
->name
, amb_len
))
1415 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1416 < (int) sizeof ambbuf
)
1418 if (strlen (ambbuf
))
1419 strcat (ambbuf
, ", ");
1420 strcat (ambbuf
, c
->name
);
1424 strcat (ambbuf
, "..");
1428 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1430 return 0; /* lint */
1435 /* We've got something. It may still not be what the caller
1436 wants (if this command *needs* a subcommand). */
1437 while (**line
== ' ' || **line
== '\t')
1440 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1441 undef_cmd_error (c
->prefixname
, *line
);
1443 /* Seems to be what he wants. Return it. */
1449 /* We are here presumably because an alias or command in *TEXT is
1450 deprecated and a warning message should be generated. This
1451 function decodes *TEXT and potentially generates a warning message
1454 Example for 'set endian big' which has a fictitious alias 'seb'.
1456 If alias wasn't used in *TEXT, and the command is deprecated:
1457 "warning: 'set endian big' is deprecated."
1459 If alias was used, and only the alias is deprecated:
1460 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1462 If alias was used and command is deprecated (regardless of whether
1463 the alias itself is deprecated:
1465 "warning: 'set endian big' (seb) is deprecated."
1467 After the message has been sent, clear the appropriate flags in the
1468 command and/or the alias so the user is no longer bothered.
1472 deprecated_cmd_warning (char **text
)
1474 struct cmd_list_element
*alias
= NULL
;
1475 struct cmd_list_element
*prefix_cmd
= NULL
;
1476 struct cmd_list_element
*cmd
= NULL
;
1478 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1479 /* Return if text doesn't evaluate to a command. */
1482 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1483 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1484 /* Return if nothing is deprecated. */
1487 printf_filtered ("Warning:");
1489 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1490 printf_filtered (" '%s', an alias for the", alias
->name
);
1492 printf_filtered (" command '");
1495 printf_filtered ("%s", prefix_cmd
->prefixname
);
1497 printf_filtered ("%s", cmd
->name
);
1499 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1500 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1502 printf_filtered ("' is deprecated.\n");
1505 /* If it is only the alias that is deprecated, we want to indicate
1506 the new alias, otherwise we'll indicate the new command. */
1508 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1510 if (alias
->replacement
)
1511 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1513 printf_filtered ("No alternative known.\n\n");
1517 if (cmd
->replacement
)
1518 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1520 printf_filtered ("No alternative known.\n\n");
1523 /* We've warned you, now we'll keep quiet. */
1525 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1527 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1531 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1532 Return 1 on success, 0 on failure.
1534 If LINE refers to an alias, *alias will point to that alias.
1536 If LINE is a postfix command (i.e. one that is preceded by a prefix
1537 command) set *prefix_cmd.
1539 Set *cmd to point to the command LINE indicates.
1541 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1542 exist, they are NULL when we return.
1546 lookup_cmd_composition (char *text
,
1547 struct cmd_list_element
**alias
,
1548 struct cmd_list_element
**prefix_cmd
,
1549 struct cmd_list_element
**cmd
)
1552 int len
, tmp
, nfound
;
1553 struct cmd_list_element
*cur_list
;
1554 struct cmd_list_element
*prev_cmd
;
1564 /* Go through as many command lists as we need to,
1565 to find the command TEXT refers to. */
1569 while (*text
== ' ' || *text
== '\t')
1572 /* Identify the name of the command. */
1573 len
= find_command_name_length (text
);
1575 /* If nothing but whitespace, return. */
1579 /* Text is the start of the first command word to lookup (and
1580 it's length is len). We copy this into a local temporary. */
1582 command
= (char *) alloca (len
+ 1);
1583 memcpy (command
, text
, len
);
1584 command
[len
] = '\0';
1589 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1591 /* We didn't find the command in the entered case, so lower case
1592 it and search again.
1594 if (!*cmd
|| nfound
== 0)
1596 for (tmp
= 0; tmp
< len
; tmp
++)
1598 char x
= command
[tmp
];
1600 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1602 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1605 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1607 return 0; /* ambiguous */
1611 return 0; /* nothing found */
1614 if ((*cmd
)->cmd_pointer
)
1616 /* cmd was actually an alias, we note that an alias was
1617 used (by assigning *alais) and we set *cmd. */
1619 *cmd
= (*cmd
)->cmd_pointer
;
1621 *prefix_cmd
= prev_cmd
;
1623 if ((*cmd
)->prefixlist
)
1624 cur_list
= *(*cmd
)->prefixlist
;
1632 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1634 /* Return a vector of char pointers which point to the different
1635 possible completions in LIST of TEXT.
1637 WORD points in the same buffer as TEXT, and completions should be
1638 returned relative to this position. For example, suppose TEXT is
1639 "foo" and we want to complete to "foobar". If WORD is "oo", return
1640 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1643 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1645 struct cmd_list_element
*ptr
;
1647 int sizeof_matchlist
;
1649 int textlen
= strlen (text
);
1651 int saw_deprecated_match
= 0;
1653 sizeof_matchlist
= 10;
1654 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1657 /* We do one or two passes. In the first pass, we skip deprecated
1658 commands. If we see no matching commands in the first pass, and
1659 if we did happen to see a matching deprecated command, we do
1660 another loop to collect those. */
1661 for (pass
= 0; matches
== 0 && pass
< 2; ++pass
)
1663 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1664 if (!strncmp (ptr
->name
, text
, textlen
)
1665 && !ptr
->abbrev_flag
1667 || ptr
->prefixlist
))
1671 if ((ptr
->flags
& CMD_DEPRECATED
) != 0)
1673 saw_deprecated_match
= 1;
1678 if (matches
== sizeof_matchlist
)
1680 sizeof_matchlist
*= 2;
1681 matchlist
= (char **) xrealloc ((char *) matchlist
,
1683 * sizeof (char *)));
1686 matchlist
[matches
] = (char *)
1687 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1689 strcpy (matchlist
[matches
], ptr
->name
);
1690 else if (word
> text
)
1692 /* Return some portion of ptr->name. */
1693 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1697 /* Return some of text plus ptr->name. */
1698 strncpy (matchlist
[matches
], word
, text
- word
);
1699 matchlist
[matches
][text
- word
] = '\0';
1700 strcat (matchlist
[matches
], ptr
->name
);
1704 /* If we saw no matching deprecated commands in the first pass,
1706 if (!saw_deprecated_match
)
1717 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1718 * sizeof (char *)));
1719 matchlist
[matches
] = (char *) 0;
1725 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1727 /* Return a vector of char pointers which point to the different
1728 possible completions in CMD of TEXT.
1730 WORD points in the same buffer as TEXT, and completions should be
1731 returned relative to this position. For example, suppose TEXT is "foo"
1732 and we want to complete to "foobar". If WORD is "oo", return
1733 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1736 complete_on_enum (const char *enumlist
[],
1741 int sizeof_matchlist
;
1743 int textlen
= strlen (text
);
1747 sizeof_matchlist
= 10;
1748 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1751 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1752 if (strncmp (name
, text
, textlen
) == 0)
1754 if (matches
== sizeof_matchlist
)
1756 sizeof_matchlist
*= 2;
1757 matchlist
= (char **) xrealloc ((char *) matchlist
,
1759 * sizeof (char *)));
1762 matchlist
[matches
] = (char *)
1763 xmalloc (strlen (word
) + strlen (name
) + 1);
1765 strcpy (matchlist
[matches
], name
);
1766 else if (word
> text
)
1768 /* Return some portion of name. */
1769 strcpy (matchlist
[matches
], name
+ (word
- text
));
1773 /* Return some of text plus name. */
1774 strncpy (matchlist
[matches
], word
, text
- word
);
1775 matchlist
[matches
][text
- word
] = '\0';
1776 strcat (matchlist
[matches
], name
);
1788 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1789 * sizeof (char *)));
1790 matchlist
[matches
] = (char *) 0;
1797 /* Check function pointer. */
1799 cmd_func_p (struct cmd_list_element
*cmd
)
1801 return (cmd
->func
!= NULL
);
1805 /* Call the command function. */
1807 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1809 if (cmd_func_p (cmd
))
1810 (*cmd
->func
) (cmd
, args
, from_tty
);
1812 error (_("Invalid command"));