From 2c3d9eba8ad1715117bb30bc655cff3cbcebbfc9 Mon Sep 17 00:00:00 2001 From: Pierre-Alexandre Meyer Date: Thu, 19 Mar 2009 19:11:03 -0700 Subject: [PATCH] hdt: Fixing indentation Impact: None. spaces -> tabs so that I can merge easily. Signed-off-by: Pierre-Alexandre Meyer --- com32/hdt/hdt-cli.c | 211 +++++++++++++++++++++++++++------------------------- com32/hdt/hdt-cli.h | 39 +++++----- 2 files changed, 130 insertions(+), 120 deletions(-) diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c index eadaf79..4b66cca 100644 --- a/com32/hdt/hdt-cli.c +++ b/com32/hdt/hdt-cli.c @@ -35,7 +35,7 @@ #define MAX_MODES 1 struct commands_mode *list_modes[] = { - &dmi_mode, + &dmi_mode, }; static void set_mode(struct s_cli_mode *cli_mode, cli_mode_t mode, @@ -209,104 +209,113 @@ static void exec_command(char *command, struct s_cli_mode *cli_mode, * The following will be specific for every mode. */ - int modes_iter = 0, modules_iter = 0; - - /* Find the mode selected */ - while (modes_iter < MAX_MODES && - list_modes[modes_iter]->mode != cli_mode->mode) - modes_iter++; - - if (modes_iter != MAX_MODES) { - struct commands_mode *current_mode = list_modes[modes_iter]; - - /* - * Find the type of command. - * - * The syntax of the cli is the following: - * - * e.g. - * dmi> show system - * dmi> show bank 1 - * dmi> show memory 0 1 - * pci> show device 12 - */ - if (!strncmp(command, CLI_SHOW, sizeof(CLI_SHOW) - 1)) { - int module_len = 0, args_len = 0; - int argc = 0, args_iter = 0, argc_iter = 0; - char* module = NULL, * args = NULL, * args_cpy = NULL; - char** argv = NULL; - - /* Get the module name and args */ - while (strncmp(command + sizeof(CLI_SHOW) + module_len, CLI_SPACE, 1)) - module_len++; - - /* cli_line is filled with \0 when initialized */ - while (strncmp(command + sizeof(CLI_SHOW) + module_len + 1 + args_len, - "\0", 1)) - args_len++; - - module = malloc(module_len + 1); - strncpy(module, command + sizeof(CLI_SHOW), module_len); - module[module_len] = '\0'; - - /* Skip arguments handling if none is supplied */ - if (!args_len) - goto find_callback; - - args = malloc(args_len + 1); - strncpy(args, command + sizeof(CLI_SHOW) + module_len + 1, - args_len); - args[args_len] = '\0'; - - /* Compute the number of arguments */ - args_cpy = args; -read_argument: - args_iter = 0; - while (args_iter < args_len && strncmp(args_cpy + args_iter, CLI_SPACE, 1)) - args_iter++; - argc++; - args_iter++; - args_cpy += args_iter; - args_len -= args_iter; - if (args_len > 0) - goto read_argument; - - /* Transform the arguments string into an array */ - char* result = NULL; - argv = malloc(argc * sizeof(char *)); - result = strtok(args, CLI_SPACE); - while (result != NULL) { - argv[argc_iter] = result; - argc_iter++; - result = strtok(NULL, CLI_SPACE); - } - -find_callback: - /* Find the callback to execute */ - while (modules_iter < current_mode->show_modules->nb_modules && - strncmp(module, - current_mode->show_modules->modules[modules_iter].name, - module_len + 1) != 0) - modules_iter++; - - if (modules_iter != current_mode->show_modules->nb_modules) { - struct commands_module current_module = - current_mode->show_modules->modules[modules_iter]; - /* Execute the callback */ - current_module.exec(argc, argv, hardware); - } else - printf("Module %s unknown.\n", module); - /* XXX Add a default help option for empty commands */ - - free(module); - if (args_len) { - free(args); - free(argv); - } - } - /* Handle here other keywords such as 'set', ... */ - } else - printf("Mode unknown.\n"); + int modes_iter = 0, modules_iter = 0; + + /* Find the mode selected */ + while (modes_iter < MAX_MODES && + list_modes[modes_iter]->mode != cli_mode->mode) + modes_iter++; + + if (modes_iter != MAX_MODES) { + struct commands_mode *current_mode = list_modes[modes_iter]; + + /* + * Find the type of command. + * + * The syntax of the cli is the following: + * + * e.g. + * dmi> show system + * dmi> show bank 1 + * dmi> show memory 0 1 + * pci> show device 12 + */ + if (!strncmp(command, CLI_SHOW, sizeof(CLI_SHOW) - 1)) { + int module_len = 0, args_len = 0; + int argc = 0, args_iter = 0, argc_iter = 0; + char *module = NULL, *args = NULL, *args_cpy = NULL; + char **argv = NULL; + + /* Get the module name and args */ + while (strncmp + (command + sizeof(CLI_SHOW) + module_len, + CLI_SPACE, 1)) + module_len++; + + /* cli_line is filled with \0 when initialized */ + while (strncmp + (command + sizeof(CLI_SHOW) + module_len + 1 + + args_len, "\0", 1)) + args_len++; + + module = malloc(module_len + 1); + strncpy(module, command + sizeof(CLI_SHOW), module_len); + module[module_len] = '\0'; + + /* Skip arguments handling if none is supplied */ + if (!args_len) + goto find_callback; + + args = malloc(args_len + 1); + strncpy(args, + command + sizeof(CLI_SHOW) + module_len + 1, + args_len); + args[args_len] = '\0'; + + /* Compute the number of arguments */ + args_cpy = args; + read_argument: + args_iter = 0; + while (args_iter < args_len + && strncmp(args_cpy + args_iter, CLI_SPACE, 1)) + args_iter++; + argc++; + args_iter++; + args_cpy += args_iter; + args_len -= args_iter; + if (args_len > 0) + goto read_argument; + + /* Transform the arguments string into an array */ + char *result = NULL; + argv = malloc(argc * sizeof(char *)); + result = strtok(args, CLI_SPACE); + while (result != NULL) { + argv[argc_iter] = result; + argc_iter++; + result = strtok(NULL, CLI_SPACE); + } + + find_callback: + /* Find the callback to execute */ + while (modules_iter < + current_mode->show_modules->nb_modules + && strncmp(module, + current_mode->show_modules-> + modules[modules_iter].name, + module_len + 1) != 0) + modules_iter++; + + if (modules_iter != + current_mode->show_modules->nb_modules) { + struct commands_module current_module = + current_mode->show_modules-> + modules[modules_iter]; + /* Execute the callback */ + current_module.exec(argc, argv, hardware); + } else + printf("Module %s unknown.\n", module); + /* XXX Add a default help option for empty commands */ + + free(module); + if (args_len) { + free(args); + free(argv); + } + } + /* Handle here other keywords such as 'set', ... */ + } else + printf("Mode unknown.\n"); /* Legacy cli */ switch (cli_mode->mode) { @@ -337,7 +346,7 @@ find_callback: } static void reset_prompt(char *command, struct s_cli_mode *cli_mode, - int *cur_pos) + int *cur_pos) { /* No need to display the prompt if we exit */ if (cli_mode->mode != EXIT_MODE) { @@ -445,7 +454,7 @@ static void main_show_summary(struct s_hardware *hardware) hardware->dmi.bios.release_date); int argc = 2; - char* argv[2] = {"0", "0"}; + char *argv[2] = { "0", "0" }; show_dmi_memory_modules(argc, argv, hardware); } main_show_pci(hardware); diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h index 20f2c84..acdb9e5 100644 --- a/com32/hdt/hdt-cli.h +++ b/com32/hdt/hdt-cli.h @@ -55,38 +55,38 @@ #define CLI_MODES "modes" typedef enum { - EXIT_MODE, - HDT_MODE, - PCI_MODE, - DMI_MODE, - CPU_MODE, - PXE_MODE, - KERNEL_MODE, - SYSLINUX_MODE, - VESA_MODE, + EXIT_MODE, + HDT_MODE, + PCI_MODE, + DMI_MODE, + CPU_MODE, + PXE_MODE, + KERNEL_MODE, + SYSLINUX_MODE, + VESA_MODE, } cli_mode_t; struct s_cli_mode { - cli_mode_t mode; - char prompt[32]; + cli_mode_t mode; + char prompt[32]; }; /* A command-line command */ struct commands_mode { - const unsigned int mode; - struct commands_module_descr* show_modules; - /* Future: set? */ + const unsigned int mode; + struct commands_module_descr *show_modules; + /* Future: set? */ }; struct commands_module { - const char *name; - void ( * exec ) ( int argc, char** argv, struct s_hardware *hardware ); + const char *name; + void (*exec) (int argc, char **argv, struct s_hardware * hardware); }; /* Describe 'show', 'set', ... commands in a module */ struct commands_module_descr { - struct commands_module* modules; - const int nb_modules; + struct commands_module *modules; + const int nb_modules; }; struct commands_mode dmi_mode; @@ -108,7 +108,8 @@ int do_exit(struct s_cli_mode *cli_mode); #define CLI_DMI_MAX_MODULES 9 void main_show_dmi(struct s_hardware *hardware); void handle_dmi_commands(char *cli_line, struct s_hardware *hardware); -void show_dmi_memory_modules(int argc, char** argv, struct s_hardware *hardware); +void show_dmi_memory_modules(int argc, char **argv, + struct s_hardware *hardware); // PCI STUFF #define CLI_PCI_DEVICE "device" -- 2.7.4