* 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.
This commit is contained in:
parent
63c2984922
commit
593e430cd6
7 changed files with 50 additions and 13 deletions
|
@ -856,19 +856,10 @@ grub_script_execute_sourcecode_getline (char **line,
|
|||
|
||||
/* 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)
|
||||
{
|
||||
|
@ -880,13 +871,35 @@ grub_script_execute_sourcecode (const char *source, int argc, char **args)
|
|||
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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue