From: BVK Chaitanya Date: Sat, 4 Sep 2010 15:14:44 +0000 (+0530) Subject: merge with mainline X-Git-Tag: 1.99~597^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=165bfce13888826dd7de65f35becc721227f60c8;p=thirdparty%2Fgrub.git merge with mainline --- 165bfce13888826dd7de65f35becc721227f60c8 diff --cc Makefile.util.def index a0ab3d3d9,45c2f9761..79541b5ed --- a/Makefile.util.def +++ b/Makefile.util.def @@@ -507,12 -507,12 +507,18 @@@ script = common = tests/grub_script_blockarg.in; }; + script = { + testcase; + name = grub_script_setparams; + common = tests/grub_script_setparams.in; + }; + +script = { + testcase; + name = grub_script_return; + common = tests/grub_script_return.in; +}; + program = { testcase; name = example_unit_test; diff --cc grub-core/script/execute.c index e71c5345a,8e3c97434..88057d44e --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@@ -34,8 -34,10 +34,11 @@@ static unsigned long is_continue; static unsigned long active_loops; static unsigned long active_breaks; +static unsigned long function_return; + #define GRUB_SCRIPT_SCOPE_MALLOCED 1 + #define GRUB_SCRIPT_SCOPE_ARGS_MALLOCED 2 + /* Scope for grub script functions. */ struct grub_script_scope { @@@ -92,30 -114,35 +115,59 @@@ grub_script_shift (grub_command_t cmd _ return GRUB_ERR_NONE; } + grub_err_t + grub_script_setparams (grub_command_t cmd __attribute__((unused)), + int argc, char **args) + { + struct grub_script_scope *new_scope; + struct grub_script_argv argv = { 0, 0, 0 }; + + if (! scope) + return GRUB_ERR_INVALID_COMMAND; + + new_scope = grub_malloc (sizeof (*new_scope)); + if (! new_scope) + return grub_errno; + + if (grub_script_argv_make (&argv, argc, args)) + { + grub_free (new_scope); + return grub_errno; + } + + new_scope->shifts = 0; + new_scope->argv = argv; + new_scope->flags = GRUB_SCRIPT_SCOPE_MALLOCED | + GRUB_SCRIPT_SCOPE_ARGS_MALLOCED; + + replace_scope (new_scope); + return GRUB_ERR_NONE; + } + +grub_err_t +grub_script_return (grub_command_t cmd __attribute__((unused)), + int argc, char *argv[]) +{ + char *p; + unsigned long n; + + if (! scope || argc > 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "not in function scope"); + + if (argc == 0) + { + function_return = 1; + return grub_strtoul (grub_env_get ("?"), NULL, 10); + } + + n = grub_strtoul (argv[0], &p, 10); + if (*p != '\0') + return grub_error (GRUB_ERR_BAD_ARGUMENT, "bad argument"); + + function_return = 1; + return n ? grub_error (GRUB_ERR_TEST_FAILURE, "false") : GRUB_ERR_NONE; +} + static int grub_env_special (const char *name) { @@@ -344,9 -370,8 +395,9 @@@ grub_script_function_call (grub_script_ ret = grub_script_execute (func->func); + function_return = 0; active_loops = loops; - scope = old_scope; + replace_scope (old_scope); /* free any scopes by setparams */ return ret; } diff --cc grub-core/script/main.c index 6daace287,4984848f0..482bb3fef --- a/grub-core/script/main.c +++ b/grub-core/script/main.c @@@ -44,7 -44,7 +44,8 @@@ grub_normal_parse_line (char *line, gru static grub_command_t cmd_break; static grub_command_t cmd_continue; static grub_command_t cmd_shift; + static grub_command_t cmd_setparams; +static grub_command_t cmd_return; void grub_script_init (void) @@@ -55,8 -55,9 +56,11 @@@ N_("[n]"), N_("Continue loops")); cmd_shift = grub_register_command ("shift", grub_script_shift, N_("[n]"), N_("Shift positional parameters.")); + cmd_setparams = grub_register_command ("setparams", grub_script_setparams, + N_("[VALUE]..."), + N_("Set positional parameters.")); + cmd_return = grub_register_command ("return", grub_script_return, + N_("[n]"), N_("Return from a function.")); } void @@@ -74,7 -75,7 +78,11 @@@ grub_script_fini (void grub_unregister_command (cmd_shift); cmd_shift = 0; + if (cmd_setparams) + grub_unregister_command (cmd_setparams); + cmd_setparams = 0; ++ + if (cmd_return) + grub_unregister_command (cmd_return); + cmd_return = 0; } diff --cc include/grub/script_sh.h index 172856e8a,b371e49f1..848e55411 --- a/include/grub/script_sh.h +++ b/include/grub/script_sh.h @@@ -342,9 -343,9 +343,12 @@@ grub_err_t grub_script_break (grub_comm /* SHIFT command for GRUB script. */ grub_err_t grub_script_shift (grub_command_t cmd, int argc, char *argv[]); + /* SETPARAMS command for GRUB script functions. */ + grub_err_t grub_script_setparams (grub_command_t cmd, int argc, char *argv[]); + +/* RETURN command for functions. */ +grub_err_t grub_script_return (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;