2005-02-19 20:56:07 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2008-01-05 12:10:28 +00:00
|
|
|
* Copyright (C) 2005,2006,2007,2008 Free Software Foundation, Inc.
|
2005-02-19 20:56:07 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2005-02-19 20:56:07 +00:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2007-07-21 23:32:33 +00:00
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
2005-02-19 20:56:07 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
2005-02-19 20:56:07 +00:00
|
|
|
* 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
|
2007-07-21 23:32:33 +00:00
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
2005-02-19 20:56:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/normal.h>
|
|
|
|
#include <grub/term.h>
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/loader.h>
|
2009-05-02 Bean <bean123ch@gmail.com>
* conf/common.rmk (grub_script.tab.c): Change normal/parser.y to
script/sh/parser.y.
(pkglib_MODULES): Add normal.mod and sh.mod.
(normal_SOURCES): New variable.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
(sh_mod_SOURCES): Likewise.
(sh_mod_CFLAGS): Likewise.
(sh_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (normal/lexer.c_DEPENDENCIES): Changed to
script/sh/lexer.c_DEPENDENCIES.
(kernel_img_SOURCES): Remove kern/rescue.c, and kern/reader.c,
kern/rescue_reader.c and kern/rescue_parser.c.
(kernel_img_HEADERS): Remove rescue.h, add reader.h.
(grub_emu_SOURCES): Change source files.
(pkglib_MODULES): Remove normal.mod.
(normal_SOURCES): Removed.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1276.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/command.h (grub_command_execute): New inline function.
* include/grub/menu.h (grub_menu_entry): Removed commands field.
* include/grub/normal.h: Remove <grub/setjmp.h>.
(grub_fs_module_list): Moved to normal/autofs.c.
(grub_exit_env): Removed.
(grub_command_execute): Likewise.
(grub_normal_menu_addentry): Renamed to grub_menu_addentry, removed
parameter script.
(read_command_list): New function declaration.
(read_fs_list): Likewise.
* include/parser.h: Include <grub/reader.h>.
(grub_parser_split_cmdline): Change type of getline parameter.
(grub_parser): New structure.
(grub_parser_class): New variable.
(grub_parser_execute): New function declaration.
(grub_register_rescue_parser): Likewise.
(grub_parser_register): New inline function.
(grub_parser_unregister): Likewise.
(grub_parser_get_current): Likewise.
(grub_parser_set_current): Likewise.
* include/grub/reader.h: New file.
* kern/reader.c: Likewise.
* kern/rescue_parser.c: Likewise.
* kern/rescue_reader.c: Likewise.
* normal/autofs.c: Likewise.
* normal/dyncmd.c: Likewise.
* include/grub/rescue.h: Removed.
* normal/command.h: Likewise.
* include/grub/script.h: Moved to ...
* include/grub/script_sh.h: ... Moved here.
* normal/execute.c: Moved to ...
* script/sh/execute.c: ... Moved here.
* normal/function.c: Moved to ...
* script/sh/function.c: ... Moved here.
* normal/lexer.c: Moved to ...
* script/sh/lexer.c: ... Moved here.
* normal/parser.y: Moved to ...
* script/sh/parser.y: ... Moved here.
* normal/script.c: Moved to ...
* script/sh/script.c: ... Moved here.
* normal/main.c: Remove <grub/rescue.h> and <grub/script.h>, include
<grub/reader.h>.
(grub_exit_env): Removed.
(fs_module_list): Moved to normal/autofs.c.
(grub_file_getline): Don't handle comment here.
(free_menu): Skip removed field entry->commands.
(grub_normal_menu_addentry): Removed as grub_menu_entry, removed
script parameter.
(read_config_file): Removed nested parameter, change getline function.
(grub_enter_normal_mode): Removed.
(grub_dyncmd_dispatcher): Moved to normal/dyncmd.c.
(read_command_list): Likewise.
(autoload_fs_module): Moved to normal/autofs.c.
(read_fs_list): Likewise.
(reader_nested): New variable.
(grub_normal_execute): Run parser.sh to switch to sh parser.
(grub_cmd_rescue): Removed.
(cmd_normal): Removed.
(grub_cmd_normal): Unregister itself at the beginning. Don't register
rescue command.
(grub_cmdline_run): New function.
(grub_normal_reader_init): Likewise.
(grub_normal_read_line): Likewise.
(grub_env_write_pager): Likewise.
(cmdline): New variable.
(grub_normal_reader): Likewise.
(GRUB_MOD_INIT): Register normal reader and set as current, register
pager hook, register normal command with grub_register_command_prio,
so that it won't show up in command.lst.
(GRUB_MOD_FINI): Unregister normal reader, unhook pager, clear
grub_fs_autoload_hook.
* normal/menu.c: Remove <grub/script.h>, add <grub/command.h>.
(grub_menu_execute_entry): Replace grub_script_execute with
grub_parser_execute, change parameter to grub_command_execute.
* normal/menu_text.c: Remove <grub/script.h>.
* normal/menu_entry.c: Remove <grub/script.h>, add <grub/command.h>
and <grub/parser.h>.
(run): Change editor_getline to use new parser interface. Change
parameter to grub_command_execute.
* kern/main.c: Remove <grub/rescue.h>, include <grub/command.h>,
<grub/reader.h> and <grub/parser.h>.
(grub_load_normal_mode): Execute normal command.
(grub_main): Call grub_register_core_commands,
grub_register_rescue_parser and grub_register_rescue_reader, use
grub_reader_loop to enter input loop.
* kern/parser.c (grub_parser_spli_cmdline): Change type of getline
parameter.
(grub_parser_class): New variable.
(grub_parser_execute): New function.
* loader/i386/multiboot.c: Remove <grub/rescue.h>.
* loader/multiboot2.c: Likewise.
* loader/sparc64/ieee1275/linux.c: Likewise.
* util/grub-emu.c (read_command_list): New dummy function.
2009-05-02 19:49:34 +00:00
|
|
|
#include <grub/command.h>
|
|
|
|
#include <grub/parser.h>
|
2009-08-24 23:55:06 +00:00
|
|
|
#include <grub/auth.h>
|
2009-11-23 20:22:36 +00:00
|
|
|
#include <grub/i18n.h>
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
enum update_mode
|
|
|
|
{
|
|
|
|
NO_LINE,
|
|
|
|
SINGLE_LINE,
|
|
|
|
ALL_LINES
|
|
|
|
};
|
|
|
|
|
|
|
|
struct line
|
|
|
|
{
|
|
|
|
/* The line buffer. */
|
|
|
|
char *buf;
|
|
|
|
/* The length of the line. */
|
|
|
|
int len;
|
|
|
|
/* The maximum length of the line. */
|
|
|
|
int max_len;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct screen
|
|
|
|
{
|
|
|
|
/* The array of lines. */
|
|
|
|
struct line *lines;
|
|
|
|
/* The number of lines. */
|
|
|
|
int num_lines;
|
|
|
|
/* The current column. */
|
|
|
|
int column;
|
|
|
|
/* The real column. */
|
|
|
|
int real_column;
|
|
|
|
/* The current line. */
|
|
|
|
int line;
|
|
|
|
/* The X coordinate. */
|
|
|
|
int x;
|
|
|
|
/* The Y coordinate. */
|
|
|
|
int y;
|
|
|
|
/* The kill buffer. */
|
|
|
|
char *killed_text;
|
2005-08-18 03:14:39 +00:00
|
|
|
/* The flag of a completion window. */
|
|
|
|
int completion_shown;
|
2005-02-19 20:56:07 +00:00
|
|
|
};
|
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
/* Used for storing completion items temporarily. */
|
|
|
|
static struct line completion_buffer;
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Initialize a line. */
|
|
|
|
static int
|
|
|
|
init_line (struct line *linep)
|
|
|
|
{
|
|
|
|
linep->len = 0;
|
|
|
|
linep->max_len = 80; /* XXX */
|
|
|
|
linep->buf = grub_malloc (linep->max_len);
|
|
|
|
if (! linep->buf)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate extra space if necessary. */
|
|
|
|
static int
|
|
|
|
ensure_space (struct line *linep, int extra)
|
|
|
|
{
|
|
|
|
if (linep->max_len < linep->len + extra)
|
|
|
|
{
|
|
|
|
linep->max_len = linep->len + extra + 80; /* XXX */
|
|
|
|
linep->buf = grub_realloc (linep->buf, linep->max_len + 1);
|
|
|
|
if (! linep->buf)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the number of lines occupied by this line on the screen. */
|
|
|
|
static int
|
|
|
|
get_logical_num_lines (struct line *linep)
|
|
|
|
{
|
|
|
|
return (linep->len / GRUB_TERM_ENTRY_WIDTH) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print a line. */
|
|
|
|
static void
|
|
|
|
print_line (struct line *linep, int offset, int start, int y)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
char *p;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + start + 1,
|
|
|
|
y + GRUB_TERM_FIRST_ENTRY_Y);
|
|
|
|
|
|
|
|
for (p = linep->buf + offset + start, i = start;
|
|
|
|
i < GRUB_TERM_ENTRY_WIDTH && offset + i < linep->len;
|
|
|
|
p++, i++)
|
|
|
|
grub_putchar (*p);
|
|
|
|
|
|
|
|
for (; i < GRUB_TERM_ENTRY_WIDTH; i++)
|
|
|
|
grub_putchar (' ');
|
|
|
|
|
|
|
|
if (linep->len >= offset + GRUB_TERM_ENTRY_WIDTH)
|
|
|
|
grub_putchar ('\\');
|
|
|
|
else
|
|
|
|
grub_putchar (' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print an empty line. */
|
|
|
|
static void
|
|
|
|
print_empty_line (int y)
|
|
|
|
{
|
|
|
|
int i;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1,
|
|
|
|
y + GRUB_TERM_FIRST_ENTRY_Y);
|
|
|
|
|
|
|
|
for (i = 0; i < GRUB_TERM_ENTRY_WIDTH + 1; i++)
|
|
|
|
grub_putchar (' ');
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print an up arrow. */
|
|
|
|
static void
|
|
|
|
print_up (int flag)
|
|
|
|
{
|
|
|
|
grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH,
|
|
|
|
GRUB_TERM_FIRST_ENTRY_Y);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (flag)
|
|
|
|
grub_putcode (GRUB_TERM_DISP_UP);
|
|
|
|
else
|
|
|
|
grub_putchar (' ');
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Print a down arrow. */
|
|
|
|
static void
|
|
|
|
print_down (int flag)
|
|
|
|
{
|
|
|
|
grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_BORDER_WIDTH,
|
|
|
|
GRUB_TERM_TOP_BORDER_Y + GRUB_TERM_NUM_ENTRIES);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (flag)
|
|
|
|
grub_putcode (GRUB_TERM_DISP_DOWN);
|
|
|
|
else
|
|
|
|
grub_putchar (' ');
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Draw the lines of the screen SCREEN. */
|
|
|
|
static void
|
|
|
|
update_screen (struct screen *screen, int region_start, int region_column,
|
|
|
|
int up, int down, enum update_mode mode)
|
|
|
|
{
|
|
|
|
int up_flag = 0;
|
|
|
|
int down_flag = 0;
|
|
|
|
int y;
|
|
|
|
int i;
|
|
|
|
struct line *linep;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Check if scrolling is necessary. */
|
|
|
|
if (screen->y < 0 || screen->y >= GRUB_TERM_NUM_ENTRIES)
|
|
|
|
{
|
|
|
|
if (screen->y < 0)
|
|
|
|
screen->y = 0;
|
|
|
|
else
|
|
|
|
screen->y = GRUB_TERM_NUM_ENTRIES - 1;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
region_start = 0;
|
|
|
|
region_column = 0;
|
|
|
|
up = 1;
|
|
|
|
down = 1;
|
|
|
|
mode = ALL_LINES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != NO_LINE)
|
|
|
|
{
|
|
|
|
/* Draw lines. This code is tricky, because this must calculate logical
|
|
|
|
positions. */
|
|
|
|
y = screen->y - screen->column / GRUB_TERM_ENTRY_WIDTH;
|
|
|
|
i = screen->line;
|
|
|
|
linep = screen->lines + i;
|
|
|
|
while (y > 0)
|
|
|
|
{
|
|
|
|
i--;
|
|
|
|
linep--;
|
|
|
|
y -= get_logical_num_lines (linep);
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (y < 0 || i > 0)
|
|
|
|
up_flag = 1;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
int column;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
for (column = 0;
|
|
|
|
column <= linep->len && y < GRUB_TERM_NUM_ENTRIES;
|
|
|
|
column += GRUB_TERM_ENTRY_WIDTH, y++)
|
|
|
|
{
|
|
|
|
if (y < 0)
|
|
|
|
continue;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (i == region_start)
|
|
|
|
{
|
|
|
|
if (region_column >= column
|
|
|
|
&& region_column < column + GRUB_TERM_ENTRY_WIDTH)
|
|
|
|
print_line (linep, column, region_column - column, y);
|
|
|
|
else if (region_column < column)
|
|
|
|
print_line (linep, column, 0, y);
|
|
|
|
}
|
|
|
|
else if (i > region_start && mode == ALL_LINES)
|
|
|
|
print_line (linep, column, 0, y);
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (y == GRUB_TERM_NUM_ENTRIES)
|
|
|
|
{
|
|
|
|
if (column <= linep->len || i + 1 < screen->num_lines)
|
|
|
|
down_flag = 1;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep++;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (mode == ALL_LINES && i == screen->num_lines)
|
|
|
|
for (; y < GRUB_TERM_NUM_ENTRIES; y++)
|
|
|
|
print_empty_line (y);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
while (y < GRUB_TERM_NUM_ENTRIES);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Draw up and down arrows. */
|
|
|
|
if (up)
|
|
|
|
print_up (up_flag);
|
|
|
|
if (down)
|
|
|
|
print_down (down_flag);
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Place the cursor. */
|
|
|
|
grub_gotoxy (GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1 + screen->x,
|
|
|
|
GRUB_TERM_FIRST_ENTRY_Y + screen->y);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
grub_refresh ();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Insert the string S into the screen SCREEN. This updates the cursor
|
|
|
|
position and redraw the screen. Return zero if fails. */
|
|
|
|
static int
|
|
|
|
insert_string (struct screen *screen, char *s, int update)
|
|
|
|
{
|
|
|
|
int region_start = screen->num_lines;
|
|
|
|
int region_column = 0;
|
|
|
|
int down = 0;
|
|
|
|
enum update_mode mode = NO_LINE;
|
|
|
|
|
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
if (*s == '\n')
|
|
|
|
{
|
|
|
|
/* LF is special because it creates a new line. */
|
|
|
|
struct line *current_linep;
|
|
|
|
struct line *next_linep;
|
|
|
|
int size;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Make a new line. */
|
|
|
|
screen->num_lines++;
|
|
|
|
screen->lines = grub_realloc (screen->lines,
|
|
|
|
screen->num_lines
|
|
|
|
* sizeof (struct line));
|
|
|
|
if (! screen->lines)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Scroll down. */
|
|
|
|
grub_memmove (screen->lines + screen->line + 2,
|
|
|
|
screen->lines + screen->line + 1,
|
|
|
|
((screen->num_lines - screen->line - 2)
|
|
|
|
* sizeof (struct line)));
|
|
|
|
|
|
|
|
if (! init_line (screen->lines + screen->line + 1))
|
|
|
|
return 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Fold the line. */
|
|
|
|
current_linep = screen->lines + screen->line;
|
|
|
|
next_linep = current_linep + 1;
|
|
|
|
size = current_linep->len - screen->column;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! ensure_space (next_linep, size))
|
|
|
|
return 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
grub_memmove (next_linep->buf,
|
|
|
|
current_linep->buf + screen->column,
|
|
|
|
size);
|
|
|
|
current_linep->len = screen->column;
|
|
|
|
next_linep->len = size;
|
|
|
|
|
|
|
|
/* Update a dirty region. */
|
|
|
|
if (region_start > screen->line)
|
|
|
|
{
|
|
|
|
region_start = screen->line;
|
|
|
|
region_column = screen->column;
|
|
|
|
}
|
|
|
|
|
|
|
|
mode = ALL_LINES;
|
|
|
|
down = 1; /* XXX not optimal. */
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Move the cursor. */
|
|
|
|
screen->column = screen->real_column = 0;
|
|
|
|
screen->line++;
|
|
|
|
screen->x = 0;
|
|
|
|
screen->y++;
|
|
|
|
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* All but LF. */
|
|
|
|
char *p;
|
|
|
|
struct line *current_linep;
|
|
|
|
int size;
|
|
|
|
int orig_num, new_num;
|
|
|
|
|
2007-12-30 08:52:06 +00:00
|
|
|
/* Find a string delimited by LF. */
|
2005-02-19 20:56:07 +00:00
|
|
|
p = grub_strchr (s, '\n');
|
|
|
|
if (! p)
|
|
|
|
p = s + grub_strlen (s);
|
|
|
|
|
|
|
|
/* Insert the string. */
|
|
|
|
current_linep = screen->lines + screen->line;
|
|
|
|
size = p - s;
|
|
|
|
if (! ensure_space (current_linep, size))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
grub_memmove (current_linep->buf + screen->column + size,
|
|
|
|
current_linep->buf + screen->column,
|
|
|
|
current_linep->len - screen->column);
|
|
|
|
grub_memmove (current_linep->buf + screen->column,
|
|
|
|
s,
|
|
|
|
size);
|
|
|
|
orig_num = get_logical_num_lines (current_linep);
|
|
|
|
current_linep->len += size;
|
|
|
|
new_num = get_logical_num_lines (current_linep);
|
|
|
|
|
|
|
|
/* Update the dirty region. */
|
|
|
|
if (region_start > screen->line)
|
|
|
|
{
|
|
|
|
region_start = screen->line;
|
|
|
|
region_column = screen->column;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (orig_num != new_num)
|
|
|
|
{
|
|
|
|
mode = ALL_LINES;
|
|
|
|
down = 1; /* XXX not optimal. */
|
|
|
|
}
|
|
|
|
else if (mode != ALL_LINES)
|
|
|
|
mode = SINGLE_LINE;
|
|
|
|
|
|
|
|
/* Move the cursor. */
|
|
|
|
screen->column += size;
|
|
|
|
screen->real_column = screen->column;
|
|
|
|
screen->x += size;
|
|
|
|
screen->y += screen->x / GRUB_TERM_ENTRY_WIDTH;
|
|
|
|
screen->x %= GRUB_TERM_ENTRY_WIDTH;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
s = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, region_start, region_column, 0, down, mode);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Release the resource allocated for SCREEN. */
|
|
|
|
static void
|
|
|
|
destroy_screen (struct screen *screen)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (screen->lines)
|
|
|
|
for (i = 0; i < screen->num_lines; i++)
|
|
|
|
{
|
|
|
|
struct line *linep = screen->lines + i;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (linep)
|
|
|
|
grub_free (linep->buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_free (screen->killed_text);
|
|
|
|
grub_free (screen->lines);
|
|
|
|
grub_free (screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a new screen. */
|
|
|
|
static struct screen *
|
|
|
|
make_screen (grub_menu_entry_t entry)
|
|
|
|
{
|
|
|
|
struct screen *screen;
|
|
|
|
|
|
|
|
/* Initialize the screen. */
|
2009-07-16 22:14:09 +00:00
|
|
|
screen = grub_zalloc (sizeof (*screen));
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! screen)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
screen->num_lines = 1;
|
|
|
|
screen->lines = grub_malloc (sizeof (struct line));
|
|
|
|
if (! screen->lines)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
/* Initialize the first line which must be always present. */
|
|
|
|
if (! init_line (screen->lines))
|
|
|
|
goto fail;
|
2006-01-17 09:50:47 +00:00
|
|
|
|
|
|
|
insert_string (screen, (char *) entry->sourcecode, 0);
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
/* Reset the cursor position. */
|
|
|
|
screen->column = 0;
|
|
|
|
screen->real_column = 0;
|
|
|
|
screen->line = 0;
|
|
|
|
screen->x = 0;
|
|
|
|
screen->y = 0;
|
|
|
|
|
|
|
|
return screen;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
destroy_screen (screen);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
forward_char (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
if (screen->column < linep->len)
|
|
|
|
{
|
|
|
|
screen->column++;
|
|
|
|
screen->x++;
|
|
|
|
if (screen->x == GRUB_TERM_ENTRY_WIDTH)
|
|
|
|
{
|
|
|
|
screen->x = 0;
|
|
|
|
screen->y++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (screen->num_lines > screen->line + 1)
|
|
|
|
{
|
|
|
|
screen->column = 0;
|
|
|
|
screen->line++;
|
|
|
|
screen->x = 0;
|
|
|
|
screen->y++;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen->real_column = screen->column;
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
backward_char (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
if (screen->column > 0)
|
|
|
|
{
|
|
|
|
screen->column--;
|
|
|
|
screen->x--;
|
|
|
|
if (screen->x == -1)
|
|
|
|
{
|
|
|
|
screen->x = GRUB_TERM_ENTRY_WIDTH - 1;
|
|
|
|
screen->y--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (screen->line > 0)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->line--;
|
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
screen->column = linep->len;
|
|
|
|
screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH;
|
|
|
|
screen->y--;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen->real_column = screen->column;
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
previous_line (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
if (screen->line > 0)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
|
|
|
int dy;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* How many physical lines from the current position
|
|
|
|
to the first physical line? */
|
|
|
|
dy = screen->column / GRUB_TERM_ENTRY_WIDTH;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->line--;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
if (linep->len < screen->real_column)
|
|
|
|
screen->column = linep->len;
|
|
|
|
else
|
|
|
|
screen->column = screen->real_column;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* How many physical lines from the current position
|
|
|
|
to the last physical line? */
|
|
|
|
dy += (linep->len / GRUB_TERM_ENTRY_WIDTH
|
|
|
|
- screen->column / GRUB_TERM_ENTRY_WIDTH);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->y -= dy + 1;
|
|
|
|
screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
screen->y -= screen->column / GRUB_TERM_ENTRY_WIDTH;
|
|
|
|
screen->column = 0;
|
|
|
|
screen->x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
next_line (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
if (screen->line < screen->num_lines - 1)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
|
|
|
int dy;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* How many physical lines from the current position
|
|
|
|
to the last physical line? */
|
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
dy = (linep->len / GRUB_TERM_ENTRY_WIDTH
|
|
|
|
- screen->column / GRUB_TERM_ENTRY_WIDTH);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->line++;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep++;
|
|
|
|
if (linep->len < screen->real_column)
|
|
|
|
screen->column = linep->len;
|
|
|
|
else
|
|
|
|
screen->column = screen->real_column;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* How many physical lines from the current position
|
|
|
|
to the first physical line? */
|
|
|
|
dy += screen->column / GRUB_TERM_ENTRY_WIDTH;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->y += dy + 1;
|
|
|
|
screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct line *linep;
|
|
|
|
|
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
screen->y += (linep->len / GRUB_TERM_ENTRY_WIDTH
|
|
|
|
- screen->column / GRUB_TERM_ENTRY_WIDTH);
|
|
|
|
screen->column = linep->len;
|
|
|
|
screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
beginning_of_line (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
screen->y -= screen->column / GRUB_TERM_ENTRY_WIDTH;
|
|
|
|
screen->column = screen->real_column = 0;
|
|
|
|
screen->x = 0;
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
end_of_line (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
screen->y += (linep->len / GRUB_TERM_ENTRY_WIDTH
|
|
|
|
- screen->column / GRUB_TERM_ENTRY_WIDTH);
|
|
|
|
screen->column = screen->real_column = linep->len;
|
|
|
|
screen->x = screen->column % GRUB_TERM_ENTRY_WIDTH;
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, screen->num_lines, 0, 0, 0, NO_LINE);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
delete_char (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
|
|
|
enum update_mode mode = NO_LINE;
|
|
|
|
int start = screen->num_lines;
|
|
|
|
int column = 0;
|
|
|
|
int down = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
if (linep->len > screen->column)
|
|
|
|
{
|
|
|
|
int orig_num, new_num;
|
|
|
|
|
|
|
|
orig_num = get_logical_num_lines (linep);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
grub_memmove (linep->buf + screen->column,
|
|
|
|
linep->buf + screen->column + 1,
|
|
|
|
linep->len - screen->column - 1);
|
|
|
|
linep->len--;
|
|
|
|
|
|
|
|
new_num = get_logical_num_lines (linep);
|
|
|
|
|
|
|
|
if (orig_num != new_num)
|
|
|
|
mode = ALL_LINES;
|
|
|
|
else
|
|
|
|
mode = SINGLE_LINE;
|
|
|
|
|
|
|
|
start = screen->line;
|
|
|
|
column = screen->column;
|
|
|
|
}
|
|
|
|
else if (screen->num_lines > screen->line + 1)
|
|
|
|
{
|
|
|
|
struct line *next_linep;
|
|
|
|
|
|
|
|
next_linep = linep + 1;
|
|
|
|
if (! ensure_space (linep, next_linep->len))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
grub_memmove (linep->buf + linep->len, next_linep->buf, next_linep->len);
|
|
|
|
linep->len += next_linep->len;
|
|
|
|
|
|
|
|
grub_free (next_linep->buf);
|
|
|
|
grub_memmove (next_linep,
|
|
|
|
next_linep + 1,
|
|
|
|
(screen->num_lines - screen->line - 2)
|
|
|
|
* sizeof (struct line));
|
|
|
|
screen->num_lines--;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
mode = ALL_LINES;
|
|
|
|
start = screen->line;
|
|
|
|
column = screen->column;
|
|
|
|
down = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
screen->real_column = screen->column;
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, start, column, 0, down, mode);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
backward_delete_char (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
int saved_column;
|
|
|
|
int saved_line;
|
|
|
|
|
|
|
|
saved_column = screen->column;
|
|
|
|
saved_line = screen->line;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! backward_char (screen, 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (saved_column != screen->column || saved_line != screen->line)
|
|
|
|
if (! delete_char (screen, update))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
kill_line (struct screen *screen, int continuous, int update)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
|
|
|
char *p;
|
|
|
|
int size;
|
|
|
|
int offset;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
p = screen->killed_text;
|
|
|
|
if (! continuous && p)
|
|
|
|
p[0] = '\0';
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
size = linep->len - screen->column;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (p)
|
|
|
|
offset = grub_strlen (p);
|
|
|
|
else
|
|
|
|
offset = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (size > 0)
|
|
|
|
{
|
|
|
|
enum update_mode mode = SINGLE_LINE;
|
|
|
|
int down = 0;
|
|
|
|
int orig_num, new_num;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
p = grub_realloc (p, offset + size + 1);
|
|
|
|
if (! p)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
grub_memmove (p + offset, linep->buf + screen->column, size);
|
|
|
|
p[offset + size - 1] = '\0';
|
|
|
|
|
|
|
|
screen->killed_text = p;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
orig_num = get_logical_num_lines (linep);
|
|
|
|
linep->len = screen->column;
|
|
|
|
new_num = get_logical_num_lines (linep);
|
|
|
|
|
|
|
|
if (orig_num != new_num)
|
|
|
|
{
|
|
|
|
mode = ALL_LINES;
|
|
|
|
down = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, screen->line, screen->column, 0, down, mode);
|
|
|
|
}
|
|
|
|
else if (screen->line + 1 < screen->num_lines)
|
|
|
|
{
|
|
|
|
p = grub_realloc (p, offset + 1 + 1);
|
|
|
|
if (! p)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
p[offset] = '\n';
|
|
|
|
p[offset + 1] = '\0';
|
|
|
|
|
|
|
|
screen->killed_text = p;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
return delete_char (screen, update);
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
yank (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
if (screen->killed_text)
|
|
|
|
return insert_string (screen, screen->killed_text, update);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
open_line (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
int saved_y = screen->y;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! insert_string (screen, "\n", 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (! backward_char (screen, 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
screen->y = saved_y;
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
update_screen (screen, screen->line, screen->column, 0, 1, ALL_LINES);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
/* A completion hook to print items. */
|
|
|
|
static void
|
|
|
|
store_completion (const char *item, grub_completion_type_t type, int count)
|
|
|
|
{
|
|
|
|
char *p;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
if (count == 0)
|
|
|
|
{
|
|
|
|
/* If this is the first time, print a label. */
|
|
|
|
const char *what;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case GRUB_COMPLETION_TYPE_COMMAND:
|
|
|
|
what = "commands";
|
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_DEVICE:
|
|
|
|
what = "devices";
|
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_FILE:
|
|
|
|
what = "files";
|
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_PARTITION:
|
|
|
|
what = "partitions";
|
|
|
|
break;
|
2005-08-28 17:01:16 +00:00
|
|
|
case GRUB_COMPLETION_TYPE_ARGUMENT:
|
|
|
|
what = "arguments";
|
|
|
|
break;
|
2005-08-18 03:14:39 +00:00
|
|
|
default:
|
|
|
|
what = "things";
|
|
|
|
break;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
|
2009-12-05 11:25:07 +00:00
|
|
|
grub_printf (" ");
|
|
|
|
grub_printf (_("Possible %s are:"), what);
|
|
|
|
grub_printf ("\n ");
|
2005-08-18 03:14:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure that the completion buffer has enough room. */
|
|
|
|
if (completion_buffer.max_len < (completion_buffer.len
|
|
|
|
+ (int) grub_strlen (item) + 1 + 1))
|
|
|
|
{
|
|
|
|
grub_size_t new_len;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
new_len = completion_buffer.len + grub_strlen (item) + 80;
|
|
|
|
p = grub_realloc (completion_buffer.buf, new_len);
|
|
|
|
if (! p)
|
|
|
|
{
|
|
|
|
/* Possibly not fatal. */
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
p[completion_buffer.len] = 0;
|
|
|
|
completion_buffer.buf = p;
|
|
|
|
completion_buffer.max_len = new_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
p = completion_buffer.buf + completion_buffer.len;
|
|
|
|
if (completion_buffer.len != 0)
|
|
|
|
{
|
|
|
|
*p++ = ' ';
|
|
|
|
completion_buffer.len++;
|
|
|
|
}
|
|
|
|
grub_strcpy (p, item);
|
|
|
|
completion_buffer.len += grub_strlen (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
complete (struct screen *screen, int continuous, int update)
|
|
|
|
{
|
|
|
|
grub_uint16_t pos;
|
|
|
|
char saved_char;
|
|
|
|
struct line *linep;
|
|
|
|
int restore;
|
|
|
|
char *insert;
|
|
|
|
static int count = -1;
|
|
|
|
|
|
|
|
if (continuous)
|
|
|
|
count++;
|
|
|
|
else
|
|
|
|
count = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
pos = grub_getxy ();
|
|
|
|
grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
completion_buffer.buf = 0;
|
|
|
|
completion_buffer.len = 0;
|
|
|
|
completion_buffer.max_len = 0;
|
|
|
|
|
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
saved_char = linep->buf[screen->column];
|
|
|
|
linep->buf[screen->column] = '\0';
|
|
|
|
|
|
|
|
insert = grub_normal_do_completion (linep->buf, &restore, store_completion);
|
|
|
|
|
|
|
|
linep->buf[screen->column] = saved_char;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
if (restore)
|
|
|
|
{
|
|
|
|
char *p = completion_buffer.buf;
|
|
|
|
|
|
|
|
screen->completion_shown = 1;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
int num_sections = ((completion_buffer.len + GRUB_TERM_WIDTH - 8 - 1)
|
|
|
|
/ (GRUB_TERM_WIDTH - 8));
|
|
|
|
char *endp;
|
|
|
|
|
|
|
|
p += (count % num_sections) * (GRUB_TERM_WIDTH - 8);
|
|
|
|
endp = p + (GRUB_TERM_WIDTH - 8);
|
|
|
|
|
|
|
|
if (p != completion_buffer.buf)
|
|
|
|
grub_putcode (GRUB_TERM_DISP_LEFT);
|
|
|
|
else
|
|
|
|
grub_putchar (' ');
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
while (*p && p < endp)
|
|
|
|
grub_putchar (*p++);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
if (*p)
|
|
|
|
grub_putcode (GRUB_TERM_DISP_RIGHT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
grub_gotoxy (pos >> 8, pos & 0xFF);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
if (insert)
|
|
|
|
{
|
|
|
|
insert_string (screen, insert, update);
|
|
|
|
count = -1;
|
|
|
|
grub_free (insert);
|
|
|
|
}
|
|
|
|
else if (update)
|
|
|
|
grub_refresh ();
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
grub_free (completion_buffer.buf);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear displayed completions. */
|
|
|
|
static void
|
|
|
|
clear_completions (void)
|
|
|
|
{
|
|
|
|
grub_uint16_t pos;
|
|
|
|
int i, j;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
pos = grub_getxy ();
|
|
|
|
grub_gotoxy (0, GRUB_TERM_HEIGHT - 3);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < GRUB_TERM_WIDTH - 1; j++)
|
|
|
|
grub_putchar (' ');
|
|
|
|
grub_putchar ('\n');
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
grub_gotoxy (pos >> 8, pos & 0xFF);
|
|
|
|
grub_refresh ();
|
|
|
|
}
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Execute the command list in the screen SCREEN. */
|
|
|
|
static int
|
|
|
|
run (struct screen *screen)
|
|
|
|
{
|
2006-01-17 09:50:47 +00:00
|
|
|
int currline = 0;
|
|
|
|
char *nextline;
|
|
|
|
|
2009-05-02 Bean <bean123ch@gmail.com>
* conf/common.rmk (grub_script.tab.c): Change normal/parser.y to
script/sh/parser.y.
(pkglib_MODULES): Add normal.mod and sh.mod.
(normal_SOURCES): New variable.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
(sh_mod_SOURCES): Likewise.
(sh_mod_CFLAGS): Likewise.
(sh_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (normal/lexer.c_DEPENDENCIES): Changed to
script/sh/lexer.c_DEPENDENCIES.
(kernel_img_SOURCES): Remove kern/rescue.c, and kern/reader.c,
kern/rescue_reader.c and kern/rescue_parser.c.
(kernel_img_HEADERS): Remove rescue.h, add reader.h.
(grub_emu_SOURCES): Change source files.
(pkglib_MODULES): Remove normal.mod.
(normal_SOURCES): Removed.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1276.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/command.h (grub_command_execute): New inline function.
* include/grub/menu.h (grub_menu_entry): Removed commands field.
* include/grub/normal.h: Remove <grub/setjmp.h>.
(grub_fs_module_list): Moved to normal/autofs.c.
(grub_exit_env): Removed.
(grub_command_execute): Likewise.
(grub_normal_menu_addentry): Renamed to grub_menu_addentry, removed
parameter script.
(read_command_list): New function declaration.
(read_fs_list): Likewise.
* include/parser.h: Include <grub/reader.h>.
(grub_parser_split_cmdline): Change type of getline parameter.
(grub_parser): New structure.
(grub_parser_class): New variable.
(grub_parser_execute): New function declaration.
(grub_register_rescue_parser): Likewise.
(grub_parser_register): New inline function.
(grub_parser_unregister): Likewise.
(grub_parser_get_current): Likewise.
(grub_parser_set_current): Likewise.
* include/grub/reader.h: New file.
* kern/reader.c: Likewise.
* kern/rescue_parser.c: Likewise.
* kern/rescue_reader.c: Likewise.
* normal/autofs.c: Likewise.
* normal/dyncmd.c: Likewise.
* include/grub/rescue.h: Removed.
* normal/command.h: Likewise.
* include/grub/script.h: Moved to ...
* include/grub/script_sh.h: ... Moved here.
* normal/execute.c: Moved to ...
* script/sh/execute.c: ... Moved here.
* normal/function.c: Moved to ...
* script/sh/function.c: ... Moved here.
* normal/lexer.c: Moved to ...
* script/sh/lexer.c: ... Moved here.
* normal/parser.y: Moved to ...
* script/sh/parser.y: ... Moved here.
* normal/script.c: Moved to ...
* script/sh/script.c: ... Moved here.
* normal/main.c: Remove <grub/rescue.h> and <grub/script.h>, include
<grub/reader.h>.
(grub_exit_env): Removed.
(fs_module_list): Moved to normal/autofs.c.
(grub_file_getline): Don't handle comment here.
(free_menu): Skip removed field entry->commands.
(grub_normal_menu_addentry): Removed as grub_menu_entry, removed
script parameter.
(read_config_file): Removed nested parameter, change getline function.
(grub_enter_normal_mode): Removed.
(grub_dyncmd_dispatcher): Moved to normal/dyncmd.c.
(read_command_list): Likewise.
(autoload_fs_module): Moved to normal/autofs.c.
(read_fs_list): Likewise.
(reader_nested): New variable.
(grub_normal_execute): Run parser.sh to switch to sh parser.
(grub_cmd_rescue): Removed.
(cmd_normal): Removed.
(grub_cmd_normal): Unregister itself at the beginning. Don't register
rescue command.
(grub_cmdline_run): New function.
(grub_normal_reader_init): Likewise.
(grub_normal_read_line): Likewise.
(grub_env_write_pager): Likewise.
(cmdline): New variable.
(grub_normal_reader): Likewise.
(GRUB_MOD_INIT): Register normal reader and set as current, register
pager hook, register normal command with grub_register_command_prio,
so that it won't show up in command.lst.
(GRUB_MOD_FINI): Unregister normal reader, unhook pager, clear
grub_fs_autoload_hook.
* normal/menu.c: Remove <grub/script.h>, add <grub/command.h>.
(grub_menu_execute_entry): Replace grub_script_execute with
grub_parser_execute, change parameter to grub_command_execute.
* normal/menu_text.c: Remove <grub/script.h>.
* normal/menu_entry.c: Remove <grub/script.h>, add <grub/command.h>
and <grub/parser.h>.
(run): Change editor_getline to use new parser interface. Change
parameter to grub_command_execute.
* kern/main.c: Remove <grub/rescue.h>, include <grub/command.h>,
<grub/reader.h> and <grub/parser.h>.
(grub_load_normal_mode): Execute normal command.
(grub_main): Call grub_register_core_commands,
grub_register_rescue_parser and grub_register_rescue_reader, use
grub_reader_loop to enter input loop.
* kern/parser.c (grub_parser_spli_cmdline): Change type of getline
parameter.
(grub_parser_class): New variable.
(grub_parser_execute): New function.
* loader/i386/multiboot.c: Remove <grub/rescue.h>.
* loader/multiboot2.c: Likewise.
* loader/sparc64/ieee1275/linux.c: Likewise.
* util/grub-emu.c (read_command_list): New dummy function.
2009-05-02 19:49:34 +00:00
|
|
|
auto grub_err_t editor_getline (char **line, int cont);
|
|
|
|
grub_err_t editor_getline (char **line, int cont __attribute__ ((unused)))
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2006-01-17 09:50:47 +00:00
|
|
|
struct line *linep = screen->lines + currline;
|
2005-02-19 20:56:07 +00:00
|
|
|
char *p;
|
2006-01-17 09:50:47 +00:00
|
|
|
|
|
|
|
if (currline > screen->num_lines)
|
|
|
|
{
|
|
|
|
*line = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Trim down space characters. */
|
|
|
|
for (p = linep->buf + linep->len - 1;
|
|
|
|
p >= linep->buf && grub_isspace (*p);
|
|
|
|
p--)
|
|
|
|
;
|
|
|
|
*++p = '\0';
|
2006-01-17 09:50:47 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep->len = p - linep->buf;
|
|
|
|
for (p = linep->buf; grub_isspace (*p); p++)
|
|
|
|
;
|
2008-08-01 18:18:32 +00:00
|
|
|
*line = grub_strdup (p);
|
2006-01-17 09:50:47 +00:00
|
|
|
currline++;
|
|
|
|
return 0;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2006-01-17 09:50:47 +00:00
|
|
|
grub_cls ();
|
2009-12-05 11:25:07 +00:00
|
|
|
grub_printf (" ");
|
|
|
|
grub_printf (_("Booting a command list"));
|
|
|
|
grub_printf ("\n\n");
|
2005-02-19 20:56:07 +00:00
|
|
|
|
2006-01-17 09:50:47 +00:00
|
|
|
|
|
|
|
/* Execute the script, line for line. */
|
2006-12-11 21:00:06 +00:00
|
|
|
while (currline < screen->num_lines)
|
2006-01-17 09:50:47 +00:00
|
|
|
{
|
2009-05-02 Bean <bean123ch@gmail.com>
* conf/common.rmk (grub_script.tab.c): Change normal/parser.y to
script/sh/parser.y.
(pkglib_MODULES): Add normal.mod and sh.mod.
(normal_SOURCES): New variable.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
(sh_mod_SOURCES): Likewise.
(sh_mod_CFLAGS): Likewise.
(sh_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (normal/lexer.c_DEPENDENCIES): Changed to
script/sh/lexer.c_DEPENDENCIES.
(kernel_img_SOURCES): Remove kern/rescue.c, and kern/reader.c,
kern/rescue_reader.c and kern/rescue_parser.c.
(kernel_img_HEADERS): Remove rescue.h, add reader.h.
(grub_emu_SOURCES): Change source files.
(pkglib_MODULES): Remove normal.mod.
(normal_SOURCES): Removed.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1276.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/command.h (grub_command_execute): New inline function.
* include/grub/menu.h (grub_menu_entry): Removed commands field.
* include/grub/normal.h: Remove <grub/setjmp.h>.
(grub_fs_module_list): Moved to normal/autofs.c.
(grub_exit_env): Removed.
(grub_command_execute): Likewise.
(grub_normal_menu_addentry): Renamed to grub_menu_addentry, removed
parameter script.
(read_command_list): New function declaration.
(read_fs_list): Likewise.
* include/parser.h: Include <grub/reader.h>.
(grub_parser_split_cmdline): Change type of getline parameter.
(grub_parser): New structure.
(grub_parser_class): New variable.
(grub_parser_execute): New function declaration.
(grub_register_rescue_parser): Likewise.
(grub_parser_register): New inline function.
(grub_parser_unregister): Likewise.
(grub_parser_get_current): Likewise.
(grub_parser_set_current): Likewise.
* include/grub/reader.h: New file.
* kern/reader.c: Likewise.
* kern/rescue_parser.c: Likewise.
* kern/rescue_reader.c: Likewise.
* normal/autofs.c: Likewise.
* normal/dyncmd.c: Likewise.
* include/grub/rescue.h: Removed.
* normal/command.h: Likewise.
* include/grub/script.h: Moved to ...
* include/grub/script_sh.h: ... Moved here.
* normal/execute.c: Moved to ...
* script/sh/execute.c: ... Moved here.
* normal/function.c: Moved to ...
* script/sh/function.c: ... Moved here.
* normal/lexer.c: Moved to ...
* script/sh/lexer.c: ... Moved here.
* normal/parser.y: Moved to ...
* script/sh/parser.y: ... Moved here.
* normal/script.c: Moved to ...
* script/sh/script.c: ... Moved here.
* normal/main.c: Remove <grub/rescue.h> and <grub/script.h>, include
<grub/reader.h>.
(grub_exit_env): Removed.
(fs_module_list): Moved to normal/autofs.c.
(grub_file_getline): Don't handle comment here.
(free_menu): Skip removed field entry->commands.
(grub_normal_menu_addentry): Removed as grub_menu_entry, removed
script parameter.
(read_config_file): Removed nested parameter, change getline function.
(grub_enter_normal_mode): Removed.
(grub_dyncmd_dispatcher): Moved to normal/dyncmd.c.
(read_command_list): Likewise.
(autoload_fs_module): Moved to normal/autofs.c.
(read_fs_list): Likewise.
(reader_nested): New variable.
(grub_normal_execute): Run parser.sh to switch to sh parser.
(grub_cmd_rescue): Removed.
(cmd_normal): Removed.
(grub_cmd_normal): Unregister itself at the beginning. Don't register
rescue command.
(grub_cmdline_run): New function.
(grub_normal_reader_init): Likewise.
(grub_normal_read_line): Likewise.
(grub_env_write_pager): Likewise.
(cmdline): New variable.
(grub_normal_reader): Likewise.
(GRUB_MOD_INIT): Register normal reader and set as current, register
pager hook, register normal command with grub_register_command_prio,
so that it won't show up in command.lst.
(GRUB_MOD_FINI): Unregister normal reader, unhook pager, clear
grub_fs_autoload_hook.
* normal/menu.c: Remove <grub/script.h>, add <grub/command.h>.
(grub_menu_execute_entry): Replace grub_script_execute with
grub_parser_execute, change parameter to grub_command_execute.
* normal/menu_text.c: Remove <grub/script.h>.
* normal/menu_entry.c: Remove <grub/script.h>, add <grub/command.h>
and <grub/parser.h>.
(run): Change editor_getline to use new parser interface. Change
parameter to grub_command_execute.
* kern/main.c: Remove <grub/rescue.h>, include <grub/command.h>,
<grub/reader.h> and <grub/parser.h>.
(grub_load_normal_mode): Execute normal command.
(grub_main): Call grub_register_core_commands,
grub_register_rescue_parser and grub_register_rescue_reader, use
grub_reader_loop to enter input loop.
* kern/parser.c (grub_parser_spli_cmdline): Change type of getline
parameter.
(grub_parser_class): New variable.
(grub_parser_execute): New function.
* loader/i386/multiboot.c: Remove <grub/rescue.h>.
* loader/multiboot2.c: Likewise.
* loader/sparc64/ieee1275/linux.c: Likewise.
* util/grub-emu.c (read_command_list): New dummy function.
2009-05-02 19:49:34 +00:00
|
|
|
editor_getline (&nextline, 0);
|
|
|
|
if (grub_parser_get_current ()->parse_line (nextline, editor_getline))
|
2005-02-19 20:56:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2006-12-11 21:00:06 +00:00
|
|
|
if (grub_errno == GRUB_ERR_NONE && grub_loader_is_loaded ())
|
|
|
|
/* Implicit execution of boot, only if something is loaded. */
|
2009-05-02 Bean <bean123ch@gmail.com>
* conf/common.rmk (grub_script.tab.c): Change normal/parser.y to
script/sh/parser.y.
(pkglib_MODULES): Add normal.mod and sh.mod.
(normal_SOURCES): New variable.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
(sh_mod_SOURCES): Likewise.
(sh_mod_CFLAGS): Likewise.
(sh_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (normal/lexer.c_DEPENDENCIES): Changed to
script/sh/lexer.c_DEPENDENCIES.
(kernel_img_SOURCES): Remove kern/rescue.c, and kern/reader.c,
kern/rescue_reader.c and kern/rescue_parser.c.
(kernel_img_HEADERS): Remove rescue.h, add reader.h.
(grub_emu_SOURCES): Change source files.
(pkglib_MODULES): Remove normal.mod.
(normal_SOURCES): Removed.
(normal_mod_CFLAGS): Likewise.
(normal_mod_LDFLAGS): Likewise.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1276.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/sparc64-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/command.h (grub_command_execute): New inline function.
* include/grub/menu.h (grub_menu_entry): Removed commands field.
* include/grub/normal.h: Remove <grub/setjmp.h>.
(grub_fs_module_list): Moved to normal/autofs.c.
(grub_exit_env): Removed.
(grub_command_execute): Likewise.
(grub_normal_menu_addentry): Renamed to grub_menu_addentry, removed
parameter script.
(read_command_list): New function declaration.
(read_fs_list): Likewise.
* include/parser.h: Include <grub/reader.h>.
(grub_parser_split_cmdline): Change type of getline parameter.
(grub_parser): New structure.
(grub_parser_class): New variable.
(grub_parser_execute): New function declaration.
(grub_register_rescue_parser): Likewise.
(grub_parser_register): New inline function.
(grub_parser_unregister): Likewise.
(grub_parser_get_current): Likewise.
(grub_parser_set_current): Likewise.
* include/grub/reader.h: New file.
* kern/reader.c: Likewise.
* kern/rescue_parser.c: Likewise.
* kern/rescue_reader.c: Likewise.
* normal/autofs.c: Likewise.
* normal/dyncmd.c: Likewise.
* include/grub/rescue.h: Removed.
* normal/command.h: Likewise.
* include/grub/script.h: Moved to ...
* include/grub/script_sh.h: ... Moved here.
* normal/execute.c: Moved to ...
* script/sh/execute.c: ... Moved here.
* normal/function.c: Moved to ...
* script/sh/function.c: ... Moved here.
* normal/lexer.c: Moved to ...
* script/sh/lexer.c: ... Moved here.
* normal/parser.y: Moved to ...
* script/sh/parser.y: ... Moved here.
* normal/script.c: Moved to ...
* script/sh/script.c: ... Moved here.
* normal/main.c: Remove <grub/rescue.h> and <grub/script.h>, include
<grub/reader.h>.
(grub_exit_env): Removed.
(fs_module_list): Moved to normal/autofs.c.
(grub_file_getline): Don't handle comment here.
(free_menu): Skip removed field entry->commands.
(grub_normal_menu_addentry): Removed as grub_menu_entry, removed
script parameter.
(read_config_file): Removed nested parameter, change getline function.
(grub_enter_normal_mode): Removed.
(grub_dyncmd_dispatcher): Moved to normal/dyncmd.c.
(read_command_list): Likewise.
(autoload_fs_module): Moved to normal/autofs.c.
(read_fs_list): Likewise.
(reader_nested): New variable.
(grub_normal_execute): Run parser.sh to switch to sh parser.
(grub_cmd_rescue): Removed.
(cmd_normal): Removed.
(grub_cmd_normal): Unregister itself at the beginning. Don't register
rescue command.
(grub_cmdline_run): New function.
(grub_normal_reader_init): Likewise.
(grub_normal_read_line): Likewise.
(grub_env_write_pager): Likewise.
(cmdline): New variable.
(grub_normal_reader): Likewise.
(GRUB_MOD_INIT): Register normal reader and set as current, register
pager hook, register normal command with grub_register_command_prio,
so that it won't show up in command.lst.
(GRUB_MOD_FINI): Unregister normal reader, unhook pager, clear
grub_fs_autoload_hook.
* normal/menu.c: Remove <grub/script.h>, add <grub/command.h>.
(grub_menu_execute_entry): Replace grub_script_execute with
grub_parser_execute, change parameter to grub_command_execute.
* normal/menu_text.c: Remove <grub/script.h>.
* normal/menu_entry.c: Remove <grub/script.h>, add <grub/command.h>
and <grub/parser.h>.
(run): Change editor_getline to use new parser interface. Change
parameter to grub_command_execute.
* kern/main.c: Remove <grub/rescue.h>, include <grub/command.h>,
<grub/reader.h> and <grub/parser.h>.
(grub_load_normal_mode): Execute normal command.
(grub_main): Call grub_register_core_commands,
grub_register_rescue_parser and grub_register_rescue_reader, use
grub_reader_loop to enter input loop.
* kern/parser.c (grub_parser_spli_cmdline): Change type of getline
parameter.
(grub_parser_class): New variable.
(grub_parser_execute): New function.
* loader/i386/multiboot.c: Remove <grub/rescue.h>.
* loader/multiboot2.c: Likewise.
* loader/sparc64/ieee1275/linux.c: Likewise.
* util/grub-emu.c (read_command_list): New dummy function.
2009-05-02 19:49:34 +00:00
|
|
|
grub_command_execute ("boot", 0, 0);
|
2006-12-11 21:00:06 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (grub_errno != GRUB_ERR_NONE)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
2008-01-05 12:10:28 +00:00
|
|
|
grub_wait_after_message ();
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
2006-01-17 09:50:47 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Edit a menu entry with an Emacs-like interface. */
|
|
|
|
void
|
|
|
|
grub_menu_entry_run (grub_menu_entry_t entry)
|
|
|
|
{
|
|
|
|
struct screen *screen;
|
|
|
|
int prev_c;
|
2009-08-24 23:55:06 +00:00
|
|
|
grub_err_t err = GRUB_ERR_NONE;
|
|
|
|
|
|
|
|
err = grub_auth_check_authentication (NULL);
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
screen = make_screen (entry);
|
|
|
|
if (! screen)
|
|
|
|
return;
|
|
|
|
|
|
|
|
refresh:
|
|
|
|
/* Draw the screen. */
|
|
|
|
grub_menu_init_page (0, 1);
|
|
|
|
update_screen (screen, 0, 0, 1, 1, ALL_LINES);
|
|
|
|
grub_setcursor (1);
|
|
|
|
prev_c = '\0';
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int c = GRUB_TERM_ASCII_CHAR (grub_getkey ());
|
2005-08-18 03:14:39 +00:00
|
|
|
|
|
|
|
if (screen->completion_shown)
|
|
|
|
{
|
|
|
|
clear_completions ();
|
|
|
|
screen->completion_shown = 0;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 16: /* C-p */
|
|
|
|
if (! previous_line (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 14: /* C-n */
|
|
|
|
if (! next_line (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6: /* C-f */
|
|
|
|
if (! forward_char (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
case 2: /* C-b */
|
|
|
|
if (! backward_char (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: /* C-a */
|
|
|
|
if (! beginning_of_line (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5: /* C-e */
|
|
|
|
if (! end_of_line (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
case '\t': /* C-i */
|
2005-08-18 03:14:39 +00:00
|
|
|
if (! complete (screen, prev_c == c, 1))
|
|
|
|
goto fail;
|
2005-02-19 20:56:07 +00:00
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
case 4: /* C-d */
|
|
|
|
if (! delete_char (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8: /* C-h */
|
|
|
|
if (! backward_delete_char (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
case 11: /* C-k */
|
|
|
|
if (! kill_line (screen, prev_c == c, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
case 21: /* C-u */
|
|
|
|
/* FIXME: What behavior is good for this key? */
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
case 25: /* C-y */
|
|
|
|
if (! yank (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 12: /* C-l */
|
|
|
|
/* FIXME: centering. */
|
|
|
|
goto refresh;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
case 15: /* C-o */
|
|
|
|
if (! open_line (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\n':
|
|
|
|
case '\r':
|
|
|
|
if (! insert_string (screen, "\n", 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\e':
|
|
|
|
destroy_screen (screen);
|
|
|
|
return;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
case 3: /* C-c */
|
|
|
|
grub_cmdline_run (1);
|
|
|
|
goto refresh;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
case 24: /* C-x */
|
|
|
|
if (! run (screen))
|
|
|
|
goto fail;
|
|
|
|
goto refresh;
|
|
|
|
|
|
|
|
case 18: /* C-r */
|
|
|
|
case 19: /* C-s */
|
|
|
|
case 20: /* C-t */
|
|
|
|
/* FIXME */
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
default:
|
|
|
|
if (grub_isprint (c))
|
|
|
|
{
|
|
|
|
char buf[2];
|
|
|
|
|
|
|
|
buf[0] = c;
|
|
|
|
buf[1] = '\0';
|
|
|
|
if (! insert_string (screen, buf, 1))
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
prev_c = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
fail:
|
|
|
|
destroy_screen (screen);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
grub_cls ();
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
2009-12-05 11:25:07 +00:00
|
|
|
grub_putchar ('\n');
|
|
|
|
grub_printf (_("Press any key to continue..."));
|
2005-02-19 20:56:07 +00:00
|
|
|
(void) grub_getkey ();
|
|
|
|
}
|