hdt: Get rid of MAX_MODES
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Thu, 16 Apr 2009 22:27:39 +0000 (15:27 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Thu, 16 Apr 2009 22:27:39 +0000 (15:27 -0700)
End the list of modes by NULL instead of managing manually the length.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
com32/hdt/hdt-cli-hdt.c
com32/hdt/hdt-cli.c
com32/hdt/hdt-cli.h

index cc7b30b..4833e26 100644 (file)
@@ -50,11 +50,13 @@ static void cli_clear_screen(int argc __unused, char** argv __unused,
 static void main_show_modes(int argc __unused, char** argv __unused,
                            struct s_hardware *hardware __unused)
 {
-       int i;
+       int i = 0;
 
        more_printf("Available modes:\n");
-       for (i = 0; i < MAX_MODES; i++)
+       while (list_modes[i]) {
                more_printf("\t%s\n", list_modes[i]->name);
+               i++;
+       }
 }
 
 /**
index 3fd7ce4..2f3836b 100644 (file)
@@ -43,6 +43,7 @@ struct cli_mode_descr *list_modes[] = {
        &cpu_mode,
        &pci_mode,
        &vesa_mode,
+       NULL,
 };
 
 /*
@@ -115,7 +116,7 @@ static void autocomplete_destroy_list()
  **/
 void set_mode(cli_mode_t mode, struct s_hardware* hardware)
 {
-       int i;
+       int i = 0;
 
        switch (mode) {
        case EXIT_MODE:
@@ -180,8 +181,10 @@ void set_mode(cli_mode_t mode, struct s_hardware* hardware)
        default:
                /* Invalid mode */
                more_printf("Unknown mode, please choose among:\n");
-               for (i = 0; i < MAX_MODES; i++)
+               while (list_modes[i]) {
                        more_printf("\t%s\n", list_modes[i]->name);
+                       i++;
+               }
        }
 
        find_cli_mode_descr(hdt_cli.mode, &current_mode);
@@ -199,12 +202,14 @@ cli_mode_t mode_s_to_mode_t(char *name)
 {
        int i = 0;
 
-       for (i = 0; i < MAX_MODES; i++)
+       while (list_modes[i]) {
                if (!strncmp(name, list_modes[i]->name,
                             sizeof(list_modes[i]->name)))
                        break;
+               i++;
+       }
 
-       if (i == MAX_MODES)
+       if (!list_modes[i])
                return INVALID_MODE;
        else
                return list_modes[i]->mode;
@@ -221,17 +226,17 @@ cli_mode_t mode_s_to_mode_t(char *name)
  **/
 void find_cli_mode_descr(cli_mode_t mode, struct cli_mode_descr **mode_found)
 {
-       int modes_iter = 0;
+       int i = 0;
 
-       while (modes_iter < MAX_MODES &&
-              list_modes[modes_iter]->mode != mode)
-               modes_iter++;
+       while (list_modes[i] &&
+              list_modes[i]->mode != mode)
+               i++;
 
        /* Shouldn't get here... */
-       if (modes_iter == MAX_MODES)
+       if (!list_modes[i])
                *mode_found = NULL;
        else
-               *mode_found = list_modes[modes_iter];
+               *mode_found = list_modes[i];
 }
 
 /**
@@ -440,7 +445,7 @@ not_found:
  **/
 static void autocomplete_command(char *command)
 {
-       int j;
+       int j = 0;
        struct cli_callback_descr* associated_module = NULL;
 
        /* First take care of the two special commands: 'show' and 'set' */
@@ -457,11 +462,12 @@ static void autocomplete_command(char *command)
         * Then, go through the modes for the special case
         *      '<mode>' -> 'set mode <mode>'
         */
-       for (j = 0; j < MAX_MODES; j++) {
+       while (list_modes[j]) {
                if (strncmp(list_modes[j]->name, command, strlen(command)) == 0) {
                        more_printf("%s\n", list_modes[j]->name);
                        autocomplete_add_token_to_list(list_modes[j]->name);
                }
+               j++;
        }
 
        /*
index 0b15fe9..378feae 100644 (file)
@@ -128,8 +128,7 @@ struct cli_alias {
 };
 
 /* List of implemented modes */
-#define MAX_MODES 8
-struct cli_mode_descr *list_modes[MAX_MODES];
+extern struct cli_mode_descr *list_modes[];
 struct cli_mode_descr hdt_mode;
 struct cli_mode_descr dmi_mode;
 struct cli_mode_descr syslinux_mode;