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