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. */
|
2012-03-27 15:07:26 +00:00
|
|
|
grub_uint32_t *buf;
|
2005-02-19 20:56:07 +00:00
|
|
|
/* The length of the line. */
|
|
|
|
int len;
|
|
|
|
/* The maximum length of the line. */
|
|
|
|
int max_len;
|
2013-01-16 12:41:16 +00:00
|
|
|
struct grub_term_pos **pos;
|
2005-02-19 20:56:07 +00:00
|
|
|
};
|
|
|
|
|
2009-12-24 14:34:33 +00:00
|
|
|
struct per_term_screen
|
|
|
|
{
|
|
|
|
struct grub_term_output *term;
|
2012-03-27 15:07:26 +00:00
|
|
|
int y_line_start;
|
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. */
|
2012-03-27 15:07:26 +00:00
|
|
|
static struct {
|
|
|
|
char *buf;
|
|
|
|
grub_size_t len;
|
|
|
|
grub_size_t max_len;
|
|
|
|
} 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
|
2013-01-16 12:41:16 +00:00
|
|
|
init_line (struct screen *screen, struct line *linep)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
|
|
|
linep->len = 0;
|
2012-03-27 15:07:26 +00:00
|
|
|
linep->max_len = 80;
|
|
|
|
linep->buf = grub_malloc ((linep->max_len + 1) * sizeof (linep->buf[0]));
|
2013-01-16 12:41:16 +00:00
|
|
|
linep->pos = grub_zalloc (screen->nterms * sizeof (linep->pos[0]));
|
|
|
|
if (! linep->buf || !linep->pos)
|
|
|
|
{
|
|
|
|
grub_free (linep->buf);
|
|
|
|
grub_free (linep->pos);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate extra space if necessary. */
|
|
|
|
static int
|
|
|
|
ensure_space (struct line *linep, int extra)
|
|
|
|
{
|
|
|
|
if (linep->max_len < linep->len + extra)
|
|
|
|
{
|
2012-03-27 15:07:26 +00:00
|
|
|
linep->max_len = 2 * (linep->len + extra);
|
|
|
|
linep->buf = grub_realloc (linep->buf, (linep->max_len + 1) * sizeof (linep->buf[0]));
|
2005-02-19 20:56:07 +00:00
|
|
|
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
|
|
|
{
|
2012-03-27 15:07:26 +00:00
|
|
|
return (grub_getstringwidth (linep->buf, linep->buf + linep->len,
|
|
|
|
term_screen->term)
|
|
|
|
/ grub_term_entry_width (term_screen->term)) + 1;
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
|
2012-03-27 15:07:26 +00:00
|
|
|
static void
|
|
|
|
advance_to (struct screen *screen, int c)
|
|
|
|
{
|
|
|
|
if (c > screen->lines[screen->line].len)
|
|
|
|
c = screen->lines[screen->line].len;
|
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
screen->column = grub_unicode_get_comb_end (screen->lines[screen->line].buf
|
|
|
|
+ screen->lines[screen->line].len,
|
|
|
|
screen->lines[screen->line].buf
|
|
|
|
+ c)
|
|
|
|
- screen->lines[screen->line].buf;
|
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
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
for (i = 0; i < grub_term_entry_width (term_screen->term); i++)
|
2009-12-24 14:34:33 +00:00
|
|
|
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,
|
2013-01-16 12:41:16 +00:00
|
|
|
int region_start, int region_column __attribute__ ((unused)),
|
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
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
y = term_screen->y_line_start;
|
|
|
|
linep = screen->lines;
|
|
|
|
|
|
|
|
for (i = 0; i < screen->line; i++, linep++)
|
|
|
|
y += get_logical_num_lines (linep, term_screen);
|
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
y += grub_getstringwidth (linep->buf, linep->buf + screen->column,
|
|
|
|
term_screen->term) / grub_term_entry_width (term_screen->term);
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
/* Check if scrolling is necessary. */
|
2013-01-16 12:41:16 +00:00
|
|
|
if (y < 0 || y >= term_screen->num_entries)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2012-03-27 15:07:26 +00:00
|
|
|
int delta;
|
2013-01-16 12:41:16 +00:00
|
|
|
if (y < 0)
|
|
|
|
delta = -y;
|
2005-02-19 20:56:07 +00:00
|
|
|
else
|
2013-01-16 12:41:16 +00:00
|
|
|
delta = term_screen->num_entries - 1 - y;
|
2012-03-27 15:07:26 +00:00
|
|
|
term_screen->y_line_start += delta;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
region_start = 0;
|
|
|
|
up = 1;
|
|
|
|
down = 1;
|
|
|
|
mode = ALL_LINES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode != NO_LINE)
|
|
|
|
{
|
|
|
|
/* Draw lines. This code is tricky, because this must calculate logical
|
|
|
|
positions. */
|
2012-03-27 15:07:26 +00:00
|
|
|
y = term_screen->y_line_start;
|
2013-01-16 12:41:16 +00:00
|
|
|
i = 0;
|
|
|
|
linep = screen->lines;
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
int add;
|
|
|
|
add = get_logical_num_lines (linep, term_screen);
|
|
|
|
if (y + add > 0)
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
linep++;
|
|
|
|
y += add;
|
|
|
|
}
|
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
|
|
|
|
{
|
2012-03-27 15:07:26 +00:00
|
|
|
int off = 0;
|
2013-01-16 12:41:16 +00:00
|
|
|
struct grub_term_pos **pos;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2010-03-23 15:46:45 +00:00
|
|
|
if (linep >= screen->lines + screen->num_lines)
|
|
|
|
break;
|
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
pos = linep->pos + (term_screen - screen->terms);
|
2012-06-02 12:30:52 +00:00
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
if (!*pos)
|
|
|
|
*pos = grub_zalloc ((linep->len + 1) * sizeof (**pos));
|
|
|
|
|
|
|
|
if (i == region_start || linep == screen->lines + screen->line)
|
|
|
|
{
|
|
|
|
int sp;
|
|
|
|
grub_term_gotoxy (term_screen->term, GRUB_TERM_LEFT_BORDER_X
|
|
|
|
+ GRUB_TERM_MARGIN + 1, (y < 0 ? 0 : y)
|
|
|
|
+ GRUB_TERM_FIRST_ENTRY_Y);
|
|
|
|
grub_print_ucs4_menu (linep->buf,
|
|
|
|
linep->buf + linep->len,
|
|
|
|
GRUB_TERM_LEFT_BORDER_X + GRUB_TERM_MARGIN
|
|
|
|
+ 1,
|
|
|
|
GRUB_TERM_MARGIN
|
|
|
|
+ GRUB_TERM_SCROLL_WIDTH + 2,
|
|
|
|
term_screen->term,
|
|
|
|
(y < 0) ? -y : 0,
|
|
|
|
term_screen->num_entries
|
|
|
|
- ((y > 0) ? y : 0), '\\',
|
|
|
|
*pos);
|
|
|
|
sp = grub_term_entry_width (term_screen->term)
|
|
|
|
- (*pos)[linep->len].x;
|
|
|
|
if (sp > 0)
|
|
|
|
grub_print_spaces (term_screen->term, sp);
|
|
|
|
}
|
|
|
|
else if (i > region_start && mode == ALL_LINES)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2013-01-16 12:41:16 +00:00
|
|
|
int sp;
|
|
|
|
grub_term_gotoxy (term_screen->term, GRUB_TERM_LEFT_BORDER_X
|
|
|
|
+ GRUB_TERM_MARGIN + 1, (y < 0 ? 0 : y)
|
|
|
|
+ GRUB_TERM_FIRST_ENTRY_Y);
|
|
|
|
grub_print_ucs4_menu (linep->buf,
|
|
|
|
linep->buf + linep->len,
|
|
|
|
GRUB_TERM_LEFT_BORDER_X
|
|
|
|
+ GRUB_TERM_MARGIN + 1,
|
|
|
|
GRUB_TERM_MARGIN
|
|
|
|
+ GRUB_TERM_SCROLL_WIDTH + 2,
|
|
|
|
term_screen->term,
|
|
|
|
(y < 0) ? -y : 0,
|
|
|
|
term_screen->num_entries
|
|
|
|
- ((y > 0) ? y : 0), '\\',
|
|
|
|
*pos);
|
|
|
|
sp = grub_term_entry_width (term_screen->term)
|
|
|
|
- (*pos)[linep->len].x;
|
|
|
|
if (sp > 0)
|
|
|
|
grub_print_spaces (term_screen->term, sp);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
2013-01-16 12:41:16 +00:00
|
|
|
y += get_logical_num_lines (linep, term_screen);
|
|
|
|
if (y >= term_screen->num_entries)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
2012-03-27 15:07:26 +00:00
|
|
|
if (off <= linep->len || i + 1 < screen->num_lines)
|
2005-02-19 20:56:07 +00:00
|
|
|
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);
|
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. */
|
2013-01-16 12:41:16 +00:00
|
|
|
if (screen->lines[screen->line].pos[term_screen - screen->terms])
|
|
|
|
{
|
|
|
|
const struct grub_term_pos *cpos;
|
|
|
|
for (cpos = &(screen->lines[screen->line].pos[term_screen - screen->terms])[screen->column];
|
|
|
|
cpos >= &(screen->lines[screen->line].pos[term_screen - screen->terms])[0];
|
|
|
|
cpos--)
|
|
|
|
if (cpos->valid)
|
|
|
|
break;
|
|
|
|
y = term_screen->y_line_start;
|
|
|
|
for (i = 0; i < screen->line; i++)
|
|
|
|
y += get_logical_num_lines (screen->lines + i, term_screen);
|
|
|
|
if (cpos >= &(screen->lines[screen->line].pos[term_screen - screen->terms])[0])
|
|
|
|
grub_term_gotoxy (term_screen->term,
|
|
|
|
cpos->x + GRUB_TERM_LEFT_BORDER_X
|
|
|
|
+ GRUB_TERM_MARGIN + 1,
|
|
|
|
cpos->y + y
|
|
|
|
+ GRUB_TERM_FIRST_ENTRY_Y);
|
|
|
|
else
|
|
|
|
grub_term_gotoxy (term_screen->term,
|
|
|
|
GRUB_TERM_LEFT_BORDER_X
|
|
|
|
+ GRUB_TERM_MARGIN + 1,
|
|
|
|
y + GRUB_TERM_FIRST_ENTRY_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
|
2011-11-30 15:20:13 +00:00
|
|
|
insert_string (struct screen *screen, const char *s, int update)
|
2005-02-19 20:56:07 +00:00
|
|
|
{
|
|
|
|
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)));
|
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
if (! init_line (screen, screen->lines + screen->line + 1))
|
2005-02-19 20:56:07 +00:00
|
|
|
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,
|
2012-03-27 15:07:26 +00:00
|
|
|
size * sizeof (next_linep->buf[0]));
|
2005-02-19 20:56:07 +00:00
|
|
|
current_linep->len = screen->column;
|
2013-01-16 12:41:16 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
grub_free (current_linep->pos[i]);
|
|
|
|
current_linep->pos[i] = 0;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
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++;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* All but LF. */
|
2011-11-30 15:20:13 +00:00
|
|
|
const char *p;
|
2005-02-19 20:56:07 +00:00
|
|
|
struct line *current_linep;
|
|
|
|
int size;
|
2009-12-24 14:34:33 +00:00
|
|
|
int orig_num[screen->nterms], new_num[screen->nterms];
|
2012-03-27 15:07:26 +00:00
|
|
|
grub_uint32_t *unicode_msg;
|
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;
|
2012-03-27 15:07:26 +00:00
|
|
|
unicode_msg = grub_malloc ((p - s) * sizeof (grub_uint32_t));
|
|
|
|
|
|
|
|
if (!unicode_msg)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
size = grub_utf8_to_ucs4 (unicode_msg, (p - s),
|
|
|
|
(grub_uint8_t *) s, (p - s), 0);
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
if (! ensure_space (current_linep, size))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
grub_memmove (current_linep->buf + screen->column + size,
|
|
|
|
current_linep->buf + screen->column,
|
2012-03-27 15:07:26 +00:00
|
|
|
(current_linep->len - screen->column)
|
|
|
|
* sizeof (current_linep->buf[0]));
|
2005-02-19 20:56:07 +00:00
|
|
|
grub_memmove (current_linep->buf + screen->column,
|
2012-03-27 15:07:26 +00:00
|
|
|
unicode_msg,
|
|
|
|
size * sizeof (current_linep->buf[0]));
|
|
|
|
grub_free (unicode_msg);
|
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
grub_free (current_linep->pos[i]);
|
|
|
|
current_linep->pos[i] = 0;
|
|
|
|
}
|
|
|
|
|
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. */
|
2012-03-27 15:07:26 +00:00
|
|
|
advance_to (screen, screen->column + size);
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->real_column = screen->column;
|
|
|
|
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. */
|
2013-01-16 12:41:16 +00:00
|
|
|
if (! init_line (screen, screen->lines))
|
2005-02-19 20:56:07 +00:00
|
|
|
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++)
|
|
|
|
{
|
2013-01-16 12:41:16 +00:00
|
|
|
screen->terms[i].y_line_start = 0;
|
2009-12-24 14:34:33 +00:00
|
|
|
}
|
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-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)
|
2013-01-16 12:41:16 +00:00
|
|
|
{
|
|
|
|
screen->column = grub_unicode_get_comb_end (screen->lines[screen->line].buf
|
|
|
|
+ screen->lines[screen->line].len,
|
|
|
|
screen->lines[screen->line].buf
|
|
|
|
+ screen->column + 1)
|
|
|
|
- screen->lines[screen->line].buf;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
else if (screen->num_lines > screen->line + 1)
|
|
|
|
{
|
|
|
|
screen->column = 0;
|
|
|
|
screen->line++;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (screen->column > 0)
|
|
|
|
{
|
2012-03-27 15:07:26 +00:00
|
|
|
struct grub_unicode_glyph glyph;
|
|
|
|
struct line *linep;
|
|
|
|
|
|
|
|
linep = screen->lines + screen->line;
|
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->column--;
|
2012-03-27 15:07:26 +00:00
|
|
|
screen->column = grub_unicode_get_comb_start (linep->buf,
|
|
|
|
linep->buf + screen->column)
|
|
|
|
- linep->buf;
|
|
|
|
|
|
|
|
grub_unicode_aglomerate_comb (screen->lines[screen->line].buf + screen->column,
|
|
|
|
screen->lines[screen->line].len - screen->column,
|
|
|
|
&glyph);
|
2013-01-16 12:41:16 +00:00
|
|
|
screen->column = grub_unicode_get_comb_start (linep->buf,
|
|
|
|
linep->buf + screen->column)
|
|
|
|
- linep->buf;
|
2012-03-27 15:07:26 +00:00
|
|
|
|
|
|
|
grub_free (glyph.combining);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
else if (screen->line > 0)
|
|
|
|
{
|
2012-03-27 15:07:26 +00:00
|
|
|
screen->line--;
|
2013-01-16 12:41:16 +00:00
|
|
|
screen->column = screen->lines[screen->line].len;
|
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)
|
|
|
|
{
|
|
|
|
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
|
|
|
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)
|
2012-03-27 15:07:26 +00:00
|
|
|
col = linep->len;
|
2005-02-19 20:56:07 +00:00
|
|
|
else
|
2012-03-27 15:07:26 +00:00
|
|
|
col = screen->real_column;
|
|
|
|
|
|
|
|
screen->column = 0;
|
|
|
|
advance_to (screen, col);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (screen->line < screen->num_lines - 1)
|
|
|
|
{
|
|
|
|
struct line *linep;
|
2012-03-27 15:07:26 +00:00
|
|
|
int c;
|
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-06-10 21:04:23 +00:00
|
|
|
|
2005-02-19 20:56:07 +00:00
|
|
|
screen->line++;
|
2012-03-27 15:07:26 +00:00
|
|
|
if ((linep + 1)->len < screen->real_column)
|
|
|
|
c = (linep + 1)->len;
|
2005-02-19 20:56:07 +00:00
|
|
|
else
|
2012-03-27 15:07:26 +00:00
|
|
|
c = screen->real_column;
|
|
|
|
screen->column = 0;
|
2009-06-10 21:04:23 +00:00
|
|
|
|
2012-03-27 15:07:26 +00:00
|
|
|
advance_to (screen, c);
|
2005-02-19 20:56:07 +00:00
|
|
|
}
|
|
|
|
else
|
2012-03-27 15:07:26 +00:00
|
|
|
advance_to (screen, screen->lines[screen->line].len);
|
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)
|
|
|
|
{
|
|
|
|
screen->column = screen->real_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
|
|
|
|
end_of_line (struct screen *screen, int update)
|
|
|
|
{
|
2012-03-27 15:07:26 +00:00
|
|
|
advance_to (screen, screen->lines[screen->line].len);
|
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,
|
2012-03-27 15:07:26 +00:00
|
|
|
(linep->len - screen->column - 1)
|
|
|
|
* sizeof (linep->buf[0]));
|
2005-02-19 20:56:07 +00:00
|
|
|
linep->len--;
|
|
|
|
|
2013-01-16 12:41:16 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
grub_free (linep->pos[i]);
|
|
|
|
linep->pos[i] = 0;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
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;
|
2013-01-16 12:41:16 +00:00
|
|
|
unsigned i;
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
next_linep = linep + 1;
|
|
|
|
if (! ensure_space (linep, next_linep->len))
|
|
|
|
return 0;
|
|
|
|
|
2012-03-27 15:07:26 +00:00
|
|
|
grub_memmove (linep->buf + linep->len, next_linep->buf,
|
|
|
|
next_linep->len * sizeof (linep->buf[0]));
|
2005-02-19 20:56:07 +00:00
|
|
|
linep->len += next_linep->len;
|
2013-01-16 12:41:16 +00:00
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
|
|
|
grub_free (linep->pos[i]);
|
|
|
|
linep->pos[i] = 0;
|
|
|
|
}
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
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);
|
2012-03-04 23:02:17 +00:00
|
|
|
p[offset + size] = '\0';
|
2005-02-19 20:56:07 +00:00
|
|
|
|
|
|
|
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
|
|
|
for (i = 0; i < screen->nterms; i++)
|
|
|
|
{
|
2012-03-04 23:02:17 +00:00
|
|
|
new_num = get_logical_num_lines (linep, &screen->terms[i]);
|
2009-12-24 14:34:33 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (! insert_string (screen, "\n", 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (! backward_char (screen, 0))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
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;
|
2012-03-27 15:07:26 +00:00
|
|
|
char *u8;
|
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;
|
2012-03-27 15:07:26 +00:00
|
|
|
u8 = grub_ucs4_to_utf8_alloc (linep->buf, screen->column);
|
|
|
|
if (!u8)
|
|
|
|
return 1;
|
2005-08-18 03:14:39 +00:00
|
|
|
|
2012-03-27 15:07:26 +00:00
|
|
|
insert = grub_normal_do_completion (u8, &restore, store_completion);
|
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
|
|
|
|
|
|
|
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. */
|
2012-12-31 17:31:38 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
grub_size_t size = 0, tot_size = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < screen->num_lines; i++)
|
|
|
|
tot_size += grub_get_num_of_utf8_bytes (screen->lines[i].buf,
|
|
|
|
screen->lines[i].len) + 1;
|
|
|
|
|
|
|
|
script = grub_malloc (tot_size + 1);
|
|
|
|
if (! script)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < screen->num_lines; i++)
|
|
|
|
{
|
|
|
|
size += grub_ucs4_to_utf8 (screen->lines[i].buf, screen->lines[i].len,
|
|
|
|
(grub_uint8_t *) script + size,
|
|
|
|
tot_size - size);
|
|
|
|
script[size++] = '\n';
|
|
|
|
}
|
|
|
|
script[size] = '\0';
|
|
|
|
}
|
2010-12-08 11:13:11 +00:00
|
|
|
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++;
|
2013-01-16 12:41:16 +00:00
|
|
|
|
|
|
|
for (i = 0; i < (unsigned) screen->num_lines; i++)
|
|
|
|
{
|
|
|
|
grub_free (screen->lines[i].pos);
|
|
|
|
screen->lines[i].pos = grub_zalloc (screen->nterms * sizeof (screen->lines[i].pos[0]));
|
|
|
|
if (! screen->lines[i].pos)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
screen->terms = grub_zalloc (screen->nterms * sizeof (screen->terms[0]));
|
2009-12-25 03:12:29 +00:00
|
|
|
if (!screen->terms)
|
|
|
|
{
|
|
|
|
grub_print_error ();
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i = 0;
|
|
|
|
FOR_ACTIVE_TERM_OUTPUTS(term)
|
|
|
|
{
|
|
|
|
screen->terms[i].term = term;
|
2013-01-16 12:41:16 +00:00
|
|
|
screen->terms[i].y_line_start = 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 ();
|
|
|
|
}
|