X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fparser.y;h=6d1de2d6c01e65b8e6ce9023555ff88f6e5be860;hb=d7ead7bd0d32daa0b8ca55213b18ba7e327648f0;hp=7f048d0d90b7a26fa8d863b1dd6f5dddc84cea29;hpb=5c7aa9c49ae9928ea26c4baa50d92bbbd16d5b64;p=liboconfig.git diff --git a/src/parser.y b/src/parser.y index 7f048d0..6d1de2d 100644 --- a/src/parser.y +++ b/src/parser.y @@ -1,3 +1,21 @@ +/** + * oconfig - src/parser.y + * Copyright (C) 2007 Florian octo Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; only version 2 of the License is applicable. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + %{ #include #include @@ -5,7 +23,13 @@ #include "aux_types.h" static char *unquote (const char *orig); -static void dump_ci (oconfig_item_t *ci, int shift); +static int yyerror (const char *s); + +/* Lexer variables */ +extern int yylineno; +extern char *yytext; + +extern oconfig_item_t *ci_root; %} %start entire_file @@ -151,15 +175,19 @@ statement_list: entire_file: statement_list { - $$.children = $1.statement; - $$.children_num = $1.statement_num; + ci_root = malloc (sizeof (oconfig_item_t)); + memset (ci_root, '\0', sizeof (oconfig_item_t)); + ci_root->children = $1.statement; + ci_root->children_num = $1.statement_num; } ; %% -#if 0 -#include "scanner.c" -#endif +static int yyerror (const char *s) +{ + fprintf (stderr, "Error in line %i near `%s': %s\n", yylineno, yytext, s); + return (-1); +} /* int yyerror */ static char *unquote (const char *orig) { @@ -190,30 +218,3 @@ static char *unquote (const char *orig) return (ret); } /* char *unquote */ - -static void dump_ci (oconfig_item_t *ci, int shift) -{ - int i; - - if (shift > 0) - printf ("%*s", shift, ""); - - printf ("%s", ci->key); - for (i = 0; i < ci->values_num; i++) - { - oconfig_value_t cv = ci->values[i]; - - if (cv.type == OCONFIG_TYPE_STRING) - printf (" `%s'", cv.value.string); - else if (cv.type == OCONFIG_TYPE_NUMBER) - printf (" %lf", cv.value.number); - else if (cv.type == OCONFIG_TYPE_BOOLEAN) - printf (" %s", cv.value.boolean ? "true" : "false"); - else - printf ("", cv.type); - } - printf ("\n"); - - for (i = 0; i < ci->children_num; i++) - dump_ci (ci->children + i, shift + 1); -}