diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2014-01-24 14:40:46 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2014-01-30 21:59:10 +0800 |
commit | 1b272c7d47390077eee0a0638329b1a7df521329 (patch) | |
tree | 43b348731a7db7585050ebc8140790f91232b01a /discover/grub2/script.c | |
parent | e1b713b0c862a93cd3e8cea59070f469510d3c39 (diff) | |
download | talos-petitboot-1b272c7d47390077eee0a0638329b1a7df521329.tar.gz talos-petitboot-1b272c7d47390077eee0a0638329b1a7df521329.zip |
discover/grub2: Add support for for-loops
GRUB2 syntax allows for for-loops; this change adds supoprt in the
parser grammar and script execution code to implement them. In the
execution code, we simply update the for-loop variable and re-execute
the body statements.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'discover/grub2/script.c')
-rw-r--r-- | discover/grub2/script.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/discover/grub2/script.c b/discover/grub2/script.c index bfca607..0618297 100644 --- a/discover/grub2/script.c +++ b/discover/grub2/script.c @@ -19,6 +19,8 @@ container_of(stmt, struct grub2_statement_menuentry, st) #define to_stmt_function(stmt) \ container_of(stmt, struct grub2_statement_function, st) +#define to_stmt_for(stmt) \ + container_of(stmt, struct grub2_statement_for, st) #define to_stmt_conditional(stmt) \ container_of(stmt, struct grub2_statement_conditional, st) @@ -401,6 +403,27 @@ int statement_function_execute(struct grub2_script *script, return 0; } +int statement_for_execute(struct grub2_script *script, + struct grub2_statement *statement) +{ + struct grub2_statement_for *st = to_stmt_for(statement); + const char *varname; + int i, rc = 0; + + if (st->var->type == GRUB2_WORD_VAR) + expand_var(script, st->var); + varname = st->var->text; + + process_expansions(script, st->list); + + for (i = 0; i < st->list->argc; ++i) { + script_env_set(script, varname, st->list->argv[i]); + rc = statements_execute(script, st->body); + } + + return rc; +} + static void init_env(struct grub2_script *script) { struct env_entry *env; |