2009-11-20 Colin D Bennett <colin@gibibit.com>

* normal/menu_text.c (get_entry_number): Move from here ...
	* normal/menu.c (get_entry_number): ... moved here.
	* include/grub/menu.h (grub_menu_get_default_entry_index):
	New prototype.
	* normal/menu.c (grub_menu_get_default_entry_index): New function.
	* normal/menu_text.c (run_menu): Use grub_menu_get_default_entry_index.
This commit is contained in:
Vladimir 'phcoder' Serbinenko 2009-11-20 14:45:33 +01:00
parent c8c33d7d1f
commit ac3b7128d6
4 changed files with 65 additions and 49 deletions

9
ChangeLog.menu Normal file
View file

@ -0,0 +1,9 @@
2009-11-20 Colin D Bennett <colin@gibibit.com>
* normal/menu_text.c (get_entry_number): Move from here ...
* normal/menu.c (get_entry_number): ... moved here.
* include/grub/menu.h (grub_menu_get_default_entry_index):
New prototype.
* normal/menu.c (grub_menu_get_default_entry_index): New function.
* normal/menu_text.c (run_menu): Use grub_menu_get_default_entry_index.

View file

@ -93,5 +93,6 @@ void grub_menu_execute_with_fallback (grub_menu_t menu,
grub_menu_execute_callback_t callback,
void *callback_data);
void grub_menu_entry_run (grub_menu_entry_t entry);
int grub_menu_get_default_entry_index (grub_menu_t menu);
#endif /* GRUB_MENU_HEADER */

View file

@ -180,3 +180,57 @@ grub_menu_execute_with_fallback (grub_menu_t menu,
callback->notify_failure (callback_data);
}
/* Get the entry number from the variable NAME. */
static int
get_entry_number (grub_menu_t menu, const char *name)
{
char *val;
int entry;
val = grub_env_get (name);
if (! val)
return -1;
grub_error_push ();
entry = (int) grub_strtoul (val, 0, 0);
if (grub_errno == GRUB_ERR_BAD_NUMBER)
{
/* See if the variable matches the title of a menu entry. */
grub_menu_entry_t e = menu->entry_list;
int i;
grub_errno = GRUB_ERR_NONE;
for (i = 0; e; i++)
{
if (grub_strcmp (e->title, val) == 0)
{
entry = i;
break;
}
e = e->next;
}
if (! e)
entry = -1;
}
if (grub_errno != GRUB_ERR_NONE)
{
grub_errno = GRUB_ERR_NONE;
entry = -1;
}
grub_error_pop ();
return entry;
}
int
grub_menu_get_default_entry_index (grub_menu_t menu)
{
return get_entry_number (menu, "default");
}

View file

@ -235,54 +235,6 @@ grub_menu_init_page (int nested, int edit)
print_message (nested, edit);
}
/* Get the entry number from the variable NAME. */
static int
get_entry_number (grub_menu_t menu, const char *name)
{
char *val;
int entry;
val = grub_env_get (name);
if (! val)
return -1;
grub_error_push ();
entry = (int) grub_strtoul (val, 0, 0);
if (grub_errno == GRUB_ERR_BAD_NUMBER)
{
/* See if the variable matches the title of a menu entry. */
grub_menu_entry_t e = menu->entry_list;
int i;
grub_errno = GRUB_ERR_NONE;
for (i = 0; e; i++)
{
if (grub_strcmp (e->title, val) == 0)
{
entry = i;
break;
}
e = e->next;
}
if (! e)
entry = -1;
}
if (grub_errno != GRUB_ERR_NONE)
{
grub_errno = GRUB_ERR_NONE;
entry = -1;
}
grub_error_pop ();
return entry;
}
static void
print_timeout (int timeout, int offset, int second_stage)
{
@ -313,7 +265,7 @@ run_menu (grub_menu_t menu, int nested, int *auto_boot)
first = 0;
default_entry = get_entry_number (menu, "default");
default_entry = grub_menu_get_default_entry_index (menu);
/* If DEFAULT_ENTRY is not within the menu entries, fall back to
the first entry. */