simplify cmdblock with cmdlist
This commit is contained in:
parent
265d68cd10
commit
a8a145eb2f
5 changed files with 31 additions and 52 deletions
|
@ -82,15 +82,6 @@ struct grub_script_cmdline
|
|||
struct grub_script_arglist *arglist;
|
||||
};
|
||||
|
||||
/* A block of commands, this can be used to group commands. */
|
||||
struct grub_script_cmdblock
|
||||
{
|
||||
struct grub_script_cmd cmd;
|
||||
|
||||
/* A chain of commands. */
|
||||
struct grub_script_cmd *cmdlist;
|
||||
};
|
||||
|
||||
/* An if statement. */
|
||||
struct grub_script_cmdif
|
||||
{
|
||||
|
@ -234,8 +225,6 @@ grub_script_add_arglist (struct grub_parser_param *state,
|
|||
struct grub_script_cmd *
|
||||
grub_script_create_cmdline (struct grub_parser_param *state,
|
||||
struct grub_script_arglist *arglist);
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdblock (struct grub_parser_param *state);
|
||||
|
||||
struct grub_script_cmd *
|
||||
grub_script_create_cmdif (struct grub_parser_param *state,
|
||||
|
@ -262,9 +251,9 @@ grub_script_create_cmdmenu (struct grub_parser_param *state,
|
|||
int options);
|
||||
|
||||
struct grub_script_cmd *
|
||||
grub_script_add_cmd (struct grub_parser_param *state,
|
||||
struct grub_script_cmdblock *cmdblock,
|
||||
struct grub_script_cmd *cmd);
|
||||
grub_script_append_cmd (struct grub_parser_param *state,
|
||||
struct grub_script_cmd *list,
|
||||
struct grub_script_cmd *last);
|
||||
struct grub_script_arg *
|
||||
grub_script_arg_add (struct grub_parser_param *state,
|
||||
struct grub_script_arg *arg,
|
||||
|
@ -301,7 +290,7 @@ void grub_script_yyerror (struct grub_parser_param *, char const *);
|
|||
|
||||
/* Commands to execute, don't use these directly. */
|
||||
grub_err_t grub_script_execute_cmdline (struct grub_script_cmd *cmd);
|
||||
grub_err_t grub_script_execute_cmdblock (struct grub_script_cmd *cmd);
|
||||
grub_err_t grub_script_execute_cmdlist (struct grub_script_cmd *cmd);
|
||||
grub_err_t grub_script_execute_cmdif (struct grub_script_cmd *cmd);
|
||||
grub_err_t grub_script_execute_cmdfor (struct grub_script_cmd *cmd);
|
||||
grub_err_t grub_script_execute_cmdwhile (struct grub_script_cmd *cmd);
|
||||
|
|
|
@ -269,13 +269,13 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|||
|
||||
/* Execute a block of one or more commands. */
|
||||
grub_err_t
|
||||
grub_script_execute_cmdblock (struct grub_script_cmd *cmd)
|
||||
grub_script_execute_cmdlist (struct grub_script_cmd *list)
|
||||
{
|
||||
int ret = 0;
|
||||
struct grub_script_cmdblock *cmdblock = (struct grub_script_cmdblock *) cmd;
|
||||
struct grub_script_cmd *cmd;
|
||||
|
||||
/* Loop over every command and execute it. */
|
||||
for (cmd = cmdblock->cmdlist; cmd; cmd = cmd->next)
|
||||
for (cmd = list->next; cmd; cmd = cmd->next)
|
||||
ret = grub_script_execute_cmd (cmd);
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -96,9 +96,7 @@ script: newlines0
|
|||
}
|
||||
| script statement delimiter newlines0
|
||||
{
|
||||
struct grub_script_cmdblock *cmdblock;
|
||||
cmdblock = (struct grub_script_cmdblock *) $1;
|
||||
$$ = grub_script_add_cmd (state, cmdblock, $2);
|
||||
$$ = grub_script_append_cmd (state, $1, $2);
|
||||
}
|
||||
| error
|
||||
{
|
||||
|
@ -183,13 +181,11 @@ command: grubcmd { $$ = $1; }
|
|||
/* A list of commands. */
|
||||
commands1: newlines0 command
|
||||
{
|
||||
$$ = grub_script_add_cmd (state, 0, $2);
|
||||
$$ = grub_script_append_cmd (state, 0, $2);
|
||||
}
|
||||
| commands1 delimiters1 command
|
||||
{
|
||||
struct grub_script_cmdblock *cmdblock;
|
||||
cmdblock = (struct grub_script_cmdblock *) $1;
|
||||
$$ = grub_script_add_cmd (state, cmdblock, $3);
|
||||
$$ = grub_script_append_cmd (state, $1, $3);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
|
@ -291,46 +291,40 @@ grub_script_create_cmdmenu (struct grub_parser_param *state,
|
|||
return (struct grub_script_cmd *) cmd;
|
||||
}
|
||||
|
||||
/* Create a block of commands. CMD contains the command that should
|
||||
be added at the end of CMDBLOCK's list. If CMDBLOCK is zero, a new
|
||||
cmdblock will be created. */
|
||||
/* Create a chain of commands. LAST contains the command that should
|
||||
be added at the end of LIST's list. If LIST is zero, a new list
|
||||
will be created. */
|
||||
struct grub_script_cmd *
|
||||
grub_script_add_cmd (struct grub_parser_param *state,
|
||||
struct grub_script_cmdblock *cmdblock,
|
||||
struct grub_script_cmd *cmd)
|
||||
grub_script_append_cmd (struct grub_parser_param *state,
|
||||
struct grub_script_cmd *list,
|
||||
struct grub_script_cmd *last)
|
||||
{
|
||||
struct grub_script_cmd *ptr;
|
||||
|
||||
grub_dprintf ("scripting", "cmdblock\n");
|
||||
grub_dprintf ("scripting", "append command\n");
|
||||
|
||||
if (!cmd)
|
||||
return (struct grub_script_cmd *) cmdblock;
|
||||
if (! last)
|
||||
return list;
|
||||
|
||||
if (!cmdblock)
|
||||
if (! list)
|
||||
{
|
||||
cmdblock = grub_script_malloc (state, sizeof (*cmdblock));
|
||||
if (!cmdblock)
|
||||
list = grub_script_malloc (state, sizeof (*list));
|
||||
if (! list)
|
||||
return 0;
|
||||
|
||||
cmdblock->cmd.exec = grub_script_execute_cmdblock;
|
||||
cmdblock->cmd.next = 0;
|
||||
cmdblock->cmdlist = cmd;
|
||||
cmd->next = 0;
|
||||
list->exec = grub_script_execute_cmdlist;
|
||||
list->next = last;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!cmdblock->cmdlist)
|
||||
cmdblock->cmdlist = cmd;
|
||||
else
|
||||
{
|
||||
ptr = cmdblock->cmdlist;
|
||||
while (ptr->next)
|
||||
ptr = ptr->next;
|
||||
ptr->next = cmd;
|
||||
}
|
||||
ptr = list;
|
||||
while (ptr->next)
|
||||
ptr = ptr->next;
|
||||
|
||||
ptr->next = last;
|
||||
}
|
||||
|
||||
return (struct grub_script_cmd *) cmdblock;
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd __attribute__ ((unused)
|
|||
}
|
||||
|
||||
grub_err_t
|
||||
grub_script_execute_cmdblock (struct grub_script_cmd *cmd __attribute__ ((unused)))
|
||||
grub_script_execute_cmdlist (struct grub_script_cmd *cmd __attribute__ ((unused)))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue