7 struct statement_list_s
9 oconfig_item_t *statement;
12 typedef struct statement_list_s statement_list_t;
14 struct argument_list_s
16 oconfig_value_t *argument;
19 typedef struct argument_list_s argument_list_t;
21 static char *unquote (const char *orig);
22 static void dump_ci (oconfig_item_t *ci, int shift);
37 %token <number> NUMBER
38 %token <boolean> TRUE FALSE
39 %token <string> QUOTED_STRING UNQUOTED_STRING
40 %token SLASH OPENBRAC CLOSEBRAC EOL
43 %type <string> identifier
46 %type <al> argument_list
48 %type <ci> block_begin
50 %type <string> block_end
54 %type <sl> statement_list
55 %type <ci> entire_file
59 QUOTED_STRING {$$ = unquote ($1);}
60 | UNQUOTED_STRING {$$ = strdup ($1);}
64 NUMBER {$$.value.number = $1; $$.type = OCONFIG_TYPE_NUMBER;}
65 | TRUE {$$.value.boolean = 1; $$.type = OCONFIG_TYPE_BOOLEAN;}
66 | FALSE {$$.value.boolean = 0; $$.type = OCONFIG_TYPE_BOOLEAN;}
67 | string {$$.value.string = $1; $$.type = OCONFIG_TYPE_STRING;}
71 argument_list argument
75 $$.argument = realloc ($$.argument, $$.argument_num * sizeof (oconfig_value_t));
76 $$.argument[$$.argument_num-1] = $2;
80 $$.argument = malloc (sizeof (oconfig_value_t));
87 UNQUOTED_STRING {$$ = strdup ($1);}
91 identifier argument_list EOL
93 memset (&$$, '\0', sizeof ($$));
95 $$.values = $2.argument;
96 $$.values_num = $2.argument_num;
101 OPENBRAC identifier argument_list CLOSEBRAC EOL
103 memset (&$$, '\0', sizeof ($$));
105 $$.values = $3.argument;
106 $$.values_num = $3.argument_num;
111 OPENBRAC SLASH identifier CLOSEBRAC EOL
118 block_begin statement_list block_end
120 if (strcmp ($1.key, $3) != 0)
122 printf ("block_begin = %s; block_end = %s;\n", $1.key, $3);
123 yyerror ("Block not closed..\n");
127 $$.children = $2.statement;
128 $$.children_num = $2.statement_num;
135 | EOL {$$.values_num = 0;}
139 statement_list statement
142 if ($2.values_num > 0)
145 $$.statement = realloc ($$.statement, $$.statement_num * sizeof (oconfig_item_t));
146 $$.statement[$$.statement_num-1] = $2;
151 if ($1.values_num > 0)
153 $$.statement = malloc (sizeof (oconfig_item_t));
154 $$.statement[0] = $1;
155 $$.statement_num = 1;
160 $$.statement_num = 0;
168 $$.children = $1.statement;
169 $$.children_num = $1.statement.num;
174 static char *unquote (const char *orig)
176 char *ret = strdup (orig);
185 if ((len < 2) || (ret[0] != '"') || (ret[len - 1] != '"'))
192 for (i = 0; i < len; i++)
196 memmove (ret + i, ret + (i + 1), len - i);
202 } /* char *unquote */
204 static void dump_ci (oconfig_item_t *ci, int shift)
209 printf ("%*s", shift, "");
211 printf ("%s", ci->key);
212 for (i = 0; i < ci->values_num; i++)
214 oconfig_value_t cv = ci->values[i];
216 if (cv.type == OCONFIG_TYPE_STRING)
217 printf (" `%s'", cv.value.string);
218 else if (cv.type == OCONFIG_TYPE_NUMBER)
219 printf (" %lf", cv.value.number);
220 else if (cv.type == OCONFIG_TYPE_BOOLEAN)
221 printf (" %s", cv.value.boolean ? "true" : "false");
223 printf ("<unknown type %i>", cv.type);
227 for (i = 0; i < ci->children_num; i++)
228 dump_ci (ci->children + i, shift + 1);