From: BVK Chaitanya Date: Sat, 4 Sep 2010 17:04:32 +0000 (+0530) Subject: merge with mainline X-Git-Tag: 1.99~593^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee14ec9935f803c3a87509092b2fda02ba563799;p=thirdparty%2Fgrub.git merge with mainline --- ee14ec9935f803c3a87509092b2fda02ba563799 diff --cc Makefile.util.def index 31985811c,a3d5381d4..dd38774fd --- a/Makefile.util.def +++ b/Makefile.util.def @@@ -507,12 -507,24 +507,30 @@@ 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; + }; + + script = { + testcase; + name = grub_cmd_regexp; + common = tests/grub_cmd_regexp.in; + }; + +script = { + testcase; + name = grub_script_expansion; + common = tests/grub_script_expansion.in; +}; + program = { testcase; name = example_unit_test; diff --cc grub-core/commands/regexp.c index 8e0ec5a3a,8edf818a3..4329483af --- a/grub-core/commands/regexp.c +++ b/grub-core/commands/regexp.c @@@ -20,17 -20,73 +20,74 @@@ #include #include #include - #include + #include + #include + #include #include +#include #include + static const struct grub_arg_option options[] = + { + { "set", 's', GRUB_ARG_OPTION_REPEATABLE, + N_("Variable names to update with matches."), + N_("[NUMBER:]VARNAME"), ARG_TYPE_STRING }, + { 0, 0, 0, 0, 0, 0 } + }; + + static grub_err_t + set_matches (char **varnames, char *str, grub_size_t nmatches, + regmatch_t *matches) + { + int i; + char ch; + char *p; + char *q; + grub_err_t err; + unsigned long j; + + auto void setvar (char *v, regmatch_t *m); + void setvar (char *v, regmatch_t *m) + { + ch = str[m->rm_eo]; + str[m->rm_eo] = '\0'; + err = grub_env_set (v, str + m->rm_so); + str[m->rm_eo] = ch; + } + + for (i = 0; varnames && varnames[i]; i++) + { + if (! (p = grub_strchr (varnames[i], ':'))) + { + /* varname w/o index defaults to 1 */ + if (nmatches < 2 || matches[1].rm_so == -1) + grub_env_unset (varnames[i]); + else + setvar (varnames[i], &matches[1]); + } + else + { + j = grub_strtoul (varnames[i], &q, 10); + if (q != p) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "invalid variable name format %s", varnames[i]); + + if (nmatches <= j || matches[j].rm_so == -1) + grub_env_unset (p + 1); + else + setvar (p + 1, &matches[j]); + } + + if (err != GRUB_ERR_NONE) + return err; + } + return GRUB_ERR_NONE; + } + static grub_err_t - grub_cmd_regexp (grub_command_t cmd __attribute__ ((unused)), - int argc, char **args) + grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args) { int argn = 0; - int matches = 0; regex_t regex; int ret; grub_size_t s; @@@ -70,16 -135,12 +136,16 @@@ static grub_extcmd_t cmd GRUB_MOD_INIT(regexp) { - cmd = grub_register_command ("regexp", grub_cmd_regexp, - N_("REGEXP STRING"), - N_("Test if REGEXP matches STRING.")); + cmd = grub_register_extcmd ("regexp", grub_cmd_regexp, + GRUB_COMMAND_FLAG_BOTH, N_("REGEXP STRING"), + N_("Test if REGEXP matches STRING."), options); + + /* Setup GRUB script wildcard translator. */ + grub_wildcard_translator = &grub_filename_translator; } GRUB_MOD_FINI(regexp) { - grub_unregister_command (cmd); + grub_unregister_extcmd (cmd); + grub_wildcard_translator = 0; } diff --cc grub-core/script/execute.c index e6be1fa31,f35e9ce76..a7baee96c --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@@ -42,9 -48,23 +48,26 @@@ struct grub_script_scop }; static struct grub_script_scope *scope = 0; +/* Wildcard translator for GRUB script. */ +struct grub_script_wildcard_translator *grub_wildcard_translator; + + static void + replace_scope (struct grub_script_scope *new_scope) + { + if (scope) + { + scope->argv.argc += scope->shifts; + scope->argv.args -= scope->shifts; + + if (scope->flags & GRUB_SCRIPT_SCOPE_ARGS_MALLOCED) + grub_script_argv_free (&scope->argv); + + if (scope->flags & GRUB_SCRIPT_SCOPE_MALLOCED) + grub_free (scope); + } + scope = new_scope; + } + grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]) {