From: BVK Chaitanya Date: Sun, 15 Aug 2010 06:41:07 +0000 (+0530) Subject: merge with setparams branch X-Git-Tag: 1.99~596^2~8 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a8876fc7ca035f94648ec75e69e0470e9f9dd5bf;p=thirdparty%2Fgrub.git merge with setparams branch --- a8876fc7ca035f94648ec75e69e0470e9f9dd5bf diff --cc include/grub/script_sh.h index ae435ff1e,e0ed5c005..de5f625a2 --- a/include/grub/script_sh.h +++ b/include/grub/script_sh.h @@@ -224,8 -226,8 +224,9 @@@ struct grub_parser_para void grub_script_init (void); void grub_script_fini (void); +void grub_script_mem_free (struct grub_script_mem *mem); void grub_script_argv_free (struct grub_script_argv *argv); + int grub_script_argv_make (struct grub_script_argv *argv, int argc, char **args); int grub_script_argv_next (struct grub_script_argv *argv); int grub_script_argv_append (struct grub_script_argv *argv, const char *s); int grub_script_argv_split_append (struct grub_script_argv *argv, char *s); diff --cc script/argv.c index 92449138b,c642ea9c5..911989d0b --- a/script/argv.c +++ b/script/argv.c @@@ -56,9 -55,25 +56,26 @@@ grub_script_argv_free (struct grub_scri argv->argc = 0; argv->args = 0; + argv->script = 0; } + /* Make argv from argc, args pair. */ + int + grub_script_argv_make (struct grub_script_argv *argv, int argc, char **args) + { + int i; - struct grub_script_argv r = { 0, 0}; ++ struct grub_script_argv r = { 0, 0, 0 }; + + for (i = 0; i < argc; i++) + if (grub_script_argv_next (&r) || grub_script_argv_append (&r, args[i])) + { + grub_script_argv_free (&r); + return 1; + } + *argv = r; + return 0; + } + /* Prepare for next argc. */ int grub_script_argv_next (struct grub_script_argv *argv) diff --cc script/execute.c index c36d4e44b,b911163f7..3962b6ba5 --- a/script/execute.c +++ b/script/execute.c @@@ -91,6 -113,35 +114,35 @@@ 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 }; ++ 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; + } + static int grub_env_special (const char *name) { @@@ -105,7 -156,8 +157,8 @@@ static char ** grub_script_env_get (const char *name, grub_script_arg_type_t type) { + unsigned i; - struct grub_script_argv result = { 0, 0 }; + struct grub_script_argv result = { 0, 0, 0 }; if (grub_script_argv_next (&result)) goto fail;