Adjustments of the language, added copyright notice and license information, ...
[liboconfig.git] / src / parser.y
index 7f048d0..6d1de2d 100644 (file)
@@ -1,3 +1,21 @@
+/**
+ * oconfig - src/parser.y
+ * Copyright (C) 2007  Florian octo Forster <octo at verplant.org>
+ *
+ * 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 <stdlib.h>
 #include <string.h>
@@ -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 ("<unknown type %i>", cv.type);
-       }
-       printf ("\n");
-
-       for (i = 0; i < ci->children_num; i++)
-               dump_ci (ci->children + i, shift + 1);
-}