2005-02-19 20:56:07 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-03 22:05:07 +00:00
|
|
|
* Copyright (C) 2005,2006,2007,2008,2009 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>
|
2010-03-26 23:19:42 +00:00
|
|
|
#include <grub/script_sh.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>
|
2010-03-15 10:49:27 +00:00
|
|
|
#include <grub/charset.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;
|
|
|
|
};
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
struct per_term_screen
|
|
|
|
{
|
|
|
|
struct grub_term_output *term;
|
|
|
|
/* The X coordinate. */
|
|
|
|
int x;
|
|
|
|
/* The Y coordinate. */
|
|
|
|
int y;
|
2011-04-10 11:56:23 +00:00
|
|
|
/* Number of entries. */
|
|
|
|
int num_entries;
|
2009-12-24 14:34:33 +00:00
|
|
|
};
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
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 kill buffer. */
|
|
|
|
char *killed_text;
|
2005-08-18 03:14:39 +00:00
|
|
|
/* The flag of a completion window. */
|
|
|
|
int completion_shown;
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-09-20 22:47:49 +00:00
|
|
|
int submenu;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
struct per_term_screen *terms;
|
|
|
|
unsigned nterms;
|
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;
|
2009-12-24 14:34:33 +00:00
|
|
|
static int completion_type;
|
2005-08-18 03:14:39 +00:00
|
|
|
|
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 */
|
2011-03-23 13:18:56 +00:00
|
|
|
linep->buf = grub_malloc (linep->max_len + 1);
|
2005-02-19 20:56:07 +00:00
|
|
|
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
|
2009-12-24 14:34:33 +00:00
|
|
|
get_logical_num_lines (struct line *linep, struct per_term_screen *term_screen)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
return (linep->len / grub_term_entry_width (term_screen->term)) + 1;
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print a line. */
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
print_line (struct line *linep, int offset, int start, int y,
|
|
|
|
struct per_term_screen *term_screen)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term_screen->term,
|
|
|
|
GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + start + 1,
|
|
|
|
y + GRUB_TERM_FIRST_ENTRY_Y);
|
2005-02-19 20:56:07 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
if (linep->len >= offset + grub_term_entry_width (term_screen->term))
|
|
|
|
{
|
|
|
|
char *p, c;
|
2009-12-25 12:18:08 +00:00
|
|
|
p = linep->buf + offset + grub_term_entry_width (term_screen->term);
|
2009-12-24 14:34:33 +00:00
|
|
|
c = *p;
|
|
|
|
*p = 0;
|
|
|
|
grub_puts_terminal (linep->buf + offset + start, term_screen->term);
|
|
|
|
*p = c;
|
|
|
|
grub_putcode ('\\', term_screen->term);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
else
|
2009-12-24 14:34:33 +00:00
|
|
|
{
|
|
|
|
int i;
|
2009-12-25 03:12:29 +00:00
|
|
|
char *p, c;
|
|
|
|
|
|
|
|
p = linep->buf + linep->len;
|
|
|
|
c = *p;
|
|
|
|
*p = 0;
|
|
|
|
grub_puts_terminal (linep->buf + offset + start, term_screen->term);
|
|
|
|
*p = c;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0;
|
2009-12-25 12:18:08 +00:00
|
|
|
i <= grub_term_entry_width (term_screen->term) - linep->len + offset;
|
2009-12-24 14:34:33 +00:00
|
|
|
i++)
|
|
|
|
grub_putcode (' ', term_screen->term);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print an empty line. */
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
print_empty_line (int y, struct per_term_screen *term_screen)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
|
|
|
int i;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term_screen->term,
|
|
|
|
GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1,
|
|
|
|
y + GRUB_TERM_FIRST_ENTRY_Y);
|
2005-02-19 20:56:07 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < grub_term_entry_width (term_screen->term) + 1; i++)
|
|
|
|
grub_putcode (' ', term_screen->term);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print an up arrow. */
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
print_up (int flag, struct per_term_screen *term_screen)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term_screen->term, GRUB_TERM_LEFT_BORDER_X
|
2010-11-18 01:08:01 +00:00
|
|
|
+ grub_term_border_width (term_screen->term),
|
2009-12-24 14:34:33 +00:00
|
|
|
GRUB_TERM_FIRST_ENTRY_Y);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (flag)
|
2010-05-09 10:56:32 +00:00
|
|
|
grub_putcode (GRUB_UNICODE_UPARROW, term_screen->term);
|
2005-02-19 20:56:07 +00:00
|
|
|
else
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (' ', term_screen->term);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Print a down arrow. */
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
print_down (int flag, struct per_term_screen *term_screen)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term_screen->term, GRUB_TERM_LEFT_BORDER_X
|
|
|
|
+ grub_term_border_width (term_screen->term),
|
|
|
|
GRUB_TERM_TOP_BORDER_Y
|
2011-04-10 11:56:23 +00:00
|
|
|
+ term_screen->num_entries);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (flag)
|
2010-05-09 10:56:32 +00:00
|
|
|
grub_putcode (GRUB_UNICODE_DOWNARROW, term_screen->term);
|
2005-02-19 20:56:07 +00:00
|
|
|
else
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_putcode (' ', term_screen->term);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
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
|
2009-12-24 14:34:33 +00:00
|
|
|
update_screen (struct screen *screen, struct per_term_screen *term_screen,
|
|
|
|
int region_start, int region_column,
|
2005-02-19 20:56:07 +00:00
|
|
|
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. */
|
2011-04-10 11:56:23 +00:00
|
|
|
if (term_screen->y < 0 || term_screen->y >= term_screen->num_entries)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
if (term_screen->y < 0)
|
|
|
|
term_screen->y = 0;
|
2005-02-19 20:56:07 +00:00
|
|
|
else
|
2011-04-10 11:56:23 +00:00
|
|
|
term_screen->y = term_screen->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. */
|
2009-12-24 14:34:33 +00:00
|
|
|
y = term_screen->y - screen->column
|
|
|
|
/ grub_term_entry_width (term_screen->term);
|
2005-02-19 20:56:07 +00:00
|
|
|
i = screen->line;
|
|
|
|
linep = screen->lines + i;
|
|
|
|
while (y > 0)
|
|
|
|
{
|
|
|
|
i--;
|
|
|
|
linep--;
|
2009-12-24 14:34:33 +00:00
|
|
|
y -= get_logical_num_lines (linep, term_screen);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
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
|
|
|
|
2010-03-23 15:46:45 +00:00
|
|
|
if (linep >= screen->lines + screen->num_lines)
|
|
|
|
break;
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
for (column = 0;
|
2009-12-24 14:34:33 +00:00
|
|
|
column <= linep->len
|
2011-04-10 11:56:23 +00:00
|
|
|
&& y < term_screen->num_entries;
|
2009-12-24 14:34:33 +00:00
|
|
|
column += grub_term_entry_width (term_screen->term), y++)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
|
|
|
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
|
2009-12-24 14:34:33 +00:00
|
|
|
&& region_column
|
|
|
|
< (column
|
|
|
|
+ grub_term_entry_width (term_screen->term)))
|
|
|
|
print_line (linep, column, region_column - column, y,
|
|
|
|
term_screen);
|
2005-02-19 20:56:07 +00:00
|
|
|
else if (region_column < column)
|
2009-12-24 14:34:33 +00:00
|
|
|
print_line (linep, column, 0, y, term_screen);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
else if (i > region_start && mode == ALL_LINES)
|
2009-12-24 14:34:33 +00:00
|
|
|
print_line (linep, column, 0, y, term_screen);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2011-04-10 11:56:23 +00:00
|
|
|
if (y == term_screen->num_entries)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
|
|
|
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)
|
2011-04-10 11:56:23 +00:00
|
|
|
for (; y < term_screen->num_entries; y++)
|
2009-12-24 14:34:33 +00:00
|
|
|
print_empty_line (y, term_screen);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
2011-04-10 11:56:23 +00:00
|
|
|
while (y < term_screen->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)
|
2009-12-24 14:34:33 +00:00
|
|
|
print_up (up_flag, term_screen);
|
2005-02-19 20:56:07 +00:00
|
|
|
if (down)
|
2009-12-24 14:34:33 +00:00
|
|
|
print_down (down_flag, term_screen);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Place the cursor. */
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term_screen->term,
|
|
|
|
GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN + 1
|
|
|
|
+ term_screen->x,
|
|
|
|
GRUB_TERM_FIRST_ENTRY_Y + term_screen->y);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_refresh (term_screen->term);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
update_screen_all (struct screen *screen,
|
|
|
|
int region_start, int region_column,
|
|
|
|
int up, int down, enum update_mode mode)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
update_screen (screen, &screen->terms[i], region_start, region_column,
|
|
|
|
up, down, mode);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
insert_string (struct screen *screen, char *s, int update)
|
|
|
|
{
|
|
|
|
int region_start = screen->num_lines;
|
|
|
|
int region_column = 0;
|
2009-12-24 14:34:33 +00:00
|
|
|
int down[screen->nterms];
|
|
|
|
enum update_mode mode[screen->nterms];
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
down[i] = 0;
|
|
|
|
mode[i] = NO_LINE;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
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
|
2010-03-23 15:46:45 +00:00
|
|
|
* sizeof (screen->lines[0]));
|
2005-02-19 20:56:07 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
mode[i] = ALL_LINES;
|
|
|
|
down[i] = 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++;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
screen->terms[i].x = 0;
|
|
|
|
screen->terms[i].y++;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
s++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* All but LF. */
|
|
|
|
char *p;
|
|
|
|
struct line *current_linep;
|
|
|
|
int size;
|
2009-12-24 14:34:33 +00:00
|
|
|
int orig_num[screen->nterms], new_num[screen->nterms];
|
2005-02-19 20:56:07 +00:00
|
|
|
|
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);
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
orig_num[i] = get_logical_num_lines (current_linep,
|
|
|
|
&screen->terms[i]);
|
2005-02-19 20:56:07 +00:00
|
|
|
current_linep->len += size;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
new_num[i] = get_logical_num_lines (current_linep,
|
|
|
|
&screen->terms[i]);
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
if (orig_num[i] != new_num[i])
|
|
|
|
{
|
|
|
|
mode[i] = ALL_LINES;
|
|
|
|
down[i] = 1; /* XXX not optimal. */
|
|
|
|
}
|
|
|
|
else if (mode[i] != ALL_LINES)
|
|
|
|
mode[i] = SINGLE_LINE;
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
/* Move the cursor. */
|
|
|
|
screen->column += size;
|
|
|
|
screen->real_column = screen->column;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
screen->terms[i].x += size;
|
|
|
|
screen->terms[i].y += screen->terms[i].x
|
|
|
|
/ grub_term_entry_width (screen->terms[i].term);
|
|
|
|
screen->terms[i].x
|
|
|
|
%= grub_term_entry_width (screen->terms[i].term);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
s = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
update_screen (screen, &screen->terms[i],
|
|
|
|
region_start, region_column, 0, down[i], mode[i]);
|
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);
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_free (screen->terms);
|
2005-02-19 20:56:07 +00:00
|
|
|
grub_free (screen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make a new screen. */
|
|
|
|
static struct screen *
|
|
|
|
make_screen (grub_menu_entry_t entry)
|
|
|
|
{
|
|
|
|
struct screen *screen;
|
2009-12-24 14:34:33 +00:00
|
|
|
unsigned i;
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
2010-09-20 22:47:49 +00:00
|
|
|
screen->submenu = entry->submenu;
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
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;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
screen->terms[i].x = 0;
|
|
|
|
screen->terms[i].y = 0;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
return screen;
|
|
|
|
|
|
|
|
fail:
|
|
|
|
destroy_screen (screen);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
forward_char (struct screen *screen, int update)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
2009-12-24 14:34:33 +00:00
|
|
|
unsigned i;
|
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++;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
screen->terms[i].x++;
|
|
|
|
if (screen->terms[i].x
|
|
|
|
== grub_term_entry_width (screen->terms[i].term))
|
|
|
|
{
|
|
|
|
screen->terms[i].x = 0;
|
|
|
|
screen->terms[i].y++;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (screen->num_lines > screen->line + 1)
|
|
|
|
{
|
|
|
|
screen->column = 0;
|
|
|
|
screen->line++;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
screen->terms[i].x = 0;
|
|
|
|
screen->terms[i].y++;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
screen->real_column = screen->column;
|
|
|
|
|
|
|
|
if (update)
|
2009-12-24 14:34:33 +00:00
|
|
|
update_screen_all (screen, screen->num_lines, 0, 0, 0, NO_LINE);
|
2005-02-19 20:56:07 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
backward_char (struct screen *screen, int update)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
unsigned i;
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (screen->column > 0)
|
|
|
|
{
|
|
|
|
screen->column--;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
screen->terms[i].x--;
|
|
|
|
if (screen->terms[i].x == -1)
|
|
|
|
{
|
|
|
|
screen->terms[i].x
|
|
|
|
= grub_term_entry_width (screen->terms[i].term) - 1;
|
|
|
|
screen->terms[i].y--;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
screen->terms[i].x = screen->column
|
|
|
|
% grub_term_entry_width (screen->terms[i].term);
|
|
|
|
screen->terms[i].y--;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
screen->real_column = screen->column;
|
|
|
|
|
|
|
|
if (update)
|
2009-12-24 14:34:33 +00:00
|
|
|
update_screen_all (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)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
unsigned i;
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (screen->line > 0)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
2009-12-24 14:34:33 +00:00
|
|
|
int col;
|
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? */
|
2009-12-24 14:34:33 +00:00
|
|
|
col = screen->column;
|
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
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
int dy;
|
|
|
|
dy = col / grub_term_entry_width (screen->terms[i].term);
|
|
|
|
|
|
|
|
/* How many physical lines from the current position
|
|
|
|
to the last physical line? */
|
|
|
|
dy += (linep->len / grub_term_entry_width (screen->terms[i].term)
|
|
|
|
- screen->column
|
|
|
|
/ grub_term_entry_width (screen->terms[i].term));
|
|
|
|
|
|
|
|
screen->terms[i].y -= dy + 1;
|
|
|
|
screen->terms[i].x
|
|
|
|
= screen->column % grub_term_entry_width (screen->terms[i].term);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
screen->terms[i].y
|
|
|
|
-= screen->column / grub_term_entry_width (screen->terms[i].term);
|
|
|
|
screen->terms[i].x = 0;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->column = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
2009-12-24 14:34:33 +00:00
|
|
|
update_screen_all (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)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
unsigned i;
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (screen->line < screen->num_lines - 1)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
2009-12-24 14:34:33 +00:00
|
|
|
int l1, c1;
|
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;
|
2009-12-24 14:34:33 +00:00
|
|
|
l1 = linep->len;
|
|
|
|
c1 = screen->column;
|
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
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
int dy;
|
|
|
|
dy = l1 / grub_term_entry_width (screen->terms[i].term)
|
|
|
|
- c1 / grub_term_entry_width (screen->terms[i].term);
|
|
|
|
/* How many physical lines from the current position
|
|
|
|
to the first physical line? */
|
|
|
|
dy += screen->column / grub_term_entry_width (screen->terms[i].term);
|
|
|
|
screen->terms[i].y += dy + 1;
|
|
|
|
screen->terms[i].x = screen->column
|
|
|
|
% grub_term_entry_width (screen->terms[i].term);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct line *linep;
|
2009-12-24 14:34:33 +00:00
|
|
|
int l, s;
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep = screen->lines + screen->line;
|
2009-12-24 14:34:33 +00:00
|
|
|
l = linep->len;
|
|
|
|
s = screen->column;
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->column = linep->len;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
screen->terms[i].y
|
|
|
|
+= (l / grub_term_entry_width (screen->terms[i].term)
|
|
|
|
- s / grub_term_entry_width (screen->terms[i].term));
|
|
|
|
screen->terms[i].x
|
|
|
|
= screen->column % grub_term_entry_width (screen->terms[i].term);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (update)
|
2009-12-24 14:34:33 +00:00
|
|
|
update_screen_all (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)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
unsigned i;
|
|
|
|
int col;
|
|
|
|
|
|
|
|
col = screen->column;
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->column = screen->real_column = 0;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
screen->terms[i].x = 0;
|
|
|
|
screen->terms[i].y -= col / grub_term_entry_width (screen->terms[i].term);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
if (update)
|
2009-12-24 14:34:33 +00:00
|
|
|
update_screen_all (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-12-24 14:34:33 +00:00
|
|
|
unsigned i;
|
|
|
|
int col;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
linep = screen->lines + screen->line;
|
2009-12-24 14:34:33 +00:00
|
|
|
col = screen->column;
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->column = screen->real_column = linep->len;
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
screen->terms[i].y
|
|
|
|
+= (linep->len / grub_term_entry_width (screen->terms->term)
|
|
|
|
- col / grub_term_entry_width (screen->terms->term));
|
|
|
|
screen->terms[i].x
|
|
|
|
= screen->column % grub_term_entry_width (screen->terms->term);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
if (update)
|
2009-12-24 14:34:33 +00:00
|
|
|
update_screen_all (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;
|
|
|
|
int start = screen->num_lines;
|
|
|
|
int column = 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)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
int orig_num[screen->nterms], new_num;
|
|
|
|
unsigned i;
|
2005-02-19 20:56:07 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
orig_num[i] = get_logical_num_lines (linep, &screen->terms[i]);
|
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--;
|
|
|
|
|
|
|
|
start = screen->line;
|
|
|
|
column = screen->column;
|
2009-12-24 14:34:33 +00:00
|
|
|
|
|
|
|
screen->real_column = screen->column;
|
|
|
|
|
|
|
|
if (update)
|
|
|
|
{
|
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
new_num = get_logical_num_lines (linep, &screen->terms[i]);
|
|
|
|
if (orig_num[i] != new_num)
|
|
|
|
update_screen (screen, &screen->terms[i],
|
|
|
|
start, column, 0, 0, ALL_LINES);
|
|
|
|
else
|
|
|
|
update_screen (screen, &screen->terms[i],
|
|
|
|
start, column, 0, 0, SINGLE_LINE);
|
|
|
|
}
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
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
|
|
|
start = screen->line;
|
|
|
|
column = screen->column;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
screen->real_column = screen->column;
|
|
|
|
if (update)
|
|
|
|
update_screen_all (screen, start, column, 0, 1, ALL_LINES);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
int orig_num[screen->nterms], new_num;
|
|
|
|
unsigned i;
|
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
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
orig_num[i] = get_logical_num_lines (linep, &screen->terms[i]);
|
2005-02-19 20:56:07 +00:00
|
|
|
linep->len = screen->column;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
if (update)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
new_num = get_logical_num_lines (linep, &screen->terms[i]);
|
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
if (orig_num[i] != new_num)
|
|
|
|
update_screen (screen, &screen->terms[i],
|
|
|
|
screen->line, screen->column, 0, 1, ALL_LINES);
|
|
|
|
else
|
|
|
|
update_screen (screen, &screen->terms[i],
|
|
|
|
screen->line, screen->column, 0, 0, SINGLE_LINE);
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
int saved_y[screen->nterms];
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
saved_y[i] = screen->terms[i].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;
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
screen->terms[i].y = saved_y[i];
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
if (update)
|
2009-12-24 14:34:33 +00:00
|
|
|
update_screen_all (screen, screen->line, screen->column, 0, 1, ALL_LINES);
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
/* A completion hook to print items. */
|
|
|
|
static void
|
2009-12-24 14:34:33 +00:00
|
|
|
store_completion (const char *item, grub_completion_type_t type,
|
|
|
|
int count __attribute__ ((unused)))
|
2005-08-18 03:14:39 +00:00
|
|
|
{
|
|
|
|
char *p;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
completion_type = type;
|
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)
|
|
|
|
{
|
|
|
|
char saved_char;
|
|
|
|
struct line *linep;
|
|
|
|
int restore;
|
|
|
|
char *insert;
|
|
|
|
static int count = -1;
|
2009-12-24 14:34:33 +00:00
|
|
|
unsigned i;
|
|
|
|
grub_uint32_t *ucs4;
|
|
|
|
grub_size_t buflen;
|
|
|
|
grub_ssize_t ucs4len;
|
2005-08-18 03:14:39 +00:00
|
|
|
|
|
|
|
if (continuous)
|
|
|
|
count++;
|
|
|
|
else
|
|
|
|
count = 0;
|
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;
|
2010-03-23 15:46:45 +00:00
|
|
|
|
|
|
|
if (completion_buffer.buf)
|
2009-12-24 14:34:33 +00:00
|
|
|
{
|
2010-03-23 15:46:45 +00:00
|
|
|
buflen = grub_strlen (completion_buffer.buf);
|
|
|
|
ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1));
|
|
|
|
|
|
|
|
if (!ucs4)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return 1;
|
|
|
|
}
|
2005-08-18 03:14:39 +00:00
|
|
|
|
2010-03-23 15:46:45 +00:00
|
|
|
ucs4len = grub_utf8_to_ucs4 (ucs4, buflen,
|
|
|
|
(grub_uint8_t *) completion_buffer.buf,
|
|
|
|
buflen, 0);
|
|
|
|
ucs4[ucs4len] = 0;
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 15:46:45 +00:00
|
|
|
if (restore)
|
|
|
|
for (i = 0; i < screen->nterms; i++)
|
2009-12-24 14:34:33 +00:00
|
|
|
{
|
2010-03-23 15:46:45 +00:00
|
|
|
int num_sections = ((completion_buffer.len
|
|
|
|
+ grub_term_width (screen->terms[i].term)
|
|
|
|
- 8 - 1)
|
|
|
|
/ (grub_term_width (screen->terms[i].term)
|
|
|
|
- 8));
|
|
|
|
grub_uint32_t *endp;
|
|
|
|
grub_uint16_t pos;
|
|
|
|
grub_uint32_t *p = ucs4;
|
|
|
|
|
|
|
|
pos = grub_term_getxy (screen->terms[i].term);
|
|
|
|
grub_term_gotoxy (screen->terms[i].term, 0,
|
|
|
|
grub_term_height (screen->terms[i].term) - 3);
|
|
|
|
|
|
|
|
screen->completion_shown = 1;
|
|
|
|
|
|
|
|
grub_term_gotoxy (screen->terms[i].term, 0,
|
|
|
|
grub_term_height (screen->terms[i].term) - 3);
|
|
|
|
grub_puts_terminal (" ", screen->terms[i].term);
|
|
|
|
switch (completion_type)
|
|
|
|
{
|
|
|
|
case GRUB_COMPLETION_TYPE_COMMAND:
|
|
|
|
grub_puts_terminal (_("Possible commands are:"),
|
|
|
|
screen->terms[i].term);
|
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_DEVICE:
|
|
|
|
grub_puts_terminal (_("Possible devices are:"),
|
|
|
|
screen->terms[i].term);
|
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_FILE:
|
|
|
|
grub_puts_terminal (_("Possible files are:"),
|
|
|
|
screen->terms[i].term);
|
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_PARTITION:
|
|
|
|
grub_puts_terminal (_("Possible partitions are:"),
|
|
|
|
screen->terms[i].term);
|
|
|
|
break;
|
|
|
|
case GRUB_COMPLETION_TYPE_ARGUMENT:
|
|
|
|
grub_puts_terminal (_("Possible arguments are:"),
|
|
|
|
screen->terms[i].term);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
grub_puts_terminal (_("Possible things are:"),
|
|
|
|
screen->terms[i].term);
|
|
|
|
break;
|
|
|
|
}
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 15:46:45 +00:00
|
|
|
grub_puts_terminal ("\n ", screen->terms[i].term);
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 15:46:45 +00:00
|
|
|
p += (count % num_sections)
|
|
|
|
* (grub_term_width (screen->terms[i].term) - 8);
|
|
|
|
endp = p + (grub_term_width (screen->terms[i].term) - 8);
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 15:46:45 +00:00
|
|
|
if (p != ucs4)
|
2010-05-09 10:56:32 +00:00
|
|
|
grub_putcode (GRUB_UNICODE_LEFTARROW, screen->terms[i].term);
|
2010-03-23 15:46:45 +00:00
|
|
|
else
|
|
|
|
grub_putcode (' ', screen->terms[i].term);
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 15:46:45 +00:00
|
|
|
grub_print_ucs4 (p, ucs4 + ucs4len < endp ? ucs4 + ucs4len : endp,
|
|
|
|
0, 0, screen->terms[i].term);
|
2009-12-24 14:34:33 +00:00
|
|
|
|
2010-03-23 15:46:45 +00:00
|
|
|
if (ucs4 + ucs4len > endp)
|
2010-05-09 10:56:32 +00:00
|
|
|
grub_putcode (GRUB_UNICODE_RIGHTARROW, screen->terms[i].term);
|
2010-03-23 15:46:45 +00:00
|
|
|
grub_term_gotoxy (screen->terms[i].term, 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
|
2009-12-24 14:34:33 +00:00
|
|
|
clear_completions (struct per_term_screen *term_screen)
|
2005-08-18 03:14:39 +00:00
|
|
|
{
|
|
|
|
grub_uint16_t pos;
|
2009-12-24 14:34:33 +00:00
|
|
|
unsigned i, j;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
pos = grub_term_getxy (term_screen->term);
|
|
|
|
grub_term_gotoxy (term_screen->term, 0,
|
|
|
|
grub_term_height (term_screen->term) - 3);
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-08-18 03:14:39 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
for (j = 0; j < grub_term_width (term_screen->term) - 1; j++)
|
|
|
|
grub_putcode (' ', term_screen->term);
|
|
|
|
grub_putcode ('\n', term_screen->term);
|
2005-08-18 03:14:39 +00:00
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
grub_term_gotoxy (term_screen->term, pos >> 8, pos & 0xFF);
|
|
|
|
grub_term_refresh (term_screen->term);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
clear_completions_all (struct screen *screen)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
|
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
clear_completions (&screen->terms[i]);
|
2005-08-18 03:14:39 +00:00
|
|
|
}
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Execute the command list in the screen SCREEN. */
|
|
|
|
static int
|
|
|
|
run (struct screen *screen)
|
|
|
|
{
|
2010-12-08 11:13:11 +00:00
|
|
|
char *script;
|
2010-09-20 15:46:35 +00:00
|
|
|
int errs_before;
|
2011-04-01 10:43:51 +00:00
|
|
|
grub_menu_t menu = NULL;
|
2010-12-08 11:13:11 +00:00
|
|
|
char *dummy[1] = { NULL };
|
2006-01-17 09:50:47 +00:00
|
|
|
|
2010-12-08 11:13:11 +00:00
|
|
|
auto char * editor_getsource (void);
|
|
|
|
char * editor_getsource (void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int size = 0;
|
|
|
|
char *source;
|
2006-01-17 09:50:47 +00:00
|
|
|
|
2010-12-08 11:13:11 +00:00
|
|
|
for (i = 0; i < screen->num_lines; i++)
|
|
|
|
size += screen->lines[i].len + 1;
|
2006-01-17 09:50:47 +00:00
|
|
|
|
2010-12-08 11:13:11 +00:00
|
|
|
source = grub_malloc (size + 1);
|
|
|
|
if (! source)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
for (i = 0; i < screen->num_lines; i++)
|
|
|
|
{
|
2011-04-08 12:37:13 +00:00
|
|
|
grub_memcpy (source + size, screen->lines[i].buf, screen->lines[i].len);
|
2010-12-08 11:13:11 +00:00
|
|
|
size += screen->lines[i].len;
|
|
|
|
source[size++] = '\n';
|
|
|
|
}
|
|
|
|
source[size] = '\0';
|
|
|
|
return source;
|
|
|
|
}
|
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 (" ");
|
2009-12-08 00:08:52 +00:00
|
|
|
grub_printf_ (N_("Booting a command list"));
|
2009-12-05 11:25:07 +00:00
|
|
|
grub_printf ("\n\n");
|
2005-02-19 20:56:07 +00:00
|
|
|
|
2010-09-20 15:46:35 +00:00
|
|
|
errs_before = grub_err_printed_errors;
|
2006-01-17 09:50:47 +00:00
|
|
|
|
2010-09-20 22:47:49 +00:00
|
|
|
if (screen->submenu)
|
|
|
|
{
|
|
|
|
grub_env_context_open ();
|
|
|
|
menu = grub_zalloc (sizeof (*menu));
|
|
|
|
if (! menu)
|
2010-09-21 18:03:11 +00:00
|
|
|
return 0;
|
2010-09-20 22:47:49 +00:00
|
|
|
grub_env_set_menu (menu);
|
|
|
|
}
|
|
|
|
|
2006-01-17 09:50:47 +00:00
|
|
|
/* Execute the script, line for line. */
|
2010-12-08 11:13:11 +00:00
|
|
|
script = editor_getsource ();
|
|
|
|
if (! script)
|
|
|
|
return 0;
|
|
|
|
grub_script_execute_sourcecode (script, 0, dummy);
|
|
|
|
grub_free (script);
|
2005-02-19 20:56:07 +00:00
|
|
|
|
2010-09-20 15:46:35 +00:00
|
|
|
if (errs_before != grub_err_printed_errors)
|
|
|
|
grub_wait_after_message ();
|
|
|
|
|
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
|
|
|
|
2010-09-20 22:47:49 +00:00
|
|
|
if (screen->submenu)
|
|
|
|
{
|
|
|
|
if (menu && menu->size)
|
|
|
|
{
|
2011-01-10 22:27:58 +00:00
|
|
|
grub_show_menu (menu, 1, 0);
|
2010-09-20 22:47:49 +00:00
|
|
|
grub_normal_free_menu (menu);
|
|
|
|
}
|
|
|
|
grub_env_context_close ();
|
|
|
|
}
|
|
|
|
|
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;
|
2009-12-24 14:34:33 +00:00
|
|
|
unsigned i;
|
2009-12-25 03:12:29 +00:00
|
|
|
grub_term_output_t term;
|
2009-08-24 23:55:06 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-12-25 03:12:29 +00:00
|
|
|
screen->terms = NULL;
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
refresh:
|
2009-12-25 03:12:29 +00:00
|
|
|
grub_free (screen->terms);
|
|
|
|
screen->nterms = 0;
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
screen->nterms++;
|
|
|
|
screen->terms = grub_malloc (screen->nterms * sizeof (screen->terms[0]));
|
|
|
|
if (!screen->terms)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
|
|
|
screen->terms[i].term = term;
|
|
|
|
screen->terms[i].x = 0;
|
|
|
|
screen->terms[i].y = 0;
|
2009-12-25 12:18:08 +00:00
|
|
|
i++;
|
2009-12-25 03:12:29 +00:00
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Draw the screen. */
|
2009-12-24 14:34:33 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
2011-04-10 11:56:23 +00:00
|
|
|
grub_menu_init_page (0, 1, &screen->terms[i].num_entries,
|
|
|
|
screen->terms[i].term);
|
2009-12-24 14:34:33 +00:00
|
|
|
update_screen_all (screen, 0, 0, 1, 1, ALL_LINES);
|
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
grub_term_setcursor (screen->terms[i].term, 1);
|
2005-02-19 20:56:07 +00:00
|
|
|
prev_c = '\0';
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2010-05-10 12:54:51 +00:00
|
|
|
int c = grub_getkey ();
|
2005-08-18 03:14:39 +00:00
|
|
|
|
|
|
|
if (screen->completion_shown)
|
|
|
|
{
|
2009-12-24 14:34:33 +00:00
|
|
|
clear_completions_all (screen);
|
2005-08-18 03:14:39 +00:00
|
|
|
screen->completion_shown = 0;
|
|
|
|
}
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2009-12-25 15:28:31 +00:00
|
|
|
if (grub_normal_exit_level)
|
|
|
|
{
|
|
|
|
destroy_screen (screen);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
switch (c)
|
|
|
|
{
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_KEY_UP:
|
|
|
|
case GRUB_TERM_CTRL | 'p':
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! previous_line (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'n':
|
|
|
|
case GRUB_TERM_KEY_DOWN:
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! next_line (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'f':
|
|
|
|
case GRUB_TERM_KEY_RIGHT:
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! forward_char (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'b':
|
|
|
|
case GRUB_TERM_KEY_LEFT:
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! backward_char (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'a':
|
|
|
|
case GRUB_TERM_KEY_HOME:
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! beginning_of_line (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'e':
|
|
|
|
case GRUB_TERM_KEY_END:
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! end_of_line (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'i':
|
|
|
|
case '\t':
|
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
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'd':
|
|
|
|
case GRUB_TERM_KEY_DC:
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! delete_char (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'h':
|
2010-08-18 23:07:50 +00:00
|
|
|
case '\b':
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! backward_delete_char (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'k':
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! kill_line (screen, prev_c == c, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'u':
|
2005-02-19 20:56:07 +00:00
|
|
|
/* FIXME: What behavior is good for this key? */
|
|
|
|
break;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'y':
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! yank (screen, 1))
|
|
|
|
goto fail;
|
|
|
|
break;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'l':
|
2005-02-19 20:56:07 +00:00
|
|
|
/* FIXME: centering. */
|
|
|
|
goto refresh;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'o':
|
2005-02-19 20:56:07 +00:00
|
|
|
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
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'c':
|
2010-08-18 23:07:50 +00:00
|
|
|
case GRUB_TERM_KEY_F2:
|
2005-02-19 20:56:07 +00:00
|
|
|
grub_cmdline_run (1);
|
|
|
|
goto refresh;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'x':
|
2010-08-18 23:07:50 +00:00
|
|
|
case GRUB_TERM_KEY_F10:
|
2010-09-20 15:46:35 +00:00
|
|
|
run (screen);
|
2005-02-19 20:56:07 +00:00
|
|
|
goto refresh;
|
|
|
|
|
2010-05-10 12:54:51 +00:00
|
|
|
case GRUB_TERM_CTRL | 'r':
|
|
|
|
case GRUB_TERM_CTRL | 's':
|
|
|
|
case GRUB_TERM_CTRL | 't':
|
2005-02-19 20:56:07 +00:00
|
|
|
/* 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;
|
2010-03-15 10:49:27 +00:00
|
|
|
grub_xputs ("\n");
|
2009-12-08 00:08:52 +00:00
|
|
|
grub_printf_ (N_("Press any key to continue..."));
|
2005-02-19 20:56:07 +00:00
|
|
|
(void) grub_getkey ();
|
|
|
|
}
|