This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[rfa:cli] Add {set,get}_cmd_context() or set_cmd_ccfunc()


Hello,

The current command mechanism doesn't provide a way for a call-back 
function (cfunc or sfunc) to bind a local state/context to a command. 
Consequently, it isn't possible to use a single callback function as a 
generic handler for a number of similar commands.

For instance the ``set/show remote ...'' (remote.c) each require an 
individual wrapper function.  By adding a context/state, it becomes 
possible for a common function to handle all cases.

I can think of two ways of implementing this.  Using:

set_cmd_context() / get_cmd_context()

as with this patch; or add a new callback function that takes an 
additional context parameter vis:

set_cmd_ccfunc(cmd, void (*ccfunc) (c, cmd, tty, context), context);

The choice, I think is pretty arbitrary and I'm happy to change it to 
either.

Preference?  Ok?

Andrew
2002-02-24  Andrew Cagney  <ac131313@redhat.com>

	* command.h (struct cmd_list_element): Add field context.
	(set_cmd_context, get_cmd_context): Declare.
	* cli/cli-decode.h: Ditto.
	* cli/cli-decode.c (get_cmd_context): New function.
	(set_cmd_context): New function.
	(add_cmd): Initialize context.

Index: command.h
===================================================================
RCS file: /cvs/src/src/gdb/command.h,v
retrieving revision 1.24
diff -u -r1.24 command.h
--- command.h	2002/02/23 21:30:23	1.24
+++ command.h	2002/02/24 23:27:24
@@ -145,6 +145,9 @@
       }
     function;
 
+    /* Local state (context) for this command.  This can be anything.  */
+    void *context;
+
     /* Documentation of this command (or help topic).
        First line is brief documentation; remaining lines form, with it,
        the full documentation.  First line should end with a period.
@@ -296,6 +299,10 @@
    around in cmd objects to test the value of the commands sfunc().  */
 extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
 			 void (*cfunc) (char *args, int from_tty));
+
+/* Access to the command's local context.  */
+extern void set_cmd_context (struct cmd_list_element *cmd, void *context);
+extern void *get_cmd_context (struct cmd_list_element *cmd);
 
 extern struct cmd_list_element *lookup_cmd (char **,
 					    struct cmd_list_element *, char *,
Index: cli/cli-decode.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-decode.c,v
retrieving revision 1.14
diff -u -r1.14 cli-decode.c
--- cli-decode.c	2002/02/23 20:12:13	1.14
+++ cli-decode.c	2002/02/24 23:27:32
@@ -86,6 +86,18 @@
   return cmd->func == do_cfunc && cmd->function.cfunc == cfunc;
 }
 
+void
+set_cmd_context (struct cmd_list_element *cmd, void *context)
+{
+  cmd->context = context;
+}
+
+void *
+get_cmd_context (struct cmd_list_element *cmd)
+{
+  return cmd->context;
+}
+
 
 /* Add element named NAME.
    CLASS is the top level category into which commands are broken down
@@ -133,6 +145,7 @@
   c->name = name;
   c->class = class;
   set_cmd_cfunc (c, fun);
+  set_cmd_context (c, NULL);
   c->doc = doc;
   c->flags = 0;
   c->replacement = NULL;
Index: cli/cli-decode.h
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-decode.h,v
retrieving revision 1.8
diff -u -r1.8 cli-decode.h
--- cli-decode.h	2002/02/23 20:12:13	1.8
+++ cli-decode.h	2002/02/24 23:27:33
@@ -139,6 +139,9 @@
       }
     function;
 
+    /* Local state (context) for this command.  This can be anything.  */
+    void *context;
+
     /* Documentation of this command (or help topic).
        First line is brief documentation; remaining lines form, with it,
        the full documentation.  First line should end with a period.
@@ -290,6 +293,10 @@
    around in cmd objects to test the value of the commands sfunc().  */
 extern int cmd_cfunc_eq (struct cmd_list_element *cmd,
 			 void (*cfunc) (char *args, int from_tty));
+
+/* Access to the command's local context.  */
+extern void set_cmd_context (struct cmd_list_element *cmd, void *context);
+extern void *get_cmd_context (struct cmd_list_element *cmd);
 
 extern struct cmd_list_element *lookup_cmd (char **,
 					    struct cmd_list_element *, char *,

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]