This is the mail archive of the
gdb-patches@sources.redhat.com
mailing list for the GDB project.
[RFA] add cmd_func() and cmd_func_p()
- From: "Martin M. Hunt" <hunt at redhat dot com>
- To: gdb-patches at sources dot redhat dot com
- Date: Tue, 2 Jul 2002 14:56:42 -0700
- Subject: [RFA] add cmd_func() and cmd_func_p()
- Organization: Red Hat Inc
These functions take another step towards making the command
struct more opaque and more portable. They are required for
an Insight fix, too.
--
Martin Hunt
GDB Engineer
Red Hat, Inc.
2002-07-02 Martin M. Hunt <hunt@redhat.com>
* top.c (execute_command): Use cmd_func() and cmd_func_p().
* cli/cli-decode.c (cmd_func_p): New function.
(cmd_func): New function.
* command.h: Add cmd_func() and cmd_func_p().
Index: command.h
===================================================================
RCS file: /cvs/src/src/gdb/command.h,v
retrieving revision 1.34
diff -u -u -r1.34 command.h
--- command.h 26 Jun 2002 20:58:16 -0000 1.34
+++ command.h 2 Jul 2002 21:53:50 -0000
@@ -280,4 +280,10 @@
extern void not_just_help_class_command (char *, int);
+/* check function pointer */
+extern int cmd_func_p (struct cmd_list_element *cmd);
+
+/* call the command function */
+extern void cmd_func (struct cmd_list_element *cmd, char *args, int from_tty);
+
#endif /* !defined (COMMAND_H) */
Index: top.c
===================================================================
RCS file: /cvs/src/src/gdb/top.c,v
retrieving revision 1.62
diff -u -u -r1.62 top.c
--- top.c 23 Apr 2002 03:00:57 -0000 1.62
+++ top.c 2 Jul 2002 21:53:51 -0000
@@ -703,12 +703,12 @@
execute_user_command (c, arg);
else if (c->type == set_cmd || c->type == show_cmd)
do_setshow_command (arg, from_tty & caution, c);
- else if (c->func == NULL)
+ else if (!cmd_func_p (c))
error ("That is not a command, just a help topic.");
else if (call_command_hook)
call_command_hook (c, arg, from_tty & caution);
else
- (*c->func) (c, arg, from_tty & caution);
+ cmd_func (c, arg, from_tty & caution);
/* If this command has been post-hooked, run the hook last. */
execute_cmd_post_hook (c);
Index: cli/cli-decode.c
===================================================================
RCS file: /cvs/src/src/gdb/cli/cli-decode.c,v
retrieving revision 1.26
diff -u -u -r1.26 cli-decode.c
--- cli/cli-decode.c 26 Jun 2002 20:58:17 -0000 1.26
+++ cli/cli-decode.c 2 Jul 2002 21:53:51 -0000
@@ -1505,3 +1505,23 @@
return matchlist;
}
+
+/* check function pointer */
+int
+cmd_func_p (struct cmd_list_element *cmd)
+{
+ return (cmd->func != NULL);
+}
+
+
+/* call the command function */
+void
+cmd_func (struct cmd_list_element *cmd, char *args, int from_tty)
+{
+ if (cmd_func_p (cmd))
+ (*cmd->func) (cmd, args, from_tty);
+ else
+ error ("Invalid command");
+}
+
+