2005-11-06 22:19:59 +00:00
|
|
|
/* execute.c -- Execute a GRUB script. */
|
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
2010-01-22 13:37:27 +00:00
|
|
|
* Copyright (C) 2005,2007,2008,2009,2010 Free Software Foundation, Inc.
|
2005-11-06 22:19:59 +00:00
|
|
|
*
|
2007-07-21 23:32:33 +00:00
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
2005-11-06 22:19:59 +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-11-06 22:19:59 +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-11-06 22:19:59 +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-11-06 22:19:59 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/misc.h>
|
|
|
|
#include <grub/mm.h>
|
|
|
|
#include <grub/env.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/script_sh.h>
|
|
|
|
#include <grub/command.h>
|
|
|
|
#include <grub/menu.h>
|
2009-03-21 Bean <bean123ch@gmail.com>
* commands/blocklist.c: Add include file <grub/command.h>, remove
<grub/normal.h> and <grub/arg.h>.
(grub_cmd_blocklist): Use the new command interface.
(GRUB_MOD_INIT): Likewise.
(GRUB_MOD_FINI): Likewise.
* commands/boot.c: Likewise.
* commands/cat.c: Likewise.
* commands/cmp.c: Likewise.
* commands/configfile.c: Likewise.
* commands/crc.c: Likewise.
* commands/echo.c: Likewise.
* commands/halt.c: Likewise.
* commands/handler.c: Likewise.
* commands/hdparm.c: Likewise.
* commands/help.c: Likewise.
* commands/hexdump.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/ls.c: Likewise.
* commands/lsmmap.c: Likewise.
* commands/lspci.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/read.c: Likewise.
* commands/reboot.c: Likewise.
* commands/search.c: Likewise.
* commands/sleep.c: Likewise.
* commands/test.c: Likewise.
* commands/usbtest.c: Likewise.
* commands/videotest.c: Likewise.
* commands/i386/cpuid.c: Likewise.
* commands/i386/pc/halt.c: Likewise.
* commands/i386/pc/play.c: Likewise.
* commands/i386/pc/pxecmd.c: Likewise.
* commands/i386/pc/vbeinfo.c: Likewise.
* commands/i386/pc/vbetest.c: Likewise.
* commands/ieee1275/suspend.c: Likewise.
* disk/loopback.c: Likewise.
* font/font_cmd.c: Likewise.
* hello/hello.c: Likewise.
* loader/efi/appleloader.c: Likewise.
* loader/efi/chainloader.c: Likewise.
* loader/i386/bsd.c: Likewise.
* loader/i386/efi/linux.c: Likewise.
* loader/i386/ieee1275/linux.c: Likewise.
* loader/i386/linux.c: Likewise.
* loader/i386/pc/chainloader.c: Likewise.
* loader/i386/pc/linux.c: Likewise.
* loader/powerpc/ieee1275/linux.c: Likewise.
* loader/multiboot_loader.c: Likewise.
* term/gfxterm.c: Likewise.
* term/i386/pc/serial.c: Likewise.
* term/terminfo.c: Likewise.
* term/i386/pc/vesafb.c: Removed <grub/arg.h>.
* term/i386/pc/vga.c: Likewise.
* video/readers/jpeg.c: Likewise.
* video/readers/png.c: Likewise.
* video/readers/tga.c: Likewise.
* util/grub-fstest (cmd_loopback): Removed.
(cmd_blocklist): Likewise.
(cmd_ls): Likewise.
(grub_register_command): Likewise.
(grub_unregister_command): Likewise.
(execute_command): Use grub_command_find to locate command and execute
it.
* include/grub/efi/chainloader.h: Removed.
* loader/efi/chainloader_normal.c: Likewise.
* loader/i386/bsd_normal.c: Likewise.
* loader/i386/pc/chainloader_normal.c: Likewise.
* loader/i386/pc/multiboot_normal.c: Likewise.
* loader/linux_normal.c: Likewise.
* loader/multiboot_loader_normal.c: Likewise.
* loader/powerpc/ieee1275/linux_normal.c: Likewise.
* gencmdlist.sh: Scan new registration command grub_register_extcmd
and grub_register_command_p1.
* conf/common.rmk (grub_fstest_SOURCES): Add kern/list.c,
kern/command.c, lib/arg.c and commands/extcmd.c.
(pkglib_MODULES): Remove boot.mod, and minicmd.mod and extcmd.mod.
(minicmd_mod_SOURCES): New variable.
(minicmd_mod_CFLAGS): Likewise.
(minicmd_mod_LDFLAGS): Likewise.
(extcmd_mod_SOURCES): Likewise.
(extcmd_mod_CFLAGS): Likewise.
(extcmd_mod_LDFLAGS): Likewise.
(boot_mod_SOURCES): Removed.
(boot_mod_CFLAGS): Likewise.
(boot_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (kernel_img_SOURCES): Add kern/command.c and
kern/corecmd.c.
(kernel_img_HEADERS): Add command.h.
(grub_emu_SOURCES): Remove commands/boot.c and normal/arg.c, add
commands/minicmd.c, kern/command.c, kern/corecmd.c, commands/extcmd.c
and lib/arg.c.
(pkglib_MODULES): Change _linux.mod, _chain.mod, _bsd.mod and
_multiboot.mod as linux.mod, chain.mod, bsd.mod and multiboot.mod,
remove the corresponding normal mode command.
(normal_mod_SOURCES): Remove normal/arg.c.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1275.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/arg.h: Move from here ...
* include/grub/lib/arg.h: ... to here.
* normal/arg.c: Move from here ...
* lib/arg.c: ... to here.
* commands/extcmd.c: New file.
* commands/minicmd.c: Likewise.
* include/grub/command.h: Likewise.
* include/grub/extcmd.h: Likewise.
* kern/command.c: Likewise.
* kern/corecmd.c: Likewise.
* kern/list.c (grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(grub_prio_list_insert): Likewise.
* kern/rescue.c (grub_rescue_command): Removed.
(grub_rescue_command_list): Likewise.
(grub_rescue_register_command): Likewise.
(grub_rescue_unregister_command): Likewise.
(grub_rescue_cmd_boot): Move to minicmd.c
(grub_rescue_cmd_help): Likewise.
(grub_rescue_cmd_info): Likewise.
(grub_rescue_cmd_boot): Likewise.
(grub_rescue_cmd_testload): Likewise.
(grub_rescue_cmd_dump): Likewise.
(grub_rescue_cmd_rmmod): Likewise.
(grub_rescue_cmd_lsmod): Likewise.
(grub_rescue_cmd_exit): Likewise.
(grub_rescue_print_devices): Moved to corecmd.c.
(grub_rescue_print_files): Likewise.
(grub_rescue_cmd_ls): Likewise.
(grub_rescue_cmd_insmod): Likewise.
(grub_rescue_cmd_set): Likewise.
(grub_rescue_cmd_unset): Likewise.
(attemp_normal_mode): Use grub_command_find to get normal module.
(grub_enter_rescue_mode): Use grub_register_core_commands to register
commands, remove grub_rescue_regiter_command calls.
* normal/command.c (grub_regiser_command): Removed.
(grub_unregister_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(rescue_command): Likewise.
(export_command): Moved to corecmd.c.
(set_command): Removed.
(unset_command): Likewise.
(insmod_command): Likewise.
(rmmod_command): Likewise.
(lsmod_command): Likewise.
(grub_command_init): Likewise.
* normal/completion.c (iterate_command): Use cmd->prio to check for
active command.
(complete_arguments): Use grub_extcmd_t structure to find options.
(grub_normal_do_completion): Change function grub_iterate_commands to
grub_command_iterate.
* normal/execute.c (grub_script_execute_cmd): No need to parse
argument here.
* normal/main.c (grub_dyncmd_dispatcher): New function.
(read_command_list): Register unload commands as dyncmd.
(grub_cmd_normal): Use new command interface, register rescue,
unregister normal at entry, register normal, unregister rescue at exit.
* include/grub/list.h (grub_list_test_t): New type.
(grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(GRUB_AS_NAMED_LIST_P): New macro.
(GRUB_AS_PRIO_LIST): Likewise.
(GRUB_AS_PRIO_LIST_P): Likewise.
(GRUB_PRIO_LIST_PRIO_MASK): New constant.
(GRUB_PRIO_LIST_FLAG_ACTIVE): Likewise.
(grub_prio_list): New structure.
(grub_prio_list_insert): New function.
(grub_prio_list_remove): New inline function.
* include/grub/normal.h: Remove <grub/arg.h>, add <grub/command.h>.
(GRUB_COMMAND_FLAG_CMDLINE): Moved to command.h.
(GRUB_COMMAND_FLAG_MENU): Likewise.
(GRUB_COMMAND_FLAG_BOTH): Likewise.
(GRUB_COMMAND_FLAG_TITLE): Likewise.
(GRUB_COMMAND_FLAG_NO_ECHO): Likewise.
(GRUB_COMMAND_FLAG_NO_ARG_PARSE): Removed.
(GRUB_COMMAND_FLAG_NOT_LOADED): Likewise.
(grub_command): Likewise.
(grub_register_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(grub_command_init): Likewise.
(grub_arg_parse): Likewise.
(grub_arg_show_help): Likewise.
* include/grub/rescue.h (grub_rescue_register_command): Removed.
(grub_rescue_unregister_command): Likewise.
* include/grub/i386/bsd.h: Remove grub_rescue_cmd_freebsd,
grub_rescue_cmd_openbsd, grub_rescue_cmd_netbsd,
grub_rescue_cmd_freebsd_loadenv and grub_rescue_cmd_freebsd_module.
* include/grub/i386/efi/loader.h: Remove grub_rescue_cmd_linux and
grub_rescue_cmd_initrd.
* include/grub/i386/loader.h: Likewise.
* include/grub/x86_64/loader.h: Likewise.
* include/grub/i386/pc/chainloader.h: Remove grub_chainloader_cmd.
2009-03-21 08:39:59 +00:00
|
|
|
#include <grub/lib/arg.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/normal.h>
|
2005-11-06 22:19:59 +00:00
|
|
|
|
2010-01-26 07:02:24 +00:00
|
|
|
/* Max digits for a char is 3 (0xFF is 255), similarly for an int it
|
|
|
|
is sizeof (int) * 3, and one extra for a possible -ve sign. */
|
|
|
|
#define ERRNO_DIGITS_MAX (sizeof (int) * 3 + 1)
|
|
|
|
|
2010-05-05 10:49:31 +00:00
|
|
|
static unsigned long is_continue;
|
2010-05-05 10:04:26 +00:00
|
|
|
static unsigned long active_loops;
|
|
|
|
static unsigned long active_breaks;
|
2010-05-12 12:29:09 +00:00
|
|
|
|
2010-05-11 05:22:10 +00:00
|
|
|
/* Scope for grub script functions. */
|
|
|
|
struct grub_script_scope
|
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
struct grub_script_argv argv;
|
2010-05-11 05:22:10 +00:00
|
|
|
};
|
2010-05-05 09:17:50 +00:00
|
|
|
static struct grub_script_scope *scope = 0;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
grub_err_t
|
2010-05-05 10:49:31 +00:00
|
|
|
grub_script_break (grub_command_t cmd, int argc, char *argv[])
|
2010-05-05 10:04:26 +00:00
|
|
|
{
|
|
|
|
char *p = 0;
|
|
|
|
unsigned long count;
|
|
|
|
|
|
|
|
if (argc == 0)
|
|
|
|
count = 1;
|
|
|
|
|
2010-05-06 04:25:06 +00:00
|
|
|
else if ((argc > 1) || (count = grub_strtoul (argv[0], &p, 10)) == 0 ||
|
2010-05-05 10:04:26 +00:00
|
|
|
(*p != '\0'))
|
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad break");
|
|
|
|
|
2010-05-05 10:49:31 +00:00
|
|
|
is_continue = grub_strcmp (cmd->name, "break") ? 1 : 0;
|
2010-05-06 04:25:06 +00:00
|
|
|
active_breaks = grub_min (active_loops, count);
|
2010-05-05 10:04:26 +00:00
|
|
|
return GRUB_ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
static int
|
|
|
|
grub_env_special (const char *name)
|
2010-05-05 09:17:50 +00:00
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
if (grub_isdigit (name[0]) ||
|
|
|
|
grub_strcmp (name, "#") == 0 ||
|
|
|
|
grub_strcmp (name, "*") == 0 ||
|
|
|
|
grub_strcmp (name, "@") == 0)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-05 09:17:50 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
static char **
|
|
|
|
grub_script_env_get (const char *name, grub_script_arg_type_t type)
|
|
|
|
{
|
|
|
|
struct grub_script_argv result = { 0, 0 };
|
2010-05-05 09:17:50 +00:00
|
|
|
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
if (! grub_env_special (name))
|
2010-05-05 09:17:50 +00:00
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
char *v = grub_env_get (name);
|
|
|
|
if (v && v[0])
|
2010-05-05 09:17:50 +00:00
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
2010-05-21 10:13:24 +00:00
|
|
|
{
|
|
|
|
if (grub_script_argv_split_append (&result, v))
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
else
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_script_argv_append (&result, v))
|
|
|
|
goto fail;
|
2010-05-05 09:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
else if (! scope)
|
2010-05-21 10:13:24 +00:00
|
|
|
{
|
|
|
|
if (grub_script_argv_append (&result, 0))
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-05 09:17:50 +00:00
|
|
|
else if (grub_strcmp (name, "#") == 0)
|
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
char buffer[ERRNO_DIGITS_MAX + 1];
|
|
|
|
grub_snprintf (buffer, sizeof (buffer), "%u", scope->argv.argc);
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_script_argv_append (&result, buffer))
|
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
|
|
|
else if (grub_strcmp (name, "*") == 0)
|
|
|
|
{
|
2010-05-19 04:55:41 +00:00
|
|
|
unsigned i;
|
2010-05-12 04:49:12 +00:00
|
|
|
|
2010-05-21 10:13:24 +00:00
|
|
|
for (i = 0; i < scope->argv.argc; i++)
|
2010-05-12 04:49:12 +00:00
|
|
|
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
if (i != 0 && grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (grub_script_argv_split_append (&result, scope->argv.args[i]))
|
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
if (i != 0 && grub_script_argv_append (&result, " "))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (grub_script_argv_append (&result, scope->argv.args[i]))
|
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (grub_strcmp (name, "@") == 0)
|
|
|
|
{
|
2010-05-19 04:55:41 +00:00
|
|
|
unsigned i;
|
2010-05-05 09:17:50 +00:00
|
|
|
|
2010-05-21 10:13:24 +00:00
|
|
|
for (i = 0; i < scope->argv.argc; i++)
|
2010-05-12 04:49:12 +00:00
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
if (i != 0 && grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
|
|
|
|
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
2010-05-21 10:13:24 +00:00
|
|
|
{
|
|
|
|
if (grub_script_argv_split_append (&result, scope->argv.args[i]))
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
else
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_script_argv_append (&result, scope->argv.args[i]))
|
|
|
|
goto fail;
|
2010-05-05 09:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2010-05-12 04:49:12 +00:00
|
|
|
{
|
|
|
|
unsigned long num = grub_strtoul (name, 0, 10);
|
|
|
|
if (num == 0)
|
|
|
|
; /* XXX no file name, for now. */
|
|
|
|
|
|
|
|
else if (num <= scope->argv.argc)
|
2010-05-05 09:17:50 +00:00
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
if (type == GRUB_SCRIPT_ARG_TYPE_VAR)
|
2010-05-21 10:13:24 +00:00
|
|
|
{
|
|
|
|
if (grub_script_argv_split_append (&result,
|
|
|
|
scope->argv.args[num - 1]))
|
|
|
|
goto fail;
|
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
else
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_script_argv_append (&result, scope->argv.args[num - 1]))
|
|
|
|
goto fail;
|
2010-05-05 09:17:50 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-12 05:15:22 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
return result.args;
|
2010-05-21 10:13:24 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
grub_script_argv_free (&result);
|
|
|
|
return 0;
|
2010-05-05 09:17:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_script_env_set (const char *name, const char *val)
|
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
if (grub_env_special (name))
|
2010-05-05 09:17:50 +00:00
|
|
|
return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad variable name");
|
|
|
|
|
|
|
|
return grub_env_set (name, val);
|
|
|
|
}
|
|
|
|
|
2010-01-22 13:37:27 +00:00
|
|
|
/* Expand arguments in ARGLIST into multiple arguments. */
|
2010-05-12 04:49:12 +00:00
|
|
|
static int
|
|
|
|
grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
|
|
|
|
struct grub_script_argv *argv)
|
2010-01-22 13:37:27 +00:00
|
|
|
{
|
|
|
|
int i;
|
2010-05-12 04:49:12 +00:00
|
|
|
char **values = 0;
|
|
|
|
struct grub_script_arg *arg = 0;
|
|
|
|
struct grub_script_argv result = { 0, 0 };
|
2010-01-22 13:37:27 +00:00
|
|
|
|
2010-05-21 10:13:24 +00:00
|
|
|
for (; arglist && arglist->arg; arglist = arglist->next)
|
2005-11-06 22:19:59 +00:00
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
2010-05-12 04:49:12 +00:00
|
|
|
|
2010-01-22 13:37:27 +00:00
|
|
|
arg = arglist->arg;
|
|
|
|
while (arg)
|
2005-11-06 22:19:59 +00:00
|
|
|
{
|
2010-01-22 13:37:27 +00:00
|
|
|
switch (arg->type)
|
|
|
|
{
|
|
|
|
case GRUB_SCRIPT_ARG_TYPE_VAR:
|
2010-05-12 04:49:12 +00:00
|
|
|
case GRUB_SCRIPT_ARG_TYPE_DQVAR:
|
|
|
|
values = grub_script_env_get (arg->str, arg->type);
|
|
|
|
for (i = 0; values && values[i]; i++)
|
2010-01-22 13:37:27 +00:00
|
|
|
{
|
2010-05-21 10:13:24 +00:00
|
|
|
if (i != 0 && grub_script_argv_next (&result))
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
if (grub_script_argv_append (&result, values[i]))
|
|
|
|
goto fail;
|
2010-01-22 13:37:27 +00:00
|
|
|
}
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_free (values);
|
2010-01-22 13:37:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GRUB_SCRIPT_ARG_TYPE_TEXT:
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_strlen (arg->str) &&
|
|
|
|
grub_script_argv_append (&result, arg->str))
|
|
|
|
goto fail;
|
2010-01-22 13:37:27 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case GRUB_SCRIPT_ARG_TYPE_DQSTR:
|
|
|
|
case GRUB_SCRIPT_ARG_TYPE_SQSTR:
|
2010-05-21 10:13:24 +00:00
|
|
|
if (grub_script_argv_append (&result, arg->str))
|
|
|
|
goto fail;
|
2010-01-22 13:37:27 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
arg = arg->next;
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
if (! result.args[result.argc - 1])
|
|
|
|
result.argc--;
|
2010-01-23 03:42:46 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
*argv = result;
|
|
|
|
return 0;
|
2010-05-21 10:13:24 +00:00
|
|
|
|
|
|
|
fail:
|
|
|
|
|
|
|
|
grub_script_argv_free (&result);
|
|
|
|
return 1;
|
2010-05-12 04:49:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static grub_err_t
|
|
|
|
grub_script_execute_cmd (struct grub_script_cmd *cmd)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
char errnobuf[ERRNO_DIGITS_MAX + 1];
|
|
|
|
|
|
|
|
if (cmd == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = cmd->exec (cmd);
|
2010-01-23 03:42:46 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
|
|
|
|
grub_env_set ("?", errnobuf);
|
|
|
|
return ret;
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 09:17:50 +00:00
|
|
|
/* Execute a function call. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_function_call (grub_script_function_t func, int argc, char **args)
|
|
|
|
{
|
|
|
|
grub_err_t ret = 0;
|
2010-05-05 10:04:26 +00:00
|
|
|
unsigned long loops = active_loops;
|
2010-05-11 05:22:10 +00:00
|
|
|
struct grub_script_scope *old_scope;
|
2010-05-05 09:17:50 +00:00
|
|
|
struct grub_script_scope new_scope;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops = 0;
|
2010-05-12 04:49:12 +00:00
|
|
|
new_scope.argv.argc = argc;
|
|
|
|
new_scope.argv.args = args;
|
2010-05-11 05:22:10 +00:00
|
|
|
|
|
|
|
old_scope = scope;
|
|
|
|
scope = &new_scope;
|
2010-05-05 09:17:50 +00:00
|
|
|
|
|
|
|
ret = grub_script_execute (func->func);
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops = loops;
|
2010-05-11 05:22:10 +00:00
|
|
|
scope = old_scope;
|
2010-05-05 09:17:50 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-11-06 22:19:59 +00:00
|
|
|
/* Execute a single command line. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|
|
|
{
|
|
|
|
struct grub_script_cmdline *cmdline = (struct grub_script_cmdline *) cmd;
|
|
|
|
grub_command_t grubcmd;
|
|
|
|
grub_err_t ret = 0;
|
|
|
|
grub_script_function_t func = 0;
|
2009-12-29 09:04:06 +00:00
|
|
|
char errnobuf[18];
|
2009-06-04 16:18:35 +00:00
|
|
|
char *cmdname;
|
2010-05-12 04:49:12 +00:00
|
|
|
struct grub_script_argv argv = { 0, 0 };
|
2005-11-06 22:19:59 +00:00
|
|
|
|
|
|
|
/* Lookup the command. */
|
2010-05-12 04:49:12 +00:00
|
|
|
if (grub_script_arglist_to_argv (cmdline->arglist, &argv))
|
2010-01-22 13:37:27 +00:00
|
|
|
return grub_errno;
|
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
cmdname = argv.args[0];
|
2009-06-04 16:18:35 +00:00
|
|
|
grubcmd = grub_command_find (cmdname);
|
2005-11-06 22:19:59 +00:00
|
|
|
if (! grubcmd)
|
|
|
|
{
|
2008-01-15 15:32:17 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
2005-11-06 22:19:59 +00:00
|
|
|
/* It's not a GRUB command, try all functions. */
|
2009-06-04 16:18:35 +00:00
|
|
|
func = grub_script_function_find (cmdname);
|
2005-11-06 22:19:59 +00:00
|
|
|
if (! func)
|
2006-04-30 20:29:51 +00:00
|
|
|
{
|
|
|
|
/* As a last resort, try if it is an assignment. */
|
2009-06-04 16:18:35 +00:00
|
|
|
char *assign = grub_strdup (cmdname);
|
2006-04-30 20:29:51 +00:00
|
|
|
char *eq = grub_strchr (assign, '=');
|
|
|
|
|
|
|
|
if (eq)
|
|
|
|
{
|
2009-12-13 12:35:20 +00:00
|
|
|
/* This was set because the command was not found. */
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
2006-04-30 20:29:51 +00:00
|
|
|
/* Create two strings and set the variable. */
|
|
|
|
*eq = '\0';
|
|
|
|
eq++;
|
2010-05-05 09:17:50 +00:00
|
|
|
grub_script_env_set (assign, eq);
|
2006-04-30 20:29:51 +00:00
|
|
|
}
|
|
|
|
grub_free (assign);
|
2009-09-08 19:10:34 +00:00
|
|
|
|
2009-12-29 09:04:06 +00:00
|
|
|
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", grub_errno);
|
2010-05-12 07:42:49 +00:00
|
|
|
grub_env_set ("?", errnobuf);
|
2009-09-08 19:10:34 +00:00
|
|
|
|
2010-05-19 04:55:41 +00:00
|
|
|
grub_script_argv_free (&argv);
|
2010-02-14 13:46:19 +00:00
|
|
|
grub_print_error ();
|
|
|
|
|
2006-04-30 20:29:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute the GRUB command or function. */
|
|
|
|
if (grubcmd)
|
2010-05-12 04:49:12 +00:00
|
|
|
ret = (grubcmd->func) (grubcmd, argv.argc - 1, argv.args + 1);
|
2005-11-06 22:19:59 +00:00
|
|
|
else
|
2010-05-12 04:49:12 +00:00
|
|
|
ret = grub_script_function_call (func, argv.argc - 1, argv.args + 1);
|
2005-11-06 22:19:59 +00:00
|
|
|
|
|
|
|
/* Free arguments. */
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_script_argv_free (&argv);
|
2005-11-06 22:19:59 +00:00
|
|
|
|
2010-02-10 17:09:44 +00:00
|
|
|
if (grub_errno == GRUB_ERR_TEST_FAILURE)
|
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
|
|
|
grub_print_error ();
|
|
|
|
|
2009-12-29 09:04:06 +00:00
|
|
|
grub_snprintf (errnobuf, sizeof (errnobuf), "%d", ret);
|
2005-11-06 22:19:59 +00:00
|
|
|
grub_env_set ("?", errnobuf);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-31 09:15:43 +00:00
|
|
|
/* Execute a block of one or more commands. */
|
2005-11-06 22:19:59 +00:00
|
|
|
grub_err_t
|
2010-05-05 08:35:06 +00:00
|
|
|
grub_script_execute_cmdlist (struct grub_script_cmd *list)
|
2005-11-06 22:19:59 +00:00
|
|
|
{
|
2010-01-26 07:02:24 +00:00
|
|
|
int ret = 0;
|
2010-05-05 08:35:06 +00:00
|
|
|
struct grub_script_cmd *cmd;
|
2005-11-06 22:19:59 +00:00
|
|
|
|
|
|
|
/* Loop over every command and execute it. */
|
2010-05-05 10:04:26 +00:00
|
|
|
for (cmd = list->next; cmd && ! active_breaks; cmd = cmd->next)
|
2010-01-26 07:02:24 +00:00
|
|
|
ret = grub_script_execute_cmd (cmd);
|
2005-11-06 22:19:59 +00:00
|
|
|
|
2010-01-26 07:02:24 +00:00
|
|
|
return ret;
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Execute an if statement. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_cmdif (struct grub_script_cmd *cmd)
|
|
|
|
{
|
|
|
|
struct grub_script_cmdif *cmdif = (struct grub_script_cmdif *) cmd;
|
2006-05-28 21:58:35 +00:00
|
|
|
char *result;
|
2005-11-06 22:19:59 +00:00
|
|
|
|
|
|
|
/* Check if the commands results in a true or a false. The value is
|
2006-05-28 21:58:35 +00:00
|
|
|
read from the env variable `?'. */
|
|
|
|
grub_script_execute_cmd (cmdif->exec_to_evaluate);
|
2010-05-12 04:49:12 +00:00
|
|
|
result = grub_env_get ("?");
|
2005-11-06 22:19:59 +00:00
|
|
|
|
2009-05-03 06:50:20 +00:00
|
|
|
grub_errno = GRUB_ERR_NONE;
|
|
|
|
|
2005-11-06 22:19:59 +00:00
|
|
|
/* Execute the `if' or the `else' part depending on the value of
|
2006-05-28 21:58:35 +00:00
|
|
|
`?'. */
|
|
|
|
if (result && ! grub_strcmp (result, "0"))
|
|
|
|
return grub_script_execute_cmd (cmdif->exec_on_true);
|
2005-11-06 22:19:59 +00:00
|
|
|
else
|
2006-05-28 21:58:35 +00:00
|
|
|
return grub_script_execute_cmd (cmdif->exec_on_false);
|
2005-11-06 22:19:59 +00:00
|
|
|
}
|
|
|
|
|
2010-01-23 05:33:41 +00:00
|
|
|
/* Execute a for statement. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_cmdfor (struct grub_script_cmd *cmd)
|
|
|
|
{
|
2010-05-19 04:55:41 +00:00
|
|
|
unsigned i;
|
|
|
|
grub_err_t result;
|
2010-05-21 10:13:24 +00:00
|
|
|
struct grub_script_argv argv = { 0, 0 };
|
2010-06-12 15:23:32 +00:00
|
|
|
|
2010-01-23 05:33:41 +00:00
|
|
|
struct grub_script_cmdfor *cmdfor = (struct grub_script_cmdfor *) cmd;
|
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
if (grub_script_arglist_to_argv (cmdfor->words, &argv))
|
2010-01-23 05:33:41 +00:00
|
|
|
return grub_errno;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops++;
|
2010-01-23 05:33:41 +00:00
|
|
|
result = 0;
|
2010-05-12 04:49:12 +00:00
|
|
|
for (i = 0; i < argv.argc; i++)
|
2010-01-23 05:33:41 +00:00
|
|
|
{
|
2010-05-05 10:49:31 +00:00
|
|
|
if (is_continue && active_breaks == 1)
|
|
|
|
active_breaks = 0;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
if (! active_breaks)
|
|
|
|
{
|
2010-05-12 12:29:09 +00:00
|
|
|
grub_script_env_set (cmdfor->name->str, argv.args[i]);
|
2010-05-05 10:04:26 +00:00
|
|
|
result = grub_script_execute_cmd (cmdfor->list);
|
|
|
|
}
|
2010-01-23 05:33:41 +00:00
|
|
|
}
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
if (active_breaks)
|
|
|
|
active_breaks--;
|
|
|
|
|
|
|
|
active_loops--;
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_script_argv_free (&argv);
|
2010-01-23 05:33:41 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2010-01-23 05:49:26 +00:00
|
|
|
/* Execute a "while" or "until" command. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_cmdwhile (struct grub_script_cmd *cmd)
|
|
|
|
{
|
|
|
|
int cond;
|
|
|
|
int result;
|
|
|
|
struct grub_script_cmdwhile *cmdwhile = (struct grub_script_cmdwhile *) cmd;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops++;
|
2010-01-23 05:49:26 +00:00
|
|
|
result = 0;
|
|
|
|
do {
|
|
|
|
cond = grub_script_execute_cmd (cmdwhile->cond);
|
2010-01-26 09:03:23 +00:00
|
|
|
if (cmdwhile->until ? !cond : cond)
|
2010-01-23 05:49:26 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
result = grub_script_execute_cmd (cmdwhile->list);
|
2010-05-05 10:04:26 +00:00
|
|
|
|
2010-05-05 10:49:31 +00:00
|
|
|
if (active_breaks == 1 && is_continue)
|
|
|
|
active_breaks = 0;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
if (active_breaks)
|
2010-05-05 10:49:31 +00:00
|
|
|
break;
|
2010-05-05 10:04:26 +00:00
|
|
|
|
2010-01-23 05:49:26 +00:00
|
|
|
} while (1); /* XXX Put a check for ^C here */
|
|
|
|
|
2010-05-05 10:49:31 +00:00
|
|
|
if (active_breaks)
|
|
|
|
active_breaks--;
|
|
|
|
|
2010-05-05 10:04:26 +00:00
|
|
|
active_loops--;
|
2010-01-23 05:49:26 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2006-01-17 09:50:47 +00:00
|
|
|
/* Execute the menu entry generate statement. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute_menuentry (struct grub_script_cmd *cmd)
|
|
|
|
{
|
|
|
|
struct grub_script_cmd_menuentry *cmd_menuentry;
|
2010-05-21 10:13:24 +00:00
|
|
|
struct grub_script_argv argv = { 0, 0 };
|
2006-01-17 09:50:47 +00:00
|
|
|
|
|
|
|
cmd_menuentry = (struct grub_script_cmd_menuentry *) cmd;
|
|
|
|
|
2009-01-31 09:15:43 +00:00
|
|
|
if (cmd_menuentry->arglist)
|
|
|
|
{
|
2010-05-12 04:49:12 +00:00
|
|
|
if (grub_script_arglist_to_argv (cmd_menuentry->arglist, &argv))
|
2010-01-22 13:37:27 +00:00
|
|
|
return grub_errno;
|
2009-01-31 09:15:43 +00:00
|
|
|
}
|
2006-01-17 09:50:47 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_normal_add_menu_entry (argv.argc, (const char **) argv.args,
|
2009-05-24 08:39:29 +00:00
|
|
|
cmd_menuentry->sourcecode);
|
2006-01-17 09:50:47 +00:00
|
|
|
|
2010-05-12 04:49:12 +00:00
|
|
|
grub_script_argv_free (&argv);
|
2009-01-31 09:15:43 +00:00
|
|
|
|
|
|
|
return grub_errno;
|
2006-01-17 09:50:47 +00:00
|
|
|
}
|
|
|
|
|
2009-01-31 09:15:43 +00:00
|
|
|
|
2005-11-06 22:19:59 +00:00
|
|
|
|
|
|
|
/* Execute any GRUB pre-parsed command or script. */
|
|
|
|
grub_err_t
|
|
|
|
grub_script_execute (struct grub_script *script)
|
|
|
|
{
|
|
|
|
if (script == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return grub_script_execute_cmd (script->cmd);
|
|
|
|
}
|
2009-03-21 Bean <bean123ch@gmail.com>
* commands/blocklist.c: Add include file <grub/command.h>, remove
<grub/normal.h> and <grub/arg.h>.
(grub_cmd_blocklist): Use the new command interface.
(GRUB_MOD_INIT): Likewise.
(GRUB_MOD_FINI): Likewise.
* commands/boot.c: Likewise.
* commands/cat.c: Likewise.
* commands/cmp.c: Likewise.
* commands/configfile.c: Likewise.
* commands/crc.c: Likewise.
* commands/echo.c: Likewise.
* commands/halt.c: Likewise.
* commands/handler.c: Likewise.
* commands/hdparm.c: Likewise.
* commands/help.c: Likewise.
* commands/hexdump.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/ls.c: Likewise.
* commands/lsmmap.c: Likewise.
* commands/lspci.c: Likewise.
* commands/loadenv.c: Likewise.
* commands/read.c: Likewise.
* commands/reboot.c: Likewise.
* commands/search.c: Likewise.
* commands/sleep.c: Likewise.
* commands/test.c: Likewise.
* commands/usbtest.c: Likewise.
* commands/videotest.c: Likewise.
* commands/i386/cpuid.c: Likewise.
* commands/i386/pc/halt.c: Likewise.
* commands/i386/pc/play.c: Likewise.
* commands/i386/pc/pxecmd.c: Likewise.
* commands/i386/pc/vbeinfo.c: Likewise.
* commands/i386/pc/vbetest.c: Likewise.
* commands/ieee1275/suspend.c: Likewise.
* disk/loopback.c: Likewise.
* font/font_cmd.c: Likewise.
* hello/hello.c: Likewise.
* loader/efi/appleloader.c: Likewise.
* loader/efi/chainloader.c: Likewise.
* loader/i386/bsd.c: Likewise.
* loader/i386/efi/linux.c: Likewise.
* loader/i386/ieee1275/linux.c: Likewise.
* loader/i386/linux.c: Likewise.
* loader/i386/pc/chainloader.c: Likewise.
* loader/i386/pc/linux.c: Likewise.
* loader/powerpc/ieee1275/linux.c: Likewise.
* loader/multiboot_loader.c: Likewise.
* term/gfxterm.c: Likewise.
* term/i386/pc/serial.c: Likewise.
* term/terminfo.c: Likewise.
* term/i386/pc/vesafb.c: Removed <grub/arg.h>.
* term/i386/pc/vga.c: Likewise.
* video/readers/jpeg.c: Likewise.
* video/readers/png.c: Likewise.
* video/readers/tga.c: Likewise.
* util/grub-fstest (cmd_loopback): Removed.
(cmd_blocklist): Likewise.
(cmd_ls): Likewise.
(grub_register_command): Likewise.
(grub_unregister_command): Likewise.
(execute_command): Use grub_command_find to locate command and execute
it.
* include/grub/efi/chainloader.h: Removed.
* loader/efi/chainloader_normal.c: Likewise.
* loader/i386/bsd_normal.c: Likewise.
* loader/i386/pc/chainloader_normal.c: Likewise.
* loader/i386/pc/multiboot_normal.c: Likewise.
* loader/linux_normal.c: Likewise.
* loader/multiboot_loader_normal.c: Likewise.
* loader/powerpc/ieee1275/linux_normal.c: Likewise.
* gencmdlist.sh: Scan new registration command grub_register_extcmd
and grub_register_command_p1.
* conf/common.rmk (grub_fstest_SOURCES): Add kern/list.c,
kern/command.c, lib/arg.c and commands/extcmd.c.
(pkglib_MODULES): Remove boot.mod, and minicmd.mod and extcmd.mod.
(minicmd_mod_SOURCES): New variable.
(minicmd_mod_CFLAGS): Likewise.
(minicmd_mod_LDFLAGS): Likewise.
(extcmd_mod_SOURCES): Likewise.
(extcmd_mod_CFLAGS): Likewise.
(extcmd_mod_LDFLAGS): Likewise.
(boot_mod_SOURCES): Removed.
(boot_mod_CFLAGS): Likewise.
(boot_mod_LDFLAGS): Likewise.
* conf/i386-pc.rmk (kernel_img_SOURCES): Add kern/command.c and
kern/corecmd.c.
(kernel_img_HEADERS): Add command.h.
(grub_emu_SOURCES): Remove commands/boot.c and normal/arg.c, add
commands/minicmd.c, kern/command.c, kern/corecmd.c, commands/extcmd.c
and lib/arg.c.
(pkglib_MODULES): Change _linux.mod, _chain.mod, _bsd.mod and
_multiboot.mod as linux.mod, chain.mod, bsd.mod and multiboot.mod,
remove the corresponding normal mode command.
(normal_mod_SOURCES): Remove normal/arg.c.
* conf/i386-coreboot.rmk: Likewise.
* conf/i386-efi.rmk: Likewise.
* conf/i386-ieee1275.rmk: Likewise.
* conf/powerpc-ieee1275.rmk: Likewise.
* conf/x86_64-efi.rmk: Likewise.
* include/grub/arg.h: Move from here ...
* include/grub/lib/arg.h: ... to here.
* normal/arg.c: Move from here ...
* lib/arg.c: ... to here.
* commands/extcmd.c: New file.
* commands/minicmd.c: Likewise.
* include/grub/command.h: Likewise.
* include/grub/extcmd.h: Likewise.
* kern/command.c: Likewise.
* kern/corecmd.c: Likewise.
* kern/list.c (grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(grub_prio_list_insert): Likewise.
* kern/rescue.c (grub_rescue_command): Removed.
(grub_rescue_command_list): Likewise.
(grub_rescue_register_command): Likewise.
(grub_rescue_unregister_command): Likewise.
(grub_rescue_cmd_boot): Move to minicmd.c
(grub_rescue_cmd_help): Likewise.
(grub_rescue_cmd_info): Likewise.
(grub_rescue_cmd_boot): Likewise.
(grub_rescue_cmd_testload): Likewise.
(grub_rescue_cmd_dump): Likewise.
(grub_rescue_cmd_rmmod): Likewise.
(grub_rescue_cmd_lsmod): Likewise.
(grub_rescue_cmd_exit): Likewise.
(grub_rescue_print_devices): Moved to corecmd.c.
(grub_rescue_print_files): Likewise.
(grub_rescue_cmd_ls): Likewise.
(grub_rescue_cmd_insmod): Likewise.
(grub_rescue_cmd_set): Likewise.
(grub_rescue_cmd_unset): Likewise.
(attemp_normal_mode): Use grub_command_find to get normal module.
(grub_enter_rescue_mode): Use grub_register_core_commands to register
commands, remove grub_rescue_regiter_command calls.
* normal/command.c (grub_regiser_command): Removed.
(grub_unregister_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(rescue_command): Likewise.
(export_command): Moved to corecmd.c.
(set_command): Removed.
(unset_command): Likewise.
(insmod_command): Likewise.
(rmmod_command): Likewise.
(lsmod_command): Likewise.
(grub_command_init): Likewise.
* normal/completion.c (iterate_command): Use cmd->prio to check for
active command.
(complete_arguments): Use grub_extcmd_t structure to find options.
(grub_normal_do_completion): Change function grub_iterate_commands to
grub_command_iterate.
* normal/execute.c (grub_script_execute_cmd): No need to parse
argument here.
* normal/main.c (grub_dyncmd_dispatcher): New function.
(read_command_list): Register unload commands as dyncmd.
(grub_cmd_normal): Use new command interface, register rescue,
unregister normal at entry, register normal, unregister rescue at exit.
* include/grub/list.h (grub_list_test_t): New type.
(grub_list_iterate): Return int instead of void.
(grub_list_insert): New function.
(GRUB_AS_NAMED_LIST_P): New macro.
(GRUB_AS_PRIO_LIST): Likewise.
(GRUB_AS_PRIO_LIST_P): Likewise.
(GRUB_PRIO_LIST_PRIO_MASK): New constant.
(GRUB_PRIO_LIST_FLAG_ACTIVE): Likewise.
(grub_prio_list): New structure.
(grub_prio_list_insert): New function.
(grub_prio_list_remove): New inline function.
* include/grub/normal.h: Remove <grub/arg.h>, add <grub/command.h>.
(GRUB_COMMAND_FLAG_CMDLINE): Moved to command.h.
(GRUB_COMMAND_FLAG_MENU): Likewise.
(GRUB_COMMAND_FLAG_BOTH): Likewise.
(GRUB_COMMAND_FLAG_TITLE): Likewise.
(GRUB_COMMAND_FLAG_NO_ECHO): Likewise.
(GRUB_COMMAND_FLAG_NO_ARG_PARSE): Removed.
(GRUB_COMMAND_FLAG_NOT_LOADED): Likewise.
(grub_command): Likewise.
(grub_register_command): Likewise.
(grub_command_find): Likewise.
(grub_iterate_commands): Likewise.
(grub_command_init): Likewise.
(grub_arg_parse): Likewise.
(grub_arg_show_help): Likewise.
* include/grub/rescue.h (grub_rescue_register_command): Removed.
(grub_rescue_unregister_command): Likewise.
* include/grub/i386/bsd.h: Remove grub_rescue_cmd_freebsd,
grub_rescue_cmd_openbsd, grub_rescue_cmd_netbsd,
grub_rescue_cmd_freebsd_loadenv and grub_rescue_cmd_freebsd_module.
* include/grub/i386/efi/loader.h: Remove grub_rescue_cmd_linux and
grub_rescue_cmd_initrd.
* include/grub/i386/loader.h: Likewise.
* include/grub/x86_64/loader.h: Likewise.
* include/grub/i386/pc/chainloader.h: Remove grub_chainloader_cmd.
2009-03-21 08:39:59 +00:00
|
|
|
|