6 static oconfig_item_t *ci_root;
7 static oconfig_item_t *ci_current;
9 static oconfig_item_t *statement_list;
10 static int statement_list_num;
12 static oconfig_value_t *argument_list;
13 static int argument_list_num;
15 struct statement_list_s
17 oconfig_item_t *statement;
20 typedef struct statement_list_s statement_list_t;
22 struct argument_list_s
24 oconfig_value_t *argument;
27 typedef struct argument_list_s argument_list_t;
29 static void dump_ci (oconfig_item_t *ci, int shift);
45 %token <number> NUMBER
46 %token <boolean> TRUE FALSE
47 %token <string> QUOTED_STRING UNQUOTED_STRING
48 %token SLASH OPENBRAC CLOSEBRAC EOL
51 %type <string> identifier
52 %type <string> block_end
54 %type <al> argument_list
55 %type <ci> block_begin
59 %type <sl> statement_list
63 QUOTED_STRING {$$ = $1;}
64 | UNQUOTED_STRING {$$ = $1;}
68 NUMBER {$$.value.number = $1; $$.type = OCONFIG_TYPE_NUMBER;}
69 | TRUE {$$.value.boolean = 1; $$.type = OCONFIG_TYPE_BOOLEAN;}
70 | FALSE {$$.value.boolean = 0; $$.type = OCONFIG_TYPE_BOOLEAN;}
71 | string {$$.value.string = $1; $$.type = OCONFIG_TYPE_STRING;}
75 argument_list argument
79 $$.argument = realloc ($$.argument, $$.argument_num * sizeof (argument_list_t));
80 $$.argument[$$.argument_num-1] = $2;
84 $$.argument = malloc (sizeof (argument_list_t));
91 UNQUOTED_STRING {$$ = $1;}
95 identifier argument_list EOL
97 memset (&$$, '\0', sizeof ($$));
99 $$.values = $2.argument;
100 $$.values_num = $2.argument_num;
101 printf ("Option `%s' has %i arguments\n", $$.key, $$.values_num);
106 OPENBRAC identifier argument_list CLOSEBRAC EOL
108 memset (&$$, '\0', sizeof ($$));
110 $$.values = $3.argument;
111 $$.values_num = $3.argument_num;
112 printf ("Begin block `%s'\n", $2);
117 OPENBRAC SLASH identifier CLOSEBRAC EOL {$$ = $3; printf ("End block `%s'\n", $3);}
121 block_begin statement_list block_end
123 if (strcmp ($1.key, $3) != 0)
124 yyerror ("Block %s not closed..\n", $1);
126 $$.children = $2.statement;
137 statement_list statement
141 $$.statement = realloc ($$.statement, $$.statement_num * sizeof (statement_list_t));
142 $$.statement[$$.statement_num-1] = $2;
143 printf ("statement_list: length = %i\n", $$.statement_num);
147 $$.statement = malloc (sizeof (statement_list_t));
148 $$.statement[0] = $1;
149 $$.statement_num = 1;
157 for (i = 0; i < $1.statement_num; i++)
158 dump_ci ($1.statement + i, 0);
166 void yyerror (char *s)
168 fprintf (stderr, "%s\n", s);
173 return (getc (stdin));
177 int main (int argc, char **argv)
183 static void dump_ci (oconfig_item_t *ci, int shift)
188 printf ("%*s", "", shift);
190 printf ("%s", ci->key);
191 for (i = 0; i < ci->values_num; i++)
193 oconfig_value_t cv = ci->values[i];
195 if (cv.type == OCONFIG_TYPE_STRING)
196 printf (" `%s'", cv.value.string);
197 else if (cv.type == OCONFIG_TYPE_NUMBER)
198 printf (" %lf", cv.value.number);
199 else if (cv.type == OCONFIG_TYPE_BOOLEAN)
200 printf (" %s", cv.value.boolean ? "true" : "false");
202 printf ("<unknown type %i>", cv.type);
206 for (i = 0; i < ci->children_num; i++)
207 dump_ci (ci->children + i, shift + 1);