From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28343 invoked by alias); 24 Feb 2002 23:43:21 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 27954 invoked from network); 24 Feb 2002 23:43:16 -0000 Received: from unknown (HELO localhost.redhat.com) (24.112.135.44) by sources.redhat.com with SMTP; 24 Feb 2002 23:43:16 -0000 Received: from cygnus.com (localhost [127.0.0.1]) by localhost.redhat.com (Postfix) with ESMTP id 6D4903D5A for ; Sun, 24 Feb 2002 18:43:12 -0500 (EST) Message-ID: <3C797A8F.7040108@cygnus.com> Date: Sun, 24 Feb 2002 15:43:00 -0000 From: Andrew Cagney User-Agent: Mozilla/5.0 (X11; U; NetBSD macppc; en-US; rv:0.9.8) Gecko/20020210 X-Accept-Language: en-us MIME-Version: 1.0 To: gdb-patches@sources.redhat.com Subject: [rfa:cli] Add {set,get}_cmd_context() or set_cmd_ccfunc() Content-Type: multipart/mixed; boundary="------------090405000508050803060902" X-SW-Source: 2002-02/txt/msg00688.txt.bz2 This is a multi-part message in MIME format. --------------090405000508050803060902 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Content-length: 832 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 --------------090405000508050803060902 Content-Type: text/plain; name="diffs" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="diffs" Content-length: 3303 2002-02-24 Andrew Cagney * 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 *, --------------090405000508050803060902--