175 |
/* Create an argument with TEXT, value type TYPE, and value VAL. |
/* Create an argument with TEXT, value type TYPE, and value VAL. |
176 |
Add the argument to the argument list of CMD. */ |
Add the argument to the argument list of CMD. */ |
177 |
static struct arg * |
static struct arg * |
178 |
add_arg (struct cmd *cmd, char *text, int type, int val) |
add_arg (struct cmd *cmd, const char *text, int textlen, int type, int val) |
179 |
{ |
{ |
180 |
struct arg *arg; |
struct arg *arg; |
181 |
|
|
182 |
arg = boot_script_malloc (sizeof (struct arg)); |
arg = boot_script_malloc (sizeof (struct arg) + textlen); |
183 |
if (arg) |
if (arg) |
184 |
{ |
{ |
185 |
arg->text = text; |
arg->text = text == 0 ? 0 : memcpy (arg + 1, text, textlen); |
186 |
arg->type = type; |
arg->type = type; |
187 |
arg->val = val; |
arg->val = val; |
188 |
if (add_list (arg, (void ***) &cmd->args, |
if (add_list (arg, (void ***) &cmd->args, |
255 |
if (p == q) |
if (p == q) |
256 |
return 0; |
return 0; |
257 |
|
|
258 |
*q = '\0'; |
*q++ = '\0'; |
259 |
|
|
260 |
/* Allocate a command structure. */ |
/* Allocate a command structure. */ |
261 |
cmd = boot_script_malloc (sizeof (struct cmd)); |
cmd = boot_script_malloc (sizeof (struct cmd) + (q - p)); |
262 |
if (! cmd) |
if (! cmd) |
263 |
return BOOT_SCRIPT_NOMEM; |
return BOOT_SCRIPT_NOMEM; |
264 |
memset (cmd, 0, sizeof (struct cmd)); |
memset (cmd, 0, sizeof (struct cmd)); |
265 |
cmd->hook = hook; |
cmd->hook = hook; |
266 |
cmd->path = p; |
cmd->path = memcpy (cmd + 1, p, q - p); |
267 |
p = q + 1; |
p = q; |
268 |
|
|
269 |
for (arg = 0;;) |
for (arg = 0;;) |
270 |
{ |
{ |
408 |
associated with an argument. */ |
associated with an argument. */ |
409 |
if (! arg && end_char == '}') |
if (! arg && end_char == '}') |
410 |
{ |
{ |
411 |
if (! add_arg (cmd, 0, type, val)) |
if (! add_arg (cmd, 0, 0, type, val)) |
412 |
{ |
{ |
413 |
error = BOOT_SCRIPT_NOMEM; |
error = BOOT_SCRIPT_NOMEM; |
414 |
goto bad; |
goto bad; |
437 |
*q = '\0'; |
*q = '\0'; |
438 |
|
|
439 |
/* Add argument to list. */ |
/* Add argument to list. */ |
440 |
arg = add_arg (cmd, p, VAL_NONE, 0); |
arg = add_arg (cmd, p, q + 1 - p, VAL_NONE, 0); |
441 |
if (! arg) |
if (! arg) |
442 |
{ |
{ |
443 |
error = BOOT_SCRIPT_NOMEM; |
error = BOOT_SCRIPT_NOMEM; |