From 45d89b3d1a4c4f4d23a440dd7f30b09017a741eb Mon Sep 17 00:00:00 2001 From: okuji Date: Tue, 22 Jun 1999 00:41:36 +0000 Subject: [PATCH] add quit command --- ChangeLog | 20 ++++++++++++++++ NEWS | 1 + TODO | 2 -- shared_src/char_io.c | 2 ++ shared_src/cmdline.c | 24 ++++++++++++++----- shared_src/shared.h | 17 ++++++++++++-- shared_src/stage2.c | 56 ++++++++++++++++++++++++++++---------------- 7 files changed, 92 insertions(+), 30 deletions(-) diff --git a/ChangeLog b/ChangeLog index 23c63b07f..acc58e13e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +1999-06-22 OKUJI Yoshinori + + * shared_src/char_io.c (get_cmdline): Add two missing `break's. + + * shared_src/cmdline.c (commands): Add quit. + (enter_cmdline): Change the return type to cmdline_t, and return + CMDLINE_OK if successful, otherwise CMDLINE_ERROR if fail. + (enter_cmdline) [GRUB_UTIL]: Return CMDLINE_ABORT if CUR_HEAP + contains "quit". + [!GRUB_UTIL]: Just print an annotation message. + * shared_src/shared.h (cmdline_t): New enum type. + (enter_cmdline): Change the return type to cmdline_t. + (cmain): Remove ``noreturn'' attribute. + * shared_src/stage2.c (menu_t): New enum type. + (run_menu): Change the return type to menu_t. + If enter_cmdline returns CMDLINE_ABORT, then return MENU_ABORT, + otherwise return MENU_OK. + (cmain): If enter_cmdline aborts, then break the command-line + loop and return. If run_menu aborts, then return. + 1999-06-22 OKUJI Yoshinori * shared_src/Makefile.am (EXTRA_DIST): Add bios.c. Reported by diff --git a/NEWS b/NEWS index a51723550..054c699cf 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,7 @@ New: * stage2_debug is removed, and the debugging features are added into stage2. * Color menu support. +* New command "quit". New in 0.5.91 - 1999-03-14, Gordon Matzigkeit: * LBA and preliminary AWARD BIOS disk extension support. diff --git a/TODO b/TODO index 9229049eb..5997e78e4 100644 --- a/TODO +++ b/TODO @@ -38,6 +38,4 @@ Add ``configfile'' command, in a clean way. Add keyboard layout configuration support. -Add ``quit'' command for /sbin/grub. - Finish the GNU GRUB manual, grub.texi. diff --git a/shared_src/char_io.c b/shared_src/char_io.c index 00658398d..2a44fd225 100644 --- a/shared_src/char_io.c +++ b/shared_src/char_io.c @@ -241,8 +241,10 @@ get_cmdline (char *prompt, char *commands, char *cmdline, int maxlen, break; case KEY_DC: c = 4; + break; case KEY_BACKSPACE: c = 8; + break; default: } diff --git a/shared_src/cmdline.c b/shared_src/cmdline.c index e2fd0c769..50c9f0a5c 100644 --- a/shared_src/cmdline.c +++ b/shared_src/cmdline.c @@ -111,7 +111,7 @@ char commands[] = \"rootnoverify= \", \"chainloader= \", \"kernel= ...\", \"testload= \", \"read= \", \"displaymem\", \"impsprobe\", \"fstest\", \"debug\", \"module= ...\", \"modulenounzip= ...\", - \"color= []\", \"makeactive\", \"boot\", and + \"color= []\", \"makeactive\", \"boot\", \"quit\" and \"install= [d] [p] []\"\n"; static void @@ -149,7 +149,11 @@ debug_fs_blocklist_func(int sector) } -int +/* Run the command-line interface or execute a command from SCRIPT if + SCRIPT is not NULL. Return CMDLINE_OK if successful, CMDLINE_ABORT + if ``quit'' command is executed, and CMDLINE_ERROR if an error + occures or ESC is pushed. */ +cmdline_t enter_cmdline (char *script, char *heap) { int bootdev, cmd_len, type = 0, run_cmdline = 1, have_run_cmdline = 0; @@ -188,7 +192,7 @@ restart: printf("Press any key to continue..."); (void) getkey (); returnit: - return 0; + return CMDLINE_OK; } run_cmdline = 1; @@ -220,7 +224,7 @@ returnit: } if (run_cmdline && get_cmdline (PACKAGE "> ", commands, cur_heap, 2048, 0)) - return 1; + return CMDLINE_ERROR; if (substring("boot", cur_heap) == 0 || (script && !*cur_heap)) { @@ -269,7 +273,7 @@ returnit: else if (substring("pause", cur_heap) < 1) { if (ASCII_CHAR (getkey ()) == 27) - return 1; + return CMDLINE_ERROR; } else if (substring("uppermem", cur_heap) < 1) { @@ -489,7 +493,7 @@ returnit: if (script) { fallback = -1; - return 1; + return CMDLINE_ERROR; } } else if (substring("testload", cur_heap) < 1) @@ -654,6 +658,14 @@ returnit: | ((normal_color & 0xf) << 4)); } } + else if (substring ("quit", cur_heap) < 1) + { +#ifdef GRUB_UTIL + return CMDLINE_ABORT; +#else + grub_printf (" The quit command is ignored in Stage2\n"); +#endif + } else if (*cur_heap && *cur_heap != ' ') errnum = ERR_UNRECOGNIZED; diff --git a/shared_src/shared.h b/shared_src/shared.h index f0f66542f..1e312d3eb 100644 --- a/shared_src/shared.h +++ b/shared_src/shared.h @@ -383,7 +383,7 @@ extern char *cur_cmdline; extern entry_func entry_addr; /* Enter the stage1.5/stage2 C code after the stack is set up. */ -void cmain (void) __attribute__ ((noreturn)); +void cmain (void); /* Halt the processor (called after an unrecoverable error). */ void stop (void) __attribute__ ((noreturn)); @@ -466,7 +466,20 @@ void stop_floppy (void); #ifndef STAGE1_5 char *skip_to (int after_equal, char *cmdline); void init_cmdline (void); -int enter_cmdline (char *script, char *heap); + +/* The constants for the return value of enter_cmdline. */ +typedef enum +{ + CMDLINE_OK = 0, + CMDLINE_ABORT, + CMDLINE_ERROR +} cmdline_t; + +/* Run the command-line interface or execute a command from SCRIPT if + SCRIPT is not NULL. Return CMDLINE_OK if successful, CMDLINE_ABORT + if ``quit'' command is executed, and CMDLINE_ERROR if an error + occures or ESC is pushed. */ +cmdline_t enter_cmdline (char *script, char *heap); #endif /* C library replacement functions with identical semantics. */ diff --git a/shared_src/stage2.c b/shared_src/stage2.c index 5602537df..98b0c5726 100644 --- a/shared_src/stage2.c +++ b/shared_src/stage2.c @@ -147,7 +147,13 @@ set_line(int y, int attr) static int grub_timeout; -static void +typedef enum +{ + MENU_OK = 0, + MENU_ABORT +} menu_t; + +static menu_t run_menu(char *menu_entries, char *config_entries, int num_entries, char *heap, int entryno) { @@ -353,7 +359,7 @@ restart: cur_entry = menu_entries; if (c == 27) - return; + return MENU_OK; if (c == 'b') break; } @@ -378,7 +384,7 @@ restart: while (isspace (*pptr)) pptr ++; while ((*(new_file ++) = *(pptr ++)) != 0); - return; + return MENU_OK; } else { @@ -464,7 +470,11 @@ restart: } if (c == 'c') { - enter_cmdline (NULL, heap); + /* Call the command-line interface, and if it aborts + (by ``quit'' command), then return. */ + if (enter_cmdline (NULL, heap) == CMDLINE_ABORT) + return MENU_ABORT; + goto restart; } } @@ -488,7 +498,7 @@ restart: if (!cur_entry) cur_entry = get_entry(config_entries, first_entry+entryno, 1); - if (!(c = enter_cmdline (cur_entry, heap))) + if ((c = enter_cmdline (cur_entry, heap)) == CMDLINE_OK) { if (fallback < 0) break; @@ -501,8 +511,12 @@ restart: } } } - while (!c); + while (c == CMDLINE_OK); + /* If aborted, then return. */ + if (c == CMDLINE_ABORT) + return MENU_ABORT; + /* Both the entry and the fallback failed, so wait for input. */ printf (" Press any key to continue..."); getkey (); @@ -675,20 +689,22 @@ cmain(void) menu_entries = config_entries + config_len; } - /* - * If no acceptable config file, goto command-line, starting heap from - * where the config entries would have been stored if there were any. - */ + if (! num_entries) + { + /* If no acceptable config file, goto command-line, starting + heap from where the config entries would have been stored + if there were any. */ + while (enter_cmdline (NULL, config_entries) != CMDLINE_ABORT) + ; - if (!num_entries) - while (1) - enter_cmdline (NULL, config_entries); - - /* - * Run menu interface (this shouldn't return!). - */ - - run_menu(menu_entries, config_entries, num_entries, - menu_entries+menu_len, default_entry); + return; + } + else + { + /* Run menu interface. */ + if (run_menu(menu_entries, config_entries, num_entries, + menu_entries+menu_len, default_entry) == MENU_ABORT) + return; + } } }