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 char *unquote (const char *orig);
21 static void dump_ci (oconfig_item_t *ci, int shift);
36 %token <number> NUMBER
37 %token <boolean> TRUE FALSE
38 %token <string> QUOTED_STRING UNQUOTED_STRING
39 %token SLASH OPENBRAC CLOSEBRAC EOL
42 %type <string> identifier
45 %type <al> argument_list
47 %type <ci> block_begin
49 %type <string> block_end
53 %type <sl> statement_list
54 %type <ci> entire_file
58 QUOTED_STRING {$$ = unquote ($1);}
59 | UNQUOTED_STRING {$$ = strdup ($1);}
63 NUMBER {$$.value.number = $1; $$.type = OCONFIG_TYPE_NUMBER;}
64 | TRUE {$$.value.boolean = 1; $$.type = OCONFIG_TYPE_BOOLEAN;}
65 | FALSE {$$.value.boolean = 0; $$.type = OCONFIG_TYPE_BOOLEAN;}
66 | string {$$.value.string = $1; $$.type = OCONFIG_TYPE_STRING;}
70 argument_list argument
74 $$.argument = realloc ($$.argument, $$.argument_num * sizeof (oconfig_value_t));
75 $$.argument[$$.argument_num-1] = $2;
79 $$.argument = malloc (sizeof (oconfig_value_t));
86 UNQUOTED_STRING {$$ = strdup ($1);}
90 identifier argument_list EOL
92 memset (&$$, '\0', sizeof ($$));
94 $$.values = $2.argument;
95 $$.values_num = $2.argument_num;
100 OPENBRAC identifier argument_list CLOSEBRAC EOL
102 memset (&$$, '\0', sizeof ($$));
104 $$.values = $3.argument;
105 $$.values_num = $3.argument_num;
110 OPENBRAC SLASH identifier CLOSEBRAC EOL
117 block_begin statement_list block_end
119 if (strcmp ($1.key, $3) != 0)
121 printf ("block_begin = %s; block_end = %s;\n", $1.key, $3);
122 yyerror ("Block not closed..\n");
126 $$.children = $2.statement;
127 $$.children_num = $2.statement_num;
134 | EOL {$$.values_num = 0;}
138 statement_list statement
141 if ($2.values_num > 0)
144 $$.statement = realloc ($$.statement, $$.statement_num * sizeof (oconfig_item_t));
145 $$.statement[$$.statement_num-1] = $2;
150 if ($1.values_num > 0)
152 $$.statement = malloc (sizeof (oconfig_item_t));
153 $$.statement[0] = $1;
154 $$.statement_num = 1;
159 $$.statement_num = 0;
167 $$.children = $1.statement;
168 $$.children_num = $1.statement_num;
175 static char *unquote (const char *orig)
177 char *ret = strdup (orig);
186 if ((len < 2) || (ret[0] != '"') || (ret[len - 1] != '"'))
193 for (i = 0; i < len; i++)
197 memmove (ret + i, ret + (i + 1), len - i);
203 } /* char *unquote */
205 static void dump_ci (oconfig_item_t *ci, int shift)
210 printf ("%*s", shift, "");
212 printf ("%s", ci->key);
213 for (i = 0; i < ci->values_num; i++)
215 oconfig_value_t cv = ci->values[i];
217 if (cv.type == OCONFIG_TYPE_STRING)
218 printf (" `%s'", cv.value.string);
219 else if (cv.type == OCONFIG_TYPE_NUMBER)
220 printf (" %lf", cv.value.number);
221 else if (cv.type == OCONFIG_TYPE_BOOLEAN)
222 printf (" %s", cv.value.boolean ? "true" : "false");
224 printf ("<unknown type %i>", cv.type);
228 for (i = 0; i < ci->children_num; i++)
229 dump_ci (ci->children + i, shift + 1);