aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-17 14:35:52 -0700
committerPierre-Alexandre Meyer <pierre@mouraf.org>2009-04-17 14:35:52 -0700
commitcb41ba728891e20af42d436526fbcd8a4a33ab5a (patch)
tree1e258c62c8743f12e43520a31d58f1ecc23a80c0
parent780c8f8361ff8f6ebd3b4b4a82e991c81c0c3562 (diff)
downloadsyslinux.git-cb41ba728891e20af42d436526fbcd8a4a33ab5a.tar.gz
syslinux.git-cb41ba728891e20af42d436526fbcd8a4a33ab5a.tar.xz
syslinux.git-cb41ba728891e20af42d436526fbcd8a4a33ab5a.zip
hdt: Get rid of nb_modules in struct cli_module_descr
End list of modules commands by NULL instead of managing manually the number in nb_modules. This should limit the number of bugs when adding new features. Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
-rw-r--r--com32/hdt/hdt-cli-cpu.c1
-rw-r--r--com32/hdt/hdt-cli-dmi.c5
-rw-r--r--com32/hdt/hdt-cli-hdt.c48
-rw-r--r--com32/hdt/hdt-cli-kernel.c1
-rw-r--r--com32/hdt/hdt-cli-pci.c5
-rw-r--r--com32/hdt/hdt-cli-pxe.c1
-rw-r--r--com32/hdt/hdt-cli-syslinux.c1
-rw-r--r--com32/hdt/hdt-cli-vesa.c5
-rw-r--r--com32/hdt/hdt-cli.c27
-rw-r--r--com32/hdt/hdt-cli.h2
10 files changed, 63 insertions, 33 deletions
diff --git a/com32/hdt/hdt-cli-cpu.c b/com32/hdt/hdt-cli-cpu.c
index 9aea1149..a21d217f 100644
--- a/com32/hdt/hdt-cli-cpu.c
+++ b/com32/hdt/hdt-cli-cpu.c
@@ -182,7 +182,6 @@ static void show_cpu(int argc __unused, char **argv __unused,
struct cli_module_descr cpu_show_modules = {
.modules = NULL,
- .nb_modules = 0,
.default_callback = show_cpu,
};
diff --git a/com32/hdt/hdt-cli-dmi.c b/com32/hdt/hdt-cli-dmi.c
index 82b326d8..acf6ff8c 100644
--- a/com32/hdt/hdt-cli-dmi.c
+++ b/com32/hdt/hdt-cli-dmi.c
@@ -479,11 +479,14 @@ struct cli_callback_descr list_dmi_show_modules[] = {
.name = CLI_DMI_LIST,
.exec = show_dmi_modules,
},
+ {
+ .name = NULL,
+ .exec = NULL,
+ },
};
struct cli_module_descr dmi_show_modules = {
.modules = list_dmi_show_modules,
- .nb_modules = CLI_DMI_MAX_MODULES,
.default_callback = main_show_dmi,
};
diff --git a/com32/hdt/hdt-cli-hdt.c b/com32/hdt/hdt-cli-hdt.c
index 4833e264..8859b338 100644
--- a/com32/hdt/hdt-cli-hdt.c
+++ b/com32/hdt/hdt-cli-hdt.c
@@ -110,7 +110,7 @@ static void do_exit(int argc __unused, char** argv __unused,
static void show_cli_help(int argc __unused, char** argv __unused,
struct s_hardware *hardware __unused)
{
- int j;
+ int j = 0;
struct cli_mode_descr *current_mode;
struct cli_callback_descr* associated_module = NULL;
@@ -119,36 +119,46 @@ static void show_cli_help(int argc __unused, char** argv __unused,
more_printf("Available commands are:\n");
/* List first default modules of the mode */
- if (current_mode->default_modules != NULL ) {
- for (j = 0; j < current_mode->default_modules->nb_modules; j++) {
+ if (current_mode->default_modules &&
+ current_mode->default_modules->modules) {
+ while (current_mode->default_modules->modules[j].name) {
more_printf("%s ",
current_mode->default_modules->modules[j].name);
+ j++;
}
more_printf("\n");
}
/* List secondly the show modules of the mode */
- if (current_mode->show_modules != NULL &&
- current_mode->show_modules->nb_modules != 0) {
+ if (current_mode->show_modules &&
+ current_mode->show_modules->modules) {
more_printf("show commands:\n");
- for (j = 0; j < current_mode->show_modules->nb_modules; j++)
+ j = 0;
+ while (current_mode->show_modules->modules[j].name) {
more_printf("\t%s\n",
current_mode->show_modules->modules[j].name);
+ j++;
+ }
}
/* List thirdly the set modules of the mode */
- if (current_mode->set_modules != NULL &&
- current_mode->set_modules->nb_modules != 0) {
+ if (current_mode->set_modules &&
+ current_mode->set_modules->modules) {
more_printf("set commands:\n");
- for (j = 0; j < current_mode->set_modules->nb_modules; j++)
+ j = 0;
+ while (current_mode->set_modules->modules[j].name) {
more_printf("\t%s\n",
current_mode->set_modules->modules[j].name);
+ j++;
+ }
}
/* List finally the default modules of the hdt mode */
if (current_mode->mode != hdt_mode.mode &&
- hdt_mode.default_modules != NULL ) {
- for (j = 0; j < hdt_mode.default_modules->nb_modules; j++) {
+ hdt_mode.default_modules &&
+ hdt_mode.default_modules->modules) {
+ j = 0;
+ while (hdt_mode.default_modules->modules[j].name) {
/*
* Any default command that is present in hdt mode but
* not in the current mode is available. A default
@@ -162,6 +172,7 @@ static void show_cli_help(int argc __unused, char** argv __unused,
if (associated_module == NULL)
more_printf("%s ",
hdt_mode.default_modules->modules[j].name);
+ j++;
}
more_printf("\n");
}
@@ -250,6 +261,10 @@ struct cli_callback_descr list_hdt_default_modules[] = {
.name = CLI_MENU,
.exec = goto_menu,
},
+ {
+ .name = NULL,
+ .exec = NULL
+ },
};
struct cli_callback_descr list_hdt_show_modules[] = {
@@ -293,6 +308,10 @@ struct cli_callback_descr list_hdt_show_modules[] = {
.name = "modes",
.exec = main_show_modes,
},
+ {
+ .name = NULL,
+ .exec = NULL,
+ },
};
struct cli_callback_descr list_hdt_set_modules[] = {
@@ -300,22 +319,23 @@ struct cli_callback_descr list_hdt_set_modules[] = {
.name = CLI_MODE,
.exec = cli_set_mode,
},
+ {
+ .name = NULL,
+ .exec = NULL,
+ },
};
struct cli_module_descr hdt_default_modules = {
.modules = list_hdt_default_modules,
- .nb_modules = 4,
};
struct cli_module_descr hdt_show_modules = {
.modules = list_hdt_show_modules,
- .nb_modules = 10,
.default_callback = main_show_summary,
};
struct cli_module_descr hdt_set_modules = {
.modules = list_hdt_set_modules,
- .nb_modules = 1,
};
struct cli_mode_descr hdt_mode = {
diff --git a/com32/hdt/hdt-cli-kernel.c b/com32/hdt/hdt-cli-kernel.c
index 700f2381..5efcecf5 100644
--- a/com32/hdt/hdt-cli-kernel.c
+++ b/com32/hdt/hdt-cli-kernel.c
@@ -148,7 +148,6 @@ static void show_kernel_modules(int argc __unused, char **argv __unused,
struct cli_module_descr kernel_show_modules = {
.modules = NULL,
- .nb_modules = 0,
.default_callback = show_kernel_modules,
};
diff --git a/com32/hdt/hdt-cli-pci.c b/com32/hdt/hdt-cli-pci.c
index a1b64c4f..d59d8610 100644
--- a/com32/hdt/hdt-cli-pci.c
+++ b/com32/hdt/hdt-cli-pci.c
@@ -271,11 +271,14 @@ struct cli_callback_descr list_pci_show_modules[] = {
.name = CLI_PCI_DEVICE,
.exec = show_pci_device,
},
+ {
+ .name = NULL,
+ .exec = NULL,
+ },
};
struct cli_module_descr pci_show_modules = {
.modules = list_pci_show_modules,
- .nb_modules = 2,
.default_callback = show_pci_devices,
};
diff --git a/com32/hdt/hdt-cli-pxe.c b/com32/hdt/hdt-cli-pxe.c
index 601619c2..1c0971dc 100644
--- a/com32/hdt/hdt-cli-pxe.c
+++ b/com32/hdt/hdt-cli-pxe.c
@@ -80,7 +80,6 @@ void main_show_pxe(int argc __unused, char **argv __unused,
struct cli_module_descr pxe_show_modules = {
.modules = NULL,
- .nb_modules = 0,
.default_callback = main_show_pxe,
};
diff --git a/com32/hdt/hdt-cli-syslinux.c b/com32/hdt/hdt-cli-syslinux.c
index 168a3d3a..c760b1e5 100644
--- a/com32/hdt/hdt-cli-syslinux.c
+++ b/com32/hdt/hdt-cli-syslinux.c
@@ -49,7 +49,6 @@ void main_show_syslinux(int argc __unused, char **argv __unused,
struct cli_module_descr syslinux_show_modules = {
.modules = NULL,
- .nb_modules = 0,
.default_callback = main_show_syslinux,
};
diff --git a/com32/hdt/hdt-cli-vesa.c b/com32/hdt/hdt-cli-vesa.c
index 4234135d..5c550167 100644
--- a/com32/hdt/hdt-cli-vesa.c
+++ b/com32/hdt/hdt-cli-vesa.c
@@ -85,11 +85,14 @@ struct cli_callback_descr list_vesa_show_modules[] = {
.name = CLI_MODES,
.exec = show_vesa_modes,
},
+ {
+ .name = NULL,
+ .exec = NULL,
+ },
};
struct cli_module_descr vesa_show_modules = {
.modules = list_vesa_show_modules,
- .nb_modules = 1,
.default_callback = main_show_vesa,
};
diff --git a/com32/hdt/hdt-cli.c b/com32/hdt/hdt-cli.c
index 2f3836b6..1711ff58 100644
--- a/com32/hdt/hdt-cli.c
+++ b/com32/hdt/hdt-cli.c
@@ -418,13 +418,13 @@ void find_cli_callback_descr(const char* module_name,
goto not_found;
/* Find the callback to execute */
- while (modules_iter < modules_list->nb_modules
- && strncmp(module_name,
- modules_list->modules[modules_iter].name,
- module_len) != 0)
+ while (modules_list->modules[modules_iter].name &&
+ strncmp(module_name,
+ modules_list->modules[modules_iter].name,
+ module_len) != 0)
modules_iter++;
- if (modules_iter != modules_list->nb_modules) {
+ if (modules_list->modules[modules_iter].name) {
*module_found = &(modules_list->modules[modules_iter]);
dprintf("CLI DEBUG: module %s found\n", (*module_found)->name);
return;
@@ -474,7 +474,8 @@ static void autocomplete_command(char *command)
* Let's go now through the list of default_modules for the current mode
* (single token commands for the current_mode)
*/
- for (j = 0; j < current_mode->default_modules->nb_modules; j++) {
+ j = 0;
+ while (current_mode->default_modules->modules[j].name) {
if (strncmp(current_mode->default_modules->modules[j].name,
command,
strlen(command)) == 0) {
@@ -482,6 +483,7 @@ static void autocomplete_command(char *command)
current_mode->default_modules->modules[j].name);
autocomplete_add_token_to_list(current_mode->default_modules->modules[j].name);
}
+ j++;
}
/*
@@ -491,7 +493,8 @@ static void autocomplete_command(char *command)
if (current_mode->mode == HDT_MODE)
return;
- for (j = 0; j < hdt_mode.default_modules->nb_modules; j++) {
+ j = 0;
+ while (hdt_mode.default_modules->modules[j].name) {
/*
* Any default command that is present in hdt mode but
* not in the current mode is available. A default
@@ -510,6 +513,7 @@ static void autocomplete_command(char *command)
hdt_mode.default_modules->modules[j].name);
autocomplete_add_token_to_list(hdt_mode.default_modules->modules[j].name);
}
+ j++;
}
}
@@ -525,11 +529,11 @@ static void autocomplete_command(char *command)
**/
static void autocomplete_module(char *command, char* module)
{
- int j;
+ int j = 0;
char autocomplete_full_line[MAX_LINE_SIZE];
if (strncmp(CLI_SHOW, command, strlen(command)) == 0) {
- for (j = 0; j < current_mode->show_modules->nb_modules; j++) {
+ while (current_mode->show_modules->modules[j].name) {
if (strncmp(current_mode->show_modules->modules[j].name,
module,
strlen(module)) == 0) {
@@ -539,9 +543,11 @@ static void autocomplete_module(char *command, char* module)
CLI_SHOW, current_mode->show_modules->modules[j].name);
autocomplete_add_token_to_list(autocomplete_full_line);
}
+ j++;
}
} else if (strncmp(CLI_SET, command, strlen(command)) == 0) {
- for (j = 0; j < current_mode->set_modules->nb_modules; j++) {
+ j = 0;
+ while (current_mode->set_modules->modules[j].name) {
if (strncmp(current_mode->set_modules->modules[j].name,
module,
strlen(module)) == 0) {
@@ -551,6 +557,7 @@ static void autocomplete_module(char *command, char* module)
CLI_SET, current_mode->set_modules->modules[j].name);
autocomplete_add_token_to_list(autocomplete_full_line);
}
+ j++;
}
}
}
diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h
index 378feae0..666af95d 100644
--- a/com32/hdt/hdt-cli.h
+++ b/com32/hdt/hdt-cli.h
@@ -109,7 +109,6 @@ struct cli_mode_descr {
/* Describe a subset of commands in a module (default, show, set, ...) */
struct cli_module_descr {
struct cli_callback_descr* modules;
- const int nb_modules;
void ( * default_callback ) ( int argc, char** argv, struct s_hardware *hardware );
};
@@ -160,7 +159,6 @@ void main_show(char *item, struct s_hardware *hardware);
#define CLI_DMI_SYSTEM "system"
#define CLI_DMI_IPMI "ipmi"
#define CLI_DMI_LIST CLI_SHOW_LIST
-#define CLI_DMI_MAX_MODULES 10
void main_show_dmi(int argc, char **argv, struct s_hardware *hardware);
void show_dmi_memory_modules(int argc, char** argv, struct s_hardware *hardware);