07a1e6c7fe3517deb46e4786472cab0312a82f64
[petitboot] / discover / grub2 / grub2.h
1 #ifndef GRUB2_H
2 #define GRUB2_H
3
4 #include <regex.h>
5 #include <stdbool.h>
6 #include <list/list.h>
7
8 struct grub2_script;
9
10 struct grub2_word {
11         const char              *text;
12         bool                    expand;
13         bool                    split;
14         struct grub2_word       *next;
15         struct list_item        argv_list;
16 };
17
18 struct grub2_argv {
19         struct list             words;
20 };
21
22 struct grub2_statements {
23         struct list             list;
24 };
25
26 struct grub2_statement {
27         struct list_item        list;
28         enum {
29                 STMT_TYPE_SIMPLE,
30                 STMT_TYPE_MENUENTRY,
31                 STMT_TYPE_IF,
32                 STMT_TYPE_BLOCK,
33         } type;
34         int                     (*exec)(struct grub2_script *,
35                                         struct grub2_statement *);
36 };
37
38 struct grub2_statement_simple {
39         struct grub2_statement  st;
40         struct grub2_argv       *argv;
41 };
42
43 struct grub2_statement_menuentry {
44         struct grub2_statement  st;
45         struct grub2_argv       *argv;
46         struct grub2_statements *statements;
47 };
48
49 struct grub2_statement_if {
50         struct grub2_statement  st;
51         struct grub2_statement  *condition;
52         struct grub2_statements *true_case;
53         struct grub2_statements *false_case;
54 };
55
56 struct grub2_statement_block {
57         struct grub2_statement  st;
58         struct grub2_statements *statements;
59 };
60
61 struct grub2_script {
62         struct grub2_statements *statements;
63         struct list             environment;
64         regex_t                 var_re;
65 };
66
67 struct grub2_parser {
68         void                    *scanner;
69         struct grub2_script     *script;
70 };
71
72 struct grub2_statements *create_statements(struct grub2_parser *parser);
73
74 struct grub2_statement *create_statement_simple(struct grub2_parser *parser,
75                 struct grub2_argv *argv);
76
77 struct grub2_statement *create_statement_menuentry(struct grub2_parser *parser,
78                 struct grub2_argv *argv, struct grub2_statements *stmts);
79
80 struct grub2_statement *create_statement_if(struct grub2_parser *parser,
81                 struct grub2_statement *condition,
82                 struct grub2_statements *true_case,
83                 struct grub2_statements *false_case);
84
85 struct grub2_statement *create_statement_block(struct grub2_parser *parser,
86                 struct grub2_statements *stmts);
87
88 struct grub2_word *create_word(struct grub2_parser *parser, const char *text,
89                 bool expand, bool split);
90
91 struct grub2_argv *create_argv(struct grub2_parser *parser);
92
93 void statement_append(struct grub2_statements *stmts,
94                 struct grub2_statement *stmt);
95
96 void argv_append(struct grub2_argv *argv, struct grub2_word *word);
97
98 void word_append(struct grub2_word *w1, struct grub2_word *w2);
99
100 /* script interface */
101 void script_execute(struct grub2_script *script);
102
103 int statement_simple_execute(struct grub2_script *script,
104                 struct grub2_statement *statement);
105 int statement_if_execute(struct grub2_script *script,
106                 struct grub2_statement *statement);
107
108 struct grub2_script *create_script(void *ctx);
109
110 #endif /* GRUB2_H */
111