Preliminary non-interactive use support

This commit is contained in:
okuji 1999-05-02 21:30:41 +00:00
parent 8c2e2a840c
commit be705674e1
6 changed files with 129 additions and 43 deletions

View file

@ -1,3 +1,38 @@
1999-05-03 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
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 <okuji@kuicr.kyoto-u.ac.jp> 1999-05-03 OKUJI Yoshinori <okuji@kuicr.kyoto-u.ac.jp>
* grub/asmstub.c (device_map): New variable. * grub/asmstub.c (device_map): New variable.

View file

@ -180,6 +180,8 @@ grub_stage2 (void)
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
/* Get into char-at-a-time mode. */ /* Get into char-at-a-time mode. */
if (use_curses)
{
initscr (); initscr ();
cbreak (); cbreak ();
noecho (); noecho ();
@ -187,6 +189,7 @@ grub_stage2 (void)
scrollok (stdscr, TRUE); scrollok (stdscr, TRUE);
keypad (stdscr, TRUE); keypad (stdscr, TRUE);
nodelay (stdscr, TRUE); nodelay (stdscr, TRUE);
}
#endif #endif
/* Set our stack, and go for it. */ /* Set our stack, and go for it. */
@ -194,6 +197,7 @@ grub_stage2 (void)
doit (); doit ();
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
if (use_curses)
endwin (); endwin ();
#endif #endif
@ -221,6 +225,7 @@ void
stop (void) stop (void)
{ {
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
if (use_curses)
endwin (); endwin ();
#endif #endif
/* FIXME: If we don't exit, then we need to free our data areas. */ /* FIXME: If we don't exit, then we need to free our data areas. */
@ -348,6 +353,7 @@ void
cls (void) cls (void)
{ {
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
if (use_curses)
clear (); clear ();
#endif #endif
} }
@ -359,10 +365,11 @@ getxy (void)
{ {
int y, x; int y, x;
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
if (use_curses)
getyx (stdscr, y, x); getyx (stdscr, y, x);
#else else
y = x = 0;
#endif #endif
y = x = 0;
return (x << 8) | (y & 0xff); return (x << 8) | (y & 0xff);
} }
@ -371,6 +378,7 @@ void
gotoxy (int x, int y) gotoxy (int x, int y)
{ {
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
if (use_curses)
move (y, x); move (y, x);
#endif #endif
} }
@ -382,10 +390,11 @@ void
grub_putchar (int c) grub_putchar (int c)
{ {
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
if (use_curses)
addch (c); addch (c);
#else else
putchar (c);
#endif #endif
putchar (c);
} }
@ -394,14 +403,17 @@ int
getkey (void) getkey (void)
{ {
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
if (use_curses)
{
int c; int c;
nodelay (stdscr, FALSE); nodelay (stdscr, FALSE);
c = getch (); c = getch ();
nodelay (stdscr, TRUE); nodelay (stdscr, TRUE);
return c; return c;
#else }
return getchar ();
#endif #endif
return getchar ();
} }
@ -410,16 +422,19 @@ int
checkkey (void) checkkey (void)
{ {
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
if (use_curses)
{
int c; int c;
c = getch (); c = getch ();
/* If C is not ERR, then put it back in the input queue. */ /* If C is not ERR, then put it back in the input queue. */
if (c != ERR) if (c != ERR)
ungetch (c); /* FIXME: ncurses-1.9.9g ungetch is buggy. */ ungetch (c); /* FIXME: ncurses-1.9.9g ungetch is buggy. */
return c; return c;
#else }
#endif
/* Just pretend they hit the space bar. */ /* Just pretend they hit the space bar. */
return ' '; return ' ';
#endif
} }
@ -428,6 +443,8 @@ void
set_attrib (int attr) set_attrib (int attr)
{ {
#ifdef HAVE_LIBCURSES #ifdef HAVE_LIBCURSES
if (use_curses)
{
/* FIXME: I don't know why, but chgat doesn't work as expected, so /* FIXME: I don't know why, but chgat doesn't work as expected, so
use this dirty way... - okuji */ use this dirty way... - okuji */
chtype ch = inch (); chtype ch = inch ();
@ -435,6 +452,7 @@ set_attrib (int attr)
# if 0 # if 0
chgat (1, attr, 0, NULL); chgat (1, attr, 0, NULL);
# endif # endif
}
#endif #endif
} }

View file

@ -32,6 +32,8 @@ int grub_stage2 (void);
#include "shared.h" #include "shared.h"
char *program_name = 0; char *program_name = 0;
int use_config_file = 1;
int use_curses = 1;
static int default_boot_drive; static int default_boot_drive;
static int default_install_partition; static int default_install_partition;
static char *default_config_file; static char *default_config_file;
@ -42,6 +44,9 @@ static char *default_config_file;
#define OPT_CONFIG_FILE -5 #define OPT_CONFIG_FILE -5
#define OPT_INSTALL_PARTITION -6 #define OPT_INSTALL_PARTITION -6
#define OPT_BOOT_DRIVE -7 #define OPT_BOOT_DRIVE -7
#define OPT_DISABLE_CONFIG_FILE -8
#define OPT_DISABLE_CURSES -9
#define OPT_BATCH -10
#define OPTSTRING "" #define OPTSTRING ""
static struct option longopts[] = static struct option longopts[] =
@ -52,6 +57,9 @@ static struct option longopts[] =
{"config-file", required_argument, 0, OPT_CONFIG_FILE}, {"config-file", required_argument, 0, OPT_CONFIG_FILE},
{"install-partition", required_argument, 0, OPT_INSTALL_PARTITION}, {"install-partition", required_argument, 0, OPT_INSTALL_PARTITION},
{"boot-drive", required_argument, 0, OPT_BOOT_DRIVE}, {"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}, {0},
}; };
@ -68,8 +76,11 @@ Usage: %s [OPTION]...\n\
\n\ \n\
Enter the GRand Unified Bootloader command shell.\n\ Enter the GRand Unified Bootloader command shell.\n\
\n\ \n\
--batch turn on batch mode for non-interactive use\n\
--boot-drive=DRIVE specify stage2 boot_drive [default=0x%x]\n\ --boot-drive=DRIVE specify stage2 boot_drive [default=0x%x]\n\
--config-file=FILE specify stage2 config_file [default=%s]\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\ --help display this message and exit\n\
--hold wait until a debugger will attach\n\ --hold wait until a debugger will attach\n\
--install-partition=PAR specify stage2 install_partition [default=0x%x]\n\ --install-partition=PAR specify stage2 install_partition [default=0x%x]\n\
@ -140,6 +151,20 @@ main (int argc, char **argv)
} }
break; 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: default:
usage (1); usage (1);
} }

View file

@ -191,7 +191,7 @@ restart:
if (password || errnum == ERR_BOOT_COMMAND) if (password || errnum == ERR_BOOT_COMMAND)
{ {
printf("Press any key to continue..."); printf("Press any key to continue...");
(void) getc (); (void) getkey ();
returnit: returnit:
return 0; return 0;
} }
@ -273,7 +273,7 @@ returnit:
} }
else if (substring("pause", cur_heap) < 1) else if (substring("pause", cur_heap) < 1)
{ {
if (getc() == 27) if (ASCII_CHAR (getkey ()) == 27)
return 1; return 1;
} }
else if (substring("uppermem", cur_heap) < 1) else if (substring("uppermem", cur_heap) < 1)

View file

@ -282,6 +282,14 @@ extern unsigned long boot_drive;
extern char version_string[]; extern char version_string[];
extern char *config_file; 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 #ifndef STAGE1_5
/* GUI interface variables. */ /* GUI interface variables. */
extern int fallback; extern int fallback;
@ -427,10 +435,6 @@ void grub_putchar (int c);
Use ASCII_CHAR(ret) to extract the ASCII code. */ Use ASCII_CHAR(ret) to extract the ASCII code. */
int getkey (void); 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 /* Like GETKEY, but doesn't block, and returns -1 if no keystroke is
available. */ available. */
int checkkey (void); int checkkey (void);

View file

@ -527,7 +527,11 @@ cmain(void)
* Here load the configuration file. * Here load the configuration file.
*/ */
#ifdef GRUB_UTIL
if (use_config_file && grub_open (config_file))
#else
if (grub_open (config_file)) if (grub_open (config_file))
#endif
{ {
int state = 0, prev_config_len = 0, prev_menu_len = 0; int state = 0, prev_config_len = 0, prev_menu_len = 0;
char cmdline[1502], *ptr; char cmdline[1502], *ptr;