hdt: Enabling "Switch to CLI" from the menu Menu: switch from "PCI <D>evice" to ...
authorErwan Velu <erwan.velu@free.fr>
Sun, 22 Feb 2009 16:51:11 +0000 (17:51 +0100)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 26 Feb 2009 04:58:44 +0000 (20:58 -0800)
com32/hdt/hdt-cli.c
com32/hdt/hdt-cli.h
com32/hdt/hdt-common.h
com32/hdt/hdt-menu.c
com32/hdt/hdt-menu.h
com32/hdt/hdt.c

index ebb2abc..d86c6cb 100644 (file)
@@ -72,15 +72,11 @@ void handle_hdt_commands(char *cli_line, struct s_cli_mode *cli_mode, struct s_h
 }
 
 /* Code that manage the cli mode */
-void start_cli_mode(int argc, char *argv[]) {
+void start_cli_mode(struct s_hardware *hardware, int argc, char *argv[]) {
  char cli_line[256];
- struct s_hardware hardware;
  struct s_cli_mode cli_mode;
 
- /* Cleaning structures */
- init_hardware(&hardware);
-
- set_mode(&cli_mode,HDT_MODE,&hardware);
+ set_mode(&cli_mode,HDT_MODE,hardware);
 
  printf("Entering CLI mode\n");
 
@@ -96,7 +92,7 @@ void start_cli_mode(int argc, char *argv[]) {
           int mode=do_exit(&cli_mode);
           if (mode ==  EXIT_MODE)
                   return;
-          set_mode(&cli_mode,mode,&hardware);
+          set_mode(&cli_mode,mode,hardware);
           continue;
     }
 
@@ -106,7 +102,7 @@ void start_cli_mode(int argc, char *argv[]) {
     }
 
     if ( !strncmp(cli_line, CLI_PCI, sizeof(CLI_PCI) - 1) ) {
-          set_mode(&cli_mode,PCI_MODE,&hardware);
+          set_mode(&cli_mode,PCI_MODE,hardware);
           continue;
     }
     if ( !strncmp(cli_line, CLI_CLEAR, sizeof(CLI_CLEAR) - 1) ) {
@@ -114,15 +110,15 @@ void start_cli_mode(int argc, char *argv[]) {
           continue;
     }
     if ( !strncmp(cli_line, CLI_DMI, sizeof(CLI_DMI) - 1) ) {
-          set_mode(&cli_mode,DMI_MODE,&hardware);
+          set_mode(&cli_mode,DMI_MODE,hardware);
           continue;
     }
     /* All commands before that line are common for all cli modes
      * the following will be specific for every mode */
     switch(cli_mode.mode) {
-     case DMI_MODE: handle_dmi_commands(cli_line,&cli_mode, &hardware); break;
-     case PCI_MODE: handle_pci_commands(cli_line,&cli_mode, &hardware); break;
-     case HDT_MODE: handle_hdt_commands(cli_line,&cli_mode, &hardware); break;
+     case DMI_MODE: handle_dmi_commands(cli_line,&cli_mode, hardware); break;
+     case PCI_MODE: handle_pci_commands(cli_line,&cli_mode, hardware); break;
+     case HDT_MODE: handle_hdt_commands(cli_line,&cli_mode, hardware); break;
      case EXIT_MODE: break; /* should not happend */
     }
  }
index 0c7085d..5208456 100644 (file)
@@ -55,7 +55,7 @@ struct s_cli_mode {
 
 
 void show_cli_help(struct s_cli_mode *cli_mode);
-void start_cli_mode(int argc, char *argv[]);
+void start_cli_mode(struct s_hardware *hardware, int argc, char *argv[]);
 void main_show(char *item, struct s_hardware *hardware, struct s_cli_mode *cli_mode);
 int do_exit(struct s_cli_mode *cli_mode);
 
index f568ea1..51a2b35 100644 (file)
 #include "dmi/dmi.h"
 #include "hdt-ata.h"
 
+/* This two values are used for switching for the menu to the CLI mode*/
+#define HDT_SWITCH_TO_CLI "hdt_switch_to_cli"
+#define HDT_RETURN_TO_CLI 100
+
 extern int display_line_nb;
 
 #define more_printf(...) do {\
index e24866e..6a8d660 100644 (file)
 
 
 
-int start_menu_mode(char *version_string) {
+int start_menu_mode(struct s_hardware *hardware, char *version_string) {
   struct s_hdt_menu hdt_menu;
-  struct s_hardware hardware;
 
-  /* Cleaning structures */
-  init_hardware(&hardware);
   memset(&hdt_menu,0,sizeof (hdt_menu));
 
   /* Detect every kind of hardware */
-  detect_hardware(&hardware);
+  detect_hardware(hardware);
 
   /* Setup the menu system*/
   setup_menu(version_string);
 
   /* Compute all sub menus */
-  compute_submenus(&hdt_menu, &hardware);
+  compute_submenus(&hdt_menu, hardware);
 
   /* Compute main menu */
-  compute_main_menu(&hdt_menu,&hardware);
+  compute_main_menu(&hdt_menu,hardware);
 
 #ifdef WITH_MENU_DISPLAY
   t_menuitem * curr;
@@ -61,7 +58,11 @@ int start_menu_mode(char *version_string) {
         /* When want to execute something */
         if (curr->action == OPT_RUN)
         {
-            strcpy(cmd,curr->data);
+           /* Tweak, we want to switch to the cli*/
+           if (! strncmp(curr->data,HDT_SWITCH_TO_CLI,sizeof(HDT_SWITCH_TO_CLI))) {
+             return HDT_RETURN_TO_CLI;
+           }
+           strcpy(cmd,curr->data);
 
             /* Use specific syslinux call if needed */
             if (issyslinux())
@@ -154,7 +155,7 @@ void compute_main_menu(struct s_hdt_menu *hdt_menu,struct s_hardware *hardware)
   set_item_options(-1,24);
 
 #ifdef WITH_PCI
-  add_item("PCI <D>evices","PCI Devices Menu",OPT_SUBMENU,NULL,hdt_menu->pci_menu.menu);
+  add_item("PC<I> Devices","PCI Devices Menu",OPT_SUBMENU,NULL,hdt_menu->pci_menu.menu);
   hdt_menu->main_menu.items_count++;
   hdt_menu->total_menu_count+=hdt_menu->pci_menu.items_count;
 #endif
@@ -205,6 +206,7 @@ if (hardware->is_dmi_valid) {
 #endif
   add_item("<S>yslinux","Syslinux Information Menu",OPT_SUBMENU,NULL,hdt_menu->syslinux_menu.menu);
   hdt_menu->main_menu.items_count++;
+  add_item("S<w>itch to CLI","Switch to Command Line",OPT_RUN,HDT_SWITCH_TO_CLI,0);
   add_item("<A>bout","About Menu",OPT_SUBMENU,NULL,hdt_menu->about_menu.menu);
   hdt_menu->main_menu.items_count++;
 
index bebdff5..9c61459 100644 (file)
@@ -105,7 +105,7 @@ void compute_syslinuxmenu(struct s_my_menu *menu);
 // About menu
 void compute_aboutmenu(struct s_my_menu *menu);
 
-int start_menu_mode(char *version_string);
+int start_menu_mode(struct s_hardware *hardware, char *version_string);
 void setup_menu(char *version);
 void compute_main_menu(struct s_hdt_menu *hdt_menu, struct s_hardware *hardware);
 void compute_submenus(struct s_hdt_menu *hdt_menu,struct s_hardware *hardware);
index 7ee3904..c96d0b9 100644 (file)
@@ -45,9 +45,13 @@ int main(int argc, char *argv[])
 {
   char version_string[256];
   char *arg;
+  struct s_hardware hardware;
 
   snprintf(version_string,sizeof version_string,"%s %s by %s",PRODUCT_NAME,VERSION,AUTHOR);
 
+  /* Cleaning structures */
+  init_hardware(&hardware);
+
   /* Opening the syslinux console */
   openconsole(&dev_stdcon_r, &dev_ansicon_w);
 
@@ -55,9 +59,14 @@ int main(int argc, char *argv[])
   printf("%s\n",version_string);
 
   if ((arg = find_argument(argv+1, "nomenu"))) {
-         start_cli_mode(argc, argv);
+         start_cli_mode(&hardware, argc, argv);
   } else{
-        return start_menu_mode(version_string);
+        int return_code = start_menu_mode(&hardware, version_string);
+        if (return_code == HDT_RETURN_TO_CLI) {
+          start_cli_mode(&hardware,argc,argv);
+        } else {
+          return return_code;
+        }
   }
 
   return 0;