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 Free Software Foundation, Inc.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 #include "gdb_regex.h"
23 #include "gdb_string.h"
24 #include "completer.h"
27 #include "cli/cli-cmds.h"
28 #include "cli/cli-decode.h"
31 #include "tui/tui.h" /* For tui_active et.al. */
34 #include "gdb_assert.h"
36 /* Prototypes for local functions */
38 static void undef_cmd_error (char *, char *);
40 static struct cmd_list_element
*delete_cmd (char *name
,
41 struct cmd_list_element
**list
,
42 struct cmd_list_element
**prehook
,
43 struct cmd_list_element
**prehookee
,
44 struct cmd_list_element
**posthook
,
45 struct cmd_list_element
**posthookee
);
47 static struct cmd_list_element
*find_cmd (char *command
,
49 struct cmd_list_element
*clist
,
50 int ignore_help_classes
,
53 static void help_all (struct ui_file
*stream
);
56 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
57 struct ui_file
*stream
);
60 /* Set the callback function for the specified command. For each both
61 the commands callback and func() are set. The latter set to a
62 bounce function (unless cfunc / sfunc is NULL that is). */
65 do_cfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
67 c
->function
.cfunc (args
, from_tty
); /* Ok. */
71 set_cmd_cfunc (struct cmd_list_element
*cmd
, cmd_cfunc_ftype
*cfunc
)
77 cmd
->function
.cfunc
= cfunc
; /* Ok. */
81 do_sfunc (struct cmd_list_element
*c
, char *args
, int from_tty
)
83 c
->function
.sfunc (args
, from_tty
, c
); /* Ok. */
87 set_cmd_sfunc (struct cmd_list_element
*cmd
, cmd_sfunc_ftype
*sfunc
)
93 cmd
->function
.sfunc
= sfunc
; /* Ok. */
97 cmd_cfunc_eq (struct cmd_list_element
*cmd
,
98 void (*cfunc
) (char *args
, int from_tty
))
100 return cmd
->func
== do_cfunc
&& cmd
->function
.cfunc
== cfunc
;
104 set_cmd_context (struct cmd_list_element
*cmd
, void *context
)
106 cmd
->context
= context
;
110 get_cmd_context (struct cmd_list_element
*cmd
)
116 cmd_type (struct cmd_list_element
*cmd
)
122 set_cmd_completer (struct cmd_list_element
*cmd
,
123 char **(*completer
) (struct cmd_list_element
*self
,
124 char *text
, char *word
))
126 cmd
->completer
= completer
; /* Ok. */
130 /* Add element named NAME.
131 CLASS is the top level category into which commands are broken down
133 FUN should be the function to execute the command;
134 it will get a character string as argument, with leading
135 and trailing blanks already eliminated.
137 DOC is a documentation string for the command.
138 Its first line should be a complete sentence.
139 It should start with ? for a command that is an abbreviation
140 or with * for a command that most users don't need to know about.
142 Add this command to command list *LIST.
144 Returns a pointer to the added command (not necessarily the head
147 struct cmd_list_element
*
148 add_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
149 char *doc
, struct cmd_list_element
**list
)
151 struct cmd_list_element
*c
152 = (struct cmd_list_element
*) xmalloc (sizeof (struct cmd_list_element
));
153 struct cmd_list_element
*p
, *iter
;
155 /* Turn each alias of the old command into an alias of the new
157 c
->aliases
= delete_cmd (name
, list
, &c
->hook_pre
, &c
->hookee_pre
,
158 &c
->hook_post
, &c
->hookee_post
);
159 for (iter
= c
->aliases
; iter
; iter
= iter
->alias_chain
)
160 iter
->cmd_pointer
= c
;
162 c
->hook_pre
->hookee_pre
= c
;
164 c
->hookee_pre
->hook_pre
= c
;
166 c
->hook_post
->hookee_post
= c
;
168 c
->hookee_post
->hook_post
= c
;
170 if (*list
== NULL
|| strcmp ((*list
)->name
, name
) >= 0)
178 while (p
->next
&& strcmp (p
->next
->name
, name
) <= 0)
188 set_cmd_cfunc (c
, fun
);
189 set_cmd_context (c
, NULL
);
192 c
->replacement
= NULL
;
193 c
->pre_show_hook
= NULL
;
195 c
->prefixlist
= NULL
;
196 c
->prefixname
= NULL
;
197 c
->allow_unknown
= 0;
199 set_cmd_completer (c
, make_symbol_completion_list_fn
);
201 c
->type
= not_set_cmd
;
203 c
->var_type
= var_boolean
;
205 c
->user_commands
= NULL
;
206 c
->cmd_pointer
= NULL
;
207 c
->alias_chain
= NULL
;
212 /* Deprecates a command CMD.
213 REPLACEMENT is the name of the command which should be used in place
214 of this command, or NULL if no such command exists.
216 This function does not check to see if command REPLACEMENT exists
217 since gdb may not have gotten around to adding REPLACEMENT when this
220 Returns a pointer to the deprecated command. */
222 struct cmd_list_element
*
223 deprecate_cmd (struct cmd_list_element
*cmd
, char *replacement
)
225 cmd
->flags
|= (CMD_DEPRECATED
| DEPRECATED_WARN_USER
);
227 if (replacement
!= NULL
)
228 cmd
->replacement
= replacement
;
230 cmd
->replacement
= NULL
;
235 struct cmd_list_element
*
236 add_alias_cmd (char *name
, char *oldname
, enum command_class
class,
237 int abbrev_flag
, struct cmd_list_element
**list
)
239 /* Must do this since lookup_cmd tries to side-effect its first arg */
241 struct cmd_list_element
*old
;
242 struct cmd_list_element
*c
;
244 copied_name
= (char *) alloca (strlen (oldname
) + 1);
245 strcpy (copied_name
, oldname
);
246 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
250 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
251 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
252 &prehook
, &prehookee
,
253 &posthook
, &posthookee
);
255 /* If this happens, it means a programmer error somewhere. */
256 gdb_assert (!aliases
&& !prehook
&& !prehookee
257 && !posthook
&& ! posthookee
);
261 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
262 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
264 c
->function
= old
->function
;
265 c
->prefixlist
= old
->prefixlist
;
266 c
->prefixname
= old
->prefixname
;
267 c
->allow_unknown
= old
->allow_unknown
;
268 c
->abbrev_flag
= abbrev_flag
;
269 c
->cmd_pointer
= old
;
270 c
->alias_chain
= old
->aliases
;
275 /* Like add_cmd but adds an element for a command prefix:
276 a name that should be followed by a subcommand to be looked up
277 in another command list. PREFIXLIST should be the address
278 of the variable containing that list. */
280 struct cmd_list_element
*
281 add_prefix_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
282 char *doc
, struct cmd_list_element
**prefixlist
,
283 char *prefixname
, int allow_unknown
,
284 struct cmd_list_element
**list
)
286 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
288 c
->prefixlist
= prefixlist
;
289 c
->prefixname
= prefixname
;
290 c
->allow_unknown
= allow_unknown
;
294 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
296 struct cmd_list_element
*
297 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
298 void (*fun
) (char *, int), char *doc
,
299 struct cmd_list_element
**prefixlist
, char *prefixname
,
300 int allow_unknown
, struct cmd_list_element
**list
)
302 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
304 c
->prefixlist
= prefixlist
;
305 c
->prefixname
= prefixname
;
306 c
->allow_unknown
= allow_unknown
;
311 /* This is an empty "cfunc". */
313 not_just_help_class_command (char *args
, int from_tty
)
317 /* This is an empty "sfunc". */
318 static void empty_sfunc (char *, int, struct cmd_list_element
*);
321 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
325 /* Add element named NAME to command list LIST (the list for set/show
326 or some sublist thereof).
327 TYPE is set_cmd or show_cmd.
328 CLASS is as in add_cmd.
329 VAR_TYPE is the kind of thing we are setting.
330 VAR is address of the variable being controlled by this command.
331 DOC is the documentation string. */
333 static struct cmd_list_element
*
334 add_set_or_show_cmd (char *name
,
336 enum command_class
class,
340 struct cmd_list_element
**list
)
342 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
344 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
346 c
->var_type
= var_type
;
348 /* This needs to be something besides NULL so that this isn't
349 treated as a help class. */
350 set_cmd_sfunc (c
, empty_sfunc
);
354 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
355 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
356 setting. VAR is address of the variable being controlled by this
357 command. SET_FUNC and SHOW_FUNC are the callback functions (if
358 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
359 strings. PRINT the format string to print the value. SET_RESULT
360 and SHOW_RESULT, if not NULL, are set to the resulting command
364 add_setshow_cmd_full (char *name
,
365 enum command_class
class,
366 var_types var_type
, void *var
,
367 const char *set_doc
, const char *show_doc
,
368 const char *help_doc
,
369 cmd_sfunc_ftype
*set_func
,
370 show_value_ftype
*show_func
,
371 struct cmd_list_element
**set_list
,
372 struct cmd_list_element
**show_list
,
373 struct cmd_list_element
**set_result
,
374 struct cmd_list_element
**show_result
)
376 struct cmd_list_element
*set
;
377 struct cmd_list_element
*show
;
381 if (help_doc
!= NULL
)
383 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
384 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
388 full_set_doc
= xstrdup (set_doc
);
389 full_show_doc
= xstrdup (show_doc
);
391 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
392 full_set_doc
, set_list
);
393 if (set_func
!= NULL
)
394 set_cmd_sfunc (set
, set_func
);
395 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
396 full_show_doc
, show_list
);
397 show
->show_value_func
= show_func
;
399 if (set_result
!= NULL
)
401 if (show_result
!= NULL
)
405 /* Add element named NAME to command list LIST (the list for set or
406 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
407 of strings which may follow NAME. VAR is address of the variable
408 which will contain the matching string (from ENUMLIST). */
411 add_setshow_enum_cmd (char *name
,
412 enum command_class
class,
413 const char *enumlist
[],
416 const char *show_doc
,
417 const char *help_doc
,
418 cmd_sfunc_ftype
*set_func
,
419 show_value_ftype
*show_func
,
420 struct cmd_list_element
**set_list
,
421 struct cmd_list_element
**show_list
)
423 struct cmd_list_element
*c
;
425 add_setshow_cmd_full (name
, class, var_enum
, var
,
426 set_doc
, show_doc
, help_doc
,
433 /* Add an auto-boolean command named NAME to both the set and show
434 command list lists. CLASS is as in add_cmd. VAR is address of the
435 variable which will contain the value. DOC is the documentation
436 string. FUNC is the corresponding callback. */
438 add_setshow_auto_boolean_cmd (char *name
,
439 enum command_class
class,
440 enum auto_boolean
*var
,
441 const char *set_doc
, const char *show_doc
,
442 const char *help_doc
,
443 cmd_sfunc_ftype
*set_func
,
444 show_value_ftype
*show_func
,
445 struct cmd_list_element
**set_list
,
446 struct cmd_list_element
**show_list
)
448 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
449 struct cmd_list_element
*c
;
451 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
452 set_doc
, show_doc
, help_doc
,
456 c
->enums
= auto_boolean_enums
;
459 /* Add element named NAME to both the set and show command LISTs (the
460 list for set/show or some sublist thereof). CLASS is as in
461 add_cmd. VAR is address of the variable which will contain the
462 value. SET_DOC and SHOW_DOC are the documentation strings. */
464 add_setshow_boolean_cmd (char *name
, enum command_class
class, int *var
,
465 const char *set_doc
, const char *show_doc
,
466 const char *help_doc
,
467 cmd_sfunc_ftype
*set_func
,
468 show_value_ftype
*show_func
,
469 struct cmd_list_element
**set_list
,
470 struct cmd_list_element
**show_list
)
472 static const char *boolean_enums
[] = { "on", "off", NULL
};
473 struct cmd_list_element
*c
;
475 add_setshow_cmd_full (name
, class, var_boolean
, var
,
476 set_doc
, show_doc
, help_doc
,
480 c
->enums
= boolean_enums
;
483 /* Add element named NAME to both the set and show command LISTs (the
484 list for set/show or some sublist thereof). */
486 add_setshow_filename_cmd (char *name
, enum command_class
class,
488 const char *set_doc
, const char *show_doc
,
489 const char *help_doc
,
490 cmd_sfunc_ftype
*set_func
,
491 show_value_ftype
*show_func
,
492 struct cmd_list_element
**set_list
,
493 struct cmd_list_element
**show_list
)
495 struct cmd_list_element
*set_result
;
497 add_setshow_cmd_full (name
, class, var_filename
, var
,
498 set_doc
, show_doc
, help_doc
,
502 set_cmd_completer (set_result
, filename_completer
);
505 /* Add element named NAME to both the set and show command LISTs (the
506 list for set/show or some sublist thereof). */
508 add_setshow_string_cmd (char *name
, enum command_class
class,
510 const char *set_doc
, const char *show_doc
,
511 const char *help_doc
,
512 cmd_sfunc_ftype
*set_func
,
513 show_value_ftype
*show_func
,
514 struct cmd_list_element
**set_list
,
515 struct cmd_list_element
**show_list
)
517 add_setshow_cmd_full (name
, class, var_string
, var
,
518 set_doc
, show_doc
, help_doc
,
524 /* Add element named NAME to both the set and show command LISTs (the
525 list for set/show or some sublist thereof). */
527 add_setshow_string_noescape_cmd (char *name
, enum command_class
class,
529 const char *set_doc
, const char *show_doc
,
530 const char *help_doc
,
531 cmd_sfunc_ftype
*set_func
,
532 show_value_ftype
*show_func
,
533 struct cmd_list_element
**set_list
,
534 struct cmd_list_element
**show_list
)
536 add_setshow_cmd_full (name
, class, var_string_noescape
, var
,
537 set_doc
, show_doc
, help_doc
,
543 /* Add element named NAME to both the set and show command LISTs (the
544 list for set/show or some sublist thereof). */
546 add_setshow_optional_filename_cmd (char *name
, enum command_class
class,
548 const char *set_doc
, const char *show_doc
,
549 const char *help_doc
,
550 cmd_sfunc_ftype
*set_func
,
551 show_value_ftype
*show_func
,
552 struct cmd_list_element
**set_list
,
553 struct cmd_list_element
**show_list
)
555 struct cmd_list_element
*set_result
;
557 add_setshow_cmd_full (name
, class, var_optional_filename
, var
,
558 set_doc
, show_doc
, help_doc
,
563 set_cmd_completer (set_result
, filename_completer
);
567 /* Add element named NAME to both the set and show command LISTs (the
568 list for set/show or some sublist thereof). CLASS is as in
569 add_cmd. VAR is address of the variable which will contain the
570 value. SET_DOC and SHOW_DOC are the documentation strings. */
572 add_setshow_integer_cmd (char *name
, enum command_class
class,
574 const char *set_doc
, const char *show_doc
,
575 const char *help_doc
,
576 cmd_sfunc_ftype
*set_func
,
577 show_value_ftype
*show_func
,
578 struct cmd_list_element
**set_list
,
579 struct cmd_list_element
**show_list
)
581 add_setshow_cmd_full (name
, class, var_integer
, var
,
582 set_doc
, show_doc
, help_doc
,
588 /* Add element named NAME to both the set and show command LISTs (the
589 list for set/show or some sublist thereof). CLASS is as in
590 add_cmd. VAR is address of the variable which will contain the
591 value. SET_DOC and SHOW_DOC are the documentation strings. */
593 add_setshow_uinteger_cmd (char *name
, enum command_class
class,
595 const char *set_doc
, const char *show_doc
,
596 const char *help_doc
,
597 cmd_sfunc_ftype
*set_func
,
598 show_value_ftype
*show_func
,
599 struct cmd_list_element
**set_list
,
600 struct cmd_list_element
**show_list
)
602 add_setshow_cmd_full (name
, class, var_uinteger
, var
,
603 set_doc
, show_doc
, help_doc
,
609 /* Add element named NAME to both the set and show command LISTs (the
610 list for set/show or some sublist thereof). CLASS is as in
611 add_cmd. VAR is address of the variable which will contain the
612 value. SET_DOC and SHOW_DOC are the documentation strings. */
614 add_setshow_zinteger_cmd (char *name
, enum command_class
class,
616 const char *set_doc
, const char *show_doc
,
617 const char *help_doc
,
618 cmd_sfunc_ftype
*set_func
,
619 show_value_ftype
*show_func
,
620 struct cmd_list_element
**set_list
,
621 struct cmd_list_element
**show_list
)
623 add_setshow_cmd_full (name
, class, var_zinteger
, var
,
624 set_doc
, show_doc
, help_doc
,
630 /* Add element named NAME to both the set and show command LISTs (the
631 list for set/show or some sublist thereof). CLASS is as in
632 add_cmd. VAR is address of the variable which will contain the
633 value. SET_DOC and SHOW_DOC are the documentation strings. */
635 add_setshow_zuinteger_cmd (char *name
, enum command_class
class,
637 const char *set_doc
, const char *show_doc
,
638 const char *help_doc
,
639 cmd_sfunc_ftype
*set_func
,
640 show_value_ftype
*show_func
,
641 struct cmd_list_element
**set_list
,
642 struct cmd_list_element
**show_list
)
644 add_setshow_cmd_full (name
, class, var_zuinteger
, var
,
645 set_doc
, show_doc
, help_doc
,
651 /* Remove the command named NAME from the command list. Return the
652 list commands which were aliased to the deleted command. If the
653 command had no aliases, return NULL. The various *HOOKs are set to
654 the pre- and post-hook commands for the deleted command. If the
655 command does not have a hook, the corresponding out parameter is
658 static struct cmd_list_element
*
659 delete_cmd (char *name
, struct cmd_list_element
**list
,
660 struct cmd_list_element
**prehook
,
661 struct cmd_list_element
**prehookee
,
662 struct cmd_list_element
**posthook
,
663 struct cmd_list_element
**posthookee
)
665 struct cmd_list_element
*iter
;
666 struct cmd_list_element
**previous_chain_ptr
;
667 struct cmd_list_element
*aliases
= NULL
;
673 previous_chain_ptr
= list
;
675 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
677 if (strcmp (iter
->name
, name
) == 0)
680 iter
->destroyer (iter
, iter
->context
);
681 if (iter
->hookee_pre
)
682 iter
->hookee_pre
->hook_pre
= 0;
683 *prehook
= iter
->hook_pre
;
684 *prehookee
= iter
->hookee_pre
;
685 if (iter
->hookee_post
)
686 iter
->hookee_post
->hook_post
= 0;
687 *posthook
= iter
->hook_post
;
688 *posthookee
= iter
->hookee_post
;
690 /* Update the link. */
691 *previous_chain_ptr
= iter
->next
;
693 aliases
= iter
->aliases
;
695 /* If this command was an alias, remove it from the list of
697 if (iter
->cmd_pointer
)
699 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
700 struct cmd_list_element
*a
= *prevp
;
704 prevp
= &a
->alias_chain
;
707 *prevp
= iter
->alias_chain
;
712 /* We won't see another command with the same name. */
716 previous_chain_ptr
= &iter
->next
;
722 /* Shorthands to the commands above. */
724 /* Add an element to the list of info subcommands. */
726 struct cmd_list_element
*
727 add_info (char *name
, void (*fun
) (char *, int), char *doc
)
729 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
732 /* Add an alias to the list of info subcommands. */
734 struct cmd_list_element
*
735 add_info_alias (char *name
, char *oldname
, int abbrev_flag
)
737 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
740 /* Add an element to the list of commands. */
742 struct cmd_list_element
*
743 add_com (char *name
, enum command_class
class, void (*fun
) (char *, int),
746 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
749 /* Add an alias or abbreviation command to the list of commands. */
751 struct cmd_list_element
*
752 add_com_alias (char *name
, char *oldname
, enum command_class
class,
755 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
758 /* Recursively walk the commandlist structures, and print out the
759 documentation of commands that match our regex in either their
760 name, or their documentation.
763 apropos_cmd (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
764 struct re_pattern_buffer
*regex
, char *prefix
)
766 struct cmd_list_element
*c
;
769 /* Walk through the commands */
770 for (c
=commandlist
;c
;c
=c
->next
)
772 returnvalue
= -1; /*Needed to avoid double printing*/
775 /* Try to match against the name*/
776 returnvalue
= re_search (regex
, c
->name
, strlen(c
->name
),
777 0, strlen (c
->name
), NULL
);
778 if (returnvalue
>= 0)
780 print_help_for_command (c
, prefix
,
781 0 /* don't recurse */, stream
);
784 if (c
->doc
!= NULL
&& returnvalue
< 0)
786 /* Try to match against documentation */
787 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
789 print_help_for_command (c
, prefix
,
790 0 /* don't recurse */, stream
);
793 /* Check if this command has subcommands and is not an abbreviation.
794 We skip listing subcommands of abbreviations in order to avoid
795 duplicates in the output.
797 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
799 /* Recursively call ourselves on the subcommand list,
800 passing the right prefix in.
802 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
807 /* This command really has to deal with two things:
808 * 1) I want documentation on *this string* (usually called by
809 * "help commandname").
810 * 2) I want documentation on *this list* (usually called by
811 * giving a command that requires subcommands. Also called by saying
814 * I am going to split this into two seperate comamnds, help_cmd and
819 help_cmd (char *command
, struct ui_file
*stream
)
821 struct cmd_list_element
*c
;
822 extern struct cmd_list_element
*cmdlist
;
826 help_list (cmdlist
, "", all_classes
, stream
);
830 if (strcmp (command
, "all") == 0)
836 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
841 /* There are three cases here.
842 If c->prefixlist is nonzero, we have a prefix command.
843 Print its documentation, then list its subcommands.
845 If c->func is non NULL, we really have a command. Print its
846 documentation and return.
848 If c->func is NULL, we have a class name. Print its
849 documentation (as if it were a command) and then set class to the
850 number of this class so that the commands in the class will be
853 fputs_filtered (c
->doc
, stream
);
854 fputs_filtered ("\n", stream
);
856 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
858 fprintf_filtered (stream
, "\n");
860 /* If this is a prefix command, print it's subcommands */
862 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
864 /* If this is a class name, print all of the commands in the class */
866 help_list (cmdlist
, "", c
->class, stream
);
868 if (c
->hook_pre
|| c
->hook_post
)
869 fprintf_filtered (stream
,
870 "\nThis command has a hook (or hooks) defined:\n");
873 fprintf_filtered (stream
,
874 "\tThis command is run after : %s (pre hook)\n",
877 fprintf_filtered (stream
,
878 "\tThis command is run before : %s (post hook)\n",
883 * Get a specific kind of help on a command list.
886 * CMDTYPE is the prefix to use in the title string.
887 * CLASS is the class with which to list the nodes of this list (see
888 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
889 * everything, ALL_CLASSES for just classes, and non-negative for only things
890 * in a specific class.
891 * and STREAM is the output stream on which to print things.
892 * If you call this routine with a class >= 0, it recurses.
895 help_list (struct cmd_list_element
*list
, char *cmdtype
,
896 enum command_class
class, struct ui_file
*stream
)
899 char *cmdtype1
, *cmdtype2
;
901 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
902 len
= strlen (cmdtype
);
903 cmdtype1
= (char *) alloca (len
+ 1);
905 cmdtype2
= (char *) alloca (len
+ 4);
910 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
912 strncpy (cmdtype2
, cmdtype
, len
- 1);
913 strcpy (cmdtype2
+ len
- 1, " sub");
916 if (class == all_classes
)
917 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
919 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
921 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
923 if (class == all_classes
)
925 fprintf_filtered (stream
, "\n\
926 Type \"help%s\" followed by a class name for a list of commands in ",
929 fprintf_filtered (stream
, "that class.");
931 fprintf_filtered (stream
, "\n\
932 Type \"help all\" for the list of all commands.");
935 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
938 fputs_filtered ("for ", stream
);
940 fputs_filtered ("full ", stream
);
942 fputs_filtered ("documentation.\n", stream
);
943 fputs_filtered ("Type \"apropos word\" to search "
944 "for commands related to \"word\".\n", stream
);
945 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
950 help_all (struct ui_file
*stream
)
952 struct cmd_list_element
*c
;
953 extern struct cmd_list_element
*cmdlist
;
954 int seen_unclassified
= 0;
956 for (c
= cmdlist
; c
; c
= c
->next
)
960 /* If this is a class name, print all of the commands in the class */
964 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
965 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
969 /* While it's expected that all commands are in some class,
970 as a safety measure, we'll print commands outside of any
973 for (c
= cmdlist
; c
; c
= c
->next
)
978 if (c
->class == no_class
)
980 if (!seen_unclassified
)
982 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
983 seen_unclassified
= 1;
985 print_help_for_command (c
, "", 1, stream
);
991 /* Print only the first line of STR on STREAM. */
993 print_doc_line (struct ui_file
*stream
, char *str
)
995 static char *line_buffer
= 0;
996 static int line_size
;
1002 line_buffer
= (char *) xmalloc (line_size
);
1006 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
1008 if (p
- str
> line_size
- 1)
1010 line_size
= p
- str
+ 1;
1011 xfree (line_buffer
);
1012 line_buffer
= (char *) xmalloc (line_size
);
1014 strncpy (line_buffer
, str
, p
- str
);
1015 line_buffer
[p
- str
] = '\0';
1016 if (islower (line_buffer
[0]))
1017 line_buffer
[0] = toupper (line_buffer
[0]);
1018 ui_out_text (uiout
, line_buffer
);
1021 /* Print one-line help for command C.
1022 If RECURSE is non-zero, also print one-line descriptions
1023 of all prefixed subcommands. */
1025 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
1026 struct ui_file
*stream
)
1028 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1029 print_doc_line (stream
, c
->doc
);
1030 fputs_filtered ("\n", stream
);
1033 && c
->prefixlist
!= 0
1034 && c
->abbrev_flag
== 0)
1035 /* Subcommands of a prefix command typically have 'all_commands'
1036 as class. If we pass CLASS to recursive invocation,
1037 most often we won't see anything. */
1038 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1042 * Implement a help command on command list LIST.
1043 * RECURSE should be non-zero if this should be done recursively on
1044 * all sublists of LIST.
1045 * PREFIX is the prefix to print before each command name.
1046 * STREAM is the stream upon which the output should be written.
1048 * A non-negative class number to list only commands in that
1050 * ALL_COMMANDS to list all commands in list.
1051 * ALL_CLASSES to list all classes in list.
1053 * Note that RECURSE will be active on *all* sublists, not just the
1054 * ones selected by the criteria above (ie. the selection mechanism
1055 * is at the low level, not the high-level).
1058 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1059 char *prefix
, int recurse
, struct ui_file
*stream
)
1061 struct cmd_list_element
*c
;
1063 for (c
= list
; c
; c
= c
->next
)
1065 if (c
->abbrev_flag
== 0
1066 && (class == all_commands
1067 || (class == all_classes
&& c
->func
== NULL
)
1068 || (class == c
->class && c
->func
!= NULL
)))
1070 print_help_for_command (c
, prefix
, recurse
, stream
);
1072 else if (c
->abbrev_flag
== 0 && recurse
1073 && class == class_user
&& c
->prefixlist
!= NULL
)
1074 /* User-defined commands may be subcommands. */
1075 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, recurse
, stream
);
1080 /* Search the input clist for 'command'. Return the command if
1081 found (or NULL if not), and return the number of commands
1084 static struct cmd_list_element
*
1085 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
1086 int ignore_help_classes
, int *nfound
)
1088 struct cmd_list_element
*found
, *c
;
1090 found
= (struct cmd_list_element
*) NULL
;
1092 for (c
= clist
; c
; c
= c
->next
)
1093 if (!strncmp (command
, c
->name
, len
)
1094 && (!ignore_help_classes
|| c
->func
))
1098 if (c
->name
[len
] == '\0')
1108 find_command_name_length (const char *text
)
1110 const char *p
= text
;
1112 /* Treating underscores as part of command words is important
1113 so that "set args_foo()" doesn't get interpreted as
1114 "set args _foo()". */
1115 /* Some characters are only used for TUI specific commands. However, they
1116 are always allowed for the sake of consistency.
1117 The XDB compatibility characters are only allowed when using the right
1118 mode because they clash with other GDB commands - specifically '/' is
1119 used as a suffix for print, examine and display.
1120 Note that this is larger than the character set allowed when creating
1121 user-defined commands. */
1122 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1123 /* Characters used by TUI specific commands. */
1124 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$'
1125 /* Characters used for XDB compatibility. */
1126 || (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')))
1132 /* This routine takes a line of TEXT and a CLIST in which to start the
1133 lookup. When it returns it will have incremented the text pointer past
1134 the section of text it matched, set *RESULT_LIST to point to the list in
1135 which the last word was matched, and will return a pointer to the cmd
1136 list element which the text matches. It will return NULL if no match at
1137 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1138 matches are possible; in this case *RESULT_LIST will be set to point to
1139 the list in which there are ambiguous choices (and *TEXT will be set to
1140 the ambiguous text string).
1142 If the located command was an abbreviation, this routine returns the base
1143 command of the abbreviation.
1145 It does no error reporting whatsoever; control will always return
1146 to the superior routine.
1148 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1149 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1150 if no prefix command was ever found. For example, in the case of "info a",
1151 "info" matches without ambiguity, but "a" could be "args" or "address", so
1152 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1153 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1154 list; it simply points to a specific command. In the case of an ambiguous
1155 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1156 "info t" can be "info types" or "info target"; upon return *TEXT has been
1157 advanced past "info ").
1159 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1160 affect the operation).
1162 This routine does *not* modify the text pointed to by TEXT.
1164 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1165 are actually help classes rather than commands (i.e. the function field of
1166 the struct cmd_list_element is NULL). */
1168 struct cmd_list_element
*
1169 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
1170 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1173 int len
, tmp
, nfound
;
1174 struct cmd_list_element
*found
, *c
;
1177 while (**text
== ' ' || **text
== '\t')
1180 /* Identify the name of the command. */
1181 len
= find_command_name_length (*text
);
1183 /* If nothing but whitespace, return 0. */
1187 /* *text and p now bracket the first command word to lookup (and
1188 it's length is len). We copy this into a local temporary */
1191 command
= (char *) alloca (len
+ 1);
1192 memcpy (command
, *text
, len
);
1193 command
[len
] = '\0';
1198 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1201 ** We didn't find the command in the entered case, so lower case it
1202 ** and search again.
1204 if (!found
|| nfound
== 0)
1206 for (tmp
= 0; tmp
< len
; tmp
++)
1208 char x
= command
[tmp
];
1210 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1212 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1215 /* If nothing matches, we have a simple failure. */
1221 if (result_list
!= NULL
)
1222 /* Will be modified in calling routine
1223 if we know what the prefix command is. */
1225 return (struct cmd_list_element
*) -1; /* Ambiguous. */
1228 /* We've matched something on this list. Move text pointer forward. */
1232 if (found
->cmd_pointer
)
1234 /* We drop the alias (abbreviation) in favor of the command it is
1235 pointing to. If the alias is deprecated, though, we need to
1236 warn the user about it before we drop it. Note that while we
1237 are warning about the alias, we may also warn about the command
1238 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1241 if (found
->flags
& DEPRECATED_WARN_USER
)
1242 deprecated_cmd_warning (&line
);
1243 found
= found
->cmd_pointer
;
1245 /* If we found a prefix command, keep looking. */
1247 if (found
->prefixlist
)
1249 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1250 ignore_help_classes
);
1253 /* Didn't find anything; this is as far as we got. */
1254 if (result_list
!= NULL
)
1255 *result_list
= clist
;
1258 else if (c
== (struct cmd_list_element
*) -1)
1260 /* We've gotten this far properly, but the next step
1261 is ambiguous. We need to set the result list to the best
1262 we've found (if an inferior hasn't already set it). */
1263 if (result_list
!= NULL
)
1265 /* This used to say *result_list = *found->prefixlist
1266 If that was correct, need to modify the documentation
1267 at the top of this function to clarify what is supposed
1269 *result_list
= found
;
1280 if (result_list
!= NULL
)
1281 *result_list
= clist
;
1286 /* All this hair to move the space to the front of cmdtype */
1289 undef_cmd_error (char *cmdtype
, char *q
)
1291 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1294 *cmdtype
? " " : "",
1295 (int) strlen (cmdtype
) - 1,
1299 /* Look up the contents of *LINE as a command in the command list LIST.
1300 LIST is a chain of struct cmd_list_element's.
1301 If it is found, return the struct cmd_list_element for that command
1302 and update *LINE to point after the command name, at the first argument.
1303 If not found, call error if ALLOW_UNKNOWN is zero
1304 otherwise (or if error returns) return zero.
1305 Call error if specified command is ambiguous,
1306 unless ALLOW_UNKNOWN is negative.
1307 CMDTYPE precedes the word "command" in the error message.
1309 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1310 elements which are actually help classes rather than commands (i.e.
1311 the function field of the struct cmd_list_element is 0). */
1313 struct cmd_list_element
*
1314 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1315 int allow_unknown
, int ignore_help_classes
)
1317 struct cmd_list_element
*last_list
= 0;
1318 struct cmd_list_element
*c
;
1320 /* Note: Do not remove trailing whitespace here because this
1321 would be wrong for complete_command. Jim Kingdon */
1324 error (_("Lack of needed %scommand"), cmdtype
);
1326 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1333 int len
= find_command_name_length (*line
);
1335 q
= (char *) alloca (len
+ 1);
1336 strncpy (q
, *line
, len
);
1338 undef_cmd_error (cmdtype
, q
);
1343 else if (c
== (struct cmd_list_element
*) -1)
1345 /* Ambigous. Local values should be off prefixlist or called
1347 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1349 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1350 struct cmd_list_element
*local_list
=
1351 (last_list
? *(last_list
->prefixlist
) : list
);
1353 if (local_allow_unknown
< 0)
1356 return last_list
; /* Found something. */
1358 return 0; /* Found nothing. */
1362 /* Report as error. */
1367 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1368 && (*line
)[amb_len
] != '\t');
1373 for (c
= local_list
; c
; c
= c
->next
)
1374 if (!strncmp (*line
, c
->name
, amb_len
))
1376 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
1378 if (strlen (ambbuf
))
1379 strcat (ambbuf
, ", ");
1380 strcat (ambbuf
, c
->name
);
1384 strcat (ambbuf
, "..");
1388 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1390 return 0; /* lint */
1395 /* We've got something. It may still not be what the caller
1396 wants (if this command *needs* a subcommand). */
1397 while (**line
== ' ' || **line
== '\t')
1400 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1401 undef_cmd_error (c
->prefixname
, *line
);
1403 /* Seems to be what he wants. Return it. */
1409 /* We are here presumably because an alias or command in *TEXT is
1410 deprecated and a warning message should be generated. This function
1411 decodes *TEXT and potentially generates a warning message as outlined
1414 Example for 'set endian big' which has a fictitious alias 'seb'.
1416 If alias wasn't used in *TEXT, and the command is deprecated:
1417 "warning: 'set endian big' is deprecated."
1419 If alias was used, and only the alias is deprecated:
1420 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1422 If alias was used and command is deprecated (regardless of whether the
1423 alias itself is deprecated:
1425 "warning: 'set endian big' (seb) is deprecated."
1427 After the message has been sent, clear the appropriate flags in the
1428 command and/or the alias so the user is no longer bothered.
1432 deprecated_cmd_warning (char **text
)
1434 struct cmd_list_element
*alias
= NULL
;
1435 struct cmd_list_element
*prefix_cmd
= NULL
;
1436 struct cmd_list_element
*cmd
= NULL
;
1438 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1439 /* return if text doesn't evaluate to a command */
1442 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1443 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1444 /* return if nothing is deprecated */
1447 printf_filtered ("Warning:");
1449 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1450 printf_filtered (" '%s', an alias for the", alias
->name
);
1452 printf_filtered (" command '");
1455 printf_filtered ("%s", prefix_cmd
->prefixname
);
1457 printf_filtered ("%s", cmd
->name
);
1459 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1460 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1462 printf_filtered ("' is deprecated.\n");
1465 /* If it is only the alias that is deprecated, we want to indicate the
1466 new alias, otherwise we'll indicate the new command. */
1468 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1470 if (alias
->replacement
)
1471 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1473 printf_filtered ("No alternative known.\n\n");
1477 if (cmd
->replacement
)
1478 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1480 printf_filtered ("No alternative known.\n\n");
1483 /* We've warned you, now we'll keep quiet */
1485 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1487 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1492 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1493 Return 1 on success, 0 on failure.
1495 If LINE refers to an alias, *alias will point to that alias.
1497 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1498 command) set *prefix_cmd.
1500 Set *cmd to point to the command LINE indicates.
1502 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1503 exist, they are NULL when we return.
1507 lookup_cmd_composition (char *text
,
1508 struct cmd_list_element
**alias
,
1509 struct cmd_list_element
**prefix_cmd
,
1510 struct cmd_list_element
**cmd
)
1513 int len
, tmp
, nfound
;
1514 struct cmd_list_element
*cur_list
;
1515 struct cmd_list_element
*prev_cmd
;
1525 /* Go through as many command lists as we need to
1526 to find the command TEXT refers to. */
1530 while (*text
== ' ' || *text
== '\t')
1533 /* Identify the name of the command. */
1534 len
= find_command_name_length (text
);
1536 /* If nothing but whitespace, return. */
1540 /* Text is the start of the first command word to lookup (and
1541 it's length is len). We copy this into a local temporary. */
1543 command
= (char *) alloca (len
+ 1);
1544 memcpy (command
, text
, len
);
1545 command
[len
] = '\0';
1550 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1552 /* We didn't find the command in the entered case, so lower case it
1555 if (!*cmd
|| nfound
== 0)
1557 for (tmp
= 0; tmp
< len
; tmp
++)
1559 char x
= command
[tmp
];
1561 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1563 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1566 if (*cmd
== (struct cmd_list_element
*) -1)
1568 return 0; /* ambiguous */
1572 return 0; /* nothing found */
1575 if ((*cmd
)->cmd_pointer
)
1577 /* cmd was actually an alias, we note that an alias was used
1578 (by assigning *alais) and we set *cmd. */
1580 *cmd
= (*cmd
)->cmd_pointer
;
1582 *prefix_cmd
= prev_cmd
;
1584 if ((*cmd
)->prefixlist
)
1585 cur_list
= *(*cmd
)->prefixlist
;
1593 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1595 /* Return a vector of char pointers which point to the different
1596 possible completions in LIST of TEXT.
1598 WORD points in the same buffer as TEXT, and completions should be
1599 returned relative to this position. For example, suppose TEXT is "foo"
1600 and we want to complete to "foobar". If WORD is "oo", return
1601 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1604 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1606 struct cmd_list_element
*ptr
;
1608 int sizeof_matchlist
;
1610 int textlen
= strlen (text
);
1612 int saw_deprecated_match
= 0;
1614 sizeof_matchlist
= 10;
1615 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1618 /* We do one or two passes. In the first pass, we skip deprecated
1619 commands. If we see no matching commands in the first pass, and
1620 if we did happen to see a matching deprecated command, we do
1621 another loop to collect those. */
1622 for (pass
= 0; matches
== 0 && pass
< 2; ++pass
)
1624 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1625 if (!strncmp (ptr
->name
, text
, textlen
)
1626 && !ptr
->abbrev_flag
1628 || ptr
->prefixlist
))
1632 if ((ptr
->flags
& CMD_DEPRECATED
) != 0)
1634 saw_deprecated_match
= 1;
1639 if (matches
== sizeof_matchlist
)
1641 sizeof_matchlist
*= 2;
1642 matchlist
= (char **) xrealloc ((char *) matchlist
,
1644 * sizeof (char *)));
1647 matchlist
[matches
] = (char *)
1648 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1650 strcpy (matchlist
[matches
], ptr
->name
);
1651 else if (word
> text
)
1653 /* Return some portion of ptr->name. */
1654 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1658 /* Return some of text plus ptr->name. */
1659 strncpy (matchlist
[matches
], word
, text
- word
);
1660 matchlist
[matches
][text
- word
] = '\0';
1661 strcat (matchlist
[matches
], ptr
->name
);
1665 /* If we saw no matching deprecated commands in the first pass,
1667 if (!saw_deprecated_match
)
1678 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1679 * sizeof (char *)));
1680 matchlist
[matches
] = (char *) 0;
1686 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1688 /* Return a vector of char pointers which point to the different
1689 possible completions in CMD of TEXT.
1691 WORD points in the same buffer as TEXT, and completions should be
1692 returned relative to this position. For example, suppose TEXT is "foo"
1693 and we want to complete to "foobar". If WORD is "oo", return
1694 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1697 complete_on_enum (const char *enumlist
[],
1702 int sizeof_matchlist
;
1704 int textlen
= strlen (text
);
1708 sizeof_matchlist
= 10;
1709 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1712 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1713 if (strncmp (name
, text
, textlen
) == 0)
1715 if (matches
== sizeof_matchlist
)
1717 sizeof_matchlist
*= 2;
1718 matchlist
= (char **) xrealloc ((char *) matchlist
,
1720 * sizeof (char *)));
1723 matchlist
[matches
] = (char *)
1724 xmalloc (strlen (word
) + strlen (name
) + 1);
1726 strcpy (matchlist
[matches
], name
);
1727 else if (word
> text
)
1729 /* Return some portion of name. */
1730 strcpy (matchlist
[matches
], name
+ (word
- text
));
1734 /* Return some of text plus name. */
1735 strncpy (matchlist
[matches
], word
, text
- word
);
1736 matchlist
[matches
][text
- word
] = '\0';
1737 strcat (matchlist
[matches
], name
);
1749 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1750 * sizeof (char *)));
1751 matchlist
[matches
] = (char *) 0;
1758 /* check function pointer */
1760 cmd_func_p (struct cmd_list_element
*cmd
)
1762 return (cmd
->func
!= NULL
);
1766 /* call the command function */
1768 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1770 if (cmd_func_p (cmd
))
1771 (*cmd
->func
) (cmd
, args
, from_tty
);
1773 error (_("Invalid command"));