pull-in block-arg again
This commit is contained in:
commit
2bcfd8a295
9 changed files with 32 additions and 72 deletions
|
@ -25,7 +25,7 @@
|
|||
|
||||
grub_err_t
|
||||
grub_extcmd_dispatcher (struct grub_command *cmd, int argc, char **args,
|
||||
struct grub_script **scripts)
|
||||
struct grub_script *script)
|
||||
{
|
||||
int new_argc;
|
||||
char **new_args;
|
||||
|
@ -38,7 +38,7 @@ grub_extcmd_dispatcher (struct grub_command *cmd, int argc, char **args,
|
|||
|
||||
context.state = 0;
|
||||
context.extcmd = ext;
|
||||
context.script_params = scripts;
|
||||
context.script = script;
|
||||
|
||||
if (! ext->options)
|
||||
{
|
||||
|
|
|
@ -33,7 +33,7 @@ grub_cmd_menuentry (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
grub_err_t r;
|
||||
|
||||
/* XXX Rewrite to make use of already parsed menu definition. */
|
||||
if (! argc || ! ctxt->script_params || ! ctxt->script_params[argc - 1])
|
||||
if (! argc || ! ctxt->script)
|
||||
return GRUB_ERR_BAD_ARGUMENT;
|
||||
|
||||
src = args[argc - 1];
|
||||
|
|
|
@ -50,8 +50,8 @@ struct grub_extcmd_context
|
|||
|
||||
struct grub_arg_list *state;
|
||||
|
||||
/* Script parameters, if any. */
|
||||
struct grub_script **script_params;
|
||||
/* Script parameter, if any. */
|
||||
struct grub_script *script;
|
||||
};
|
||||
typedef struct grub_extcmd_context *grub_extcmd_context_t;
|
||||
|
||||
|
@ -74,6 +74,6 @@ void grub_unregister_extcmd (grub_extcmd_t cmd);
|
|||
|
||||
grub_err_t
|
||||
grub_extcmd_dispatcher (struct grub_command *cmd, int argc, char **args,
|
||||
struct grub_script **scripts);
|
||||
struct grub_script *script);
|
||||
|
||||
#endif /* ! GRUB_EXTCMD_HEADER */
|
||||
|
|
|
@ -62,7 +62,7 @@ struct grub_script_arg
|
|||
char *str;
|
||||
|
||||
/* Parsed block argument. */
|
||||
struct grub_script *block;
|
||||
struct grub_script *script;
|
||||
|
||||
/* Next argument part. */
|
||||
struct grub_script_arg *next;
|
||||
|
@ -73,7 +73,7 @@ struct grub_script_argv
|
|||
{
|
||||
unsigned argc;
|
||||
char **args;
|
||||
struct grub_script **scripts;
|
||||
struct grub_script *script;
|
||||
};
|
||||
|
||||
/* A complete argument. It consists of a list of one or more `struct
|
||||
|
@ -219,8 +219,6 @@ void grub_script_argv_free (struct grub_script_argv *argv);
|
|||
int grub_script_argv_next (struct grub_script_argv *argv);
|
||||
int grub_script_argv_append (struct grub_script_argv *argv, const char *s);
|
||||
int grub_script_argv_split_append (struct grub_script_argv *argv, char *s);
|
||||
int grub_script_argv_script_append (struct grub_script_argv *argv,
|
||||
struct grub_script *s);
|
||||
|
||||
struct grub_script_arglist *
|
||||
grub_script_create_arglist (struct grub_parser_param *state);
|
||||
|
|
|
@ -54,8 +54,7 @@ grub_dyncmd_dispatcher (struct grub_extcmd_context *ctxt,
|
|||
{
|
||||
if (cmd->flags & GRUB_COMMAND_FLAG_BLOCKS &&
|
||||
cmd->flags & GRUB_COMMAND_FLAG_EXTCMD)
|
||||
ret = grub_extcmd_dispatcher (cmd, argc, args,
|
||||
ctxt->script_params);
|
||||
ret = grub_extcmd_dispatcher (cmd, argc, args, ctxt->script);
|
||||
else
|
||||
ret = (cmd->func) (cmd, argc, args);
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
|
||||
#include <grub/mm.h>
|
||||
#include <grub/misc.h>
|
||||
#include <grub/script_sh.h>
|
||||
|
||||
static unsigned
|
||||
|
@ -52,18 +53,8 @@ grub_script_argv_free (struct grub_script_argv *argv)
|
|||
grub_free (argv->args);
|
||||
}
|
||||
|
||||
if (argv->scripts)
|
||||
{
|
||||
for (i = 0; i < argv->argc; i++)
|
||||
if (argv->scripts[i])
|
||||
grub_script_put (argv->scripts[i]);
|
||||
|
||||
grub_free (argv->scripts);
|
||||
}
|
||||
|
||||
argv->argc = 0;
|
||||
argv->args = 0;
|
||||
argv->scripts = 0;
|
||||
}
|
||||
|
||||
/* Prepare for next argc. */
|
||||
|
@ -71,7 +62,6 @@ int
|
|||
grub_script_argv_next (struct grub_script_argv *argv)
|
||||
{
|
||||
char **p = argv->args;
|
||||
struct grub_script **q = argv->scripts;
|
||||
|
||||
if (argv->args && argv->argc && argv->args[argv->argc - 1] == 0)
|
||||
return 0;
|
||||
|
@ -80,24 +70,12 @@ grub_script_argv_next (struct grub_script_argv *argv)
|
|||
if (! p)
|
||||
return 1;
|
||||
|
||||
q = grub_realloc (q, round_up_exp ((argv->argc + 2) * sizeof (struct grub_script *)));
|
||||
if (! q)
|
||||
{
|
||||
grub_free (p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
argv->argc++;
|
||||
argv->args = p;
|
||||
argv->scripts = q;
|
||||
|
||||
if (argv->argc == 1)
|
||||
{
|
||||
argv->args[0] = 0;
|
||||
argv->scripts[0] = 0;
|
||||
}
|
||||
argv->args[argv->argc] = 0;
|
||||
argv->scripts[argv->argc] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -123,18 +101,6 @@ grub_script_argv_append (struct grub_script_argv *argv, const char *s)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Append grub_script `s' as the last argument. */
|
||||
int
|
||||
grub_script_argv_script_append (struct grub_script_argv *argv,
|
||||
struct grub_script *script)
|
||||
{
|
||||
if (argv->scripts[argv->argc - 1])
|
||||
grub_script_put (argv->scripts[argv->argc - 1]);
|
||||
|
||||
argv->scripts[argv->argc - 1] = grub_script_get (script);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Split `s' and append words as multiple arguments. */
|
||||
int
|
||||
grub_script_argv_split_append (struct grub_script_argv *argv, char *s)
|
||||
|
|
|
@ -199,9 +199,9 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
|
|||
case GRUB_SCRIPT_ARG_TYPE_BLOCK:
|
||||
if (grub_script_argv_append (&result, "{") ||
|
||||
grub_script_argv_append (&result, arg->str) ||
|
||||
grub_script_argv_append (&result, "}") ||
|
||||
grub_script_argv_script_append (&result, arg->block))
|
||||
grub_script_argv_append (&result, "}"))
|
||||
goto fail;
|
||||
result.script = arg->script;
|
||||
break;
|
||||
|
||||
case GRUB_SCRIPT_ARG_TYPE_TEXT:
|
||||
|
@ -326,7 +326,7 @@ grub_script_execute_cmdline (struct grub_script_cmd *cmd)
|
|||
if ((grubcmd->flags & GRUB_COMMAND_FLAG_BLOCKS) &&
|
||||
(grubcmd->flags & GRUB_COMMAND_FLAG_EXTCMD))
|
||||
ret = grub_extcmd_dispatcher (grubcmd, argv.argc - 1, argv.args + 1,
|
||||
argv.scripts + 1);
|
||||
argv.script);
|
||||
else
|
||||
ret = (grubcmd->func) (grubcmd, argv.argc - 1, argv.args + 1);
|
||||
}
|
||||
|
|
|
@ -78,7 +78,8 @@
|
|||
%token <arg> GRUB_PARSER_TOKEN_NAME "name"
|
||||
%token <arg> GRUB_PARSER_TOKEN_WORD "word"
|
||||
|
||||
%type <arglist> word argument block parameters0 parameters1 arguments0 arguments1
|
||||
%type <arg> block block0
|
||||
%type <arglist> word argument parameters0 parameters1 arguments0 arguments1
|
||||
|
||||
%type <cmd> script_init script
|
||||
%type <cmd> grubcmd ifclause ifcmd forcmd whilecmd untilcmd
|
||||
|
@ -157,21 +158,22 @@ block: "{"
|
|||
commands1 delimiters0 "}"
|
||||
{
|
||||
char *p;
|
||||
struct grub_script_arg *arg;
|
||||
struct grub_script_mem *memory;
|
||||
|
||||
memory = grub_script_mem_record_stop (state, $<memory>2);
|
||||
if ((p = grub_script_lexer_record_stop (state, $<offset>2)))
|
||||
*grub_strrchr (p, '}') = '\0';
|
||||
|
||||
arg = grub_script_arg_add (state, 0, GRUB_SCRIPT_ARG_TYPE_BLOCK, p);
|
||||
if (! arg || ! (arg->block = grub_script_create ($3, memory)))
|
||||
$$ = grub_script_arg_add (state, 0, GRUB_SCRIPT_ARG_TYPE_BLOCK, p);
|
||||
if (! $$ || ! ($$->script = grub_script_create ($3, memory)))
|
||||
grub_script_mem_free (memory);
|
||||
|
||||
$$ = grub_script_add_arglist (state, 0, arg);
|
||||
grub_script_lexer_deref (state->lexerstate);
|
||||
}
|
||||
;
|
||||
block0: /* Empty */ { $$ = 0; }
|
||||
| block { $$ = $1; }
|
||||
;
|
||||
|
||||
arguments0: /* Empty */ { $$ = 0; }
|
||||
| arguments1 { $$ = $1; }
|
||||
|
@ -198,27 +200,22 @@ parameters1: argument parameters0
|
|||
}
|
||||
$$ = $1;
|
||||
}
|
||||
| block parameters0
|
||||
{
|
||||
if ($1 && $2)
|
||||
{
|
||||
$1->next = $2;
|
||||
$1->argcount += $2->argcount;
|
||||
$2->argcount = 0;
|
||||
}
|
||||
$$ = $1;
|
||||
}
|
||||
;
|
||||
parameters0: /* Empty */ { $$ = 0; }
|
||||
| parameters1 { $$ = $1; }
|
||||
;
|
||||
|
||||
grubcmd: word parameters0
|
||||
grubcmd: word parameters0 block0
|
||||
{
|
||||
if ($1 && $2) {
|
||||
$1->next = $2;
|
||||
$1->argcount += $2->argcount;
|
||||
$2->argcount = 0;
|
||||
struct grub_script_arglist *x = $2;
|
||||
|
||||
if ($3)
|
||||
x = grub_script_add_arglist (state, $2, $3);
|
||||
|
||||
if ($1 && x) {
|
||||
$1->next = x;
|
||||
$1->argcount += x->argcount;
|
||||
x->argcount = 0;
|
||||
}
|
||||
$$ = grub_script_create_cmdline (state, $1);
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ grub_script_arg_add (struct grub_parser_param *state,
|
|||
return arg;
|
||||
|
||||
argpart->type = type;
|
||||
argpart->block = 0;
|
||||
argpart->script = 0;
|
||||
|
||||
len = grub_strlen (str) + 1;
|
||||
argpart->str = grub_script_malloc (state, len);
|
||||
|
|
Loading…
Reference in a new issue