Preliminary non-interactive use support
This commit is contained in:
parent
8c2e2a840c
commit
be705674e1
6 changed files with 129 additions and 43 deletions
35
ChangeLog
35
ChangeLog
|
@ -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.
|
||||||
|
|
|
@ -180,13 +180,16 @@ grub_stage2 (void)
|
||||||
|
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
/* Get into char-at-a-time mode. */
|
/* Get into char-at-a-time mode. */
|
||||||
initscr ();
|
if (use_curses)
|
||||||
cbreak ();
|
{
|
||||||
noecho ();
|
initscr ();
|
||||||
nonl ();
|
cbreak ();
|
||||||
scrollok (stdscr, TRUE);
|
noecho ();
|
||||||
keypad (stdscr, TRUE);
|
nonl ();
|
||||||
nodelay (stdscr, TRUE);
|
scrollok (stdscr, TRUE);
|
||||||
|
keypad (stdscr, TRUE);
|
||||||
|
nodelay (stdscr, TRUE);
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Set our stack, and go for it. */
|
/* Set our stack, and go for it. */
|
||||||
|
@ -194,7 +197,8 @@ grub_stage2 (void)
|
||||||
doit ();
|
doit ();
|
||||||
|
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
endwin ();
|
if (use_curses)
|
||||||
|
endwin ();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Close off the file descriptors we used. */
|
/* Close off the file descriptors we used. */
|
||||||
|
@ -221,7 +225,8 @@ void
|
||||||
stop (void)
|
stop (void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
endwin ();
|
if (use_curses)
|
||||||
|
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. */
|
||||||
fprintf (stderr, "grub: aborting...\n");
|
fprintf (stderr, "grub: aborting...\n");
|
||||||
|
@ -348,7 +353,8 @@ void
|
||||||
cls (void)
|
cls (void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
clear ();
|
if (use_curses)
|
||||||
|
clear ();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,10 +365,11 @@ getxy (void)
|
||||||
{
|
{
|
||||||
int y, x;
|
int y, x;
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
getyx (stdscr, y, x);
|
if (use_curses)
|
||||||
#else
|
getyx (stdscr, y, x);
|
||||||
y = x = 0;
|
else
|
||||||
#endif
|
#endif
|
||||||
|
y = x = 0;
|
||||||
return (x << 8) | (y & 0xff);
|
return (x << 8) | (y & 0xff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +378,8 @@ void
|
||||||
gotoxy (int x, int y)
|
gotoxy (int x, int y)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
move (y, x);
|
if (use_curses)
|
||||||
|
move (y, x);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,10 +390,11 @@ void
|
||||||
grub_putchar (int c)
|
grub_putchar (int c)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
addch (c);
|
if (use_curses)
|
||||||
#else
|
addch (c);
|
||||||
putchar (c);
|
else
|
||||||
#endif
|
#endif
|
||||||
|
putchar (c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -394,14 +403,17 @@ int
|
||||||
getkey (void)
|
getkey (void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
int c;
|
if (use_curses)
|
||||||
nodelay (stdscr, FALSE);
|
{
|
||||||
c = getch ();
|
int c;
|
||||||
nodelay (stdscr, TRUE);
|
nodelay (stdscr, FALSE);
|
||||||
return c;
|
c = getch ();
|
||||||
#else
|
nodelay (stdscr, TRUE);
|
||||||
return getchar ();
|
return c;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
return getchar ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -410,16 +422,19 @@ int
|
||||||
checkkey (void)
|
checkkey (void)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
int c;
|
if (use_curses)
|
||||||
c = getch ();
|
{
|
||||||
/* If C is not ERR, then put it back in the input queue. */
|
int c;
|
||||||
if (c != ERR)
|
c = getch ();
|
||||||
ungetch (c); /* FIXME: ncurses-1.9.9g ungetch is buggy. */
|
/* If C is not ERR, then put it back in the input queue. */
|
||||||
return c;
|
if (c != ERR)
|
||||||
#else
|
ungetch (c); /* FIXME: ncurses-1.9.9g ungetch is buggy. */
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Just pretend they hit the space bar. */
|
/* Just pretend they hit the space bar. */
|
||||||
return ' ';
|
return ' ';
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -428,13 +443,16 @@ void
|
||||||
set_attrib (int attr)
|
set_attrib (int attr)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_LIBCURSES
|
#ifdef HAVE_LIBCURSES
|
||||||
/* FIXME: I don't know why, but chgat doesn't work as expected, so
|
if (use_curses)
|
||||||
use this dirty way... - okuji */
|
{
|
||||||
chtype ch = inch ();
|
/* FIXME: I don't know why, but chgat doesn't work as expected, so
|
||||||
addch ((ch & A_CHARTEXT) | attr);
|
use this dirty way... - okuji */
|
||||||
|
chtype ch = inch ();
|
||||||
|
addch ((ch & A_CHARTEXT) | attr);
|
||||||
# if 0
|
# if 0
|
||||||
chgat (1, attr, 0, NULL);
|
chgat (1, attr, 0, NULL);
|
||||||
# endif
|
# endif
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
grub/main.c
25
grub/main.c
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue