[rfa/cli] add_set_auto_boolean_cmd()
Andrew Cagney
ac131313@cygnus.com
Sun Jun 18 20:51:00 GMT 2000
Hello,
The attatched adds support for an ``auto boolean'' command vis:
set xxx on or enable or 1
set xxx off or disable or 0
set xxx auto
remote.c already has a home brew version of this (ref ``set remote
X-packet ...''') faced with the possibility of needing to do the same in
mips-tdep.c, I figured a generic function would be easier.
It also adds enable/disable to the existing var_boolean.
One thing to note - it makes use of c->enums[] to provide command line
competion (the traditional var_boolean doesn't provide this :-).
Instead of using c->enums[] I could change it to use c->completer().
Ok?
Andrew
PS: I also added a few things to the TODO list.
Mon Jun 19 11:29:35 2000 Andrew Cagney <cagney@b1.cygnus.com>
* command.h (add_set_auto_boolean_cmd): Add declaration.
(enum var_types): Add var_auto_boolean.
* command.c (add_set_auto_boolean_cmd): New function.
(do_setshow_command):
(parse_binary_operation): Recognize enable and disable.
(parse_auto_binary_operation): Parse auto binary variables.
* TODO: Update
Index: command.c
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/command.c,v
retrieving revision 1.71
diff -p -r1.71 command.c
*** command.c 2000/06/12 12:46:50 1.71
--- command.c 2000/06/19 03:47:42
*************** add_set_enum_cmd (char *name,
*** 327,332 ****
--- 327,351 ----
return c;
}
+ /* Add element named NAME to command list LIST (the list for set
+ or some sublist thereof).
+ CLASS is as in add_cmd.
+ VAR is address of the variable which will contain the value.
+ DOC is the documentation string. */
+ struct cmd_list_element *
+ add_set_auto_boolean_cmd (char *name,
+ enum command_class class,
+ enum cmd_auto_boolean *var,
+ char *doc,
+ struct cmd_list_element **list)
+ {
+ static const char *auto_boolean_enums[] = { "on", "off", "auto", NULL };
+ struct cmd_list_element *c;
+ c = add_set_cmd (name, class, var_auto_boolean, var, doc, list);
+ c->enums = auto_boolean_enums;
+ return c;
+ }
+
/* Where SETCMD has already been added, add the corresponding show
command to LIST and return a pointer to the added command (not
necessarily the head of LIST). */
*************** complete_on_enum (const char *enumlist[]
*** 1530,1535 ****
--- 1549,1580 ----
return matchlist;
}
+ static enum cmd_auto_boolean
+ parse_auto_binary_operation (const char *arg)
+ {
+ if (arg != NULL && *arg != '\0')
+ {
+ int length = strlen (arg);
+ while (isspace (arg[length - 1]) && length > 0)
+ length--;
+ if (strncmp (arg, "on", length) == 0
+ || strncmp (arg, "1", length) == 0
+ || strncmp (arg, "yes", length) == 0
+ || strncmp (arg, "enable", length) == 0)
+ return CMD_AUTO_BOOLEAN_TRUE;
+ else if (strncmp (arg, "off", length) == 0
+ || strncmp (arg, "0", length) == 0
+ || strncmp (arg, "no", length) == 0
+ || strncmp (arg, "disable", length) == 0)
+ return CMD_AUTO_BOOLEAN_FALSE;
+ else if (strncmp (arg, "auto", length) == 0
+ || (strncmp (arg, "-1", length) == 0 && length > 1))
+ return CMD_AUTO_BOOLEAN_AUTO;
+ }
+ error ("\"on\", \"off\" or \"auto\" expected.");
+ return CMD_AUTO_BOOLEAN_AUTO; /* pacify GCC */
+ }
+
static int
parse_binary_operation (arg)
char *arg;
*************** parse_binary_operation (arg)
*** 1544,1556 ****
while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
length--;
! if (!strncmp (arg, "on", length)
! || !strncmp (arg, "1", length)
! || !strncmp (arg, "yes", length))
return 1;
! else if (!strncmp (arg, "off", length)
! || !strncmp (arg, "0", length)
! || !strncmp (arg, "no", length))
return 0;
else
{
--- 1589,1603 ----
while (arg[length - 1] == ' ' || arg[length - 1] == '\t')
length--;
! if (strncmp (arg, "on", length) == 0
! || strncmp (arg, "1", length) == 0
! || strncmp (arg, "yes", length) == 0
! || strncmp (arg, "enable", length) == 0)
return 1;
! else if (strncmp (arg, "off", length) == 0
! || strncmp (arg, "0", length) == 0
! || strncmp (arg, "no", length) == 0
! || strncmp (arg, "disable", length) == 0)
return 0;
else
{
*************** do_setshow_command (arg, from_tty, c)
*** 1635,1640 ****
--- 1682,1690 ----
case var_boolean:
*(int *) c->var = parse_binary_operation (arg);
break;
+ case var_auto_boolean:
+ *(enum cmd_auto_boolean *) c->var = parse_auto_binary_operation (arg);
+ break;
case var_uinteger:
if (arg == NULL)
error_no_arg ("integer to set it to.");
*************** do_setshow_command (arg, from_tty, c)
*** 1760,1765 ****
--- 1810,1832 ----
case var_boolean:
fputs_filtered (*(int *) c->var ? "on" : "off", stb->stream);
break;
+ case var_auto_boolean:
+ switch (*(enum auto_boolean*) c->var)
+ {
+ case CMD_AUTO_BOOLEAN_TRUE:
+ fputs_filtered ("on", stb->stream);
+ break;
+ case CMD_AUTO_BOOLEAN_FALSE:
+ fputs_filtered ("off", stb->stream);
+ break;
+ case CMD_AUTO_BOOLEAN_AUTO:
+ fputs_filtered ("auto", stb->stream);
+ break;
+ default:
+ internal_error ("do_setshow_command: invalid var_auto_boolean");
+ break;
+ }
+ break;
case var_uinteger:
if (*(unsigned int *) c->var == UINT_MAX)
{
*************** do_setshow_command (arg, from_tty, c)
*** 1812,1817 ****
--- 1879,1901 ----
break;
case var_boolean:
fputs_filtered (*(int *) c->var ? "on" : "off", gdb_stdout);
+ break;
+ case var_auto_boolean:
+ switch (*(enum cmd_auto_boolean*) c->var)
+ {
+ case CMD_AUTO_BOOLEAN_TRUE:
+ fputs_filtered ("on", gdb_stdout);
+ break;
+ case CMD_AUTO_BOOLEAN_FALSE:
+ fputs_filtered ("off", gdb_stdout);
+ break;
+ case CMD_AUTO_BOOLEAN_AUTO:
+ fputs_filtered ("auto", gdb_stdout);
+ break;
+ default:
+ internal_error ("do_setshow_command: invalid var_auto_boolean");
+ break;
+ }
break;
case var_uinteger:
if (*(unsigned int *) c->var == UINT_MAX)
Index: command.h
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/command.h,v
retrieving revision 1.25
diff -p -r1.25 command.h
*** command.h 2000/06/12 12:46:50 1.25
--- command.h 2000/06/19 03:47:42
*************** typedef enum cmd_types
*** 47,58 ****
--- 47,74 ----
}
cmd_types;
+ /* Reasonable values for an AUTO_BOOLEAN variable. */
+ enum cmd_auto_boolean
+ {
+ CMD_AUTO_BOOLEAN_TRUE,
+ CMD_AUTO_BOOLEAN_FALSE,
+ CMD_AUTO_BOOLEAN_AUTO
+ };
+
/* Types of "set" or "show" command. */
typedef enum var_types
{
/* "on" or "off". *VAR is an integer which is nonzero for on,
zero for off. */
var_boolean,
+
+ /* "on" / "true" / "enable" or "off" / "false" / "disable" or
+ "auto. *VAR is an ``enum cmd_auto_boolean''. NOTE: In general
+ a custom show command will need to be implemented - one that
+ for "auto" prints both the "auto" and the current auto-selected
+ value. */
+ var_auto_boolean,
+
/* Unsigned Integer. *VAR is an unsigned int. The user can type 0
to mean "unlimited", which is stored in *VAR as UINT_MAX. */
var_uinteger,
*************** extern struct cmd_list_element *add_set_
*** 298,303 ****
--- 314,325 ----
const char **var,
char *doc,
struct cmd_list_element **list);
+
+ extern struct cmd_list_element *add_set_auto_boolean_cmd (char *name,
+ enum command_class class,
+ enum cmd_auto_boolean *var,
+ char *doc,
+ struct cmd_list_element **list);
extern struct cmd_list_element *add_show_from_set (struct cmd_list_element *,
struct cmd_list_element
Index: TODO
===================================================================
RCS file: /cvs/cvsfiles/devo/gdb/TODO,v
retrieving revision 1.48
diff -p -r1.48 TODO
*** TODO 2000/06/12 12:46:50 1.48
--- TODO 2000/06/19 03:47:34
*************** output / error-messages when things go w
*** 1123,1128 ****
--- 1123,1158 ----
--
+ do_setshow_command contains a 1024 byte buffer.
+
+ The function assumes that there will never be any more than 1024 bytes
+ of enum. It should use mem_file.
+
+ --
+
+ Should struct cmd_list_element . completer take the command as an
+ argument?
+
+ --
+
+ Should the bulk of top.c:line_completion_function() be moved to
+ command.[hc]? complete_on_cmdlist() and complete_on_enums() could
+ then be made private.
+
+ --
+
+ top.c (execute_command): Should a command being valid when the target
+ is running be made an attribute (predicate) to the command rather than
+ an explicit set of tests.
+
+ --
+
+ top.c (execute_command): Should the bulk of this function be moved
+ into command.[hc] so that top.c doesn't grub around in the command
+ internals?
+
+ --
+
Architectural Change: Async
===========================
More information about the Gdb-patches
mailing list