7 static char *unquote (const char *orig);
8 static void dump_ci (oconfig_item_t *ci, int shift);
23 %token <number> NUMBER
24 %token <boolean> TRUE FALSE
25 %token <string> QUOTED_STRING UNQUOTED_STRING
26 %token SLASH OPENBRAC CLOSEBRAC EOL
29 %type <string> identifier
32 %type <al> argument_list
34 %type <ci> block_begin
36 %type <string> block_end
40 %type <sl> statement_list
41 %type <ci> entire_file
45 QUOTED_STRING {$$ = unquote ($1);}
46 | UNQUOTED_STRING {$$ = strdup ($1);}
50 NUMBER {$$.value.number = $1; $$.type = OCONFIG_TYPE_NUMBER;}
51 | TRUE {$$.value.boolean = 1; $$.type = OCONFIG_TYPE_BOOLEAN;}
52 | FALSE {$$.value.boolean = 0; $$.type = OCONFIG_TYPE_BOOLEAN;}
53 | string {$$.value.string = $1; $$.type = OCONFIG_TYPE_STRING;}
57 argument_list argument
61 $$.argument = realloc ($$.argument, $$.argument_num * sizeof (oconfig_value_t));
62 $$.argument[$$.argument_num-1] = $2;
66 $$.argument = malloc (sizeof (oconfig_value_t));
73 UNQUOTED_STRING {$$ = strdup ($1);}
77 identifier argument_list EOL
79 memset (&$$, '\0', sizeof ($$));
81 $$.values = $2.argument;
82 $$.values_num = $2.argument_num;
87 OPENBRAC identifier argument_list CLOSEBRAC EOL
89 memset (&$$, '\0', sizeof ($$));
91 $$.values = $3.argument;
92 $$.values_num = $3.argument_num;
97 OPENBRAC SLASH identifier CLOSEBRAC EOL
104 block_begin statement_list block_end
106 if (strcmp ($1.key, $3) != 0)
108 printf ("block_begin = %s; block_end = %s;\n", $1.key, $3);
109 yyerror ("Block not closed..\n");
113 $$.children = $2.statement;
114 $$.children_num = $2.statement_num;
121 | EOL {$$.values_num = 0;}
125 statement_list statement
128 if ($2.values_num > 0)
131 $$.statement = realloc ($$.statement, $$.statement_num * sizeof (oconfig_item_t));
132 $$.statement[$$.statement_num-1] = $2;
137 if ($1.values_num > 0)
139 $$.statement = malloc (sizeof (oconfig_item_t));
140 $$.statement[0] = $1;
141 $$.statement_num = 1;
146 $$.statement_num = 0;
154 $$.children = $1.statement;
155 $$.children_num = $1.statement_num;
164 static char *unquote (const char *orig)
166 char *ret = strdup (orig);
175 if ((len < 2) || (ret[0] != '"') || (ret[len - 1] != '"'))
182 for (i = 0; i < len; i++)
186 memmove (ret + i, ret + (i + 1), len - i);
192 } /* char *unquote */
194 static void dump_ci (oconfig_item_t *ci, int shift)
199 printf ("%*s", shift, "");
201 printf ("%s", ci->key);
202 for (i = 0; i < ci->values_num; i++)
204 oconfig_value_t cv = ci->values[i];
206 if (cv.type == OCONFIG_TYPE_STRING)
207 printf (" `%s'", cv.value.string);
208 else if (cv.type == OCONFIG_TYPE_NUMBER)
209 printf (" %lf", cv.value.number);
210 else if (cv.type == OCONFIG_TYPE_BOOLEAN)
211 printf (" %s", cv.value.boolean ? "true" : "false");
213 printf ("<unknown type %i>", cv.type);
217 for (i = 0; i < ci->children_num; i++)
218 dump_ci (ci->children + i, shift + 1);