]> git.ozlabs.org Git - petitboot/blob - discover/grub2/parser-api.c
37c88a264d750590f282bf0bfa39262ec9b7c2f5
[petitboot] / discover / grub2 / parser-api.c
1
2 #include <talloc/talloc.h>
3
4 #include "grub2.h"
5
6 struct grub2_statements *create_statements(struct grub2_parser *parser)
7 {
8         struct grub2_statements *stmts = talloc(parser,
9                         struct grub2_statements);
10         list_init(&stmts->list);
11         return stmts;
12 }
13
14 struct grub2_statement *create_statement_simple(struct grub2_parser *parser,
15                 struct grub2_argv *argv)
16 {
17         struct grub2_statement *stmt = talloc(parser, struct grub2_statement);
18         stmt->type = STMT_TYPE_SIMPLE;
19         stmt->simple.argv = argv;
20         return stmt;
21 }
22
23 struct grub2_statement *create_statement_menuentry(struct grub2_parser *parser,
24                 struct grub2_argv *argv, struct grub2_statements *stmts)
25 {
26         struct grub2_statement *stmt = talloc(parser, struct grub2_statement);
27         stmt->type = STMT_TYPE_MENUENTRY;
28         stmt->menuentry.argv = argv;
29         stmt->menuentry.statements = stmts;
30         return stmt;
31 }
32
33 struct grub2_statement *create_statement_if(struct grub2_parser *parser,
34                 struct grub2_statement *condition,
35                 struct grub2_statements *true_case,
36                 struct grub2_statements *false_case)
37 {
38         struct grub2_statement *stmt = talloc(parser, struct grub2_statement);
39         stmt->type = STMT_TYPE_IF;
40         stmt->ifstmt.condition = condition;
41         stmt->ifstmt.true_case = true_case;
42         stmt->ifstmt.false_case = false_case;
43         return stmt;
44 }
45
46 struct grub2_statement *create_statement_block(struct grub2_parser *parser,
47                 struct grub2_statements *stmts)
48 {
49         struct grub2_statement *stmt = talloc(parser, struct grub2_statement);
50         stmt->type = STMT_TYPE_BLOCK;
51         stmt->block.statements = stmts;
52         return stmt;
53 }
54
55 void statement_append(struct grub2_statements *stmts,
56                 struct grub2_statement *stmt)
57 {
58         if (!stmt)
59                 return;
60         list_add_tail(&stmts->list, &stmt->list);
61 }
62
63 struct grub2_word *create_word(struct grub2_parser *parser, const char *text,
64                 bool expand, bool split)
65 {
66         struct grub2_word *word = talloc(parser, struct grub2_word);
67         word->text = talloc_strdup(word, text);
68         word->expand = expand;
69         word->split = split;
70         word->next = NULL;
71         return word;
72 }
73
74 struct grub2_argv *create_argv(struct grub2_parser *parser)
75 {
76         struct grub2_argv *argv = talloc(parser, struct grub2_argv);
77         list_init(&argv->words);
78         return argv;
79 }
80
81 void argv_append(struct grub2_argv *argv, struct grub2_word *word)
82 {
83         list_add_tail(&argv->words, &word->argv_list);
84 }
85
86 void word_append(struct grub2_word *w1, struct grub2_word *w2)
87 {
88         w1->next = w2;
89 }