From: BVK Chaitanya Date: Sun, 13 Jun 2010 04:18:47 +0000 (+0530) Subject: merge with mainline X-Git-Tag: 1.99~665^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49e38cf4758add725fa1379a2a3d6f5a35dc8689;p=thirdparty%2Fgrub.git merge with mainline --- 49e38cf4758add725fa1379a2a3d6f5a35dc8689 diff --cc conf/tests.rmk index 9cda007db,57cae95c5..c14fe0fda --- a/conf/tests.rmk +++ b/conf/tests.rmk @@@ -74,9 -74,12 +74,15 @@@ grub_script_comments_SOURCES = tests/gr check_SCRIPTS += grub_script_functions grub_script_functions_SOURCES = tests/grub_script_functions.in + check_SCRIPTS += grub_script_break + grub_script_break_SOURCES = tests/grub_script_break.in + + check_SCRIPTS += grub_script_continue + grub_script_continue_SOURCES = tests/grub_script_continue.in + +check_SCRIPTS += grub_script_shift +grub_script_shift_SOURCES = tests/grub_script_shift.in + # List of tests to execute on "make check" # SCRIPTED_TESTS = example_scripted_test # SCRIPTED_TESTS += example_grub_script_test @@@ -94,7 -97,8 +100,9 @@@ SCRIPTED_TESTS += grub_script_final_sem SCRIPTED_TESTS += grub_script_dollar SCRIPTED_TESTS += grub_script_comments SCRIPTED_TESTS += grub_script_functions + SCRIPTED_TESTS += grub_script_break + SCRIPTED_TESTS += grub_script_continue +SCRIPTED_TESTS += grub_script_shift # dependencies between tests and testing-tools $(SCRIPTED_TESTS): grub-shell grub-shell-tester diff --cc include/grub/script_sh.h index 2b4c4e2f2,512498a59..77e807360 --- a/include/grub/script_sh.h +++ b/include/grub/script_sh.h @@@ -312,9 -315,9 +315,12 @@@ grub_err_t grub_script_execute_menuentr /* Execute any GRUB pre-parsed command or script. */ grub_err_t grub_script_execute (struct grub_script *script); + /* Break command for loops. */ + grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]); + +/* SHIFT command for GRUB script. */ - grub_err_t grub_script_cmd_shift (grub_command_t cmd, int argc, char *argv[]); ++grub_err_t grub_script_shift (grub_command_t cmd, int argc, char *argv[]); + /* This variable points to the parsed command. This is used to communicate with the bison code. */ extern struct grub_script_cmd *grub_script_parsed; diff --cc script/execute.c index ce973dbde,15eb7d142..fef8c766a --- a/script/execute.c +++ b/script/execute.c @@@ -38,36 -42,23 +42,54 @@@ struct grub_script_scop static struct grub_script_scope *scope = 0; grub_err_t - grub_script_cmd_shift (grub_command_t cmd __attribute__((unused)), - int argc, char *argv[]) + grub_script_break (grub_command_t cmd, int argc, char *argv[]) + { + char *p = 0; + unsigned long count; + + if (argc == 0) + count = 1; + + else if ((argc > 1) || (count = grub_strtoul (argv[0], &p, 10)) == 0 || + (*p != '\0')) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad break"); + + is_continue = grub_strcmp (cmd->name, "break") ? 1 : 0; + active_breaks = grub_min (active_loops, count); + return GRUB_ERR_NONE; + } + ++grub_err_t ++grub_script_shift (grub_command_t cmd __attribute__((unused)), ++ int argc, char *argv[]) +{ + char *p = 0; + unsigned long n = 0; + + if (! scope) + return GRUB_ERR_NONE; + + if (argc == 0) + n = 1; + + else if (argc > 1) + return GRUB_ERR_BAD_ARGUMENT; + + else + { + n = grub_strtoul (argv[0], &p, 10); + if (*p != '\0') + return GRUB_ERR_BAD_ARGUMENT; + } + + if (n > scope->argv.argc) + return GRUB_ERR_BAD_ARGUMENT; + + scope->argv.argc -= n; + scope->argv.args += n; + return GRUB_ERR_NONE; +} + static int grub_env_special (const char *name) { diff --cc script/main.c index ef810611c,9354f3ed8..ff714d060 --- a/script/main.c +++ b/script/main.c @@@ -41,20 -41,27 +41,33 @@@ grub_normal_parse_line (char *line, gru return grub_errno; } - static struct grub_parser grub_sh_parser = - { - .name = "grub", - .parse_line = grub_normal_parse_line - }; + static grub_command_t cmd_break; + static grub_command_t cmd_continue; ++static grub_command_t cmd_shift; - GRUB_MOD_INIT(sh) + void + grub_script_init (void) { - grub_parser_register ("grub", &grub_sh_parser); - grub_register_command ("shift", grub_script_cmd_shift, - N_("[n]"), N_("Shift positional parameters.")); + cmd_break = grub_register_command ("break", grub_script_break, + N_("[n]"), N_("Exit from loops")); + cmd_continue = grub_register_command ("continue", grub_script_break, - N_("[n]"), N_("Coninue loops")); ++ N_("[n]"), N_("Continue loops")); ++ cmd_shift = grub_register_command ("shift", grub_script_shift, ++ N_("[n]"), N_("Shift positional parameters.")); } - GRUB_MOD_FINI(sh) + void + grub_script_fini (void) { - grub_parser_unregister (&grub_sh_parser); + if (cmd_break) + grub_unregister_command (cmd_break); + cmd_break = 0; + + if (cmd_continue) + grub_unregister_command (cmd_continue); + cmd_continue = 0; + ++ if (cmd_shift) ++ grub_unregister_command (cmd_shift); ++ cmd_shift = 0; } diff --cc util/grub-script-check.c index 1d9ebd57f,a66a1f272..811838cac --- a/util/grub-script-check.c +++ b/util/grub-script-check.c @@@ -58,13 -56,13 +56,22 @@@ grub_refresh (void } grub_err_t - grub_script_cmd_shift (grub_command_t cmd __attribute__((unused)), - int argc __attribute__((unused)), - char *argv[] __attribute__((unused))) + grub_script_break (grub_command_t cmd __attribute__((unused)), + int argc __attribute__((unused)), + char *argv[] __attribute__((unused))) + { + return 0; + } + ++grub_err_t ++grub_script_shift (grub_command_t cmd __attribute__((unused)), ++ int argc __attribute__((unused)), ++ char *argv[] __attribute__((unused))) +{ + return 0; +} + ++ char * grub_script_execute_argument_to_string (struct grub_script_arg *arg __attribute__ ((unused))) {