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. */
130 /* Add element named NAME.
131 Space for NAME and DOC must be allocated by the caller.
132 CLASS is the top level category into which commands are broken down
134 FUN should be the function to execute the command;
135 it will get a character string as argument, with leading
136 and trailing blanks already eliminated.
138 DOC is a documentation string for the command.
139 Its first line should be a complete sentence.
140 It should start with ? for a command that is an abbreviation
141 or with * for a command that most users don't need to know about.
143 Add this command to command list *LIST.
145 Returns a pointer to the added command (not necessarily the head
148 struct cmd_list_element
*
149 add_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
150 char *doc
, struct cmd_list_element
**list
)
152 struct cmd_list_element
*c
153 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
154 struct cmd_list_element
*p
, *iter
;
156 /* Turn each alias of the old command into an alias of the new
158 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
159 &c
->hook_post
, &c
->hookee_post
);
160 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
161 iter
->cmd_pointer
= c
;
163 c
->hook_pre
->hookee_pre
= c
;
165 c
->hookee_pre
->hook_pre
= c
;
167 c
->hook_post
->hookee_post
= c
;
169 c
->hookee_post
->hook_post
= c
;
171 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
179 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
189 set_cmd_cfunc (c
, fun
);
190 set_cmd_context (c
, NULL
);
193 c
->replacement
= NULL
;
194 c
->pre_show_hook
= NULL
;
196 c
->prefixlist
= NULL
;
197 c
->prefixname
= NULL
;
198 c
->allow_unknown
= 0;
200 set_cmd_completer (c
, make_symbol_completion_list_fn
);
202 c
->type
= not_set_cmd
;
204 c
->var_type
= var_boolean
;
206 c
->user_commands
= NULL
;
207 c
->cmd_pointer
= NULL
;
208 c
->alias_chain
= NULL
;
213 /* Deprecates a command CMD.
214 REPLACEMENT is the name of the command which should be used in
215 place of this command, or NULL if no such command exists.
217 This function does not check to see if command REPLACEMENT exists
218 since gdb may not have gotten around to adding REPLACEMENT when
219 this function is called.
221 Returns a pointer to the deprecated command. */
223 struct cmd_list_element
*
224 deprecate_cmd (struct cmd_list_element
*cmd
, char *replacement
)
226 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
228 if (replacement
!= NULL
)
229 cmd
->replacement
= replacement
;
231 cmd
->replacement
= NULL
;
236 struct cmd_list_element
*
237 add_alias_cmd (char *name
, char *oldname
, enum command_class
class,
238 int abbrev_flag
, struct cmd_list_element
**list
)
240 /* Must do this since lookup_cmd tries to side-effect its first
243 struct cmd_list_element
*old
;
244 struct cmd_list_element
*c
;
246 copied_name
= (char *) alloca (strlen (oldname
) + 1);
247 strcpy (copied_name
, oldname
);
248 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
252 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
253 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
254 &prehook
, &prehookee
,
255 &posthook
, &posthookee
);
257 /* If this happens, it means a programmer error somewhere. */
258 gdb_assert (!aliases
&& !prehook
&& !prehookee
259 && !posthook
&& ! posthookee
);
263 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
264 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
266 c
->function
= old
->function
;
267 c
->prefixlist
= old
->prefixlist
;
268 c
->prefixname
= old
->prefixname
;
269 c
->allow_unknown
= old
->allow_unknown
;
270 c
->abbrev_flag
= abbrev_flag
;
271 c
->cmd_pointer
= old
;
272 c
->alias_chain
= old
->aliases
;
277 /* Like add_cmd but adds an element for a command prefix: a name that
278 should be followed by a subcommand to be looked up in another
279 command list. PREFIXLIST should be the address of the variable
280 containing that list. */
282 struct cmd_list_element
*
283 add_prefix_cmd (char *name
, enum command_class
class,
284 void (*fun
) (char *, int),
285 char *doc
, struct cmd_list_element
**prefixlist
,
286 char *prefixname
, int allow_unknown
,
287 struct cmd_list_element
**list
)
289 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
291 c
->prefixlist
= prefixlist
;
292 c
->prefixname
= prefixname
;
293 c
->allow_unknown
= allow_unknown
;
297 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
299 struct cmd_list_element
*
300 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
301 void (*fun
) (char *, int), char *doc
,
302 struct cmd_list_element
**prefixlist
, char *prefixname
,
303 int allow_unknown
, struct cmd_list_element
**list
)
305 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
307 c
->prefixlist
= prefixlist
;
308 c
->prefixname
= prefixname
;
309 c
->allow_unknown
= allow_unknown
;
314 /* This is an empty "cfunc". */
316 not_just_help_class_command (char *args
, int from_tty
)
320 /* This is an empty "sfunc". */
321 static void empty_sfunc (char *, int, struct cmd_list_element
*);
324 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
328 /* Add element named NAME to command list LIST (the list for set/show
329 or some sublist thereof).
330 TYPE is set_cmd or show_cmd.
331 CLASS is as in add_cmd.
332 VAR_TYPE is the kind of thing we are setting.
333 VAR is address of the variable being controlled by this command.
334 DOC is the documentation string. */
336 static struct cmd_list_element
*
337 add_set_or_show_cmd (char *name
,
339 enum command_class
class,
343 struct cmd_list_element
**list
)
345 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
347 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
349 c
->var_type
= var_type
;
351 /* This needs to be something besides NULL so that this isn't
352 treated as a help class. */
353 set_cmd_sfunc (c
, empty_sfunc
);
357 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
358 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
359 setting. VAR is address of the variable being controlled by this
360 command. SET_FUNC and SHOW_FUNC are the callback functions (if
361 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
362 strings. PRINT the format string to print the value. SET_RESULT
363 and SHOW_RESULT, if not NULL, are set to the resulting command
367 add_setshow_cmd_full (char *name
,
368 enum command_class
class,
369 var_types var_type
, void *var
,
370 const char *set_doc
, const char *show_doc
,
371 const char *help_doc
,
372 cmd_sfunc_ftype
*set_func
,
373 show_value_ftype
*show_func
,
374 struct cmd_list_element
**set_list
,
375 struct cmd_list_element
**show_list
,
376 struct cmd_list_element
**set_result
,
377 struct cmd_list_element
**show_result
)
379 struct cmd_list_element
*set
;
380 struct cmd_list_element
*show
;
384 if (help_doc
!= NULL
)
386 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
387 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
391 full_set_doc
= xstrdup (set_doc
);
392 full_show_doc
= xstrdup (show_doc
);
394 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
395 full_set_doc
, set_list
);
396 if (set_func
!= NULL
)
397 set_cmd_sfunc (set
, set_func
);
398 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
399 full_show_doc
, show_list
);
400 show
->show_value_func
= show_func
;
402 if (set_result
!= NULL
)
404 if (show_result
!= NULL
)
408 /* Add element named NAME to command list LIST (the list for set or
409 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
410 of strings which may follow NAME. VAR is address of the variable
411 which will contain the matching string (from ENUMLIST). */
414 add_setshow_enum_cmd (char *name
,
415 enum command_class
class,
416 const char *enumlist
[],
419 const char *show_doc
,
420 const char *help_doc
,
421 cmd_sfunc_ftype
*set_func
,
422 show_value_ftype
*show_func
,
423 struct cmd_list_element
**set_list
,
424 struct cmd_list_element
**show_list
)
426 struct cmd_list_element
*c
;
428 add_setshow_cmd_full (name
, class, var_enum
, var
,
429 set_doc
, show_doc
, help_doc
,
436 /* Add an auto-boolean command named NAME to both the set and show
437 command list lists. CLASS is as in add_cmd. VAR is address of the
438 variable which will contain the value. DOC is the documentation
439 string. FUNC is the corresponding callback. */
441 add_setshow_auto_boolean_cmd (char *name
,
442 enum command_class
class,
443 enum auto_boolean
*var
,
444 const char *set_doc
, const char *show_doc
,
445 const char *help_doc
,
446 cmd_sfunc_ftype
*set_func
,
447 show_value_ftype
*show_func
,
448 struct cmd_list_element
**set_list
,
449 struct cmd_list_element
**show_list
)
451 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
452 struct cmd_list_element
*c
;
454 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
455 set_doc
, show_doc
, help_doc
,
459 c
->enums
= auto_boolean_enums
;
462 /* Add element named NAME to both the set and show command LISTs (the
463 list for set/show or some sublist thereof). CLASS is as in
464 add_cmd. VAR is address of the variable which will contain the
465 value. SET_DOC and SHOW_DOC are the documentation strings. */
467 add_setshow_boolean_cmd (char *name
, enum command_class
class, int *var
,
468 const char *set_doc
, const char *show_doc
,
469 const char *help_doc
,
470 cmd_sfunc_ftype
*set_func
,
471 show_value_ftype
*show_func
,
472 struct cmd_list_element
**set_list
,
473 struct cmd_list_element
**show_list
)
475 static const char *boolean_enums
[] = { "on", "off", NULL
};
476 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
;
500 add_setshow_cmd_full (name
, class, var_filename
, var
,
501 set_doc
, show_doc
, help_doc
,
505 set_cmd_completer (set_result
, filename_completer
);
508 /* Add element named NAME to both the set and show command LISTs (the
509 list for set/show or some sublist thereof). */
511 add_setshow_string_cmd (char *name
, enum command_class
class,
513 const char *set_doc
, const char *show_doc
,
514 const char *help_doc
,
515 cmd_sfunc_ftype
*set_func
,
516 show_value_ftype
*show_func
,
517 struct cmd_list_element
**set_list
,
518 struct cmd_list_element
**show_list
)
520 add_setshow_cmd_full (name
, class, var_string
, var
,
521 set_doc
, show_doc
, help_doc
,
527 /* Add element named NAME to both the set and show command LISTs (the
528 list for set/show or some sublist thereof). */
530 add_setshow_string_noescape_cmd (char *name
, enum command_class
class,
532 const char *set_doc
, const char *show_doc
,
533 const char *help_doc
,
534 cmd_sfunc_ftype
*set_func
,
535 show_value_ftype
*show_func
,
536 struct cmd_list_element
**set_list
,
537 struct cmd_list_element
**show_list
)
539 add_setshow_cmd_full (name
, class, var_string_noescape
, var
,
540 set_doc
, show_doc
, help_doc
,
546 /* Add element named NAME to both the set and show command LISTs (the
547 list for set/show or some sublist thereof). */
549 add_setshow_optional_filename_cmd (char *name
, enum command_class
class,
551 const char *set_doc
, const char *show_doc
,
552 const char *help_doc
,
553 cmd_sfunc_ftype
*set_func
,
554 show_value_ftype
*show_func
,
555 struct cmd_list_element
**set_list
,
556 struct cmd_list_element
**show_list
)
558 struct cmd_list_element
*set_result
;
560 add_setshow_cmd_full (name
, class, var_optional_filename
, var
,
561 set_doc
, show_doc
, help_doc
,
566 set_cmd_completer (set_result
, filename_completer
);
570 /* Add element named NAME to both the set and show command LISTs (the
571 list for set/show or some sublist thereof). CLASS is as in
572 add_cmd. VAR is address of the variable which will contain the
573 value. SET_DOC and SHOW_DOC are the documentation strings. */
575 add_setshow_integer_cmd (char *name
, enum command_class
class,
577 const char *set_doc
, const char *show_doc
,
578 const char *help_doc
,
579 cmd_sfunc_ftype
*set_func
,
580 show_value_ftype
*show_func
,
581 struct cmd_list_element
**set_list
,
582 struct cmd_list_element
**show_list
)
584 add_setshow_cmd_full (name
, class, var_integer
, var
,
585 set_doc
, show_doc
, help_doc
,
591 /* Add element named NAME to both the set and show command LISTs (the
592 list for set/show or some sublist thereof). CLASS is as in
593 add_cmd. VAR is address of the variable which will contain the
594 value. SET_DOC and SHOW_DOC are the documentation strings. */
596 add_setshow_uinteger_cmd (char *name
, enum command_class
class,
598 const char *set_doc
, const char *show_doc
,
599 const char *help_doc
,
600 cmd_sfunc_ftype
*set_func
,
601 show_value_ftype
*show_func
,
602 struct cmd_list_element
**set_list
,
603 struct cmd_list_element
**show_list
)
605 add_setshow_cmd_full (name
, class, var_uinteger
, var
,
606 set_doc
, show_doc
, help_doc
,
612 /* Add element named NAME to both the set and show command LISTs (the
613 list for set/show or some sublist thereof). CLASS is as in
614 add_cmd. VAR is address of the variable which will contain the
615 value. SET_DOC and SHOW_DOC are the documentation strings. */
617 add_setshow_zinteger_cmd (char *name
, enum command_class
class,
619 const char *set_doc
, const char *show_doc
,
620 const char *help_doc
,
621 cmd_sfunc_ftype
*set_func
,
622 show_value_ftype
*show_func
,
623 struct cmd_list_element
**set_list
,
624 struct cmd_list_element
**show_list
)
626 add_setshow_cmd_full (name
, class, var_zinteger
, var
,
627 set_doc
, show_doc
, help_doc
,
633 /* Add element named NAME to both the set and show command LISTs (the
634 list for set/show or some sublist thereof). CLASS is as in
635 add_cmd. VAR is address of the variable which will contain the
636 value. SET_DOC and SHOW_DOC are the documentation strings. */
638 add_setshow_zuinteger_cmd (char *name
, enum command_class
class,
640 const char *set_doc
, const char *show_doc
,
641 const char *help_doc
,
642 cmd_sfunc_ftype
*set_func
,
643 show_value_ftype
*show_func
,
644 struct cmd_list_element
**set_list
,
645 struct cmd_list_element
**show_list
)
647 add_setshow_cmd_full (name
, class, var_zuinteger
, var
,
648 set_doc
, show_doc
, help_doc
,
654 /* Remove the command named NAME from the command list. Return the
655 list commands which were aliased to the deleted command. If the
656 command had no aliases, return NULL. The various *HOOKs are set to
657 the pre- and post-hook commands for the deleted command. If the
658 command does not have a hook, the corresponding out parameter is
661 static struct cmd_list_element
*
662 delete_cmd (char *name
, struct cmd_list_element
**list
,
663 struct cmd_list_element
**prehook
,
664 struct cmd_list_element
**prehookee
,
665 struct cmd_list_element
**posthook
,
666 struct cmd_list_element
**posthookee
)
668 struct cmd_list_element
*iter
;
669 struct cmd_list_element
**previous_chain_ptr
;
670 struct cmd_list_element
*aliases
= NULL
;
676 previous_chain_ptr
= list
;
678 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
680 if (strcmp (iter
->name
, name
) == 0)
683 iter
->destroyer (iter
, iter
->context
);
684 if (iter
->hookee_pre
)
685 iter
->hookee_pre
->hook_pre
= 0;
686 *prehook
= iter
->hook_pre
;
687 *prehookee
= iter
->hookee_pre
;
688 if (iter
->hookee_post
)
689 iter
->hookee_post
->hook_post
= 0;
690 *posthook
= iter
->hook_post
;
691 *posthookee
= iter
->hookee_post
;
693 /* Update the link. */
694 *previous_chain_ptr
= iter
->next
;
696 aliases
= iter
->aliases
;
698 /* If this command was an alias, remove it from the list of
700 if (iter
->cmd_pointer
)
702 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
703 struct cmd_list_element
*a
= *prevp
;
707 prevp
= &a
->alias_chain
;
710 *prevp
= iter
->alias_chain
;
715 /* We won't see another command with the same name. */
719 previous_chain_ptr
= &iter
->next
;
725 /* Shorthands to the commands above. */
727 /* Add an element to the list of info subcommands. */
729 struct cmd_list_element
*
730 add_info (char *name
, void (*fun
) (char *, int), char *doc
)
732 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
735 /* Add an alias to the list of info subcommands. */
737 struct cmd_list_element
*
738 add_info_alias (char *name
, char *oldname
, int abbrev_flag
)
740 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
743 /* Add an element to the list of commands. */
745 struct cmd_list_element
*
746 add_com (char *name
, enum command_class
class, void (*fun
) (char *, int),
749 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
752 /* Add an alias or abbreviation command to the list of commands. */
754 struct cmd_list_element
*
755 add_com_alias (char *name
, char *oldname
, enum command_class
class,
758 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
761 /* Recursively walk the commandlist structures, and print out the
762 documentation of commands that match our regex in either their
763 name, or their documentation.
766 apropos_cmd (struct ui_file
*stream
,
767 struct cmd_list_element
*commandlist
,
768 struct re_pattern_buffer
*regex
, char *prefix
)
770 struct cmd_list_element
*c
;
773 /* Walk through the commands. */
774 for (c
=commandlist
;c
;c
=c
->next
)
776 returnvalue
= -1; /* Needed to avoid double printing. */
779 /* Try to match against the name. */
780 returnvalue
= re_search (regex
, c
->name
, strlen(c
->name
),
781 0, strlen (c
->name
), NULL
);
782 if (returnvalue
>= 0)
784 print_help_for_command (c
, prefix
,
785 0 /* don't recurse */, stream
);
788 if (c
->doc
!= NULL
&& returnvalue
< 0)
790 /* Try to match against documentation. */
791 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
793 print_help_for_command (c
, prefix
,
794 0 /* don't recurse */, stream
);
797 /* Check if this command has subcommands and is not an
798 abbreviation. We skip listing subcommands of abbreviations
799 in order to avoid duplicates in the output. */
800 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
802 /* Recursively call ourselves on the subcommand list,
803 passing the right prefix in. */
804 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
809 /* This command really has to deal with two things:
810 1) I want documentation on *this string* (usually called by
813 2) I want documentation on *this list* (usually called by giving a
814 command that requires subcommands. Also called by saying just
817 I am going to split this into two seperate comamnds, help_cmd and
821 help_cmd (char *command
, struct ui_file
*stream
)
823 struct cmd_list_element
*c
;
824 extern struct cmd_list_element
*cmdlist
;
828 help_list (cmdlist
, "", all_classes
, stream
);
832 if (strcmp (command
, "all") == 0)
838 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
843 /* There are three cases here.
844 If c->prefixlist is nonzero, we have a prefix command.
845 Print its documentation, then list its subcommands.
847 If c->func is non NULL, we really have a command. Print its
848 documentation and return.
850 If c->func is NULL, we have a class name. Print its
851 documentation (as if it were a command) and then set class to the
852 number of this class so that the commands in the class will be
855 fputs_filtered (c
->doc
, stream
);
856 fputs_filtered ("\n", stream
);
858 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
860 fprintf_filtered (stream
, "\n");
862 /* If this is a prefix command, print it's subcommands. */
864 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
866 /* If this is a class name, print all of the commands in the class. */
868 help_list (cmdlist
, "", c
->class, stream
);
870 if (c
->hook_pre
|| c
->hook_post
)
871 fprintf_filtered (stream
,
872 "\nThis command has a hook (or hooks) defined:\n");
875 fprintf_filtered (stream
,
876 "\tThis command is run after : %s (pre hook)\n",
879 fprintf_filtered (stream
,
880 "\tThis command is run before : %s (post hook)\n",
885 * Get a specific kind of help on a command list.
888 * CMDTYPE is the prefix to use in the title string.
889 * CLASS is the class with which to list the nodes of this list (see
890 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
891 * everything, ALL_CLASSES for just classes, and non-negative for only things
892 * in a specific class.
893 * and STREAM is the output stream on which to print things.
894 * If you call this routine with a class >= 0, it recurses.
897 help_list (struct cmd_list_element
*list
, char *cmdtype
,
898 enum command_class
class, struct ui_file
*stream
)
901 char *cmdtype1
, *cmdtype2
;
903 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub".
905 len
= strlen (cmdtype
);
906 cmdtype1
= (char *) alloca (len
+ 1);
908 cmdtype2
= (char *) alloca (len
+ 4);
913 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
915 strncpy (cmdtype2
, cmdtype
, len
- 1);
916 strcpy (cmdtype2
+ len
- 1, " sub");
919 if (class == all_classes
)
920 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
922 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
924 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
926 if (class == all_classes
)
928 fprintf_filtered (stream
, "\n\
929 Type \"help%s\" followed by a class name for a list of commands in ",
932 fprintf_filtered (stream
, "that class.");
934 fprintf_filtered (stream
, "\n\
935 Type \"help all\" for the list of all commands.");
938 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
941 fputs_filtered ("for ", stream
);
943 fputs_filtered ("full ", stream
);
945 fputs_filtered ("documentation.\n", stream
);
946 fputs_filtered ("Type \"apropos word\" to search "
947 "for commands related to \"word\".\n", stream
);
948 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
953 help_all (struct ui_file
*stream
)
955 struct cmd_list_element
*c
;
956 extern struct cmd_list_element
*cmdlist
;
957 int seen_unclassified
= 0;
959 for (c
= cmdlist
; c
; c
= c
->next
)
963 /* If this is a class name, print all of the commands in the
968 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
969 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
973 /* While it's expected that all commands are in some class,
974 as a safety measure, we'll print commands outside of any
977 for (c
= cmdlist
; c
; c
= c
->next
)
982 if (c
->class == no_class
)
984 if (!seen_unclassified
)
986 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
987 seen_unclassified
= 1;
989 print_help_for_command (c
, "", 1, stream
);
995 /* Print only the first line of STR on STREAM. */
997 print_doc_line (struct ui_file
*stream
, char *str
)
999 static char *line_buffer
= 0;
1000 static int line_size
;
1006 line_buffer
= (char *) xmalloc (line_size
);
1010 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
1012 if (p
- str
> line_size
- 1)
1014 line_size
= p
- str
+ 1;
1015 xfree (line_buffer
);
1016 line_buffer
= (char *) xmalloc (line_size
);
1018 strncpy (line_buffer
, str
, p
- str
);
1019 line_buffer
[p
- str
] = '\0';
1020 if (islower (line_buffer
[0]))
1021 line_buffer
[0] = toupper (line_buffer
[0]);
1022 ui_out_text (current_uiout
, line_buffer
);
1025 /* Print one-line help for command C.
1026 If RECURSE is non-zero, also print one-line descriptions
1027 of all prefixed subcommands. */
1029 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
1030 struct ui_file
*stream
)
1032 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1033 print_doc_line (stream
, c
->doc
);
1034 fputs_filtered ("\n", stream
);
1037 && c
->prefixlist
!= 0
1038 && c
->abbrev_flag
== 0)
1039 /* Subcommands of a prefix command typically have 'all_commands'
1040 as class. If we pass CLASS to recursive invocation,
1041 most often we won't see anything. */
1042 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1046 * Implement a help command on command list LIST.
1047 * RECURSE should be non-zero if this should be done recursively on
1048 * all sublists of LIST.
1049 * PREFIX is the prefix to print before each command name.
1050 * STREAM is the stream upon which the output should be written.
1052 * A non-negative class number to list only commands in that
1054 * ALL_COMMANDS to list all commands in list.
1055 * ALL_CLASSES to list all classes in list.
1057 * Note that RECURSE will be active on *all* sublists, not just the
1058 * ones selected by the criteria above (ie. the selection mechanism
1059 * is at the low level, not the high-level).
1062 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1063 char *prefix
, int recurse
, struct ui_file
*stream
)
1065 struct cmd_list_element
*c
;
1067 for (c
= list
; c
; c
= c
->next
)
1069 if (c
->abbrev_flag
== 0
1070 && (class == all_commands
1071 || (class == all_classes
&& c
->func
== NULL
)
1072 || (class == c
->class && c
->func
!= NULL
)))
1074 print_help_for_command (c
, prefix
, recurse
, stream
);
1076 else if (c
->abbrev_flag
== 0 && recurse
1077 && class == class_user
&& c
->prefixlist
!= NULL
)
1078 /* User-defined commands may be subcommands. */
1079 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
,
1085 /* Search the input clist for 'command'. Return the command if
1086 found (or NULL if not), and return the number of commands
1089 static struct cmd_list_element
*
1090 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
1091 int ignore_help_classes
, int *nfound
)
1093 struct cmd_list_element
*found
, *c
;
1095 found
= (struct cmd_list_element
*) NULL
;
1097 for (c
= clist
; c
; c
= c
->next
)
1098 if (!strncmp (command
, c
->name
, len
)
1099 && (!ignore_help_classes
|| c
->func
))
1103 if (c
->name
[len
] == '\0')
1113 find_command_name_length (const char *text
)
1115 const char *p
= text
;
1117 /* Treating underscores as part of command words is important
1118 so that "set args_foo()" doesn't get interpreted as
1119 "set args _foo()". */
1120 /* Some characters are only used for TUI specific commands.
1121 However, they are always allowed for the sake of consistency.
1123 The XDB compatibility characters are only allowed when using the
1124 right mode because they clash with other GDB commands -
1125 specifically '/' is used as a suffix for print, examine and
1128 Note that this is larger than the character set allowed when
1129 creating user-defined commands. */
1131 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1132 /* Characters used by TUI specific commands. */
1133 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$'
1134 /* Characters used for XDB compatibility. */
1135 || (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')))
1141 /* This routine takes a line of TEXT and a CLIST in which to start the
1142 lookup. When it returns it will have incremented the text pointer past
1143 the section of text it matched, set *RESULT_LIST to point to the list in
1144 which the last word was matched, and will return a pointer to the cmd
1145 list element which the text matches. It will return NULL if no match at
1146 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1147 matches are possible; in this case *RESULT_LIST will be set to point to
1148 the list in which there are ambiguous choices (and *TEXT will be set to
1149 the ambiguous text string).
1151 If the located command was an abbreviation, this routine returns the base
1152 command of the abbreviation.
1154 It does no error reporting whatsoever; control will always return
1155 to the superior routine.
1157 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1158 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1159 if no prefix command was ever found. For example, in the case of "info a",
1160 "info" matches without ambiguity, but "a" could be "args" or "address", so
1161 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1162 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1163 list; it simply points to a specific command. In the case of an ambiguous
1164 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1165 "info t" can be "info types" or "info target"; upon return *TEXT has been
1166 advanced past "info ").
1168 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1169 affect the operation).
1171 This routine does *not* modify the text pointed to by TEXT.
1173 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1174 are actually help classes rather than commands (i.e. the function field of
1175 the struct cmd_list_element is NULL). */
1177 struct cmd_list_element
*
1178 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
1179 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1182 int len
, tmp
, nfound
;
1183 struct cmd_list_element
*found
, *c
;
1186 while (**text
== ' ' || **text
== '\t')
1189 /* Identify the name of the command. */
1190 len
= find_command_name_length (*text
);
1192 /* If nothing but whitespace, return 0. */
1196 /* *text and p now bracket the first command word to lookup (and
1197 it's length is len). We copy this into a local temporary. */
1200 command
= (char *) alloca (len
+ 1);
1201 memcpy (command
, *text
, len
);
1202 command
[len
] = '\0';
1207 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1209 /* We didn't find the command in the entered case, so lower case it
1210 and search again. */
1211 if (!found
|| nfound
== 0)
1213 for (tmp
= 0; tmp
< len
; tmp
++)
1215 char x
= command
[tmp
];
1217 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1219 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1222 /* If nothing matches, we have a simple failure. */
1228 if (result_list
!= NULL
)
1229 /* Will be modified in calling routine
1230 if we know what the prefix command is. */
1232 return CMD_LIST_AMBIGUOUS
; /* Ambiguous. */
1235 /* We've matched something on this list. Move text pointer forward. */
1239 if (found
->cmd_pointer
)
1241 /* We drop the alias (abbreviation) in favor of the command it
1242 is pointing to. If the alias is deprecated, though, we need to
1243 warn the user about it before we drop it. Note that while we
1244 are warning about the alias, we may also warn about the command
1245 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1248 if (found
->flags
& DEPRECATED_WARN_USER
)
1249 deprecated_cmd_warning (&line
);
1250 found
= found
->cmd_pointer
;
1252 /* If we found a prefix command, keep looking. */
1254 if (found
->prefixlist
)
1256 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1257 ignore_help_classes
);
1260 /* Didn't find anything; this is as far as we got. */
1261 if (result_list
!= NULL
)
1262 *result_list
= clist
;
1265 else if (c
== CMD_LIST_AMBIGUOUS
)
1267 /* We've gotten this far properly, but the next step is
1268 ambiguous. We need to set the result list to the best
1269 we've found (if an inferior hasn't already set it). */
1270 if (result_list
!= NULL
)
1272 /* This used to say *result_list = *found->prefixlist.
1273 If that was correct, need to modify the documentation
1274 at the top of this function to clarify what is
1275 supposed to be going on. */
1276 *result_list
= found
;
1287 if (result_list
!= NULL
)
1288 *result_list
= clist
;
1293 /* All this hair to move the space to the front of cmdtype */
1296 undef_cmd_error (char *cmdtype
, char *q
)
1298 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1301 *cmdtype
? " " : "",
1302 (int) strlen (cmdtype
) - 1,
1306 /* Look up the contents of *LINE as a command in the command list LIST.
1307 LIST is a chain of struct cmd_list_element's.
1308 If it is found, return the struct cmd_list_element for that command
1309 and update *LINE to point after the command name, at the first argument.
1310 If not found, call error if ALLOW_UNKNOWN is zero
1311 otherwise (or if error returns) return zero.
1312 Call error if specified command is ambiguous,
1313 unless ALLOW_UNKNOWN is negative.
1314 CMDTYPE precedes the word "command" in the error message.
1316 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1317 elements which are actually help classes rather than commands (i.e.
1318 the function field of the struct cmd_list_element is 0). */
1320 struct cmd_list_element
*
1321 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1322 int allow_unknown
, int ignore_help_classes
)
1324 struct cmd_list_element
*last_list
= 0;
1325 struct cmd_list_element
*c
;
1327 /* Note: Do not remove trailing whitespace here because this
1328 would be wrong for complete_command. Jim Kingdon */
1331 error (_("Lack of needed %scommand"), cmdtype
);
1333 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1340 int len
= find_command_name_length (*line
);
1342 q
= (char *) alloca (len
+ 1);
1343 strncpy (q
, *line
, len
);
1345 undef_cmd_error (cmdtype
, q
);
1350 else if (c
== CMD_LIST_AMBIGUOUS
)
1352 /* Ambigous. Local values should be off prefixlist or called
1354 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1356 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1357 struct cmd_list_element
*local_list
=
1358 (last_list
? *(last_list
->prefixlist
) : list
);
1360 if (local_allow_unknown
< 0)
1363 return last_list
; /* Found something. */
1365 return 0; /* Found nothing. */
1369 /* Report as error. */
1374 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1375 && (*line
)[amb_len
] != '\t');
1380 for (c
= local_list
; c
; c
= c
->next
)
1381 if (!strncmp (*line
, c
->name
, amb_len
))
1383 if (strlen (ambbuf
) + strlen (c
->name
) + 6
1384 < (int) sizeof ambbuf
)
1386 if (strlen (ambbuf
))
1387 strcat (ambbuf
, ", ");
1388 strcat (ambbuf
, c
->name
);
1392 strcat (ambbuf
, "..");
1396 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1398 return 0; /* lint */
1403 /* We've got something. It may still not be what the caller
1404 wants (if this command *needs* a subcommand). */
1405 while (**line
== ' ' || **line
== '\t')
1408 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1409 undef_cmd_error (c
->prefixname
, *line
);
1411 /* Seems to be what he wants. Return it. */
1417 /* We are here presumably because an alias or command in *TEXT is
1418 deprecated and a warning message should be generated. This
1419 function decodes *TEXT and potentially generates a warning message
1422 Example for 'set endian big' which has a fictitious alias 'seb'.
1424 If alias wasn't used in *TEXT, and the command is deprecated:
1425 "warning: 'set endian big' is deprecated."
1427 If alias was used, and only the alias is deprecated:
1428 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1430 If alias was used and command is deprecated (regardless of whether
1431 the alias itself is deprecated:
1433 "warning: 'set endian big' (seb) is deprecated."
1435 After the message has been sent, clear the appropriate flags in the
1436 command and/or the alias so the user is no longer bothered.
1440 deprecated_cmd_warning (char **text
)
1442 struct cmd_list_element
*alias
= NULL
;
1443 struct cmd_list_element
*prefix_cmd
= NULL
;
1444 struct cmd_list_element
*cmd
= NULL
;
1446 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1447 /* Return if text doesn't evaluate to a command. */
1450 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1451 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1452 /* Return if nothing is deprecated. */
1455 printf_filtered ("Warning:");
1457 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1458 printf_filtered (" '%s', an alias for the", alias
->name
);
1460 printf_filtered (" command '");
1463 printf_filtered ("%s", prefix_cmd
->prefixname
);
1465 printf_filtered ("%s", cmd
->name
);
1467 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1468 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1470 printf_filtered ("' is deprecated.\n");
1473 /* If it is only the alias that is deprecated, we want to indicate
1474 the new alias, otherwise we'll indicate the new command. */
1476 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1478 if (alias
->replacement
)
1479 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1481 printf_filtered ("No alternative known.\n\n");
1485 if (cmd
->replacement
)
1486 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1488 printf_filtered ("No alternative known.\n\n");
1491 /* We've warned you, now we'll keep quiet. */
1493 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1495 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1499 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1500 Return 1 on success, 0 on failure.
1502 If LINE refers to an alias, *alias will point to that alias.
1504 If LINE is a postfix command (i.e. one that is preceded by a prefix
1505 command) set *prefix_cmd.
1507 Set *cmd to point to the command LINE indicates.
1509 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1510 exist, they are NULL when we return.
1514 lookup_cmd_composition (char *text
,
1515 struct cmd_list_element
**alias
,
1516 struct cmd_list_element
**prefix_cmd
,
1517 struct cmd_list_element
**cmd
)
1520 int len
, tmp
, nfound
;
1521 struct cmd_list_element
*cur_list
;
1522 struct cmd_list_element
*prev_cmd
;
1532 /* Go through as many command lists as we need to,
1533 to find the command TEXT refers to. */
1537 while (*text
== ' ' || *text
== '\t')
1540 /* Identify the name of the command. */
1541 len
= find_command_name_length (text
);
1543 /* If nothing but whitespace, return. */
1547 /* Text is the start of the first command word to lookup (and
1548 it's length is len). We copy this into a local temporary. */
1550 command
= (char *) alloca (len
+ 1);
1551 memcpy (command
, text
, len
);
1552 command
[len
] = '\0';
1557 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1559 /* We didn't find the command in the entered case, so lower case
1560 it and search again.
1562 if (!*cmd
|| nfound
== 0)
1564 for (tmp
= 0; tmp
< len
; tmp
++)
1566 char x
= command
[tmp
];
1568 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1570 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1573 if (*cmd
== CMD_LIST_AMBIGUOUS
)
1575 return 0; /* ambiguous */
1579 return 0; /* nothing found */
1582 if ((*cmd
)->cmd_pointer
)
1584 /* cmd was actually an alias, we note that an alias was
1585 used (by assigning *alais) and we set *cmd. */
1587 *cmd
= (*cmd
)->cmd_pointer
;
1589 *prefix_cmd
= prev_cmd
;
1591 if ((*cmd
)->prefixlist
)
1592 cur_list
= *(*cmd
)->prefixlist
;
1600 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1602 /* Return a vector of char pointers which point to the different
1603 possible completions in LIST of TEXT.
1605 WORD points in the same buffer as TEXT, and completions should be
1606 returned relative to this position. For example, suppose TEXT is
1607 "foo" and we want to complete to "foobar". If WORD is "oo", return
1608 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1611 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1613 struct cmd_list_element
*ptr
;
1615 int sizeof_matchlist
;
1617 int textlen
= strlen (text
);
1619 int saw_deprecated_match
= 0;
1621 sizeof_matchlist
= 10;
1622 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1625 /* We do one or two passes. In the first pass, we skip deprecated
1626 commands. If we see no matching commands in the first pass, and
1627 if we did happen to see a matching deprecated command, we do
1628 another loop to collect those. */
1629 for (pass
= 0; matches
== 0 && pass
< 2; ++pass
)
1631 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1632 if (!strncmp (ptr
->name
, text
, textlen
)
1633 && !ptr
->abbrev_flag
1635 || ptr
->prefixlist
))
1639 if ((ptr
->flags
& CMD_DEPRECATED
) != 0)
1641 saw_deprecated_match
= 1;
1646 if (matches
== sizeof_matchlist
)
1648 sizeof_matchlist
*= 2;
1649 matchlist
= (char **) xrealloc ((char *) matchlist
,
1651 * sizeof (char *)));
1654 matchlist
[matches
] = (char *)
1655 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1657 strcpy (matchlist
[matches
], ptr
->name
);
1658 else if (word
> text
)
1660 /* Return some portion of ptr->name. */
1661 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1665 /* Return some of text plus ptr->name. */
1666 strncpy (matchlist
[matches
], word
, text
- word
);
1667 matchlist
[matches
][text
- word
] = '\0';
1668 strcat (matchlist
[matches
], ptr
->name
);
1672 /* If we saw no matching deprecated commands in the first pass,
1674 if (!saw_deprecated_match
)
1685 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1686 * sizeof (char *)));
1687 matchlist
[matches
] = (char *) 0;
1693 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1695 /* Return a vector of char pointers which point to the different
1696 possible completions in CMD of TEXT.
1698 WORD points in the same buffer as TEXT, and completions should be
1699 returned relative to this position. For example, suppose TEXT is "foo"
1700 and we want to complete to "foobar". If WORD is "oo", return
1701 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1704 complete_on_enum (const char *enumlist
[],
1709 int sizeof_matchlist
;
1711 int textlen
= strlen (text
);
1715 sizeof_matchlist
= 10;
1716 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1719 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1720 if (strncmp (name
, text
, textlen
) == 0)
1722 if (matches
== sizeof_matchlist
)
1724 sizeof_matchlist
*= 2;
1725 matchlist
= (char **) xrealloc ((char *) matchlist
,
1727 * sizeof (char *)));
1730 matchlist
[matches
] = (char *)
1731 xmalloc (strlen (word
) + strlen (name
) + 1);
1733 strcpy (matchlist
[matches
], name
);
1734 else if (word
> text
)
1736 /* Return some portion of name. */
1737 strcpy (matchlist
[matches
], name
+ (word
- text
));
1741 /* Return some of text plus name. */
1742 strncpy (matchlist
[matches
], word
, text
- word
);
1743 matchlist
[matches
][text
- word
] = '\0';
1744 strcat (matchlist
[matches
], name
);
1756 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1757 * sizeof (char *)));
1758 matchlist
[matches
] = (char *) 0;
1765 /* Check function pointer. */
1767 cmd_func_p (struct cmd_list_element
*cmd
)
1769 return (cmd
->func
!= NULL
);
1773 /* Call the command function. */
1775 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1777 if (cmd_func_p (cmd
))
1778 (*cmd
->func
) (cmd
, args
, from_tty
);
1780 error (_("Invalid command"));