diff options
Diffstat (limited to 'com32/hdt/hdt-cli.c')
-rw-r--r-- | com32/hdt/hdt-cli.c | 68 |
1 files changed, 45 insertions, 23 deletions
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index 8b5335eb..7542da83 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -132,7 +132,7 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) break; case PXE_MODE: if (hardware->sv->filesystem != SYSLINUX_FS_PXELINUX) { - printf("You are not currently using PXELINUX\n"); + more_printf("You are not currently using PXELINUX\n"); break; } hdt_cli.mode = mode; @@ -160,7 +160,7 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) break; case DMI_MODE: if (!hardware->is_dmi_valid) { - printf("No valid DMI table found, exiting.\n"); + more_printf("No valid DMI table found, exiting.\n"); break; } hdt_cli.mode = mode; @@ -172,7 +172,7 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) break; case VPD_MODE: if (!hardware->is_vpd_valid) { - printf("No valid VPD table found, exiting.\n"); + more_printf("No valid VPD table found, exiting.\n"); break; } hdt_cli.mode = mode; @@ -188,9 +188,9 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) break; default: /* Invalid mode */ - printf("Unknown mode, please choose among:\n"); + more_printf("Unknown mode, please choose among:\n"); while (list_modes[i]) { - printf("\t%s\n", list_modes[i]->name); + more_printf("\t%s\n", list_modes[i]->name); i++; } } @@ -199,7 +199,7 @@ void set_mode(cli_mode_t mode, struct s_hardware *hardware) /* There is not cli_mode_descr struct for the exit mode */ if (current_mode == NULL && hdt_cli.mode != EXIT_MODE) { /* Shouldn't get here... */ - printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode); + more_printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode); } } @@ -365,14 +365,14 @@ static void parse_command_line(char *line, char **command, char **module, *command = malloc((token_len + 1) * sizeof(char)); strlcpy(*command, pch, token_len); (*command)[token_len] = '\0'; - dprintf("CLI DEBUG: command = %s\n", *command); + dprintf("CLI DEBUG parse: command = %s\n", *command); args_pos += args_len; } else if (token_found == 1) { /* Module */ *module = malloc((token_len + 1) * sizeof(char)); strlcpy(*module, pch, token_len); (*module)[token_len] = '\0'; - dprintf("CLI DEBUG: module = %s\n", *module); + dprintf("CLI DEBUG parse: module = %s\n", *module); args_pos += args_len; } else (*argc)++; @@ -380,7 +380,7 @@ static void parse_command_line(char *line, char **command, char **module, token_found++; pch = pch_next; } - dprintf("CLI DEBUG: argc = %d\n", *argc); + dprintf("CLI DEBUG parse: argc = %d\n", *argc); /* Skip arguments handling if none is supplied */ if (!*argc) @@ -390,9 +390,9 @@ static void parse_command_line(char *line, char **command, char **module, *argv = malloc(*argc * sizeof(char *)); pch = strtok(line + args_pos, CLI_SPACE); while (pch != NULL) { - dprintf("CLI DEBUG: argv[%d] = %s\n", argc_iter, pch); - argv[argc_iter] = malloc(sizeof(pch) * sizeof(char)); - strlcpy(argv[argc_iter], pch, sizeof(pch)); + dprintf("CLI DEBUG parse: argv[%d] = %s\n", argc_iter, pch); + argv[argc_iter] = malloc(strlen(pch) * sizeof(char)); + strlcpy(argv[argc_iter], pch, strlen(pch)); argc_iter++; pch = strtok(NULL, CLI_SPACE); /* @@ -585,6 +585,7 @@ static void autocomplete(char *line) parse_command_line(line, &command, &module, &argc, argv); + dprintf("CLI DEBUG autocomplete: before checking args\n"); /* If the user specified arguments, there is nothing we can complete */ if (argc != 0) goto out; @@ -625,22 +626,43 @@ static void exec_command(char *line, struct s_hardware *hardware) /* This will allocate memory for command and module */ parse_command_line(line, &command, &module, &argc, argv); + dprintf("CLI DEBUG exec: Checking for aliases\n"); /* * Expand shortcuts, if needed * This will allocate memory for argc/argv */ expand_aliases(line, &command, &module, &argc, argv); + + find_cli_callback_descr(command, current_mode->default_modules, + ¤t_module); - if (module == NULL) { - dprintf("CLI DEBUG: single command detected\n"); + if ((module == NULL) || (current_module->nomodule == true)) { + dprintf("CLI DEBUG exec : single command detected\n"); /* * A single word was specified: look at the list of default * commands in the current mode to see if there is a match. * If not, it may be a generic function (exit, help, ...). These * are stored in the list of default commands of the hdt mode. */ - find_cli_callback_descr(command, current_mode->default_modules, - ¤t_module); + + /* First of all it the command doesn't need module, let's rework the arguments */ + if ((current_module->nomodule == true) && ( module != NULL)) { + dprintf("CLI_DEBUG exec: Reworking arguments with argc=%d\n",argc); + char **new_argv=NULL; + new_argv=malloc((argc + 2)*sizeof(char)); + for (int argc_iter=0; argc_iter<argc; argc_iter++) { + dprintf("CLI_DEBUG exec rework : copy %d to %d (%s)\n",argc_iter,argc_iter+1,argv[argc_iter]); + new_argv[argc_iter+1] = malloc(strlen(argv[argc_iter])); + strlcpy(new_argv[argc_iter+1], argv[argc_iter], strlen(argv[argc_iter])); + free(argv[argc_iter]); + } + new_argv[0] = malloc(strlen(module)*sizeof(char)); + strlcpy(new_argv[0], module, strlen(module)); + argc++; + free(argv); + argv=new_argv; + } + if (current_module != NULL) current_module->exec(argc, argv, hardware); else if (!strncmp(command, CLI_SHOW, sizeof(CLI_SHOW) - 1) && @@ -657,7 +679,7 @@ static void exec_command(char *line, struct s_hardware *hardware) if (current_module != NULL) current_module->exec(argc, argv, hardware); else - printf("unknown command: '%s'\n", command); + more_printf("unknown command: '%s'\n", command); } } else { /* @@ -673,7 +695,7 @@ static void exec_command(char *line, struct s_hardware *hardware) * hdt> set mode dmi */ if (!strncmp(command, CLI_SHOW, sizeof(CLI_SHOW) - 1)) { - dprintf("CLI DEBUG: %s command detected\n", CLI_SHOW); + dprintf("CLI DEBUG exec: %s command detected\n", CLI_SHOW); /* Look first for a 'show' callback in the current mode */ find_cli_callback_descr(module, current_mode->show_modules, ¤t_module); @@ -681,6 +703,7 @@ static void exec_command(char *line, struct s_hardware *hardware) if (current_module != NULL) current_module->exec(argc, argv, hardware); else { + dprintf("CLI DEBUG exec: Looking for callback\n"); /* Look now for a 'show' callback in the hdt mode */ find_cli_callback_descr(module, hdt_mode.show_modules, ¤t_module); @@ -691,7 +714,7 @@ static void exec_command(char *line, struct s_hardware *hardware) printf("unknown module: '%s'\n", module); } } else if (!strncmp(command, CLI_SET, sizeof(CLI_SET) - 1)) { - dprintf("CLI DEBUG: %s command detected\n", CLI_SET); + dprintf("CLI DEBUG exec : %s command detected\n", CLI_SET); /* Look now for a 'set' callback in the hdt mode */ find_cli_callback_descr(module, current_mode->set_modules, ¤t_module); @@ -738,8 +761,7 @@ void start_auto_mode(struct s_hardware *hardware) int nb_commands = 0; char *commands[MAX_NB_AUTO_COMMANDS]; - if (!quiet) - more_printf("\nEntering Auto mode\n"); + more_printf("\nEntering Auto mode\n"); /* Protecting the auto_label from the strtok modifications */ char *temp = strdup(hardware->auto_label); @@ -811,7 +833,7 @@ void start_cli_mode(struct s_hardware *hardware) find_cli_mode_descr(hdt_cli.mode, ¤t_mode); if (current_mode == NULL) { /* Shouldn't get here... */ - printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode); + more_printf("!!! BUG: Mode '%d' unknown.\n", hdt_cli.mode); return; } @@ -820,7 +842,7 @@ void start_cli_mode(struct s_hardware *hardware) start_auto_mode(hardware); } - printf("Entering CLI mode\n"); + more_printf("Entering CLI mode\n"); reset_prompt(); |