merged with mainline
This commit is contained in:
commit
dae0d05f2d
50 changed files with 1089 additions and 1503 deletions
|
@ -291,6 +291,32 @@ grub_script_execute_cmdif (struct grub_script_cmd *cmd)
|
|||
return grub_script_execute_cmd (cmdif->exec_on_false);
|
||||
}
|
||||
|
||||
/* Execute a for statement. */
|
||||
grub_err_t
|
||||
grub_script_execute_cmdfor (struct grub_script_cmd *cmd)
|
||||
{
|
||||
int i;
|
||||
int result;
|
||||
char **args;
|
||||
int argcount;
|
||||
struct grub_script_cmdfor *cmdfor = (struct grub_script_cmdfor *) cmd;
|
||||
|
||||
args = grub_script_execute_arglist_to_argv (cmdfor->words, &argcount);
|
||||
if (!args)
|
||||
return grub_errno;
|
||||
|
||||
result = 0;
|
||||
for (i = 0; i < argcount; i++)
|
||||
{
|
||||
grub_env_set (cmdfor->name->str, args[i]);
|
||||
result = grub_script_execute_cmd (cmdfor->list);
|
||||
grub_free (args[i]);
|
||||
}
|
||||
|
||||
grub_free (args);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Execute the menu entry generate statement. */
|
||||
grub_err_t
|
||||
grub_script_execute_menuentry (struct grub_script_cmd *cmd)
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
%token <arg> GRUB_PARSER_TOKEN_WORD "word"
|
||||
|
||||
%type <arglist> word argument arguments0 arguments1
|
||||
%type <cmd> script_init script grubcmd ifcmd command
|
||||
%type <cmd> script_init script grubcmd ifcmd forcmd command
|
||||
%type <cmd> commands1 menuentry statement
|
||||
|
||||
%pure-parser
|
||||
|
@ -173,6 +173,7 @@ grubcmd: word arguments0
|
|||
/* A single command. */
|
||||
command: grubcmd { $$ = $1; }
|
||||
| ifcmd { $$ = $1; }
|
||||
| forcmd { $$ = $1; }
|
||||
;
|
||||
|
||||
/* A list of commands. */
|
||||
|
@ -236,3 +237,14 @@ ifcmd: if commands1 delimiters1 "then" commands1 delimiters1 "fi"
|
|||
grub_script_lexer_deref (state->lexerstate);
|
||||
}
|
||||
;
|
||||
|
||||
forcmd: "for" "name"
|
||||
{
|
||||
grub_script_lexer_ref (state->lexerstate);
|
||||
}
|
||||
"in" arguments0 delimiters1 "do" commands1 delimiters1 "done"
|
||||
{
|
||||
$$ = grub_script_create_cmdfor (state, $2, $5, $8);
|
||||
grub_script_lexer_deref (state->lexerstate);
|
||||
}
|
||||
;
|
||||
|
|
|
@ -221,6 +221,30 @@ grub_script_create_cmdif (struct grub_parser_param *state,
|
|||
return (struct grub_script_cmd *) cmd;
|
||||
}
|
||||
|
||||
/* Create a command that functions as a for statement. */
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdfor (struct grub_parser_param *state,
|
||||
struct grub_script_arg *name,
|
||||
struct grub_script_arglist *words,
|
||||
struct grub_script_cmd *list)
|
||||
{
|
||||
struct grub_script_cmdfor *cmd;
|
||||
|
||||
grub_dprintf ("scripting", "cmdfor\n");
|
||||
|
||||
cmd = grub_script_malloc (state, sizeof (*cmd));
|
||||
if (! cmd)
|
||||
return 0;
|
||||
|
||||
cmd->cmd.exec = grub_script_execute_cmdfor;
|
||||
cmd->cmd.next = 0;
|
||||
cmd->name = name;
|
||||
cmd->words = words;
|
||||
cmd->list = list;
|
||||
|
||||
return (struct grub_script_cmd *) cmd;
|
||||
}
|
||||
|
||||
/* Create a command that adds a menu entry to the menu. Title is an
|
||||
argument that is parsed to generate a string that can be used as
|
||||
the title. The sourcecode for this entry is passed in SOURCECODE.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue