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
;
243 copied_name
= (char *) alloca (strlen (oldname
) + 1);
244 strcpy (copied_name
, oldname
);
245 old
= lookup_cmd (&copied_name
, *list
, "", 1, 1);
249 struct cmd_list_element
*prehook
, *prehookee
, *posthook
, *posthookee
;
250 struct cmd_list_element
*aliases
= delete_cmd (name
, list
,
251 &prehook
, &prehookee
,
252 &posthook
, &posthookee
);
253 /* If this happens, it means a programmer error somewhere. */
254 gdb_assert (!aliases
&& !prehook
&& !prehookee
255 && !posthook
&& ! posthookee
);
259 c
= add_cmd (name
, class, NULL
, old
->doc
, list
);
260 /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */
262 c
->function
= old
->function
;
263 c
->prefixlist
= old
->prefixlist
;
264 c
->prefixname
= old
->prefixname
;
265 c
->allow_unknown
= old
->allow_unknown
;
266 c
->abbrev_flag
= abbrev_flag
;
267 c
->cmd_pointer
= old
;
268 c
->alias_chain
= old
->aliases
;
273 /* Like add_cmd but adds an element for a command prefix:
274 a name that should be followed by a subcommand to be looked up
275 in another command list. PREFIXLIST should be the address
276 of the variable containing that list. */
278 struct cmd_list_element
*
279 add_prefix_cmd (char *name
, enum command_class
class, void (*fun
) (char *, int),
280 char *doc
, struct cmd_list_element
**prefixlist
,
281 char *prefixname
, int allow_unknown
,
282 struct cmd_list_element
**list
)
284 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
285 c
->prefixlist
= prefixlist
;
286 c
->prefixname
= prefixname
;
287 c
->allow_unknown
= allow_unknown
;
291 /* Like add_prefix_cmd but sets the abbrev_flag on the new command. */
293 struct cmd_list_element
*
294 add_abbrev_prefix_cmd (char *name
, enum command_class
class,
295 void (*fun
) (char *, int), char *doc
,
296 struct cmd_list_element
**prefixlist
, char *prefixname
,
297 int allow_unknown
, struct cmd_list_element
**list
)
299 struct cmd_list_element
*c
= add_cmd (name
, class, fun
, doc
, list
);
300 c
->prefixlist
= prefixlist
;
301 c
->prefixname
= prefixname
;
302 c
->allow_unknown
= allow_unknown
;
307 /* This is an empty "cfunc". */
309 not_just_help_class_command (char *args
, int from_tty
)
313 /* This is an empty "sfunc". */
314 static void empty_sfunc (char *, int, struct cmd_list_element
*);
317 empty_sfunc (char *args
, int from_tty
, struct cmd_list_element
*c
)
321 /* Add element named NAME to command list LIST (the list for set/show
322 or some sublist thereof).
323 TYPE is set_cmd or show_cmd.
324 CLASS is as in add_cmd.
325 VAR_TYPE is the kind of thing we are setting.
326 VAR is address of the variable being controlled by this command.
327 DOC is the documentation string. */
329 static struct cmd_list_element
*
330 add_set_or_show_cmd (char *name
,
332 enum command_class
class,
336 struct cmd_list_element
**list
)
338 struct cmd_list_element
*c
= add_cmd (name
, class, NULL
, doc
, list
);
339 gdb_assert (type
== set_cmd
|| type
== show_cmd
);
341 c
->var_type
= var_type
;
343 /* This needs to be something besides NULL so that this isn't
344 treated as a help class. */
345 set_cmd_sfunc (c
, empty_sfunc
);
349 /* Add element named NAME to both the command SET_LIST and SHOW_LIST.
350 CLASS is as in add_cmd. VAR_TYPE is the kind of thing we are
351 setting. VAR is address of the variable being controlled by this
352 command. SET_FUNC and SHOW_FUNC are the callback functions (if
353 non-NULL). SET_DOC, SHOW_DOC and HELP_DOC are the documentation
354 strings. PRINT the format string to print the value. SET_RESULT
355 and SHOW_RESULT, if not NULL, are set to the resulting command
359 add_setshow_cmd_full (char *name
,
360 enum command_class
class,
361 var_types var_type
, void *var
,
362 const char *set_doc
, const char *show_doc
,
363 const char *help_doc
,
364 cmd_sfunc_ftype
*set_func
,
365 show_value_ftype
*show_func
,
366 struct cmd_list_element
**set_list
,
367 struct cmd_list_element
**show_list
,
368 struct cmd_list_element
**set_result
,
369 struct cmd_list_element
**show_result
)
371 struct cmd_list_element
*set
;
372 struct cmd_list_element
*show
;
376 if (help_doc
!= NULL
)
378 full_set_doc
= xstrprintf ("%s\n%s", set_doc
, help_doc
);
379 full_show_doc
= xstrprintf ("%s\n%s", show_doc
, help_doc
);
383 full_set_doc
= xstrdup (set_doc
);
384 full_show_doc
= xstrdup (show_doc
);
386 set
= add_set_or_show_cmd (name
, set_cmd
, class, var_type
, var
,
387 full_set_doc
, set_list
);
388 if (set_func
!= NULL
)
389 set_cmd_sfunc (set
, set_func
);
390 show
= add_set_or_show_cmd (name
, show_cmd
, class, var_type
, var
,
391 full_show_doc
, show_list
);
392 show
->show_value_func
= show_func
;
394 if (set_result
!= NULL
)
396 if (show_result
!= NULL
)
400 /* Add element named NAME to command list LIST (the list for set or
401 some sublist thereof). CLASS is as in add_cmd. ENUMLIST is a list
402 of strings which may follow NAME. VAR is address of the variable
403 which will contain the matching string (from ENUMLIST). */
406 add_setshow_enum_cmd (char *name
,
407 enum command_class
class,
408 const char *enumlist
[],
411 const char *show_doc
,
412 const char *help_doc
,
413 cmd_sfunc_ftype
*set_func
,
414 show_value_ftype
*show_func
,
415 struct cmd_list_element
**set_list
,
416 struct cmd_list_element
**show_list
)
418 struct cmd_list_element
*c
;
419 add_setshow_cmd_full (name
, class, var_enum
, var
,
420 set_doc
, show_doc
, help_doc
,
427 /* Add an auto-boolean command named NAME to both the set and show
428 command list lists. CLASS is as in add_cmd. VAR is address of the
429 variable which will contain the value. DOC is the documentation
430 string. FUNC is the corresponding callback. */
432 add_setshow_auto_boolean_cmd (char *name
,
433 enum command_class
class,
434 enum auto_boolean
*var
,
435 const char *set_doc
, const char *show_doc
,
436 const char *help_doc
,
437 cmd_sfunc_ftype
*set_func
,
438 show_value_ftype
*show_func
,
439 struct cmd_list_element
**set_list
,
440 struct cmd_list_element
**show_list
)
442 static const char *auto_boolean_enums
[] = { "on", "off", "auto", NULL
};
443 struct cmd_list_element
*c
;
444 add_setshow_cmd_full (name
, class, var_auto_boolean
, var
,
445 set_doc
, show_doc
, help_doc
,
449 c
->enums
= auto_boolean_enums
;
452 /* Add element named NAME to both the set and show command LISTs (the
453 list for set/show or some sublist thereof). CLASS is as in
454 add_cmd. VAR is address of the variable which will contain the
455 value. SET_DOC and SHOW_DOC are the documentation strings. */
457 add_setshow_boolean_cmd (char *name
, enum command_class
class, int *var
,
458 const char *set_doc
, const char *show_doc
,
459 const char *help_doc
,
460 cmd_sfunc_ftype
*set_func
,
461 show_value_ftype
*show_func
,
462 struct cmd_list_element
**set_list
,
463 struct cmd_list_element
**show_list
)
465 static const char *boolean_enums
[] = { "on", "off", NULL
};
466 struct cmd_list_element
*c
;
467 add_setshow_cmd_full (name
, class, var_boolean
, var
,
468 set_doc
, show_doc
, help_doc
,
472 c
->enums
= boolean_enums
;
475 /* Add element named NAME to both the set and show command LISTs (the
476 list for set/show or some sublist thereof). */
478 add_setshow_filename_cmd (char *name
, enum command_class
class,
480 const char *set_doc
, const char *show_doc
,
481 const char *help_doc
,
482 cmd_sfunc_ftype
*set_func
,
483 show_value_ftype
*show_func
,
484 struct cmd_list_element
**set_list
,
485 struct cmd_list_element
**show_list
)
487 struct cmd_list_element
*set_result
;
488 add_setshow_cmd_full (name
, class, var_filename
, var
,
489 set_doc
, show_doc
, help_doc
,
493 set_cmd_completer (set_result
, filename_completer
);
496 /* Add element named NAME to both the set and show command LISTs (the
497 list for set/show or some sublist thereof). */
499 add_setshow_string_cmd (char *name
, enum command_class
class,
501 const char *set_doc
, const char *show_doc
,
502 const char *help_doc
,
503 cmd_sfunc_ftype
*set_func
,
504 show_value_ftype
*show_func
,
505 struct cmd_list_element
**set_list
,
506 struct cmd_list_element
**show_list
)
508 add_setshow_cmd_full (name
, class, var_string
, var
,
509 set_doc
, show_doc
, help_doc
,
515 /* Add element named NAME to both the set and show command LISTs (the
516 list for set/show or some sublist thereof). */
518 add_setshow_string_noescape_cmd (char *name
, enum command_class
class,
520 const char *set_doc
, const char *show_doc
,
521 const char *help_doc
,
522 cmd_sfunc_ftype
*set_func
,
523 show_value_ftype
*show_func
,
524 struct cmd_list_element
**set_list
,
525 struct cmd_list_element
**show_list
)
527 add_setshow_cmd_full (name
, class, var_string_noescape
, var
,
528 set_doc
, show_doc
, help_doc
,
534 /* Add element named NAME to both the set and show command LISTs (the
535 list for set/show or some sublist thereof). */
537 add_setshow_optional_filename_cmd (char *name
, enum command_class
class,
539 const char *set_doc
, const char *show_doc
,
540 const char *help_doc
,
541 cmd_sfunc_ftype
*set_func
,
542 show_value_ftype
*show_func
,
543 struct cmd_list_element
**set_list
,
544 struct cmd_list_element
**show_list
)
546 struct cmd_list_element
*set_result
;
548 add_setshow_cmd_full (name
, class, var_optional_filename
, var
,
549 set_doc
, show_doc
, help_doc
,
554 set_cmd_completer (set_result
, filename_completer
);
558 /* Add element named NAME to both the set and show command LISTs (the
559 list for set/show or some sublist thereof). CLASS is as in
560 add_cmd. VAR is address of the variable which will contain the
561 value. SET_DOC and SHOW_DOC are the documentation strings. */
563 add_setshow_integer_cmd (char *name
, enum command_class
class,
565 const char *set_doc
, const char *show_doc
,
566 const char *help_doc
,
567 cmd_sfunc_ftype
*set_func
,
568 show_value_ftype
*show_func
,
569 struct cmd_list_element
**set_list
,
570 struct cmd_list_element
**show_list
)
572 add_setshow_cmd_full (name
, class, var_integer
, var
,
573 set_doc
, show_doc
, help_doc
,
579 /* Add element named NAME to both the set and show command LISTs (the
580 list for set/show or some sublist thereof). CLASS is as in
581 add_cmd. VAR is address of the variable which will contain the
582 value. SET_DOC and SHOW_DOC are the documentation strings. */
584 add_setshow_uinteger_cmd (char *name
, enum command_class
class,
586 const char *set_doc
, const char *show_doc
,
587 const char *help_doc
,
588 cmd_sfunc_ftype
*set_func
,
589 show_value_ftype
*show_func
,
590 struct cmd_list_element
**set_list
,
591 struct cmd_list_element
**show_list
)
593 add_setshow_cmd_full (name
, class, var_uinteger
, var
,
594 set_doc
, show_doc
, help_doc
,
600 /* Add element named NAME to both the set and show command LISTs (the
601 list for set/show or some sublist thereof). CLASS is as in
602 add_cmd. VAR is address of the variable which will contain the
603 value. SET_DOC and SHOW_DOC are the documentation strings. */
605 add_setshow_zinteger_cmd (char *name
, enum command_class
class,
607 const char *set_doc
, const char *show_doc
,
608 const char *help_doc
,
609 cmd_sfunc_ftype
*set_func
,
610 show_value_ftype
*show_func
,
611 struct cmd_list_element
**set_list
,
612 struct cmd_list_element
**show_list
)
614 add_setshow_cmd_full (name
, class, var_zinteger
, var
,
615 set_doc
, show_doc
, help_doc
,
621 /* Add element named NAME to both the set and show command LISTs (the
622 list for set/show or some sublist thereof). CLASS is as in
623 add_cmd. VAR is address of the variable which will contain the
624 value. SET_DOC and SHOW_DOC are the documentation strings. */
626 add_setshow_zuinteger_cmd (char *name
, enum command_class
class,
628 const char *set_doc
, const char *show_doc
,
629 const char *help_doc
,
630 cmd_sfunc_ftype
*set_func
,
631 show_value_ftype
*show_func
,
632 struct cmd_list_element
**set_list
,
633 struct cmd_list_element
**show_list
)
635 add_setshow_cmd_full (name
, class, var_zuinteger
, var
,
636 set_doc
, show_doc
, help_doc
,
642 /* Remove the command named NAME from the command list. Return the
643 list commands which were aliased to the deleted command. If the
644 command had no aliases, return NULL. The various *HOOKs are set to
645 the pre- and post-hook commands for the deleted command. If the
646 command does not have a hook, the corresponding out parameter is
649 static struct cmd_list_element
*
650 delete_cmd (char *name
, struct cmd_list_element
**list
,
651 struct cmd_list_element
**prehook
,
652 struct cmd_list_element
**prehookee
,
653 struct cmd_list_element
**posthook
,
654 struct cmd_list_element
**posthookee
)
656 struct cmd_list_element
*iter
;
657 struct cmd_list_element
**previous_chain_ptr
;
658 struct cmd_list_element
*aliases
= NULL
;
664 previous_chain_ptr
= list
;
666 for (iter
= *previous_chain_ptr
; iter
; iter
= *previous_chain_ptr
)
668 if (strcmp (iter
->name
, name
) == 0)
671 iter
->destroyer (iter
, iter
->context
);
672 if (iter
->hookee_pre
)
673 iter
->hookee_pre
->hook_pre
= 0;
674 *prehook
= iter
->hook_pre
;
675 *prehookee
= iter
->hookee_pre
;
676 if (iter
->hookee_post
)
677 iter
->hookee_post
->hook_post
= 0;
678 *posthook
= iter
->hook_post
;
679 *posthookee
= iter
->hookee_post
;
681 /* Update the link. */
682 *previous_chain_ptr
= iter
->next
;
684 aliases
= iter
->aliases
;
686 /* If this command was an alias, remove it from the list of
688 if (iter
->cmd_pointer
)
690 struct cmd_list_element
**prevp
= &iter
->cmd_pointer
->aliases
;
691 struct cmd_list_element
*a
= *prevp
;
695 prevp
= &a
->alias_chain
;
698 *prevp
= iter
->alias_chain
;
703 /* We won't see another command with the same name. */
707 previous_chain_ptr
= &iter
->next
;
713 /* Shorthands to the commands above. */
715 /* Add an element to the list of info subcommands. */
717 struct cmd_list_element
*
718 add_info (char *name
, void (*fun
) (char *, int), char *doc
)
720 return add_cmd (name
, no_class
, fun
, doc
, &infolist
);
723 /* Add an alias to the list of info subcommands. */
725 struct cmd_list_element
*
726 add_info_alias (char *name
, char *oldname
, int abbrev_flag
)
728 return add_alias_cmd (name
, oldname
, 0, abbrev_flag
, &infolist
);
731 /* Add an element to the list of commands. */
733 struct cmd_list_element
*
734 add_com (char *name
, enum command_class
class, void (*fun
) (char *, int),
737 return add_cmd (name
, class, fun
, doc
, &cmdlist
);
740 /* Add an alias or abbreviation command to the list of commands. */
742 struct cmd_list_element
*
743 add_com_alias (char *name
, char *oldname
, enum command_class
class,
746 return add_alias_cmd (name
, oldname
, class, abbrev_flag
, &cmdlist
);
749 /* Recursively walk the commandlist structures, and print out the
750 documentation of commands that match our regex in either their
751 name, or their documentation.
754 apropos_cmd (struct ui_file
*stream
, struct cmd_list_element
*commandlist
,
755 struct re_pattern_buffer
*regex
, char *prefix
)
757 struct cmd_list_element
*c
;
759 /* Walk through the commands */
760 for (c
=commandlist
;c
;c
=c
->next
)
762 returnvalue
= -1; /*Needed to avoid double printing*/
765 /* Try to match against the name*/
766 returnvalue
=re_search(regex
,c
->name
,strlen(c
->name
),0,strlen(c
->name
),NULL
);
767 if (returnvalue
>= 0)
769 print_help_for_command (c
, prefix
,
770 0 /* don't recurse */, stream
);
773 if (c
->doc
!= NULL
&& returnvalue
< 0)
775 /* Try to match against documentation */
776 if (re_search(regex
,c
->doc
,strlen(c
->doc
),0,strlen(c
->doc
),NULL
) >=0)
778 print_help_for_command (c
, prefix
,
779 0 /* don't recurse */, stream
);
782 /* Check if this command has subcommands and is not an abbreviation.
783 We skip listing subcommands of abbreviations in order to avoid
784 duplicates in the output.
786 if (c
->prefixlist
!= NULL
&& !c
->abbrev_flag
)
788 /* Recursively call ourselves on the subcommand list,
789 passing the right prefix in.
791 apropos_cmd (stream
,*c
->prefixlist
,regex
,c
->prefixname
);
796 /* This command really has to deal with two things:
797 * 1) I want documentation on *this string* (usually called by
798 * "help commandname").
799 * 2) I want documentation on *this list* (usually called by
800 * giving a command that requires subcommands. Also called by saying
803 * I am going to split this into two seperate comamnds, help_cmd and
808 help_cmd (char *command
, struct ui_file
*stream
)
810 struct cmd_list_element
*c
;
811 extern struct cmd_list_element
*cmdlist
;
815 help_list (cmdlist
, "", all_classes
, stream
);
819 if (strcmp (command
, "all") == 0)
825 c
= lookup_cmd (&command
, cmdlist
, "", 0, 0);
830 /* There are three cases here.
831 If c->prefixlist is nonzero, we have a prefix command.
832 Print its documentation, then list its subcommands.
834 If c->func is non NULL, we really have a command. Print its
835 documentation and return.
837 If c->func is NULL, we have a class name. Print its
838 documentation (as if it were a command) and then set class to the
839 number of this class so that the commands in the class will be
842 fputs_filtered (c
->doc
, stream
);
843 fputs_filtered ("\n", stream
);
845 if (c
->prefixlist
== 0 && c
->func
!= NULL
)
847 fprintf_filtered (stream
, "\n");
849 /* If this is a prefix command, print it's subcommands */
851 help_list (*c
->prefixlist
, c
->prefixname
, all_commands
, stream
);
853 /* If this is a class name, print all of the commands in the class */
855 help_list (cmdlist
, "", c
->class, stream
);
857 if (c
->hook_pre
|| c
->hook_post
)
858 fprintf_filtered (stream
,
859 "\nThis command has a hook (or hooks) defined:\n");
862 fprintf_filtered (stream
,
863 "\tThis command is run after : %s (pre hook)\n",
866 fprintf_filtered (stream
,
867 "\tThis command is run before : %s (post hook)\n",
872 * Get a specific kind of help on a command list.
875 * CMDTYPE is the prefix to use in the title string.
876 * CLASS is the class with which to list the nodes of this list (see
877 * documentation for help_cmd_list below), As usual, ALL_COMMANDS for
878 * everything, ALL_CLASSES for just classes, and non-negative for only things
879 * in a specific class.
880 * and STREAM is the output stream on which to print things.
881 * If you call this routine with a class >= 0, it recurses.
884 help_list (struct cmd_list_element
*list
, char *cmdtype
,
885 enum command_class
class, struct ui_file
*stream
)
888 char *cmdtype1
, *cmdtype2
;
890 /* If CMDTYPE is "foo ", CMDTYPE1 gets " foo" and CMDTYPE2 gets "foo sub" */
891 len
= strlen (cmdtype
);
892 cmdtype1
= (char *) alloca (len
+ 1);
894 cmdtype2
= (char *) alloca (len
+ 4);
899 strncpy (cmdtype1
+ 1, cmdtype
, len
- 1);
901 strncpy (cmdtype2
, cmdtype
, len
- 1);
902 strcpy (cmdtype2
+ len
- 1, " sub");
905 if (class == all_classes
)
906 fprintf_filtered (stream
, "List of classes of %scommands:\n\n", cmdtype2
);
908 fprintf_filtered (stream
, "List of %scommands:\n\n", cmdtype2
);
910 help_cmd_list (list
, class, cmdtype
, (int) class >= 0, stream
);
912 if (class == all_classes
)
914 fprintf_filtered (stream
, "\n\
915 Type \"help%s\" followed by a class name for a list of commands in ",
918 fprintf_filtered (stream
, "that class.");
920 fprintf_filtered (stream
, "\n\
921 Type \"help all\" for the list of all commands.");
924 fprintf_filtered (stream
, "\nType \"help%s\" followed by %scommand name ",
927 fputs_filtered ("for ", stream
);
929 fputs_filtered ("full ", stream
);
931 fputs_filtered ("documentation.\n", stream
);
932 fputs_filtered ("Type \"apropos word\" to search "
933 "for commands related to \"word\".\n", stream
);
934 fputs_filtered ("Command name abbreviations are allowed if unambiguous.\n",
939 help_all (struct ui_file
*stream
)
941 struct cmd_list_element
*c
;
942 extern struct cmd_list_element
*cmdlist
;
943 int seen_unclassified
= 0;
945 for (c
= cmdlist
; c
; c
= c
->next
)
949 /* If this is a class name, print all of the commands in the class */
953 fprintf_filtered (stream
, "\nCommand class: %s\n\n", c
->name
);
954 help_cmd_list (cmdlist
, c
->class, "", 1, stream
);
958 /* While it's expected that all commands are in some class,
959 as a safety measure, we'll print commands outside of any
962 for (c
= cmdlist
; c
; c
= c
->next
)
967 if (c
->class == no_class
)
969 if (!seen_unclassified
)
971 fprintf_filtered (stream
, "\nUnclassified commands\n\n");
972 seen_unclassified
= 1;
974 print_help_for_command (c
, "", 1, stream
);
980 /* Print only the first line of STR on STREAM. */
982 print_doc_line (struct ui_file
*stream
, char *str
)
984 static char *line_buffer
= 0;
985 static int line_size
;
991 line_buffer
= (char *) xmalloc (line_size
);
995 while (*p
&& *p
!= '\n' && *p
!= '.' && *p
!= ',')
997 if (p
- str
> line_size
- 1)
999 line_size
= p
- str
+ 1;
1000 xfree (line_buffer
);
1001 line_buffer
= (char *) xmalloc (line_size
);
1003 strncpy (line_buffer
, str
, p
- str
);
1004 line_buffer
[p
- str
] = '\0';
1005 if (islower (line_buffer
[0]))
1006 line_buffer
[0] = toupper (line_buffer
[0]);
1007 ui_out_text (uiout
, line_buffer
);
1010 /* Print one-line help for command C.
1011 If RECURSE is non-zero, also print one-line descriptions
1012 of all prefixed subcommands. */
1014 print_help_for_command (struct cmd_list_element
*c
, char *prefix
, int recurse
,
1015 struct ui_file
*stream
)
1017 fprintf_filtered (stream
, "%s%s -- ", prefix
, c
->name
);
1018 print_doc_line (stream
, c
->doc
);
1019 fputs_filtered ("\n", stream
);
1022 && c
->prefixlist
!= 0
1023 && c
->abbrev_flag
== 0)
1024 /* Subcommands of a prefix command typically have 'all_commands'
1025 as class. If we pass CLASS to recursive invocation,
1026 most often we won't see anything. */
1027 help_cmd_list (*c
->prefixlist
, all_commands
, c
->prefixname
, 1, stream
);
1031 * Implement a help command on command list LIST.
1032 * RECURSE should be non-zero if this should be done recursively on
1033 * all sublists of LIST.
1034 * PREFIX is the prefix to print before each command name.
1035 * STREAM is the stream upon which the output should be written.
1037 * A non-negative class number to list only commands in that
1039 * ALL_COMMANDS to list all commands in list.
1040 * ALL_CLASSES to list all classes in list.
1042 * Note that RECURSE will be active on *all* sublists, not just the
1043 * ones selected by the criteria above (ie. the selection mechanism
1044 * is at the low level, not the high-level).
1047 help_cmd_list (struct cmd_list_element
*list
, enum command_class
class,
1048 char *prefix
, int recurse
, struct ui_file
*stream
)
1050 struct cmd_list_element
*c
;
1052 for (c
= list
; c
; c
= c
->next
)
1054 if (c
->abbrev_flag
== 0
1055 && (class == all_commands
1056 || (class == all_classes
&& c
->func
== NULL
)
1057 || (class == c
->class && c
->func
!= NULL
)))
1059 print_help_for_command (c
, prefix
, recurse
, stream
);
1061 else if (c
->abbrev_flag
== 0 && recurse
1062 && class == class_user
&& c
->prefixlist
!= NULL
)
1063 /* User-defined commands may be subcommands. */
1064 help_cmd_list (*c
->prefixlist
, class, c
->prefixname
, recurse
, stream
);
1069 /* Search the input clist for 'command'. Return the command if
1070 found (or NULL if not), and return the number of commands
1073 static struct cmd_list_element
*
1074 find_cmd (char *command
, int len
, struct cmd_list_element
*clist
,
1075 int ignore_help_classes
, int *nfound
)
1077 struct cmd_list_element
*found
, *c
;
1079 found
= (struct cmd_list_element
*) NULL
;
1081 for (c
= clist
; c
; c
= c
->next
)
1082 if (!strncmp (command
, c
->name
, len
)
1083 && (!ignore_help_classes
|| c
->func
))
1087 if (c
->name
[len
] == '\0')
1097 find_command_name_length (const char *text
)
1099 const char *p
= text
;
1101 /* Treating underscores as part of command words is important
1102 so that "set args_foo()" doesn't get interpreted as
1103 "set args _foo()". */
1104 /* Some characters are only used for TUI specific commands. However, they
1105 are always allowed for the sake of consistency.
1106 The XDB compatibility characters are only allowed when using the right
1107 mode because they clash with other GDB commands - specifically '/' is
1108 used as a suffix for print, examine and display.
1109 Note that this is larger than the character set allowed when creating
1110 user-defined commands. */
1111 while (isalnum (*p
) || *p
== '-' || *p
== '_'
1112 /* Characters used by TUI specific commands. */
1113 || *p
== '+' || *p
== '<' || *p
== '>' || *p
== '$'
1114 /* Characters used for XDB compatibility. */
1115 || (xdb_commands
&& (*p
== '!' || *p
== '/' || *p
== '?')))
1121 /* This routine takes a line of TEXT and a CLIST in which to start the
1122 lookup. When it returns it will have incremented the text pointer past
1123 the section of text it matched, set *RESULT_LIST to point to the list in
1124 which the last word was matched, and will return a pointer to the cmd
1125 list element which the text matches. It will return NULL if no match at
1126 all was possible. It will return -1 (cast appropriately, ick) if ambigous
1127 matches are possible; in this case *RESULT_LIST will be set to point to
1128 the list in which there are ambiguous choices (and *TEXT will be set to
1129 the ambiguous text string).
1131 If the located command was an abbreviation, this routine returns the base
1132 command of the abbreviation.
1134 It does no error reporting whatsoever; control will always return
1135 to the superior routine.
1137 In the case of an ambiguous return (-1), *RESULT_LIST will be set to point
1138 at the prefix_command (ie. the best match) *or* (special case) will be NULL
1139 if no prefix command was ever found. For example, in the case of "info a",
1140 "info" matches without ambiguity, but "a" could be "args" or "address", so
1141 *RESULT_LIST is set to the cmd_list_element for "info". So in this case
1142 RESULT_LIST should not be interpeted as a pointer to the beginning of a
1143 list; it simply points to a specific command. In the case of an ambiguous
1144 return *TEXT is advanced past the last non-ambiguous prefix (e.g.
1145 "info t" can be "info types" or "info target"; upon return *TEXT has been
1146 advanced past "info ").
1148 If RESULT_LIST is NULL, don't set *RESULT_LIST (but don't otherwise
1149 affect the operation).
1151 This routine does *not* modify the text pointed to by TEXT.
1153 If IGNORE_HELP_CLASSES is nonzero, ignore any command list elements which
1154 are actually help classes rather than commands (i.e. the function field of
1155 the struct cmd_list_element is NULL). */
1157 struct cmd_list_element
*
1158 lookup_cmd_1 (char **text
, struct cmd_list_element
*clist
,
1159 struct cmd_list_element
**result_list
, int ignore_help_classes
)
1162 int len
, tmp
, nfound
;
1163 struct cmd_list_element
*found
, *c
;
1166 while (**text
== ' ' || **text
== '\t')
1169 /* Identify the name of the command. */
1170 len
= find_command_name_length (*text
);
1172 /* If nothing but whitespace, return 0. */
1176 /* *text and p now bracket the first command word to lookup (and
1177 it's length is len). We copy this into a local temporary */
1180 command
= (char *) alloca (len
+ 1);
1181 memcpy (command
, *text
, len
);
1182 command
[len
] = '\0';
1187 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1190 ** We didn't find the command in the entered case, so lower case it
1191 ** and search again.
1193 if (!found
|| nfound
== 0)
1195 for (tmp
= 0; tmp
< len
; tmp
++)
1197 char x
= command
[tmp
];
1198 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1200 found
= find_cmd (command
, len
, clist
, ignore_help_classes
, &nfound
);
1203 /* If nothing matches, we have a simple failure. */
1209 if (result_list
!= NULL
)
1210 /* Will be modified in calling routine
1211 if we know what the prefix command is. */
1213 return (struct cmd_list_element
*) -1; /* Ambiguous. */
1216 /* We've matched something on this list. Move text pointer forward. */
1220 if (found
->cmd_pointer
)
1222 /* We drop the alias (abbreviation) in favor of the command it is
1223 pointing to. If the alias is deprecated, though, we need to
1224 warn the user about it before we drop it. Note that while we
1225 are warning about the alias, we may also warn about the command
1226 itself and we will adjust the appropriate DEPRECATED_WARN_USER
1229 if (found
->flags
& DEPRECATED_WARN_USER
)
1230 deprecated_cmd_warning (&line
);
1231 found
= found
->cmd_pointer
;
1233 /* If we found a prefix command, keep looking. */
1235 if (found
->prefixlist
)
1237 c
= lookup_cmd_1 (text
, *found
->prefixlist
, result_list
,
1238 ignore_help_classes
);
1241 /* Didn't find anything; this is as far as we got. */
1242 if (result_list
!= NULL
)
1243 *result_list
= clist
;
1246 else if (c
== (struct cmd_list_element
*) -1)
1248 /* We've gotten this far properly, but the next step
1249 is ambiguous. We need to set the result list to the best
1250 we've found (if an inferior hasn't already set it). */
1251 if (result_list
!= NULL
)
1253 /* This used to say *result_list = *found->prefixlist
1254 If that was correct, need to modify the documentation
1255 at the top of this function to clarify what is supposed
1257 *result_list
= found
;
1268 if (result_list
!= NULL
)
1269 *result_list
= clist
;
1274 /* All this hair to move the space to the front of cmdtype */
1277 undef_cmd_error (char *cmdtype
, char *q
)
1279 error (_("Undefined %scommand: \"%s\". Try \"help%s%.*s\"."),
1282 *cmdtype
? " " : "",
1283 (int) strlen (cmdtype
) - 1,
1287 /* Look up the contents of *LINE as a command in the command list LIST.
1288 LIST is a chain of struct cmd_list_element's.
1289 If it is found, return the struct cmd_list_element for that command
1290 and update *LINE to point after the command name, at the first argument.
1291 If not found, call error if ALLOW_UNKNOWN is zero
1292 otherwise (or if error returns) return zero.
1293 Call error if specified command is ambiguous,
1294 unless ALLOW_UNKNOWN is negative.
1295 CMDTYPE precedes the word "command" in the error message.
1297 If INGNORE_HELP_CLASSES is nonzero, ignore any command list
1298 elements which are actually help classes rather than commands (i.e.
1299 the function field of the struct cmd_list_element is 0). */
1301 struct cmd_list_element
*
1302 lookup_cmd (char **line
, struct cmd_list_element
*list
, char *cmdtype
,
1303 int allow_unknown
, int ignore_help_classes
)
1305 struct cmd_list_element
*last_list
= 0;
1306 struct cmd_list_element
*c
;
1308 /* Note: Do not remove trailing whitespace here because this
1309 would be wrong for complete_command. Jim Kingdon */
1312 error (_("Lack of needed %scommand"), cmdtype
);
1314 c
= lookup_cmd_1 (line
, list
, &last_list
, ignore_help_classes
);
1321 int len
= find_command_name_length (*line
);
1323 q
= (char *) alloca (len
+ 1);
1324 strncpy (q
, *line
, len
);
1326 undef_cmd_error (cmdtype
, q
);
1331 else if (c
== (struct cmd_list_element
*) -1)
1333 /* Ambigous. Local values should be off prefixlist or called
1335 int local_allow_unknown
= (last_list
? last_list
->allow_unknown
:
1337 char *local_cmdtype
= last_list
? last_list
->prefixname
: cmdtype
;
1338 struct cmd_list_element
*local_list
=
1339 (last_list
? *(last_list
->prefixlist
) : list
);
1341 if (local_allow_unknown
< 0)
1344 return last_list
; /* Found something. */
1346 return 0; /* Found nothing. */
1350 /* Report as error. */
1355 ((*line
)[amb_len
] && (*line
)[amb_len
] != ' '
1356 && (*line
)[amb_len
] != '\t');
1361 for (c
= local_list
; c
; c
= c
->next
)
1362 if (!strncmp (*line
, c
->name
, amb_len
))
1364 if (strlen (ambbuf
) + strlen (c
->name
) + 6 < (int) sizeof ambbuf
)
1366 if (strlen (ambbuf
))
1367 strcat (ambbuf
, ", ");
1368 strcat (ambbuf
, c
->name
);
1372 strcat (ambbuf
, "..");
1376 error (_("Ambiguous %scommand \"%s\": %s."), local_cmdtype
,
1378 return 0; /* lint */
1383 /* We've got something. It may still not be what the caller
1384 wants (if this command *needs* a subcommand). */
1385 while (**line
== ' ' || **line
== '\t')
1388 if (c
->prefixlist
&& **line
&& !c
->allow_unknown
)
1389 undef_cmd_error (c
->prefixname
, *line
);
1391 /* Seems to be what he wants. Return it. */
1397 /* We are here presumably because an alias or command in *TEXT is
1398 deprecated and a warning message should be generated. This function
1399 decodes *TEXT and potentially generates a warning message as outlined
1402 Example for 'set endian big' which has a fictitious alias 'seb'.
1404 If alias wasn't used in *TEXT, and the command is deprecated:
1405 "warning: 'set endian big' is deprecated."
1407 If alias was used, and only the alias is deprecated:
1408 "warning: 'seb' an alias for the command 'set endian big' is deprecated."
1410 If alias was used and command is deprecated (regardless of whether the
1411 alias itself is deprecated:
1413 "warning: 'set endian big' (seb) is deprecated."
1415 After the message has been sent, clear the appropriate flags in the
1416 command and/or the alias so the user is no longer bothered.
1420 deprecated_cmd_warning (char **text
)
1422 struct cmd_list_element
*alias
= NULL
;
1423 struct cmd_list_element
*prefix_cmd
= NULL
;
1424 struct cmd_list_element
*cmd
= NULL
;
1425 struct cmd_list_element
*c
;
1428 if (!lookup_cmd_composition (*text
, &alias
, &prefix_cmd
, &cmd
))
1429 /* return if text doesn't evaluate to a command */
1432 if (!((alias
? (alias
->flags
& DEPRECATED_WARN_USER
) : 0)
1433 || (cmd
->flags
& DEPRECATED_WARN_USER
) ) )
1434 /* return if nothing is deprecated */
1437 printf_filtered ("Warning:");
1439 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1440 printf_filtered (" '%s', an alias for the", alias
->name
);
1442 printf_filtered (" command '");
1445 printf_filtered ("%s", prefix_cmd
->prefixname
);
1447 printf_filtered ("%s", cmd
->name
);
1449 if (alias
&& (cmd
->flags
& CMD_DEPRECATED
))
1450 printf_filtered ("' (%s) is deprecated.\n", alias
->name
);
1452 printf_filtered ("' is deprecated.\n");
1455 /* if it is only the alias that is deprecated, we want to indicate the
1456 new alias, otherwise we'll indicate the new command */
1458 if (alias
&& !(cmd
->flags
& CMD_DEPRECATED
))
1460 if (alias
->replacement
)
1461 printf_filtered ("Use '%s'.\n\n", alias
->replacement
);
1463 printf_filtered ("No alternative known.\n\n");
1467 if (cmd
->replacement
)
1468 printf_filtered ("Use '%s'.\n\n", cmd
->replacement
);
1470 printf_filtered ("No alternative known.\n\n");
1473 /* We've warned you, now we'll keep quiet */
1475 alias
->flags
&= ~DEPRECATED_WARN_USER
;
1477 cmd
->flags
&= ~DEPRECATED_WARN_USER
;
1482 /* Look up the contents of LINE as a command in the command list 'cmdlist'.
1483 Return 1 on success, 0 on failure.
1485 If LINE refers to an alias, *alias will point to that alias.
1487 If LINE is a postfix command (i.e. one that is preceeded by a prefix
1488 command) set *prefix_cmd.
1490 Set *cmd to point to the command LINE indicates.
1492 If any of *alias, *prefix_cmd, or *cmd cannot be determined or do not
1493 exist, they are NULL when we return.
1497 lookup_cmd_composition (char *text
,
1498 struct cmd_list_element
**alias
,
1499 struct cmd_list_element
**prefix_cmd
,
1500 struct cmd_list_element
**cmd
)
1503 int len
, tmp
, nfound
;
1504 struct cmd_list_element
*cur_list
;
1505 struct cmd_list_element
*prev_cmd
;
1514 /* Go through as many command lists as we need to
1515 to find the command TEXT refers to. */
1519 while (*text
== ' ' || *text
== '\t')
1522 /* Identify the name of the command. */
1523 len
= find_command_name_length (text
);
1525 /* If nothing but whitespace, return. */
1529 /* text is the start of the first command word to lookup (and
1530 it's length is len). We copy this into a local temporary */
1532 command
= (char *) alloca (len
+ 1);
1533 memcpy (command
, text
, len
);
1534 command
[len
] = '\0';
1539 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1541 /* We didn't find the command in the entered case, so lower case it
1544 if (!*cmd
|| nfound
== 0)
1546 for (tmp
= 0; tmp
< len
; tmp
++)
1548 char x
= command
[tmp
];
1549 command
[tmp
] = isupper (x
) ? tolower (x
) : x
;
1551 *cmd
= find_cmd (command
, len
, cur_list
, 1, &nfound
);
1554 if (*cmd
== (struct cmd_list_element
*) -1)
1556 return 0; /* ambiguous */
1560 return 0; /* nothing found */
1563 if ((*cmd
)->cmd_pointer
)
1565 /* cmd was actually an alias, we note that an alias was used
1566 (by assigning *alais) and we set *cmd.
1569 *cmd
= (*cmd
)->cmd_pointer
;
1571 *prefix_cmd
= prev_cmd
;
1573 if ((*cmd
)->prefixlist
)
1574 cur_list
= *(*cmd
)->prefixlist
;
1582 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1584 /* Return a vector of char pointers which point to the different
1585 possible completions in LIST of TEXT.
1587 WORD points in the same buffer as TEXT, and completions should be
1588 returned relative to this position. For example, suppose TEXT is "foo"
1589 and we want to complete to "foobar". If WORD is "oo", return
1590 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1593 complete_on_cmdlist (struct cmd_list_element
*list
, char *text
, char *word
)
1595 struct cmd_list_element
*ptr
;
1597 int sizeof_matchlist
;
1599 int textlen
= strlen (text
);
1601 sizeof_matchlist
= 10;
1602 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1605 for (ptr
= list
; ptr
; ptr
= ptr
->next
)
1606 if (!strncmp (ptr
->name
, text
, textlen
)
1607 && !ptr
->abbrev_flag
1609 || ptr
->prefixlist
))
1611 if (matches
== sizeof_matchlist
)
1613 sizeof_matchlist
*= 2;
1614 matchlist
= (char **) xrealloc ((char *) matchlist
,
1616 * sizeof (char *)));
1619 matchlist
[matches
] = (char *)
1620 xmalloc (strlen (word
) + strlen (ptr
->name
) + 1);
1622 strcpy (matchlist
[matches
], ptr
->name
);
1623 else if (word
> text
)
1625 /* Return some portion of ptr->name. */
1626 strcpy (matchlist
[matches
], ptr
->name
+ (word
- text
));
1630 /* Return some of text plus ptr->name. */
1631 strncpy (matchlist
[matches
], word
, text
- word
);
1632 matchlist
[matches
][text
- word
] = '\0';
1633 strcat (matchlist
[matches
], ptr
->name
);
1645 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1646 * sizeof (char *)));
1647 matchlist
[matches
] = (char *) 0;
1653 /* Helper function for SYMBOL_COMPLETION_FUNCTION. */
1655 /* Return a vector of char pointers which point to the different
1656 possible completions in CMD of TEXT.
1658 WORD points in the same buffer as TEXT, and completions should be
1659 returned relative to this position. For example, suppose TEXT is "foo"
1660 and we want to complete to "foobar". If WORD is "oo", return
1661 "oobar"; if WORD is "baz/foo", return "baz/foobar". */
1664 complete_on_enum (const char *enumlist
[],
1669 int sizeof_matchlist
;
1671 int textlen
= strlen (text
);
1675 sizeof_matchlist
= 10;
1676 matchlist
= (char **) xmalloc (sizeof_matchlist
* sizeof (char *));
1679 for (i
= 0; (name
= enumlist
[i
]) != NULL
; i
++)
1680 if (strncmp (name
, text
, textlen
) == 0)
1682 if (matches
== sizeof_matchlist
)
1684 sizeof_matchlist
*= 2;
1685 matchlist
= (char **) xrealloc ((char *) matchlist
,
1687 * sizeof (char *)));
1690 matchlist
[matches
] = (char *)
1691 xmalloc (strlen (word
) + strlen (name
) + 1);
1693 strcpy (matchlist
[matches
], name
);
1694 else if (word
> text
)
1696 /* Return some portion of name. */
1697 strcpy (matchlist
[matches
], name
+ (word
- text
));
1701 /* Return some of text plus name. */
1702 strncpy (matchlist
[matches
], word
, text
- word
);
1703 matchlist
[matches
][text
- word
] = '\0';
1704 strcat (matchlist
[matches
], name
);
1716 matchlist
= (char **) xrealloc ((char *) matchlist
, ((matches
+ 1)
1717 * sizeof (char *)));
1718 matchlist
[matches
] = (char *) 0;
1725 /* check function pointer */
1727 cmd_func_p (struct cmd_list_element
*cmd
)
1729 return (cmd
->func
!= NULL
);
1733 /* call the command function */
1735 cmd_func (struct cmd_list_element
*cmd
, char *args
, int from_tty
)
1737 if (cmd_func_p (cmd
))
1738 (*cmd
->func
) (cmd
, args
, from_tty
);
1740 error (_("Invalid command"));