+2013-06-07 Andrey Borzenkov <arvidjaar@gmail.com>
+
+ * grub-core/script/execute.c (grub_script_execute_sourcecode): Split
+ off new function grub_script_execute_new_scope. Change callers to use
+ either of them as appropriate.
+ * grub-core/commands/eval.c: New command eval.
+ * docs/grub.texi (Commands): Document it.
+
2013-06-07 Andrey Borzenkov <arvidjaar@gmail.com>
* grub-core/kern/corecmd.c (grub_core_cmd_set): Use grub_env_get
* date:: Display or set current date and time
* drivemap:: Map a drive to another
* echo:: Display a line of text
+* eval:: Evaluate agruments as GRUB commands
* export:: Export an environment variable
* false:: Do nothing, unsuccessfully
* gettext:: Translate a string
@end deffn
+@node eval
+@subsection eval
+
+@deffn Command eval string ...
+Concatenate arguments together using single space as separator and evaluate
+result as sequence of GRUB commands.
+@end deffn
+
+
@node export
@subsection export
common = commands/echo.c;
};
+module = {
+ name = eval;
+ common = commands/eval.c;
+};
+
module = {
name = extcmd;
common = commands/extcmd.c;
else
grub_env_unset ("default");
- grub_script_execute_sourcecode (entry->sourcecode, entry->argc, entry->args);
+ grub_script_execute_new_scope (entry->sourcecode, entry->argc, entry->args);
if (errs_before != grub_err_printed_errors)
grub_wait_after_message ();
}
script[size] = '\0';
}
- grub_script_execute_sourcecode (script, 0, dummy);
+ grub_script_execute_new_scope (script, 0, dummy);
grub_free (script);
if (errs_before != grub_err_printed_errors)
/* Execute a source script. */
grub_err_t
-grub_script_execute_sourcecode (const char *source, int argc, char **args)
+grub_script_execute_sourcecode (const char *source)
{
grub_err_t ret = 0;
struct grub_script *parsed_script;
- struct grub_script_scope new_scope;
- struct grub_script_scope *old_scope;
-
- new_scope.argv.argc = argc;
- new_scope.argv.args = args;
- new_scope.flags = 0;
-
- old_scope = scope;
- scope = &new_scope;
while (source)
{
if (! parsed_script)
{
ret = grub_errno;
+ grub_free (line);
break;
}
ret = grub_script_execute (parsed_script);
+ grub_script_free (parsed_script);
grub_free (line);
}
+ return ret;
+}
+
+/* Execute a source script in new scope. */
+grub_err_t
+grub_script_execute_new_scope (const char *source, int argc, char **args)
+{
+ grub_err_t ret = 0;
+ struct grub_script_scope new_scope;
+ struct grub_script_scope *old_scope;
+
+ new_scope.argv.argc = argc;
+ new_scope.argv.args = args;
+ new_scope.flags = 0;
+
+ old_scope = scope;
+ scope = &new_scope;
+
+ ret = grub_script_execute_sourcecode (source);
+
scope = old_scope;
return ret;
}
/* Execute any GRUB pre-parsed command or script. */
grub_err_t grub_script_execute (struct grub_script *script);
-grub_err_t grub_script_execute_sourcecode (const char *source, int argc, char **args);
+grub_err_t grub_script_execute_sourcecode (const char *source);
+grub_err_t grub_script_execute_new_scope (const char *source, int argc, char **args);
/* Break command for loops. */
grub_err_t grub_script_break (grub_command_t cmd, int argc, char *argv[]);