* [rfa:cli] Add {set,get}_cmd_context() or set_cmd_ccfunc()
@ 2002-02-24 15:43 Andrew Cagney
2002-03-18 9:06 ` Fernando Nasser
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Cagney @ 2002-02-24 15:43 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 832 bytes --]
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
[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 3303 bytes --]
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 *,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rfa:cli] Add {set,get}_cmd_context() or set_cmd_ccfunc()
2002-02-24 15:43 [rfa:cli] Add {set,get}_cmd_context() or set_cmd_ccfunc() Andrew Cagney
@ 2002-03-18 9:06 ` Fernando Nasser
2002-03-18 18:11 ` Andrew Cagney
0 siblings, 1 reply; 3+ messages in thread
From: Fernando Nasser @ 2002-03-18 9:06 UTC (permalink / raw)
To: Andrew Cagney; +Cc: gdb-patches
Andrew Cagney wrote:
>
> 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?
>
I prefer the first one (your patch), which I think is OK for check-in.
As nobody has objected or stated another preference so far I would
say you go ahead and commit your patch.
Thanks.
Fernando
--
Fernando Nasser
Red Hat Canada Ltd. E-Mail: fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario M4P 2C9
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [rfa:cli] Add {set,get}_cmd_context() or set_cmd_ccfunc()
2002-03-18 9:06 ` Fernando Nasser
@ 2002-03-18 18:11 ` Andrew Cagney
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Cagney @ 2002-03-18 18:11 UTC (permalink / raw)
To: Fernando Nasser; +Cc: gdb-patches
> Andrew Cagney wrote:
> I prefer the first one (your patch), which I think is OK for check-in.
>
> As nobody has objected or stated another preference so far I would
> say you go ahead and commit your patch.
Ok. Once my re-build has finished, it is in. It is now possible to
dramatically simplify remote.c's packet configury!
thanks,
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2002-03-19 2:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-02-24 15:43 [rfa:cli] Add {set,get}_cmd_context() or set_cmd_ccfunc() Andrew Cagney
2002-03-18 9:06 ` Fernando Nasser
2002-03-18 18:11 ` Andrew Cagney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox