2002-01-06 Yoshinori K. Okuji <okuji@gnu.org>

The preset menu has a priority over the configuration file.
	Suggested by Christoph Plattner.

	* stage2/stage2.c [PRESET_MENU_STRING] (open_preset_menu):
	Check if PRESET_MENU is not NULL.
	[PRESET_MENU_STRING] (close_preset_menu): Set PRESET_MENU to
	NULL.
	(cmain): New internal function, reset. This function resets
	AUTO_FILL, CONFIG_LEN, MENU_LEN, NUM_ENTRIES, CONFIG_ENTRIES,
	MENU_ENTRIES and call init_config.
	Try to open the preset menu first, and try to open the
	configuration file, only if that failed.
	Even if the preset menu was read, try to open the configuration
	file. This time, opening the preset menu never succeed, because
	close_preset_menu ensures that the preset menu is available at
	most once.
This commit is contained in:
okuji 2002-01-05 19:59:29 +00:00
parent 41e19993b5
commit 686f75d678
2 changed files with 148 additions and 110 deletions

View file

@ -1,3 +1,22 @@
2002-01-06 Yoshinori K. Okuji <okuji@gnu.org>
The preset menu has a priority over the configuration file.
Suggested by Christoph Plattner.
* stage2/stage2.c [PRESET_MENU_STRING] (open_preset_menu):
Check if PRESET_MENU is not NULL.
[PRESET_MENU_STRING] (close_preset_menu): Set PRESET_MENU to
NULL.
(cmain): New internal function, reset. This function resets
AUTO_FILL, CONFIG_LEN, MENU_LEN, NUM_ENTRIES, CONFIG_ENTRIES,
MENU_ENTRIES and call init_config.
Try to open the preset menu first, and try to open the
configuration file, only if that failed.
Even if the preset menu was read, try to open the configuration
file. This time, opening the preset menu never succeed, because
close_preset_menu ensures that the preset menu is available at
most once.
2002-01-06 Yoshinori K. Okuji <okuji@gnu.org> 2002-01-06 Yoshinori K. Okuji <okuji@gnu.org>
* netboot/misc.c (inet_aton): Don't check if *P is an asterisk, * netboot/misc.c (inet_aton): Don't check if *P is an asterisk,

View file

@ -30,7 +30,7 @@ static int
open_preset_menu (void) open_preset_menu (void)
{ {
preset_menu_offset = 0; preset_menu_offset = 0;
return 1; return preset_menu != 0;
} }
static int static int
@ -50,7 +50,8 @@ read_from_preset_menu (char *buf, int maxlen)
static void static void
close_preset_menu (void) close_preset_menu (void)
{ {
/* Do nothing. */ /* Disable the preset menu. */
preset_menu = 0;
} }
#else /* ! PRESET_MENU_STRING */ #else /* ! PRESET_MENU_STRING */
@ -899,6 +900,18 @@ cmain (void)
char *config_entries, *menu_entries; char *config_entries, *menu_entries;
char *kill_buf = (char *) KILL_BUF; char *kill_buf = (char *) KILL_BUF;
auto void reset (void);
void reset (void)
{
auto_fill = 1;
config_len = 0;
menu_len = 0;
num_entries = 0;
config_entries = (char *) mbi.drives_addr + mbi.drives_length;
menu_entries = (char *) MENU_BUF;
init_config ();
}
/* Initialize the environment for restarting Stage 2. */ /* Initialize the environment for restarting Stage 2. */
grub_setjmp (restart_env); grub_setjmp (restart_env);
@ -908,133 +921,139 @@ cmain (void)
/* Never return. */ /* Never return. */
for (;;) for (;;)
{ {
int is_opened = 0; int is_opened, is_preset;
int is_preset = 0;
reset ();
auto_fill = 1;
config_len = 0;
menu_len = 0;
num_entries = 0;
config_entries = (char *) mbi.drives_addr + mbi.drives_length;
menu_entries = (char *) MENU_BUF;
init_config ();
/* Here load the configuration file. */ /* Here load the configuration file. */
#ifdef GRUB_UTIL #ifdef GRUB_UTIL
if (use_config_file) if (use_config_file)
#endif /* GRUB_UTIL */ #endif /* GRUB_UTIL */
{ {
is_opened = grub_open (config_file); do
errnum = ERR_NONE;
if (! is_opened)
is_opened = is_preset = open_preset_menu ();
}
if (is_opened)
{
/* STATE 0: Before any title command.
STATE 1: In a title command.
STATE >1: In a entry after a title command. */
int state = 0, prev_config_len = 0, prev_menu_len = 0;
char *cmdline;
cmdline = (char *) CMDLINE_BUF;
while (get_line_from_config (cmdline, NEW_HEAPSIZE, ! is_preset))
{ {
struct builtin *builtin; /* STATE 0: Before any title command.
STATE 1: In a title command.
STATE >1: In a entry after a title command. */
int state = 0, prev_config_len = 0, prev_menu_len = 0;
char *cmdline;
/* Get the pointer to the builtin structure. */ /* Try the preset menu first. This will succeed at most once,
builtin = find_command (cmdline); because close_preset_menu disables the preset menu. */
errnum = 0; is_opened = is_preset = open_preset_menu ();
if (! builtin) if (! is_opened)
/* Unknown command. Just skip now. */
continue;
if (builtin->flags & BUILTIN_TITLE)
{ {
char *ptr; is_opened = grub_open (config_file);
errnum = ERR_NONE;
/* the command "title" is specially treated. */
if (state > 1)
{
/* The next title is found. */
num_entries++;
config_entries[config_len++] = 0;
prev_menu_len = menu_len;
prev_config_len = config_len;
}
else
{
/* The first title is found. */
menu_len = prev_menu_len;
config_len = prev_config_len;
}
/* Reset the state. */
state = 1;
/* Copy title into menu area. */
ptr = skip_to (1, cmdline);
while ((menu_entries[menu_len++] = *(ptr++)) != 0)
;
} }
else if (! state)
if (! is_opened)
break;
/* This is necessary, because the menu must be overrided. */
reset ();
cmdline = (char *) CMDLINE_BUF;
while (get_line_from_config (cmdline, NEW_HEAPSIZE,
! is_preset))
{ {
/* Run a command found is possible. */ struct builtin *builtin;
if (builtin->flags & BUILTIN_MENU)
{ /* Get the pointer to the builtin structure. */
char *arg = skip_to (1, cmdline); builtin = find_command (cmdline);
(builtin->func) (arg, BUILTIN_MENU); errnum = 0;
errnum = 0; if (! builtin)
} /* Unknown command. Just skip now. */
else
/* Ignored. */
continue; continue;
if (builtin->flags & BUILTIN_TITLE)
{
char *ptr;
/* the command "title" is specially treated. */
if (state > 1)
{
/* The next title is found. */
num_entries++;
config_entries[config_len++] = 0;
prev_menu_len = menu_len;
prev_config_len = config_len;
}
else
{
/* The first title is found. */
menu_len = prev_menu_len;
config_len = prev_config_len;
}
/* Reset the state. */
state = 1;
/* Copy title into menu area. */
ptr = skip_to (1, cmdline);
while ((menu_entries[menu_len++] = *(ptr++)) != 0)
;
}
else if (! state)
{
/* Run a command found is possible. */
if (builtin->flags & BUILTIN_MENU)
{
char *arg = skip_to (1, cmdline);
(builtin->func) (arg, BUILTIN_MENU);
errnum = 0;
}
else
/* Ignored. */
continue;
}
else
{
char *ptr = cmdline;
state++;
/* Copy config file data to config area. */
while ((config_entries[config_len++] = *ptr++) != 0)
;
}
}
if (state > 1)
{
/* Finish the last entry. */
num_entries++;
config_entries[config_len++] = 0;
} }
else else
{ {
char *ptr = cmdline; menu_len = prev_menu_len;
config_len = prev_config_len;
state++;
/* Copy config file data to config area. */
while ((config_entries[config_len++] = *ptr++) != 0)
;
} }
}
menu_entries[menu_len++] = 0;
if (state > 1)
{
/* Finish the last entry. */
num_entries++;
config_entries[config_len++] = 0; config_entries[config_len++] = 0;
} grub_memmove (config_entries + config_len, menu_entries,
else menu_len);
{ menu_entries = config_entries + config_len;
menu_len = prev_menu_len;
config_len = prev_config_len; /* Check if the default entry is present. Otherwise reset
} it to fallback if fallback is valid, or to DEFAULT_ENTRY
if not. */
menu_entries[menu_len++] = 0; if (default_entry >= num_entries)
config_entries[config_len++] = 0; {
grub_memmove (config_entries + config_len, menu_entries, menu_len); if (fallback_entry < 0 || fallback_entry >= num_entries)
menu_entries = config_entries + config_len; default_entry = 0;
else
/* Check if the default entry is present. Otherwise reset default_entry = fallback_entry;
it to fallback if fallback is valid, or to DEFAULT_ENTRY }
if not. */
if (default_entry >= num_entries) if (is_preset)
{ close_preset_menu ();
if (fallback_entry < 0 || fallback_entry >= num_entries)
default_entry = 0;
else else
default_entry = fallback_entry; grub_close ();
} }
while (is_preset);
if (is_preset)
close_preset_menu ();
else
grub_close ();
} }
if (! num_entries) if (! num_entries)