discover/grub2: Implement statement blocks
[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_statement_simple {
22         struct grub2_argv       *argv;
23 };
24
25 struct grub2_statement_menuentry {
26         struct grub2_argv       *argv;
27         struct grub2_statements *statements;
28 };
29
30 struct grub2_statement_if {
31         struct grub2_statement  *condition;
32         struct grub2_statements *true_case;
33         struct grub2_statements *false_case;
34 };
35
36 struct grub2_statement_block {
37         struct grub2_statements *statements;
38 };
39
40 struct grub2_statement {
41         struct list_item        list;
42         enum {
43                 STMT_TYPE_SIMPLE,
44                 STMT_TYPE_MENUENTRY,
45                 STMT_TYPE_IF,
46                 STMT_TYPE_BLOCK,
47         } type;
48         union {
49                 struct grub2_statement_simple           simple;
50                 struct grub2_statement_menuentry        menuentry;
51                 struct grub2_statement_if               ifstmt;
52                 struct grub2_statement_block            block;
53         };
54 };
55
56 struct grub2_statements {
57         struct list             list;
58 };
59
60 struct grub2_parser {
61         void                    *scanner;
62         struct grub2_statements *statements;
63 };
64
65 struct grub2_statements *create_statements(struct grub2_parser *parser);
66
67 struct grub2_statement *create_statement_simple(struct grub2_parser *parser,
68                 struct grub2_argv *argv);
69
70 struct grub2_statement *create_statement_menuentry(struct grub2_parser *parser,
71                 struct grub2_argv *argv, struct grub2_statements *stmts);
72
73 struct grub2_statement *create_statement_if(struct grub2_parser *parser,
74                 struct grub2_statement *condition,
75                 struct grub2_statements *true_case,
76                 struct grub2_statements *false_case);
77
78 struct grub2_statement *create_statement_block(struct grub2_parser *parser,
79                 struct grub2_statements *stmts);
80
81 struct grub2_word *create_word(struct grub2_parser *parser, const char *text,
82                 bool expand, bool split);
83
84 struct grub2_argv *create_argv(struct grub2_parser *parser);
85
86 void statement_append(struct grub2_statements *stmts,
87                 struct grub2_statement *stmt);
88
89 void argv_append(struct grub2_argv *argv, struct grub2_word *word);
90
91 void word_append(struct grub2_word *w1, struct grub2_word *w2);
92
93 #endif /* GRUB2_H */
94