log: Allow runtime selection of 'debug' log level
[petitboot] / discover / grub2 / grub2.h
index de74fa5a46e43e8ed92c68beb800036a376e215d..e79bf41d4b655598a3019394a0c2f5ccbbac0ca3 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef GRUB2_H
 #define GRUB2_H
 
+#include <discover/device-handler.h>
+
 #include <stdbool.h>
 #include <list/list.h>
 
@@ -12,12 +14,10 @@ struct grub2_word {
                GRUB2_WORD_VAR,
        } type;
        union {
-               char    *text;
-               struct {
-                       const char      *name;
-                       bool            split;
-               } var;
+               char            *text;
+               const char      *name;
        };
+       bool                    split;
        struct grub2_word       *next;
        struct grub2_word       *last;
        struct list_item        argv_list;
@@ -25,6 +25,11 @@ struct grub2_word {
 
 struct grub2_argv {
        struct list             words;
+
+       /* postprocessing (with process_expansions) populates these to hand to
+        * the grub2_command callbacks */
+       char                    **argv;
+       int                     argc;
 };
 
 struct grub2_statements {
@@ -38,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 *);
@@ -54,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 {
@@ -66,9 +77,27 @@ struct grub2_statement_block {
        struct grub2_statements *statements;
 };
 
+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 grub2_statements         *statements;
+       struct list                     environment;
+       struct list                     symtab;
+       struct discover_context         *ctx;
+       struct discover_boot_option     *opt;
+       const char                      *filename;
+       unsigned int                    n_options;
 };
 
 struct grub2_parser {
@@ -76,6 +105,10 @@ struct grub2_parser {
        struct grub2_script     *script;
 };
 
+/* 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);
 
 struct grub2_statement *create_statement_simple(struct grub2_parser *parser,
@@ -84,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);
 
@@ -112,12 +156,41 @@ 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);
+
+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_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(struct discover_boot_option *opt,
+               struct discover_device *orig_device,
+               const char *root, const char *path);
 
-struct grub2_script *create_script(void *ctx);
+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, const char *filename,
+               char *buf, int len);
 #endif /* GRUB2_H */