2003-01-20 04:13:46 +00:00
|
|
|
/*
|
2004-04-04 13:46:03 +00:00
|
|
|
* GRUB -- GRand Unified Bootloader
|
2004-09-10 20:31:55 +00:00
|
|
|
* Copyright (C) 2003,2004 Free Software Foundation, Inc.
|
2003-01-20 04:13:46 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
#include <grub/normal.h>
|
|
|
|
#include <grub/term.h>
|
|
|
|
#include <grub/misc.h>
|
2004-09-10 20:31:55 +00:00
|
|
|
#include <grub/loader.h>
|
2004-09-18 13:42:05 +00:00
|
|
|
#include <grub/mm.h>
|
2004-09-10 20:31:55 +00:00
|
|
|
#include <grub/machine/time.h>
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
/* FIXME: These below are all runaround. */
|
|
|
|
|
2003-09-25 20:15:53 +00:00
|
|
|
#define DISP_LEFT 0x2190
|
|
|
|
#define DISP_UP 0x2191
|
|
|
|
#define DISP_RIGHT 0x2192
|
|
|
|
#define DISP_DOWN 0x2193
|
|
|
|
#define DISP_HLINE 0x2501
|
|
|
|
#define DISP_VLINE 0x2503
|
|
|
|
#define DISP_UL 0x250F
|
|
|
|
#define DISP_UR 0x2513
|
|
|
|
#define DISP_LL 0x2517
|
|
|
|
#define DISP_LR 0x251B
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
/* FIXME: These should be dynamically obtained from a terminal. */
|
|
|
|
#define TERM_WIDTH (80 - 1)
|
|
|
|
#define TERM_HEIGHT 25
|
|
|
|
|
|
|
|
/* The number of lines of "GRUB version..." at the top. */
|
|
|
|
#define TERM_INFO_HEIGHT 1
|
|
|
|
|
|
|
|
/* The number of columns/lines between messages/borders/etc. */
|
|
|
|
#define TERM_MARGIN 1
|
|
|
|
|
|
|
|
/* The number of columns of scroll information. */
|
|
|
|
#define TERM_SCROLL_WIDTH 1
|
|
|
|
|
|
|
|
/* The Y position of the top border. */
|
|
|
|
#define TERM_TOP_BORDER_Y (TERM_MARGIN + TERM_HEIGHT + TERM_MARGIN)
|
|
|
|
|
|
|
|
/* The X position of the left border. */
|
|
|
|
#define TERM_LEFT_BORDER_X TERM_MARGIN
|
|
|
|
|
|
|
|
/* The width of the border. */
|
|
|
|
#define TERM_BORDER_WIDTH (TERM_WIDTH \
|
|
|
|
- TERM_MARGIN * 3 \
|
|
|
|
- TERM_SCROLL_WIDTH)
|
|
|
|
|
|
|
|
/* The number of lines of messages at the bottom. */
|
|
|
|
#define TERM_MESSAGE_HEIGHT 8
|
|
|
|
|
|
|
|
/* The height of the border. */
|
|
|
|
#define TERM_BORDER_HEIGHT (TERM_HEIGHT \
|
|
|
|
- TERM_TOP_BORDER_Y \
|
|
|
|
- TERM_MESSAGE_HEIGHT)
|
|
|
|
|
|
|
|
/* The number of entries shown at a time. */
|
|
|
|
#define TERM_NUM_ENTRIES (TERM_BORDER_HEIGHT - 2)
|
|
|
|
|
|
|
|
/* The Y position of the first entry. */
|
|
|
|
#define TERM_FIRST_ENTRY_Y (TERM_TOP_BORDER_Y + 1)
|
|
|
|
|
|
|
|
/* The max column number of an entry. The last "-1" is for a
|
|
|
|
continuation marker. */
|
|
|
|
#define TERM_ENTRY_WIDTH (TERM_BORDER_WIDTH - 2 - TERM_MARGIN * 2 - 1)
|
|
|
|
|
|
|
|
/* The standard X position of the cursor. */
|
|
|
|
#define TERM_CURSOR_X (TERM_LEFT_BORDER_X \
|
|
|
|
+ TERM_BORDER_WIDTH \
|
|
|
|
- TERM_MARGIN \
|
|
|
|
- 1)
|
|
|
|
|
2003-01-20 04:13:46 +00:00
|
|
|
static void
|
|
|
|
draw_border (void)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_setcolorstate (GRUB_TERM_COLOR_NORMAL);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_MARGIN, TERM_TOP_BORDER_Y);
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putcode (DISP_UL);
|
2004-09-18 13:42:05 +00:00
|
|
|
for (i = 0; i < TERM_BORDER_WIDTH - 2; i++)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putcode (DISP_HLINE);
|
|
|
|
grub_putcode (DISP_UR);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
i = 1;
|
|
|
|
while (1)
|
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_MARGIN, TERM_TOP_BORDER_Y + i);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
if (i > (unsigned) TERM_NUM_ENTRIES)
|
2003-01-20 04:13:46 +00:00
|
|
|
break;
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putcode (DISP_VLINE);
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_MARGIN + TERM_BORDER_WIDTH - 1, TERM_TOP_BORDER_Y + i);
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putcode (DISP_VLINE);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putcode (DISP_LL);
|
2004-09-18 13:42:05 +00:00
|
|
|
for (i = 0; i < TERM_BORDER_WIDTH - 2; i++)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putcode (DISP_HLINE);
|
|
|
|
grub_putcode (DISP_LR);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-09-18 13:42:05 +00:00
|
|
|
print_message (int nested, int edit)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
if (edit)
|
|
|
|
{
|
|
|
|
grub_printf ("\n\
|
|
|
|
Minimum Emacs-like screen editing is supported. TAB lists\n\
|
|
|
|
available completions. Press C-x (\'x\' with Ctrl) to boot,\n\
|
|
|
|
C-c (\'c\' with Ctrl) for a command-line or ESC to return menu.");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
grub_printf ("\n\
|
2003-09-25 20:15:53 +00:00
|
|
|
Use the %C and %C keys to select which entry is highlighted.\n",
|
2004-09-18 13:42:05 +00:00
|
|
|
(grub_uint32_t) DISP_UP, (grub_uint32_t) DISP_DOWN);
|
|
|
|
grub_printf ("\
|
2003-01-20 04:13:46 +00:00
|
|
|
Press enter to boot the selected OS, \'e\' to edit the\n\
|
2004-09-18 13:42:05 +00:00
|
|
|
commands before booting or \'c\' for a command-line.");
|
|
|
|
if (nested)
|
|
|
|
grub_printf ("\n\
|
2003-01-20 04:13:46 +00:00
|
|
|
ESC to return previous menu.");
|
2004-09-18 13:42:05 +00:00
|
|
|
}
|
|
|
|
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
static grub_menu_entry_t
|
|
|
|
get_entry (grub_menu_t menu, int no)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_menu_entry_t e;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
for (e = menu->entry_list; e && no > 0; e = e->next, no--)
|
|
|
|
;
|
|
|
|
|
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-04-04 13:46:03 +00:00
|
|
|
print_entry (int y, int highlight, grub_menu_entry_t entry)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
const char *title;
|
|
|
|
|
|
|
|
title = entry ? entry->title : "";
|
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_setcolorstate (highlight
|
|
|
|
? GRUB_TERM_COLOR_HIGHLIGHT
|
|
|
|
: GRUB_TERM_COLOR_NORMAL);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_LEFT_BORDER_X + TERM_MARGIN, y);
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putchar (' ');
|
2004-09-18 13:42:05 +00:00
|
|
|
for (x = TERM_LEFT_BORDER_X + TERM_MARGIN + 1;
|
|
|
|
x < TERM_LEFT_BORDER_X + TERM_BORDER_WIDTH - 1;
|
|
|
|
x++)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
if (*title && x <= TERM_LEFT_BORDER_X + TERM_ENTRY_WIDTH + 1)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
if (x == TERM_LEFT_BORDER_X + TERM_ENTRY_WIDTH + 1)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putcode (DISP_RIGHT);
|
2003-01-20 04:13:46 +00:00
|
|
|
else
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putchar (*title++);
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
else
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putchar (' ');
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_CURSOR_X, y);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_setcolorstate (GRUB_TERM_COLOR_STANDARD);
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-04-04 13:46:03 +00:00
|
|
|
print_entries (grub_menu_t menu, int first, int offset)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_menu_entry_t e;
|
2003-01-20 04:13:46 +00:00
|
|
|
int i;
|
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_LEFT_BORDER_X + TERM_BORDER_WIDTH + TERM_MARGIN,
|
|
|
|
TERM_FIRST_ENTRY_Y);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
if (first)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putcode (DISP_UP);
|
2003-01-20 04:13:46 +00:00
|
|
|
else
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putchar (' ');
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
e = get_entry (menu, first);
|
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
for (i = 0; i < TERM_NUM_ENTRIES; i++)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
print_entry (TERM_FIRST_ENTRY_Y + i, offset == i, e);
|
2003-01-20 04:13:46 +00:00
|
|
|
if (e)
|
|
|
|
e = e->next;
|
|
|
|
}
|
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_LEFT_BORDER_X + TERM_BORDER_WIDTH + TERM_MARGIN,
|
|
|
|
TERM_TOP_BORDER_Y + TERM_NUM_ENTRIES);
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
if (e)
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putcode (DISP_DOWN);
|
2003-01-20 04:13:46 +00:00
|
|
|
else
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_putchar (' ');
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_CURSOR_X, TERM_FIRST_ENTRY_Y + offset);
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-09-18 13:42:05 +00:00
|
|
|
init_page (int nested, int edit)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_normal_init_page ();
|
2003-01-20 04:13:46 +00:00
|
|
|
draw_border ();
|
2004-09-18 13:42:05 +00:00
|
|
|
print_message (nested, edit);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Edit a menu entry with an Emacs-like interface. */
|
|
|
|
static void
|
|
|
|
edit_menu_entry (grub_menu_entry_t entry)
|
|
|
|
{
|
|
|
|
/* Not yet implemented. */
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2004-04-04 13:46:03 +00:00
|
|
|
run_menu (grub_menu_t menu, int nested)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
|
|
|
int first, offset;
|
2004-09-10 20:31:55 +00:00
|
|
|
unsigned long saved_time;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
first = 0;
|
|
|
|
offset = menu->default_entry;
|
2004-09-18 13:42:05 +00:00
|
|
|
if (offset > TERM_NUM_ENTRIES - 1)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
first = offset - (TERM_NUM_ENTRIES - 1);
|
|
|
|
offset = TERM_NUM_ENTRIES - 1;
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
/* Initialize the time. */
|
|
|
|
saved_time = grub_get_rtc ();
|
|
|
|
|
|
|
|
refresh:
|
|
|
|
grub_setcursor (0);
|
|
|
|
init_page (nested, 0);
|
2003-01-20 04:13:46 +00:00
|
|
|
print_entries (menu, first, offset);
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_refresh ();
|
2004-09-10 20:31:55 +00:00
|
|
|
|
2003-01-20 04:13:46 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2004-09-10 20:31:55 +00:00
|
|
|
if (menu->timeout > 0)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-10 20:31:55 +00:00
|
|
|
unsigned long current_time;
|
|
|
|
|
|
|
|
current_time = grub_get_rtc ();
|
|
|
|
if (current_time - saved_time >= GRUB_TICKS_PER_SECOND)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-10 20:31:55 +00:00
|
|
|
menu->timeout--;
|
|
|
|
saved_time = current_time;
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2004-09-10 20:31:55 +00:00
|
|
|
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (0, TERM_HEIGHT - 3);
|
|
|
|
/* NOTE: Do not remove the trailing space characters.
|
|
|
|
They are required to clear the line. */
|
|
|
|
grub_printf ("\
|
|
|
|
The highlighted entry will be booted automatically in %d seconds. ",
|
2004-09-10 20:31:55 +00:00
|
|
|
menu->timeout);
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_CURSOR_X, TERM_FIRST_ENTRY_Y + offset);
|
2004-09-10 20:31:55 +00:00
|
|
|
grub_refresh ();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (menu->timeout == 0)
|
|
|
|
return menu->default_entry;
|
|
|
|
|
|
|
|
if (grub_checkkey () >= 0 || menu->timeout < 0)
|
|
|
|
{
|
|
|
|
c = GRUB_TERM_ASCII_CHAR (grub_getkey ());
|
|
|
|
|
|
|
|
if (menu->timeout >= 0)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (0, TERM_HEIGHT - 3);
|
|
|
|
grub_printf ("\
|
|
|
|
");
|
2004-09-10 20:31:55 +00:00
|
|
|
menu->timeout = -1;
|
|
|
|
menu->fallback_entry = -1;
|
2004-09-18 13:42:05 +00:00
|
|
|
grub_gotoxy (TERM_CURSOR_X, TERM_FIRST_ENTRY_Y + offset);
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2004-09-10 20:31:55 +00:00
|
|
|
|
|
|
|
switch (c)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-10 20:31:55 +00:00
|
|
|
case 16:
|
|
|
|
case '^':
|
|
|
|
if (offset > 0)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
print_entry (TERM_FIRST_ENTRY_Y + offset, 0,
|
2003-01-20 04:13:46 +00:00
|
|
|
get_entry (menu, first + offset));
|
2004-09-10 20:31:55 +00:00
|
|
|
offset--;
|
2004-09-18 13:42:05 +00:00
|
|
|
print_entry (TERM_FIRST_ENTRY_Y + offset, 1,
|
2003-01-20 04:13:46 +00:00
|
|
|
get_entry (menu, first + offset));
|
|
|
|
}
|
2004-09-10 20:31:55 +00:00
|
|
|
else if (first > 0)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
2004-09-10 20:31:55 +00:00
|
|
|
first--;
|
2003-01-20 04:13:46 +00:00
|
|
|
print_entries (menu, first, offset);
|
|
|
|
}
|
2004-09-10 20:31:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 14:
|
|
|
|
case 'v':
|
|
|
|
if (menu->size > first + offset + 1)
|
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
if (offset < TERM_NUM_ENTRIES - 1)
|
2004-09-10 20:31:55 +00:00
|
|
|
{
|
2004-09-18 13:42:05 +00:00
|
|
|
print_entry (TERM_FIRST_ENTRY_Y + offset, 0,
|
2004-09-10 20:31:55 +00:00
|
|
|
get_entry (menu, first + offset));
|
|
|
|
offset++;
|
2004-09-18 13:42:05 +00:00
|
|
|
print_entry (TERM_FIRST_ENTRY_Y + offset, 1,
|
2004-09-10 20:31:55 +00:00
|
|
|
get_entry (menu, first + offset));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
first++;
|
|
|
|
print_entries (menu, first, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
case 6:
|
|
|
|
grub_setcursor (1);
|
|
|
|
return first + offset;
|
|
|
|
|
|
|
|
case '\e':
|
|
|
|
if (nested)
|
|
|
|
{
|
|
|
|
grub_setcursor (1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'c':
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_setcursor (1);
|
2004-09-10 20:31:55 +00:00
|
|
|
grub_cmdline_run (1);
|
2004-09-18 13:42:05 +00:00
|
|
|
goto refresh;
|
|
|
|
|
|
|
|
case 'e':
|
|
|
|
edit_menu_entry (get_entry (menu, first + offset));
|
|
|
|
goto refresh;
|
2004-09-10 20:31:55 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2004-09-10 20:31:55 +00:00
|
|
|
|
|
|
|
grub_refresh ();
|
|
|
|
}
|
|
|
|
}
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2004-09-10 20:31:55 +00:00
|
|
|
/* Never reach here. */
|
|
|
|
return -1;
|
|
|
|
}
|
2003-01-20 04:13:46 +00:00
|
|
|
|
2004-09-10 20:31:55 +00:00
|
|
|
/* Run a menu entry. */
|
|
|
|
static void
|
|
|
|
run_menu_entry (grub_menu_entry_t entry)
|
|
|
|
{
|
|
|
|
grub_command_list_t cl;
|
|
|
|
|
|
|
|
for (cl = entry->command_list; cl != 0; cl = cl->next)
|
|
|
|
{
|
|
|
|
grub_command_t c;
|
2004-09-18 13:42:05 +00:00
|
|
|
|
|
|
|
if (cl->command[0] == '\0')
|
|
|
|
/* Ignore an empty command line. */
|
|
|
|
continue;
|
2004-09-10 20:31:55 +00:00
|
|
|
|
|
|
|
c = grub_command_find (cl->command);
|
|
|
|
if (! c)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (! (c->flags & GRUB_COMMAND_FLAG_CMDLINE))
|
|
|
|
{
|
|
|
|
grub_error (GRUB_ERR_INVALID_COMMAND,
|
|
|
|
"invalid command `%s'",
|
|
|
|
cl->command);
|
2003-01-20 04:13:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2003-11-17 18:07:09 +00:00
|
|
|
|
2004-09-10 20:31:55 +00:00
|
|
|
if (! (c->flags & GRUB_COMMAND_FLAG_NO_ECHO))
|
|
|
|
grub_printf ("%s\n", cl->command);
|
|
|
|
|
|
|
|
if (grub_command_execute (cl->command) != 0)
|
|
|
|
break;
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
2004-09-10 20:31:55 +00:00
|
|
|
|
|
|
|
if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
|
|
|
|
/* Implicit execution of boot, only if something is loaded. */
|
|
|
|
grub_command_execute ("boot");
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-04-04 13:46:03 +00:00
|
|
|
grub_menu_run (grub_menu_t menu, int nested)
|
2003-01-20 04:13:46 +00:00
|
|
|
{
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int boot_entry;
|
2004-09-10 20:31:55 +00:00
|
|
|
grub_menu_entry_t e;
|
2003-01-20 04:13:46 +00:00
|
|
|
|
|
|
|
boot_entry = run_menu (menu, nested);
|
|
|
|
if (boot_entry < 0)
|
|
|
|
break;
|
|
|
|
|
2004-09-10 20:31:55 +00:00
|
|
|
grub_cls ();
|
|
|
|
grub_setcursor (1);
|
|
|
|
|
|
|
|
e = get_entry (menu, boot_entry);
|
|
|
|
grub_printf (" Booting \'%s\'\n\n", e->title);
|
|
|
|
|
|
|
|
run_menu_entry (e);
|
|
|
|
|
|
|
|
/* Deal with a fallback entry. */
|
2004-09-17 09:36:52 +00:00
|
|
|
/* FIXME: Multiple fallback entries like GRUB Legacy. */
|
2004-09-10 20:31:55 +00:00
|
|
|
if (menu->fallback_entry >= 0)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
|
|
|
e = get_entry (menu, menu->fallback_entry);
|
|
|
|
menu->fallback_entry = -1;
|
|
|
|
grub_printf ("\n Falling back to \'%s\'\n\n", e->title);
|
|
|
|
run_menu_entry (e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (grub_errno != GRUB_ERR_NONE)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
|
|
|
/* Wait until the user pushes any key so that the user
|
|
|
|
can see what happened. */
|
|
|
|
grub_printf ("\nPress any key to continue...");
|
|
|
|
(void) grub_getkey ();
|
|
|
|
}
|
2003-01-20 04:13:46 +00:00
|
|
|
}
|
|
|
|
}
|