6 struct statement_list_s
8 oconfig_item_t *statement;
11 typedef struct statement_list_s statement_list_t;
13 struct argument_list_s
15 oconfig_value_t *argument;
18 typedef struct argument_list_s argument_list_t;
20 static void dump_ci (oconfig_item_t *ci, int shift);
35 %token <number> NUMBER
36 %token <boolean> TRUE FALSE
37 %token <string> QUOTED_STRING UNQUOTED_STRING
38 %token SLASH OPENBRAC CLOSEBRAC EOL
41 %type <string> identifier
44 %type <al> argument_list
46 %type <ci> block_begin
48 %type <string> block_end
52 %type <sl> statement_list
56 QUOTED_STRING {$$ = $1;}
57 | UNQUOTED_STRING {$$ = $1;}
61 NUMBER {$$.value.number = $1; $$.type = OCONFIG_TYPE_NUMBER;}
62 | TRUE {$$.value.boolean = 1; $$.type = OCONFIG_TYPE_BOOLEAN;}
63 | FALSE {$$.value.boolean = 0; $$.type = OCONFIG_TYPE_BOOLEAN;}
64 | string {$$.value.string = $1; $$.type = OCONFIG_TYPE_STRING;}
68 argument_list argument
72 $$.argument = realloc ($$.argument, $$.argument_num * sizeof (oconfig_value_t));
73 $$.argument[$$.argument_num-1] = $2;
77 $$.argument = malloc (sizeof (oconfig_value_t));
84 UNQUOTED_STRING {$$ = $1;}
88 identifier argument_list EOL
90 memset (&$$, '\0', sizeof ($$));
92 $$.values = $2.argument;
93 $$.values_num = $2.argument_num;
98 OPENBRAC identifier argument_list CLOSEBRAC EOL
100 memset (&$$, '\0', sizeof ($$));
102 $$.values = $3.argument;
103 $$.values_num = $3.argument_num;
108 OPENBRAC SLASH identifier CLOSEBRAC EOL
115 block_begin statement_list block_end
117 if (strcmp ($1.key, $3) != 0)
118 yyerror ("Block %s not closed..\n", $1);
120 $$.children = $2.statement;
121 $$.children_num = $2.statement_num;
132 statement_list statement
136 $$.statement = realloc ($$.statement, $$.statement_num * sizeof (oconfig_item_t));
137 $$.statement[$$.statement_num-1] = $2;
141 $$.statement = malloc (sizeof (oconfig_item_t));
142 $$.statement[0] = $1;
143 $$.statement_num = 1;
151 for (i = 0; i < $1.statement_num; i++)
152 dump_ci ($1.statement + i, 0);
160 void yyerror (char *s)
162 fprintf (stderr, "%s\n", s);
167 return (getc (stdin));
171 int main (int argc, char **argv)
177 static void dump_ci (oconfig_item_t *ci, int shift)
182 printf ("%*s", shift, "");
184 printf ("%s", ci->key);
185 for (i = 0; i < ci->values_num; i++)
187 oconfig_value_t cv = ci->values[i];
189 if (cv.type == OCONFIG_TYPE_STRING)
190 printf (" `%s'", cv.value.string);
191 else if (cv.type == OCONFIG_TYPE_NUMBER)
192 printf (" %lf", cv.value.number);
193 else if (cv.type == OCONFIG_TYPE_BOOLEAN)
194 printf (" %s", cv.value.boolean ? "true" : "false");
196 printf ("<unknown type %i>", cv.type);
200 for (i = 0; i < ci->children_num; i++)
201 dump_ci (ci->children + i, shift + 1);