menuentry can pass parameters to its definition
This commit is contained in:
parent
639cc5ab44
commit
1767f7096c
6 changed files with 91 additions and 48 deletions
|
@ -268,6 +268,62 @@ grub_script_function_call (grub_script_function_t func, int argc, char **args)
|
|||
return ret;
|
||||
}
|
||||
|
||||
/* Execute a source script. */
|
||||
grub_err_t
|
||||
grub_script_execute_sourcecode (const char *source, int argc, char **args)
|
||||
{
|
||||
grub_err_t ret = 0;
|
||||
struct grub_script *parsed_script;
|
||||
struct grub_script_scope new_scope;
|
||||
struct grub_script_scope *old_scope;
|
||||
|
||||
auto grub_err_t getline (char **line, int cont);
|
||||
grub_err_t getline (char **line, int cont __attribute__ ((unused)))
|
||||
{
|
||||
const char *p;
|
||||
|
||||
if (! source)
|
||||
{
|
||||
*line = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
p = grub_strchr (source, '\n');
|
||||
|
||||
if (p)
|
||||
*line = grub_strndup (source, p - source);
|
||||
else
|
||||
*line = grub_strdup (source);
|
||||
source = p ? p + 1 : 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
new_scope.argv.argc = argc;
|
||||
new_scope.argv.args = args;
|
||||
|
||||
old_scope = scope;
|
||||
scope = &new_scope;
|
||||
|
||||
while (source)
|
||||
{
|
||||
char *line;
|
||||
|
||||
getline (&line, 0);
|
||||
parsed_script = grub_script_parse (line, getline);
|
||||
if (! parsed_script)
|
||||
{
|
||||
ret = grub_errno;
|
||||
break;
|
||||
}
|
||||
|
||||
ret = grub_script_execute (parsed_script);
|
||||
grub_free (line);
|
||||
}
|
||||
|
||||
scope = old_scope;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Execute a single command line. */
|
||||
grub_err_t
|
||||
grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
||||
|
|
|
@ -95,6 +95,7 @@ void
|
|||
grub_script_free (struct grub_script *script)
|
||||
{
|
||||
struct grub_script *s;
|
||||
struct grub_script *t;
|
||||
|
||||
if (!script)
|
||||
return;
|
||||
|
@ -104,8 +105,9 @@ grub_script_free (struct grub_script *script)
|
|||
|
||||
s = script->children;
|
||||
while (s) {
|
||||
s = s->siblings;
|
||||
t = s->siblings;
|
||||
grub_script_put (s);
|
||||
s = t;
|
||||
}
|
||||
grub_free (script);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue