]> git.ozlabs.org Git - petitboot/blobdiff - discover/grub2/script.c
ui/ncurses: Always provide a key definition for backtab
[petitboot] / discover / grub2 / script.c
index bfca607e1bf3c9266240d6b40873daee94faf56f..36f73b21abfc4a0992a5a8a5540382d6102581c1 100644 (file)
@@ -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)
 
@@ -307,7 +309,7 @@ int statement_if_execute(struct grub2_script *script,
 {
        struct grub2_statement_if *st = to_stmt_if(statement);
        struct grub2_statement *conditional;
-       bool executed;
+       bool executed = false;
        int rc = 0;
 
        list_for_each_entry(&st->conditionals->list, conditional, list) {
@@ -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;