hdt: Make KERNEL module use the new framework
authorPierre-Alexandre Meyer <pierre@mouraf.org>
Sun, 22 Mar 2009 03:46:34 +0000 (20:46 -0700)
committerPierre-Alexandre Meyer <pierre@mouraf.org>
Sun, 22 Mar 2009 03:46:34 +0000 (20:46 -0700)
Impact: Cleanups in the KERNEL module.

The KERNEL module now uses the new framework.

Misc.: fix indentation in the KERNEL module.

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

index 5a82876..700f238 100644 (file)
 void main_show_kernel(int argc __unused, char **argv __unused,
                      struct s_hardware *hardware)
 {
-  char buffer[1024];
-  struct pci_device *pci_device;
-  bool found = false;
-  char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
-          MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+       char buffer[1024];
+       struct pci_device *pci_device;
+       bool found = false;
+       char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
+                           MAX_KERNEL_MODULES_PER_PCI_DEVICE];
 
-  memset(buffer, 0, sizeof(buffer));
+       memset(buffer, 0, sizeof(buffer));
 
-  detect_pci(hardware);
-  more_printf("Kernel modules\n");
+       detect_pci(hardware);
+       more_printf("Kernel modules\n");
 
 // more_printf(" PCI device no: %d \n", p->pci_device_pos);
 
-  if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
-    more_printf(" modules.pcimap is missing\n");
-    return;
-  }
-
-  /* For every detected pci device, compute its submenu */
-  for_each_pci_func(pci_device, hardware->pci_domain) {
-    memset(kernel_modules, 0, sizeof kernel_modules);
-
-    for (int kmod = 0;
-         kmod < pci_device->dev_info->linux_kernel_module_count;
-         kmod++) {
-      if (kmod > 0) {
-        strncat(kernel_modules, " | ", 3);
-      }
-      strncat(kernel_modules,
-        pci_device->dev_info->linux_kernel_module[kmod],
-        LINUX_KERNEL_MODULE_SIZE - 1);
-    }
-
-    if ((pci_device->dev_info->linux_kernel_module_count > 0)
-        && (!strstr(buffer, kernel_modules))) {
-      found = true;
-      if (pci_device->dev_info->linux_kernel_module_count > 1)
-        strncat(buffer, "(", 1);
-      strncat(buffer, kernel_modules, sizeof(kernel_modules));
-      if (pci_device->dev_info->linux_kernel_module_count > 1)
-        strncat(buffer, ")", 1);
-      strncat(buffer, " # ", 3);
-    }
-
-  }
-  if (found == true) {
-    strncat(buffer, "\n", 1);
-    more_printf(buffer);
-  }
+       if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
+               more_printf(" modules.pcimap is missing\n");
+               return;
+       }
+
+       /* For every detected pci device, compute its submenu */
+       for_each_pci_func(pci_device, hardware->pci_domain) {
+               memset(kernel_modules, 0, sizeof kernel_modules);
+
+               for (int kmod = 0;
+                    kmod < pci_device->dev_info->linux_kernel_module_count;
+                    kmod++) {
+                       if (kmod > 0) {
+                               strncat(kernel_modules, " | ", 3);
+                       }
+                       strncat(kernel_modules,
+                               pci_device->dev_info->linux_kernel_module[kmod],
+                               LINUX_KERNEL_MODULE_SIZE - 1);
+               }
+
+               if ((pci_device->dev_info->linux_kernel_module_count > 0)
+                   && (!strstr(buffer, kernel_modules))) {
+                       found = true;
+                       if (pci_device->dev_info->linux_kernel_module_count > 1)
+                               strncat(buffer, "(", 1);
+                       strncat(buffer, kernel_modules, sizeof(kernel_modules));
+                       if (pci_device->dev_info->linux_kernel_module_count > 1)
+                               strncat(buffer, ")", 1);
+                       strncat(buffer, " # ", 3);
+               }
+
+       }
+       if (found == true) {
+               strncat(buffer, "\n", 1);
+               more_printf(buffer);
+       }
 }
 
-static void show_kernel_modules(struct s_hardware *hardware)
+static void show_kernel_modules(int argc __unused, char **argv __unused,
+                               struct s_hardware *hardware)
 {
-  struct pci_device *pci_device;
-  char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
-          MAX_KERNEL_MODULES_PER_PCI_DEVICE];
-  bool nopciids = false;
-  bool nomodulespcimap = false;
-  char modules[MAX_PCI_CLASSES][256];
-  char category_name[MAX_PCI_CLASSES][256];
-
-  detect_pci(hardware);
-  memset(&modules, 0, sizeof(modules));
-
-  if (hardware->pci_ids_return_code == -ENOPCIIDS) {
-    nopciids = true;
-    more_printf(" Missing pci.ids, we can't compute the list\n");
-    return;
-  }
-
-  if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
-    nomodulespcimap = true;
-    more_printf
-        (" Missing modules.pcimap, we can't compute the list\n");
-    return;
-  }
-
-  clear_screen();
-
-  for_each_pci_func(pci_device, hardware->pci_domain) {
-    memset(kernel_modules, 0, sizeof kernel_modules);
-
-    for (int kmod = 0;
-         kmod < pci_device->dev_info->linux_kernel_module_count;
-         kmod++) {
-      strncat(kernel_modules,
-        pci_device->dev_info->linux_kernel_module[kmod],
-        LINUX_KERNEL_MODULE_SIZE - 1);
-      strncat(kernel_modules, " ", 1);
-    }
-
-    if ((pci_device->dev_info->linux_kernel_module_count > 0)
-        && (!strstr(modules[pci_device->class[2]], kernel_modules)))
-    {
-      strncat(modules[pci_device->class[2]], kernel_modules,
-        sizeof(kernel_modules));
-      snprintf(category_name[pci_device->class[2]],
-         sizeof(category_name[pci_device->class[2]]),
-         "%s", pci_device->dev_info->category_name);
-    }
-  }
-  /* Print the found items */
-  for (int i = 0; i < MAX_PCI_CLASSES; i++) {
-    if (strlen(category_name[i]) > 1) {
-      more_printf("%s : %s\n", category_name[i], modules[i]);
-    }
-  }
+       struct pci_device *pci_device;
+       char kernel_modules[LINUX_KERNEL_MODULE_SIZE *
+                           MAX_KERNEL_MODULES_PER_PCI_DEVICE];
+       bool nopciids = false;
+       bool nomodulespcimap = false;
+       char modules[MAX_PCI_CLASSES][256];
+       char category_name[MAX_PCI_CLASSES][256];
+
+       detect_pci(hardware);
+       memset(&modules, 0, sizeof(modules));
+
+       if (hardware->pci_ids_return_code == -ENOPCIIDS) {
+               nopciids = true;
+               more_printf(" Missing pci.ids, we can't compute the list\n");
+               return;
+       }
+
+       if (hardware->modules_pcimap_return_code == -ENOMODULESPCIMAP) {
+               nomodulespcimap = true;
+               more_printf
+                   (" Missing modules.pcimap, we can't compute the list\n");
+               return;
+       }
+
+       clear_screen();
+
+       for_each_pci_func(pci_device, hardware->pci_domain) {
+               memset(kernel_modules, 0, sizeof kernel_modules);
+
+               for (int kmod = 0;
+                    kmod < pci_device->dev_info->linux_kernel_module_count;
+                    kmod++) {
+                       strncat(kernel_modules,
+                               pci_device->dev_info->linux_kernel_module[kmod],
+                               LINUX_KERNEL_MODULE_SIZE - 1);
+                       strncat(kernel_modules, " ", 1);
+               }
+
+               if ((pci_device->dev_info->linux_kernel_module_count > 0)
+                   && (!strstr(modules[pci_device->class[2]], kernel_modules))) {
+                       strncat(modules[pci_device->class[2]], kernel_modules,
+                               sizeof(kernel_modules));
+                       snprintf(category_name[pci_device->class[2]],
+                                sizeof(category_name[pci_device->class[2]]),
+                                "%s", pci_device->dev_info->category_name);
+               }
+       }
+       /* Print the found items */
+       for (int i = 0; i < MAX_PCI_CLASSES; i++) {
+               if (strlen(category_name[i]) > 1) {
+                       more_printf("%s : %s\n", category_name[i], modules[i]);
+               }
+       }
 }
 
-static void show_kernel_help()
-{
-  more_printf("Show supports the following commands : %s\n",
-              CLI_SHOW_LIST);
-}
-
-void kernel_show(char *item, struct s_hardware *hardware)
-{
-  if (!strncmp(item, CLI_SHOW_LIST, sizeof(CLI_SHOW_LIST) - 1)) {
-    show_kernel_modules(hardware);
-    return;
-  }
-  show_kernel_help();
-}
-
-void handle_kernel_commands(char *cli_line, struct s_hardware *hardware)
-{
-  if (!strncmp(cli_line, CLI_SHOW, sizeof(CLI_SHOW) - 1)) {
-    kernel_show(strstr(cli_line, "show") + sizeof(CLI_SHOW),
-          hardware);
-    return;
-  }
-}
+struct cli_module_descr kernel_show_modules = {
+       .modules = NULL,
+       .nb_modules = 0,
+       .default_callback = show_kernel_modules,
+};
+
+struct cli_mode_descr kernel_mode = {
+       .mode = KERNEL_MODE,
+       .name = CLI_KERNEL,
+       .default_modules = NULL,
+       .show_modules = &kernel_show_modules,
+       .set_modules = NULL,
+};
index 17ed565..e94aa47 100644 (file)
@@ -38,6 +38,7 @@ struct cli_mode_descr *list_modes[] = {
        &dmi_mode,
        &syslinux_mode,
        &pxe_mode,
+       &kernel_mode,
 };
 
 /**
@@ -375,9 +376,6 @@ old_cli:
        case VESA_MODE:
                handle_vesa_commands(line, hardware);
                break;
-       case KERNEL_MODE:
-               handle_kernel_commands(line, hardware);
-               break;
        case EXIT_MODE:
                break;          /* should not happen */
        }
index b786e3f..c4f5981 100644 (file)
@@ -114,12 +114,13 @@ struct cli_callback_descr {
 };
 
 /* List of implemented modes */
-#define MAX_MODES 4
+#define MAX_MODES 5
 struct cli_mode_descr *list_modes[MAX_MODES];
 struct cli_mode_descr hdt_mode;
 struct cli_mode_descr dmi_mode;
 struct cli_mode_descr syslinux_mode;
 struct cli_mode_descr pxe_mode;
+struct cli_mode_descr kernel_mode;
 
 /* cli helpers */
 void find_cli_mode_descr(cli_mode_t mode, struct cli_mode_descr **mode_found);