From 9f60d481c28a949dc41179ecee5320ba1905398f Mon Sep 17 00:00:00 2001 From: Andrew Cagney Date: Tue, 5 Feb 2002 04:37:23 +0000 Subject: * cli/cli-decode.c (do_cfunc, set_cmd_cfunc): New functions. (do_sfunc, set_cmd_sfunc): New functions. * command.h (struct cmd_list_element): Add field func. * cli/cli-decode.h (struct cmd_list_element): Ditto. * command.h (set_cmd_sfunc, set_cmd_cfunc): Declare. * cli/cli-decode.h: Ditto. * cli/cli-decode.c (help_cmd): Test for func not cfunc/sfunc. (help_all, help_cmd_list): Ditto. (find_cmd, complete_on_cmdlist): Ditto. * top.c (execute_command): Ditto. * cli/cli-setshow.c (do_setshow_command): Call func instead of function.sfunc. * infcmd.c (notice_args_read): Fix function signature. * cli/cli-cmds.c (init_cli_cmds): Use set_cmd_sfunc. * cli/cli-decode.c (add_set_cmd): Ditto. * utils.c (initialize_utils): Ditto. * maint.c (_initialize_maint_cmds): Ditto. * infrun.c (_initialize_infrun): Ditto. * demangle.c (_initialize_demangler): Ditto. * remote.c (add_packet_config_cmd): Ditto. * mips-tdep.c (_initialize_mips_tdep): Ditto. * cris-tdep.c (_initialize_cris_tdep): Ditto. * proc-api.c (_initialize_proc_api): Ditto. * kod.c (_initialize_kod): Ditto. * valprint.c (_initialize_valprint): Ditto. * top.c (init_main): Ditto. * infcmd.c (_initialize_infcmd): Ditto. * corefile.c (_initialize_core): Ditto. * arm-tdep.c (_initialize_arm_tdep): Ditto. * arch-utils.c (initialize_current_architecture): Ditto. (_initialize_gdbarch_utils): Ditto. * alpha-tdep.c (_initialize_alpha_tdep): Ditto. * cli/cli-decode.c (add_cmd): Use set_cmd_cfunc. * wince.c (_initialize_inftarg): Ditto. * symfile.c (_initialize_symfile): Ditto. * mips-tdep.c (_initialize_mips_tdep): Ditto. * language.c (_initialize_language): Ditto. * arc-tdep.c (_initialize_arc_tdep): Ditto. --- gdb/cli/cli-cmds.c | 2 +- gdb/cli/cli-decode.c | 75 ++++++++++++++++++++++++++++++++++++++++----------- gdb/cli/cli-decode.h | 18 ++++++++++++- gdb/cli/cli-setshow.c | 2 +- 4 files changed, 78 insertions(+), 19 deletions(-) (limited to 'gdb/cli') diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 4f033a3..f229a70 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -676,7 +676,7 @@ when gdb is started.", &cmdlist); "Set ", &setlist), add_show_from_set (c, &showlist); - c->function.sfunc = set_verbose; + set_cmd_sfunc (c, set_verbose); set_verbose (NULL, 0, c); add_prefix_cmd ("history", class_support, set_history, diff --git a/gdb/cli/cli-decode.c b/gdb/cli/cli-decode.c index 3821faf..d64b2f6 100644 --- a/gdb/cli/cli-decode.c +++ b/gdb/cli/cli-decode.c @@ -40,6 +40,46 @@ static struct cmd_list_element *find_cmd (char *command, static void help_all (struct ui_file *stream); +/* Set the callback function for the specified command. For each both + the commands callback and func() are set. The latter set to a + bounce function (unless cfunc / sfunc is NULL that is). */ + +static void +do_cfunc (struct cmd_list_element *c, char *args, int from_tty) +{ + c->function.cfunc (args, from_tty); /* Ok. */ +} + +void +set_cmd_cfunc (struct cmd_list_element *cmd, + void (*cfunc) (char *args, int from_tty)) +{ + if (cfunc == NULL) + cmd->func = NULL; + else + cmd->func = do_cfunc; + cmd->function.cfunc = cfunc; /* Ok. */ +} + +static void +do_sfunc (struct cmd_list_element *c, char *args, int from_tty) +{ + c->function.sfunc (args, from_tty, c); /* Ok. */ +} + +void +set_cmd_sfunc (struct cmd_list_element *cmd, + void (*sfunc) (char *args, int from_tty, + struct cmd_list_element * c)) +{ + if (sfunc == NULL) + cmd->func = NULL; + else + cmd->func = do_sfunc; + cmd->function.sfunc = sfunc; /* Ok. */ +} + + /* Add element named NAME. CLASS is the top level category into which commands are broken down for "help" purposes. @@ -85,7 +125,7 @@ add_cmd (char *name, enum command_class class, void (*fun) (char *, int), c->name = name; c->class = class; - c->function.cfunc = fun; + set_cmd_cfunc (c, fun); c->doc = doc; c->flags = 0; c->replacement = NULL; @@ -165,7 +205,10 @@ add_alias_cmd (char *name, char *oldname, enum command_class class, return 0; } - c = add_cmd (name, class, old->function.cfunc, old->doc, list); + c = add_cmd (name, class, NULL, old->doc, list); + /* NOTE: Both FUNC and all the FUNCTIONs need to be copied. */ + c->func = old->func; + c->function = old->function; c->prefixlist = old->prefixlist; c->prefixname = old->prefixname; c->allow_unknown = old->allow_unknown; @@ -244,7 +287,7 @@ add_set_cmd (char *name, c->var = var; /* This needs to be something besides NULL so that this isn't treated as a help class. */ - c->function.sfunc = empty_sfunc; + set_cmd_sfunc (c, empty_sfunc); return c; } @@ -516,18 +559,18 @@ help_cmd (char *command, struct ui_file *stream) If c->prefixlist is nonzero, we have a prefix command. Print its documentation, then list its subcommands. - If c->function is nonzero, we really have a command. - Print its documentation and return. + If c->func is non NULL, we really have a command. Print its + documentation and return. - If c->function is zero, we have a class name. - Print its documentation (as if it were a command) - and then set class to the number of this class - so that the commands in the class will be listed. */ + If c->func is NULL, we have a class name. Print its + documentation (as if it were a command) and then set class to the + number of this class so that the commands in the class will be + listed. */ fputs_filtered (c->doc, stream); fputs_filtered ("\n", stream); - if (c->prefixlist == 0 && c->function.cfunc != NULL) + if (c->prefixlist == 0 && c->func != NULL) return; fprintf_filtered (stream, "\n"); @@ -536,7 +579,7 @@ help_cmd (char *command, struct ui_file *stream) help_list (*c->prefixlist, c->prefixname, all_commands, stream); /* If this is a class name, print all of the commands in the class */ - if (c->function.cfunc == NULL) + if (c->func == NULL) help_list (cmdlist, "", c->class, stream); if (c->hook_pre || c->hook_post) @@ -620,7 +663,7 @@ help_all (struct ui_file *stream) help_cmd_list (*c->prefixlist, all_commands, c->prefixname, 0, stream); /* If this is a class name, print all of the commands in the class */ - else if (c->function.cfunc == NULL) + else if (c->func == NULL) help_cmd_list (cmdlist, c->class, "", 0, stream); } } @@ -681,8 +724,8 @@ help_cmd_list (struct cmd_list_element *list, enum command_class class, { if (c->abbrev_flag == 0 && (class == all_commands - || (class == all_classes && c->function.cfunc == NULL) - || (class == c->class && c->function.cfunc != NULL))) + || (class == all_classes && c->func == NULL) + || (class == c->class && c->func != NULL))) { fprintf_filtered (stream, "%s%s -- ", prefix, c->name); print_doc_line (stream, c->doc); @@ -710,7 +753,7 @@ find_cmd (char *command, int len, struct cmd_list_element *clist, *nfound = 0; for (c = clist; c; c = c->next) if (!strncmp (command, c->name, len) - && (!ignore_help_classes || c->function.cfunc)) + && (!ignore_help_classes || c->func)) { found = c; (*nfound)++; @@ -1241,7 +1284,7 @@ complete_on_cmdlist (struct cmd_list_element *list, char *text, char *word) for (ptr = list; ptr; ptr = ptr->next) if (!strncmp (ptr->name, text, textlen) && !ptr->abbrev_flag - && (ptr->function.cfunc + && (ptr->func || ptr->prefixlist)) { if (matches == sizeof_matchlist) diff --git a/gdb/cli/cli-decode.h b/gdb/cli/cli-decode.h index 9e1e094..6c7c22b 100644 --- a/gdb/cli/cli-decode.h +++ b/gdb/cli/cli-decode.h @@ -121,7 +121,13 @@ struct cmd_list_element enum command_class class; /* Function definition of this command. NULL for command class - names and for help topics that are not really commands. */ + names and for help topics that are not really commands. NOTE: + cagney/2002-02-02: This function signature is evolving. For + the moment suggest sticking with either set_cmd_cfunc() or + set_cmd_sfunc(). */ + void (*func) (struct cmd_list_element *c, char *args, int from_tty); + /* The command's real callback. At present func() bounces through + to one of the below. */ union { /* If type is not_set_cmd, call it like this: */ @@ -271,6 +277,16 @@ extern struct cmd_list_element *add_abbrev_prefix_cmd (char *, struct cmd_list_element **); +/* Set the commands corresponding callback. */ + +extern void set_cmd_cfunc (struct cmd_list_element *cmd, + void (*cfunc) (char *args, int from_tty)); + +extern void set_cmd_sfunc (struct cmd_list_element *cmd, + void (*sfunc) (char *args, int from_tty, + struct cmd_list_element * c)); + + extern struct cmd_list_element *lookup_cmd (char **, struct cmd_list_element *, char *, int, int); diff --git a/gdb/cli/cli-setshow.c b/gdb/cli/cli-setshow.c index 5904d33..f967b0c 100644 --- a/gdb/cli/cli-setshow.c +++ b/gdb/cli/cli-setshow.c @@ -345,7 +345,7 @@ do_setshow_command (char *arg, int from_tty, struct cmd_list_element *c) } else error ("gdb internal error: bad cmd_type in do_setshow_command"); - (*c->function.sfunc) (NULL, from_tty, c); + c->func (c, NULL, from_tty); if (c->type == set_cmd && set_hook) set_hook (c); } -- cgit v1.1