* cli/cli-decode.c: Include "gdb_assert.h".

(add_set_or_show_cmd): New static function.
(add_set_cmd): Rewrite.  Use add_set_or_show_cmd.
(add_show_from_set): Rewrite. Use add_set_or_show_cmd.  Don't copy
all fields, such as func, from the set command.
This commit is contained in:
Andrew Cagney 2002-03-24 00:24:35 +00:00
parent c78a341714
commit b2875cc0a2
2 changed files with 51 additions and 41 deletions

View file

@ -1,3 +1,11 @@
2002-03-23 Andrew Cagney <ac131313@redhat.com>
* cli/cli-decode.c: Include "gdb_assert.h".
(add_set_or_show_cmd): New static function.
(add_set_cmd): Rewrite. Use add_set_or_show_cmd.
(add_show_from_set): Rewrite. Use add_set_or_show_cmd. Don't copy
all fields, such as func, from the set command.
2002-03-23 Andrew Cagney <ac131313@redhat.com> 2002-03-23 Andrew Cagney <ac131313@redhat.com>
* MAINTAINERS (sh-elf): Change warning flag to -w. * MAINTAINERS (sh-elf): Change warning flag to -w.

View file

@ -28,6 +28,8 @@
#include "cli/cli-cmds.h" #include "cli/cli-cmds.h"
#include "cli/cli-decode.h" #include "cli/cli-decode.h"
#include "gdb_assert.h"
/* Prototypes for local functions */ /* Prototypes for local functions */
static void undef_cmd_error (char *, char *); static void undef_cmd_error (char *, char *);
@ -298,13 +300,35 @@ empty_sfunc (char *args, int from_tty, struct cmd_list_element *c)
{ {
} }
/* Add element named NAME to command list LIST (the list for set /* Add element named NAME to command list LIST (the list for set/show
or some sublist thereof). or some sublist thereof).
TYPE is set_cmd or show_cmd.
CLASS is as in add_cmd. CLASS is as in add_cmd.
VAR_TYPE is the kind of thing we are setting. VAR_TYPE is the kind of thing we are setting.
VAR is address of the variable being controlled by this command. VAR is address of the variable being controlled by this command.
DOC is the documentation string. */ DOC is the documentation string. */
static struct cmd_list_element *
add_set_or_show_cmd (char *name,
enum cmd_types type,
enum command_class class,
var_types var_type,
void *var,
char *doc,
struct cmd_list_element **list)
{
struct cmd_list_element *c = add_cmd (name, class, NULL, doc, list);
gdb_assert (type == set_cmd || type == show_cmd);
c->type = type;
c->var_type = var_type;
c->var = var;
/* This needs to be something besides NULL so that this isn't
treated as a help class. */
set_cmd_sfunc (c, empty_sfunc);
return c;
}
struct cmd_list_element * struct cmd_list_element *
add_set_cmd (char *name, add_set_cmd (char *name,
enum command_class class, enum command_class class,
@ -313,15 +337,7 @@ add_set_cmd (char *name,
char *doc, char *doc,
struct cmd_list_element **list) struct cmd_list_element **list)
{ {
struct cmd_list_element *c = add_cmd (name, class, NULL, doc, list); return add_set_or_show_cmd (name, set_cmd, class, var_type, var, doc, list);
c->type = set_cmd;
c->var_type = var_type;
c->var = var;
/* This needs to be something besides NULL so that this isn't
treated as a help class. */
set_cmd_sfunc (c, empty_sfunc);
return c;
} }
/* Add element named NAME to command list LIST (the list for set /* Add element named NAME to command list LIST (the list for set
@ -388,42 +404,28 @@ add_set_boolean_cmd (char *name,
/* Where SETCMD has already been added, add the corresponding show /* Where SETCMD has already been added, add the corresponding show
command to LIST and return a pointer to the added command (not command to LIST and return a pointer to the added command (not
necessarily the head of LIST). */ necessarily the head of LIST). */
/* NOTE: cagney/2002-03-17: The original version of add_show_from_set
used memcpy() to clone `set' into `show'. This ment that in
addition to all the needed fields (var, name, et.al.) some
unnecessary fields were copied (namely the callback function). The
function explictly copies relevant fields. For a `set' and `show'
command to share the same callback, the caller must set both
explicitly. */
struct cmd_list_element * struct cmd_list_element *
add_show_from_set (struct cmd_list_element *setcmd, add_show_from_set (struct cmd_list_element *setcmd,
struct cmd_list_element **list) struct cmd_list_element **list)
{ {
struct cmd_list_element *showcmd = char *doc;
(struct cmd_list_element *) xmalloc (sizeof (struct cmd_list_element)); const static char setstring[] = "Set ";
struct cmd_list_element *p;
memcpy (showcmd, setcmd, sizeof (struct cmd_list_element)); /* Create a doc string by replacing "Set " at the start of the
delete_cmd (showcmd->name, list); `set'' command's doco with "Show ". */
showcmd->type = show_cmd; gdb_assert (strncmp (setcmd->doc, setstring, sizeof (setstring) - 1) == 0);
doc = concat ("Show ", setcmd->doc + sizeof (setstring) - 1, NULL);
/* Replace "set " at start of docstring with "show ". */ /* Insert the basic command. */
if (setcmd->doc[0] == 'S' && setcmd->doc[1] == 'e' return add_set_or_show_cmd (setcmd->name, show_cmd, setcmd->class,
&& setcmd->doc[2] == 't' && setcmd->doc[3] == ' ') setcmd->var_type, setcmd->var, doc, list);
showcmd->doc = concat ("Show ", setcmd->doc + 4, NULL);
else
fprintf_unfiltered (gdb_stderr, "GDB internal error: Bad docstring for set command\n");
if (*list == NULL || strcmp ((*list)->name, showcmd->name) >= 0)
{
showcmd->next = *list;
*list = showcmd;
}
else
{
p = *list;
while (p->next && strcmp (p->next->name, showcmd->name) <= 0)
{
p = p->next;
}
showcmd->next = p->next;
p->next = showcmd;
}
return showcmd;
} }
/* Remove the command named NAME from the command list. */ /* Remove the command named NAME from the command list. */