log: Allow runtime selection of 'debug' log level
[petitboot] / discover / grub2 / grub2.h
index 1ac9f88db896b257d38c8c9c0347f0b7857b44d7..e79bf41d4b655598a3019394a0c2f5ccbbac0ca3 100644 (file)
@@ -43,6 +43,7 @@ struct grub2_statement {
                STMT_TYPE_MENUENTRY,
                STMT_TYPE_IF,
                STMT_TYPE_BLOCK,
+               STMT_TYPE_CONDITIONAL,
        } type;
        int                     (*exec)(struct grub2_script *,
                                        struct grub2_statement *);
@@ -59,11 +60,16 @@ struct grub2_statement_menuentry {
        struct grub2_statements *statements;
 };
 
-struct grub2_statement_if {
+struct grub2_statement_conditional {
        struct grub2_statement  st;
        struct grub2_statement  *condition;
-       struct grub2_statements *true_case;
-       struct grub2_statements *false_case;
+       struct grub2_statements *statements;
+};
+
+struct grub2_statement_if {
+       struct grub2_statement  st;
+       struct grub2_statements *conditionals;
+       struct grub2_statements *else_case;
 };
 
 struct grub2_statement_block {
@@ -71,20 +77,27 @@ struct grub2_statement_block {
        struct grub2_statements *statements;
 };
 
-struct grub2_command {
-       const char              *name;
-       int                     (*exec)(struct grub2_script *script,
-                                       int argc, char *argv[]);
-       struct list_item        list;
+struct grub2_statement_function {
+       struct grub2_statement  st;
+       struct grub2_word       *name;
+       struct grub2_statements *body;
+};
+
+struct grub2_statement_for {
+       struct grub2_statement  st;
+       struct grub2_word       *var;
+       struct grub2_argv       *list;
+       struct grub2_statements *body;
 };
 
 struct grub2_script {
        struct grub2_statements         *statements;
        struct list                     environment;
-       struct list                     commands;
        struct list                     symtab;
        struct discover_context         *ctx;
        struct discover_boot_option     *opt;
+       const char                      *filename;
+       unsigned int                    n_options;
 };
 
 struct grub2_parser {
@@ -92,9 +105,9 @@ struct grub2_parser {
        struct grub2_script     *script;
 };
 
-struct grub2_root {
-       char *uuid;
-};
+/* type for builtin functions */
+typedef int (*grub2_function)(struct grub2_script *script, void *data,
+                               int argc, char *argv[]);
 
 struct grub2_statements *create_statements(struct grub2_parser *parser);
 
@@ -104,14 +117,25 @@ struct grub2_statement *create_statement_simple(struct grub2_parser *parser,
 struct grub2_statement *create_statement_menuentry(struct grub2_parser *parser,
                struct grub2_argv *argv, struct grub2_statements *stmts);
 
+struct grub2_statement *create_statement_conditional(
+               struct grub2_parser *parser, struct grub2_statement *condition,
+               struct grub2_statements *statements);
+
 struct grub2_statement *create_statement_if(struct grub2_parser *parser,
-               struct grub2_statement *condition,
-               struct grub2_statements *true_case,
-               struct grub2_statements *false_case);
+               struct grub2_statement *conditional,
+               struct grub2_statements *elifs,
+               struct grub2_statements *else_case);
 
 struct grub2_statement *create_statement_block(struct grub2_parser *parser,
                struct grub2_statements *stmts);
 
+struct grub2_statement *create_statement_function(struct grub2_parser *parser,
+               struct grub2_word *name, struct grub2_statements *body);
+
+struct grub2_statement *create_statement_for(struct grub2_parser *parser,
+               struct grub2_word *var, struct grub2_argv *list,
+               struct grub2_statements *body);
+
 struct grub2_word *create_word_text(struct grub2_parser *parser,
                const char *text);
 
@@ -132,10 +156,16 @@ void script_execute(struct grub2_script *script);
 
 int statement_simple_execute(struct grub2_script *script,
                struct grub2_statement *statement);
+int statement_block_execute(struct grub2_script *script,
+               struct grub2_statement *statement);
 int statement_if_execute(struct grub2_script *script,
                struct grub2_statement *statement);
 int statement_menuentry_execute(struct grub2_script *script,
                struct grub2_statement *statement);
+int statement_function_execute(struct grub2_script *script,
+               struct grub2_statement *statement);
+int statement_for_execute(struct grub2_script *script,
+               struct grub2_statement *statement);
 
 struct grub2_script *create_script(struct grub2_parser *parser,
                struct discover_context *ctx);
@@ -145,24 +175,22 @@ const char *script_env_get(struct grub2_script *script, const char *name);
 void script_env_set(struct grub2_script *script,
                const char *name, const char *value);
 
-void script_register_command(struct grub2_script *script,
-               struct grub2_command *command);
-
-struct grub2_command *script_lookup_command(struct grub2_script *script,
-               const char *name);
+void script_register_function(struct grub2_script *script,
+               const char *name, grub2_function fn, void *data);
 
 void register_builtins(struct grub2_script *script);
 
 /* resources */
-struct resource *create_grub2_resource(void *ctx,
+struct resource *create_grub2_resource(struct discover_boot_option *opt,
                struct discover_device *orig_device,
-               struct grub2_root *root, const char *path);
+               const char *root, const char *path);
 
 bool resolve_grub2_resource(struct device_handler *handler,
                struct resource *res);
 
 /* external parser api */
 struct grub2_parser *grub2_parser_create(struct discover_context *ctx);
-void grub2_parser_parse(struct grub2_parser *parser, char *buf, int len);
+void grub2_parser_parse(struct grub2_parser *parser, const char *filename,
+               char *buf, int len);
 #endif /* GRUB2_H */