From be705674e1f5bd3dc228e796d0ccdd32f3eb8a3b Mon Sep 17 00:00:00 2001 From: okuji Date: Sun, 2 May 1999 21:30:41 +0000 Subject: [PATCH] Preliminary non-interactive use support --- ChangeLog | 35 +++++++++++++++++ grub/asmstub.c | 92 ++++++++++++++++++++++++++------------------ grub/main.c | 25 ++++++++++++ shared_src/cmdline.c | 4 +- shared_src/shared.h | 12 ++++-- shared_src/stage2.c | 4 ++ 6 files changed, 129 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ebed2e26..b06e35914 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,38 @@ +1999-05-03 OKUJI Yoshinori + + Preliminary non-interactive use support. + + * grub/main.c (use_config_file): New variable. + (use_curses): Likewise. + (OPT_DISABLE_CONFIG_FILE): New constant. + (OPT_DISABLE_CURSES): Likewise. + (OPT_BATCH): Likewise. + (longopts): Add new options, --disable-config-file, --disable-curses, + and --batch. + (usage): Print the help messages about these new options. + (main): Handle them. + + * grub/asmstub.c (grub_stage2) [HAVE_LIBCURSES]: If ! USE_CURSES, + fallback non-curses code. + (stop) [HAVE_LIBCURSES]: Likewise. + (cls) [HAVE_LIBCURSES]: Likewise. + (getxy) [HAVE_LIBCURSES]: Likewise. + (gotoxy) [HAVE_LIBCURSES]: Likewise. + (grub_putchar) [HAVE_LIBCURSES]: Likewise. + (getkey) [HAVE_LIBCURSES]: Likewise. + (checkkey) [HAVE_LIBCURSES]: Likewise. + (set_attrib) [HAVE_LIBCURSES]: Likewise. + + * shared_src/cmdline.c (enter_cmdline): Do not use getc, but use + getkey. + + * shared_src/stage2.c (cmain) [GRUB_UTIL]: Check if USE_CONFIG_FILE + is non-zero or not. + + * shared_src/shared.h (getc): Removed. + (use_config_file) [GRUB_UTIL]: Add the declaration. + (use_curses) [GRUB_UTIL]: Likewise. + 1999-05-03 OKUJI Yoshinori * grub/asmstub.c (device_map): New variable. diff --git a/grub/asmstub.c b/grub/asmstub.c index 986be6b5b..29b1b0e6a 100644 --- a/grub/asmstub.c +++ b/grub/asmstub.c @@ -180,13 +180,16 @@ grub_stage2 (void) #ifdef HAVE_LIBCURSES /* Get into char-at-a-time mode. */ - initscr (); - cbreak (); - noecho (); - nonl (); - scrollok (stdscr, TRUE); - keypad (stdscr, TRUE); - nodelay (stdscr, TRUE); + if (use_curses) + { + initscr (); + cbreak (); + noecho (); + nonl (); + scrollok (stdscr, TRUE); + keypad (stdscr, TRUE); + nodelay (stdscr, TRUE); + } #endif /* Set our stack, and go for it. */ @@ -194,7 +197,8 @@ grub_stage2 (void) doit (); #ifdef HAVE_LIBCURSES - endwin (); + if (use_curses) + endwin (); #endif /* Close off the file descriptors we used. */ @@ -221,7 +225,8 @@ void stop (void) { #ifdef HAVE_LIBCURSES - endwin (); + if (use_curses) + endwin (); #endif /* FIXME: If we don't exit, then we need to free our data areas. */ fprintf (stderr, "grub: aborting...\n"); @@ -348,7 +353,8 @@ void cls (void) { #ifdef HAVE_LIBCURSES - clear (); + if (use_curses) + clear (); #endif } @@ -359,10 +365,11 @@ getxy (void) { int y, x; #ifdef HAVE_LIBCURSES - getyx (stdscr, y, x); -#else - y = x = 0; + if (use_curses) + getyx (stdscr, y, x); + else #endif + y = x = 0; return (x << 8) | (y & 0xff); } @@ -371,7 +378,8 @@ void gotoxy (int x, int y) { #ifdef HAVE_LIBCURSES - move (y, x); + if (use_curses) + move (y, x); #endif } @@ -382,10 +390,11 @@ void grub_putchar (int c) { #ifdef HAVE_LIBCURSES - addch (c); -#else - putchar (c); + if (use_curses) + addch (c); + else #endif + putchar (c); } @@ -394,14 +403,17 @@ int getkey (void) { #ifdef HAVE_LIBCURSES - int c; - nodelay (stdscr, FALSE); - c = getch (); - nodelay (stdscr, TRUE); - return c; -#else - return getchar (); + if (use_curses) + { + int c; + nodelay (stdscr, FALSE); + c = getch (); + nodelay (stdscr, TRUE); + return c; + } #endif + + return getchar (); } @@ -410,16 +422,19 @@ int checkkey (void) { #ifdef HAVE_LIBCURSES - int c; - c = getch (); - /* If C is not ERR, then put it back in the input queue. */ - if (c != ERR) - ungetch (c); /* FIXME: ncurses-1.9.9g ungetch is buggy. */ - return c; -#else + if (use_curses) + { + int c; + c = getch (); + /* If C is not ERR, then put it back in the input queue. */ + if (c != ERR) + ungetch (c); /* FIXME: ncurses-1.9.9g ungetch is buggy. */ + return c; + } +#endif + /* Just pretend they hit the space bar. */ return ' '; -#endif } @@ -428,13 +443,16 @@ void set_attrib (int attr) { #ifdef HAVE_LIBCURSES - /* FIXME: I don't know why, but chgat doesn't work as expected, so - use this dirty way... - okuji */ - chtype ch = inch (); - addch ((ch & A_CHARTEXT) | attr); + if (use_curses) + { + /* FIXME: I don't know why, but chgat doesn't work as expected, so + use this dirty way... - okuji */ + chtype ch = inch (); + addch ((ch & A_CHARTEXT) | attr); # if 0 - chgat (1, attr, 0, NULL); + chgat (1, attr, 0, NULL); # endif + } #endif } diff --git a/grub/main.c b/grub/main.c index 71b0b8a1e..6bcb31645 100644 --- a/grub/main.c +++ b/grub/main.c @@ -32,6 +32,8 @@ int grub_stage2 (void); #include "shared.h" char *program_name = 0; +int use_config_file = 1; +int use_curses = 1; static int default_boot_drive; static int default_install_partition; static char *default_config_file; @@ -42,6 +44,9 @@ static char *default_config_file; #define OPT_CONFIG_FILE -5 #define OPT_INSTALL_PARTITION -6 #define OPT_BOOT_DRIVE -7 +#define OPT_DISABLE_CONFIG_FILE -8 +#define OPT_DISABLE_CURSES -9 +#define OPT_BATCH -10 #define OPTSTRING "" static struct option longopts[] = @@ -52,6 +57,9 @@ static struct option longopts[] = {"config-file", required_argument, 0, OPT_CONFIG_FILE}, {"install-partition", required_argument, 0, OPT_INSTALL_PARTITION}, {"boot-drive", required_argument, 0, OPT_BOOT_DRIVE}, + {"disable-config-file", no_argument, 0, OPT_DISABLE_CONFIG_FILE}, + {"disable-curses", no_argument, 0, OPT_DISABLE_CURSES}, + {"batch", no_argument, 0, OPT_BATCH}, {0}, }; @@ -68,8 +76,11 @@ Usage: %s [OPTION]...\n\ \n\ Enter the GRand Unified Bootloader command shell.\n\ \n\ + --batch turn on batch mode for non-interactive use\n\ --boot-drive=DRIVE specify stage2 boot_drive [default=0x%x]\n\ --config-file=FILE specify stage2 config_file [default=%s]\n\ + --disable-config-file disable to use the config file\n\ + --disable-curses disable to use curses\n\ --help display this message and exit\n\ --hold wait until a debugger will attach\n\ --install-partition=PAR specify stage2 install_partition [default=0x%x]\n\ @@ -140,6 +151,20 @@ main (int argc, char **argv) } break; + case OPT_DISABLE_CONFIG_FILE: + use_config_file = 0; + break; + + case OPT_DISABLE_CURSES: + use_curses = 0; + break; + + case OPT_BATCH: + /* This is the same as "--disable-config-file --disable-curses". */ + use_config_file = 0; + use_curses = 0; + break; + default: usage (1); } diff --git a/shared_src/cmdline.c b/shared_src/cmdline.c index 689ccd775..ecb734da9 100644 --- a/shared_src/cmdline.c +++ b/shared_src/cmdline.c @@ -191,7 +191,7 @@ restart: if (password || errnum == ERR_BOOT_COMMAND) { printf("Press any key to continue..."); - (void) getc (); + (void) getkey (); returnit: return 0; } @@ -273,7 +273,7 @@ returnit: } else if (substring("pause", cur_heap) < 1) { - if (getc() == 27) + if (ASCII_CHAR (getkey ()) == 27) return 1; } else if (substring("uppermem", cur_heap) < 1) diff --git a/shared_src/shared.h b/shared_src/shared.h index 066267cef..bc93c206c 100644 --- a/shared_src/shared.h +++ b/shared_src/shared.h @@ -282,6 +282,14 @@ extern unsigned long boot_drive; extern char version_string[]; extern char *config_file; +#ifdef GRUB_UTIL +/* If not using config file, this variable is set to zero, + otherwise non-zero. */ +extern int use_config_file; +/* If not using curses, this variable is set to zero, otherwise non-zero. */ +extern int use_curses; +#endif + #ifndef STAGE1_5 /* GUI interface variables. */ extern int fallback; @@ -427,10 +435,6 @@ void grub_putchar (int c); Use ASCII_CHAR(ret) to extract the ASCII code. */ int getkey (void); -/* returns 0 if non-ASCII character */ -#undef getc -#define getc() ASCII_CHAR (getkey ()) - /* Like GETKEY, but doesn't block, and returns -1 if no keystroke is available. */ int checkkey (void); diff --git a/shared_src/stage2.c b/shared_src/stage2.c index c816922d3..3eb1290b9 100644 --- a/shared_src/stage2.c +++ b/shared_src/stage2.c @@ -527,7 +527,11 @@ cmain(void) * Here load the configuration file. */ +#ifdef GRUB_UTIL + if (use_config_file && grub_open (config_file)) +#else if (grub_open (config_file)) +#endif { int state = 0, prev_config_len = 0, prev_menu_len = 0; char cmdline[1502], *ptr;