hdt: Implement show commands (hdt mode) with the new framework
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Sun, 22 Mar 2009 00:46:34 +0000 (17:46 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Sun, 22 Mar 2009 00:46:34 +0000 (17:46 -0700)
Impact: Cleanups.

The summary of each mode (show <module> in hdt mode) is now implemented
using the new framework, as show modules of the hdt mode.

Misc.: cleanups.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
com32/hdt/hdt-cli-cpu.c
com32/hdt/hdt-cli-dmi.c
com32/hdt/hdt-cli-hdt.c
com32/hdt/hdt-cli-kernel.c
com32/hdt/hdt-cli-pci.c
com32/hdt/hdt-cli-pxe.c
com32/hdt/hdt-cli-syslinux.c
com32/hdt/hdt-cli-vesa.c
com32/hdt/hdt-cli.c
com32/hdt/hdt-cli.h

index cfd66ef..b57c165 100644 (file)
@@ -169,7 +169,8 @@ void handle_cpu_commands(char *cli_line, struct s_hardware *hardware)
   }
 }
 
-void main_show_cpu(struct s_hardware *hardware)
+void main_show_cpu(int argc __unused, char **argv __unused,
+                  struct s_hardware *hardware)
 {
   cpu_detect(hardware);
   detect_dmi(hardware);
index bc09e2d..6fb954e 100644 (file)
@@ -330,7 +330,8 @@ static void show_dmi_memory_bank(int argc, char** argv,
         hardware->dmi.memory[bank].part_number);
 }
 
-void main_show_dmi(struct s_hardware *hardware)
+void main_show_dmi(int argc __unused, char **argv __unused,
+                  struct s_hardware *hardware)
 {
 
   detect_dmi(hardware);
index 296bead..fe2c11e 100644 (file)
@@ -108,17 +108,27 @@ static void show_cli_help(int argc __unused, char** argv __unused,
                        printf("%s ",
                               current_mode->default_modules->modules[j].name);
                }
+               printf("\n");
        }
 
        /* List secondly the show modules of the mode */
        if (current_mode->show_modules != NULL ) {
-               more_printf("show commands:\n");
+               printf("show commands:\n");
                for (j = 0; j < current_mode->show_modules->nb_modules; j++) {
-                       printf("     %s\n",
+                       printf("\t%s\n",
                               current_mode->show_modules->modules[j].name);
                }
        }
 
+       /* List thirdly the set modules of the mode */
+       if (current_mode->set_modules != NULL ) {
+               printf("set commands:\n");
+               for (j = 0; j < current_mode->set_modules->nb_modules; j++) {
+                       printf("\t%s\n",
+                              current_mode->set_modules->modules[j].name);
+               }
+       }
+
        /* List finally the default modules of the hdt mode */
        if (current_mode->mode != hdt_mode.mode &&
            hdt_mode.default_modules != NULL ) {
@@ -137,8 +147,44 @@ static void show_cli_help(int argc __unused, char** argv __unused,
                                printf("%s ",
                                       hdt_mode.default_modules->modules[j].name);
                }
+               printf("\n");
        }
-       printf("\n");
+}
+
+/**
+ * main_show_summary - give an overview of the system
+ **/
+void main_show_summary(int argc __unused, char **argv __unused,
+                      struct s_hardware *hardware)
+{
+       detect_pci(hardware);   /* pxe is detected in the pci */
+       detect_dmi(hardware);
+       cpu_detect(hardware);
+       clear_screen();
+       main_show_cpu(argc, argv, hardware);
+       if (hardware->is_dmi_valid) {
+               more_printf("System\n");
+               more_printf(" Manufacturer : %s\n",
+                           hardware->dmi.system.manufacturer);
+               more_printf(" Product Name : %s\n",
+                           hardware->dmi.system.product_name);
+               more_printf(" Serial       : %s\n",
+                           hardware->dmi.system.serial);
+               more_printf("Bios\n");
+               more_printf(" Version      : %s\n", hardware->dmi.bios.version);
+               more_printf(" Release      : %s\n",
+                           hardware->dmi.bios.release_date);
+
+               int argc = 2;
+               char *argv[2] = { "0", "0" };
+               show_dmi_memory_modules(argc, argv, hardware);
+       }
+       main_show_pci(argc, argv, hardware);
+
+       if (hardware->is_pxe_valid)
+               main_show_pxe(argc, argv, hardware);
+
+       main_show_kernel(argc, argv, hardware);
 }
 
 /* Default hdt mode */
@@ -157,6 +203,41 @@ struct cli_callback_descr list_hdt_default_modules[] = {
        },
 };
 
+struct cli_callback_descr list_hdt_show_modules[] = {
+       {
+               .name = CLI_SUMMARY,
+               .exec = main_show_summary,
+       },
+       {
+               .name = CLI_PCI,
+               .exec = main_show_pci,
+       },
+       {
+               .name = CLI_DMI,
+               .exec = main_show_dmi,
+       },
+       {
+               .name = CLI_CPU,
+               .exec = main_show_cpu,
+       },
+       {
+               .name = CLI_PXE,
+               .exec = main_show_pxe,
+       },
+       {
+               .name = CLI_SYSLINUX,
+               .exec = main_show_syslinux,
+       },
+       {
+               .name = CLI_KERNEL,
+               .exec = main_show_kernel,
+       },
+       {
+               .name = CLI_VESA,
+               .exec = main_show_vesa,
+       },
+};
+
 struct cli_callback_descr list_hdt_set_modules[] = {
        {
                .name = CLI_MODE,
@@ -169,6 +250,11 @@ struct cli_module_descr hdt_default_modules = {
        .nb_modules = 3,
 };
 
+struct cli_module_descr hdt_show_modules = {
+       .modules = list_hdt_show_modules,
+       .nb_modules = 8,
+};
+
 struct cli_module_descr hdt_set_modules = {
        .modules = list_hdt_set_modules,
        .nb_modules = 1,
@@ -178,6 +264,6 @@ struct cli_mode_descr hdt_mode = {
        .mode = HDT_MODE,
        .name = CLI_HDT,
        .default_modules = &hdt_default_modules,
-       .show_modules = NULL,
+       .show_modules = &hdt_show_modules,
        .set_modules = &hdt_set_modules,
 };
index 5b0df1d..5a82876 100644 (file)
@@ -34,7 +34,8 @@
 #include "hdt-cli.h"
 #include "hdt-common.h"
 
-void main_show_kernel(struct s_hardware *hardware)
+void main_show_kernel(int argc __unused, char **argv __unused,
+                     struct s_hardware *hardware)
 {
   char buffer[1024];
   struct pci_device *pci_device;
index 31cfe77..b5a4252 100644 (file)
@@ -299,7 +299,8 @@ void cli_detect_pci(struct s_hardware *hardware)
   }
 }
 
-void main_show_pci(struct s_hardware *hardware)
+void main_show_pci(int argc __unused, char **argv __unused,
+                  struct s_hardware *hardware)
 {
   cli_detect_pci(hardware);
 
index 772c0df..f7972b0 100644 (file)
@@ -36,7 +36,8 @@
 #include "hdt-cli.h"
 #include "hdt-common.h"
 
-void main_show_pxe(struct s_hardware *hardware)
+void main_show_pxe(int argc __unused, char **argv __unused,
+                  struct s_hardware *hardware)
 {
   char buffer[81];
   memset(buffer, 0, sizeof(81));
@@ -85,7 +86,7 @@ static void show_pxe_help()
 static void pxe_show(char *item, struct s_hardware *hardware)
 {
   if (!strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1)) {
-    main_show_pxe(hardware);
+    main_show_pxe(0, NULL, hardware);
     return;
   }
   show_pxe_help();
index 77a44f3..e483864 100644 (file)
@@ -36,7 +36,8 @@
 #include "hdt-cli.h"
 #include "hdt-common.h"
 
-void main_show_syslinux(struct s_hardware *hardware)
+void main_show_syslinux(int argc __unused, char **argv __unused,
+                       struct s_hardware *hardware)
 {
   more_printf("SYSLINUX\n");
   more_printf(" Bootloader : %s\n", hardware->syslinux_fs);
@@ -55,7 +56,7 @@ static void show_syslinux_help()
 static void syslinux_show(char *item, struct s_hardware *hardware)
 {
   if (!strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1)) {
-    main_show_syslinux(hardware);
+    main_show_syslinux(0, NULL, hardware);
     return;
   }
   show_syslinux_help();
index e6843ee..a48227d 100644 (file)
@@ -33,7 +33,9 @@
 #include <stdlib.h>
 #include <errno.h>
 
-void main_show_vesa(struct s_hardware *hardware) {
+void main_show_vesa(int argc __unused, char **argv __unused,
+                   struct s_hardware *hardware)
+{
   detect_vesa(hardware);
   if (hardware->is_vesa_valid==false) {
     more_printf("No VESA BIOS detected\n");
@@ -72,7 +74,7 @@ static void show_vesa_help() {
 
 static void vesa_show(char *item, struct s_hardware *hardware) {
  if ( !strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1) ) {
-   main_show_vesa(hardware);
+   main_show_vesa(0, NULL, hardware);
    return;
  }
  if ( !strncmp(item, CLI_MODES, sizeof(CLI_MODES) - 1) ) {
index 1b1fded..99163c4 100644 (file)
@@ -38,16 +38,6 @@ struct cli_mode_descr *list_modes[] = {
        &dmi_mode,
 };
 
-static void handle_hdt_commands(char *cli_line, struct s_hardware *hardware)
-{
-       /* hdt cli mode specific commands */
-       if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
-               main_show(strstr(cli_line, "show") + sizeof(CLI_SHOW),
-                         hardware);
-               return;
-       }
-}
-
 /**
  * set_mode - set the current mode of the cli
  * @mode:      mode to set
@@ -309,8 +299,10 @@ static void exec_command(char *line,
                 */
                find_cli_callback_descr(command, current_mode->default_modules,
                                        &current_module);
-               if (current_module != NULL)
+               if (current_module != NULL) {
                        current_module->exec(argc, argv, hardware);
+                       return;
+               }
                else {
                        find_cli_callback_descr(command, hdt_mode.default_modules,
                                             &current_module);
@@ -319,7 +311,7 @@ static void exec_command(char *line,
                                return;
                        }
 
-                       printf("Command '%s' unknown.\n", command);
+                       printf("Command '%s' incorrect. See `help'.\n", command);
                }
        }
 
@@ -363,9 +355,6 @@ old_cli:
        case PCI_MODE:
                handle_pci_commands(line, hardware);
                break;
-       case HDT_MODE:
-               handle_hdt_commands(line, hardware);
-               break;
        case CPU_MODE:
                handle_cpu_commands(line, hardware);
                break;
@@ -556,86 +545,3 @@ void start_cli_mode(struct s_hardware *hardware)
                }
        }
 }
-
-static void main_show_summary(struct s_hardware *hardware)
-{
-       detect_pci(hardware);   /* pxe is detected in the pci */
-       detect_dmi(hardware);
-       cpu_detect(hardware);
-       clear_screen();
-       main_show_cpu(hardware);
-       if (hardware->is_dmi_valid) {
-               more_printf("System\n");
-               more_printf(" Manufacturer : %s\n",
-                           hardware->dmi.system.manufacturer);
-               more_printf(" Product Name : %s\n",
-                           hardware->dmi.system.product_name);
-               more_printf(" Serial       : %s\n",
-                           hardware->dmi.system.serial);
-               more_printf("Bios\n");
-               more_printf(" Version      : %s\n", hardware->dmi.bios.version);
-               more_printf(" Release      : %s\n",
-                           hardware->dmi.bios.release_date);
-
-               int argc = 2;
-               char *argv[2] = { "0", "0" };
-               show_dmi_memory_modules(argc, argv, hardware);
-       }
-       main_show_pci(hardware);
-
-       if (hardware->is_pxe_valid)
-               main_show_pxe(hardware);
-
-       main_show_kernel(hardware);
-}
-
-void show_main_help(struct s_hardware *hardware)
-{
-       more_printf("Show supports the following commands : \n");
-       more_printf(" %s\n", CLI_SUMMARY);
-       more_printf(" %s\n", CLI_PCI);
-       more_printf(" %s\n", CLI_DMI);
-       more_printf(" %s\n", CLI_CPU);
-       more_printf(" %s\n", CLI_KERNEL);
-       more_printf(" %s\n", CLI_SYSLINUX);
-       more_printf(" %s\n", CLI_VESA);
-       if (hardware->sv->filesystem == SYSLINUX_FS_PXELINUX)
-               more_printf(" %s\n", CLI_PXE);
-}
-
-void main_show(char *item, struct s_hardware *hardware)
-{
-       if (!strncmp(item, CLI_SUMMARY, sizeof(CLI_SUMMARY))) {
-               main_show_summary(hardware);
-               return;
-       }
-       if (!strncmp(item, CLI_PCI, sizeof(CLI_PCI))) {
-               main_show_pci(hardware);
-               return;
-       }
-       if (!strncmp(item, CLI_DMI, sizeof(CLI_DMI))) {
-               main_show_dmi(hardware);
-               return;
-       }
-       if (!strncmp(item, CLI_CPU, sizeof(CLI_CPU))) {
-               main_show_cpu(hardware);
-               return;
-       }
-       if (!strncmp(item, CLI_PXE, sizeof(CLI_PXE))) {
-               main_show_pxe(hardware);
-               return;
-       }
-       if (!strncmp(item, CLI_SYSLINUX, sizeof(CLI_SYSLINUX))) {
-               main_show_syslinux(hardware);
-               return;
-       }
-       if (!strncmp(item, CLI_KERNEL, sizeof(CLI_KERNEL))) {
-               main_show_kernel(hardware);
-               return;
-       }
-       if (!strncmp(item, CLI_VESA, sizeof(CLI_VESA))) {
-               main_show_vesa(hardware);
-               return;
-       }
-       show_main_help(hardware);
-}
index 4bb9566..186c015 100644 (file)
@@ -140,33 +140,33 @@ void main_show(char *item, struct s_hardware *hardware);
 #define CLI_DMI_SYSTEM "system"
 #define CLI_DMI_LIST CLI_SHOW_LIST
 #define CLI_DMI_MAX_MODULES 9
-void main_show_dmi(struct s_hardware *hardware);
+void main_show_dmi(int argc, char **argv, 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);
 
 // PCI STUFF
 #define CLI_PCI_DEVICE "device"
-void main_show_pci(struct s_hardware *hardware);
+void main_show_pci(int argc, char **argv, struct s_hardware *hardware);
 void handle_pci_commands(char *cli_line, struct s_hardware *hardware);
 void cli_detect_pci(struct s_hardware *hardware);
 
 // CPU STUFF
-void main_show_cpu(struct s_hardware *hardware);
+void main_show_cpu(int argc, char **argv, struct s_hardware *hardware);
 void handle_cpu_commands(char *cli_line, struct s_hardware *hardware);
 
 // PXE STUFF
-void main_show_pxe(struct s_hardware *hardware);
+void main_show_pxe(int argc, char **argv, struct s_hardware *hardware);
 void handle_pxe_commands(char *cli_line, struct s_hardware *hardware);
 
 // KERNEL STUFF
-void main_show_kernel(struct s_hardware *hardware);
+void main_show_kernel(int argc, char **argv, struct s_hardware *hardware);
 void handle_kernel_commands(char *cli_line, struct s_hardware *hardware);
 
 // SYSLINUX STUFF
-void main_show_syslinux(struct s_hardware *hardware);
+void main_show_syslinux(int argc, char **argv, struct s_hardware *hardware);
 void handle_syslinux_commands(char *cli_line, struct s_hardware *hardware);
 
 // VESA STUFF
-void main_show_vesa(struct s_hardware *hardware);
+void main_show_vesa(int argc, char **argv, struct s_hardware *hardware);
 void handle_vesa_commands(char *cli_line, struct s_hardware *hardware);
 #endif