From cfdfe37709aaeb6c1b97344b453f78a14bd7df86 Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Meyer Date: Tue, 24 Mar 2009 22:37:53 -0700 Subject: [PATCH] hdt: Execute hdt default callbacks in each mode if needed Impact: One can switch modes without going back through hdt Given a command `dmi> show foo', the ordering of callbacks is now the following: 1/ execute module 'foo' of commands set 'show' of mode dmi 2/ execute default callback of commands set 'show' of mode dmi 3/ [NEW] execute module 'foo' of commands set 'show' of mode hdt (2/ is executed if 1/ doesn't exist, 3/ is executed if 2/ doesn't exist either, if 3/ doesn't exist an error is displayed). This allows for instance to switch between modes without exiting first to hdt. Signed-off-by: Pierre-Alexandre Meyer --- com32/hdt/hdt-cli.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index 12bbb98..18c023d 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -429,13 +429,17 @@ static void exec_command(char *line, /* Execute the callback */ if (current_module != NULL) return current_module->exec(argc, argv, hardware); + else if (current_mode->show_modules != NULL && + current_mode->show_modules->default_callback != NULL) + return current_mode->show_modules + ->default_callback(argc, + argv, + hardware); else { - if (current_mode->show_modules != NULL && - current_mode->show_modules->default_callback != NULL) - return current_mode->show_modules - ->default_callback(argc, - argv, - hardware); + find_cli_callback_descr(module, hdt_mode.show_modules, + ¤t_module); + if (current_module != NULL) + return current_module->exec(argc, argv, hardware); } } else if (!strncmp(command, CLI_SET, sizeof(CLI_SET) - 1)) { dprintf("CLI DEBUG: %s command detected\n", CLI_SET); @@ -444,13 +448,17 @@ static void exec_command(char *line, /* Execute the callback */ if (current_module != NULL) return current_module->exec(argc, argv, hardware); + else if (current_mode->set_modules != NULL && + current_mode->set_modules->default_callback != NULL) + return current_mode->set_modules + ->default_callback(argc, + argv, + hardware); else { - if (current_mode->set_modules != NULL && - current_mode->set_modules->default_callback != NULL) - return current_mode->set_modules - ->default_callback(argc, - argv, - hardware); + find_cli_callback_descr(module, hdt_mode.set_modules, + ¤t_module); + if (current_module != NULL) + return current_module->exec(argc, argv, hardware); } } dprintf("CLI DEBUG: callback not found!\n", argc); -- 2.7.4