]> Dogcows Code - chaz/openbox/blobdiff - openbox/cparse.l
dont lower below lower layers
[chaz/openbox] / openbox / cparse.l
index 5a077493f8de04c080c763cfef1d2330450caf3d..70524007b91f1628ec461e3bcb07f3d08b5e9be4 100644 (file)
@@ -2,17 +2,18 @@
 #include <glib.h>
 #include "config.h"
 
-static char *yyfilename;
-static int yylineno = 1;
+static char *filename;
+static int lineno = 1;
 static gboolean haserror = FALSE;
 static gboolean comment = FALSE;
 static ConfigEntry entry = { NULL, -1 };
 
 static void stringvalue();
 static void numbervalue();
+static void boolvalue();
 static void identifier();
 static void newline();
-static int yywrap();
+static int cparsewrap();
 %}
 
 number [0-9]+
@@ -20,17 +21,19 @@ string \"[^"\n]*\"
 identifier [a-zA-Z][a-zA-Z0-9_.]*
 white [ \t]*
 assign {white}={white}
+bool ([tT][rR][uU][eE]|[fF][aA][lL][sS][eE]|[yY][eE][sS]|[nN][oO]|[oO][nN]|[oO][fF][fF])
 
 %%
 
+^{white}# comment = TRUE;
+{bool}/{white}\n boolvalue();
 {string}/{white}\n stringvalue();
 {number}/{white}\n numbervalue();
 ^{identifier}/{assign} identifier();
 \n newline();
-^# comment = TRUE;
 =
 [ \t]
-. haserror = TRUE;
+. if (!comment) haserror = TRUE;
 
 %%
 
@@ -39,12 +42,12 @@ static void stringvalue()
     if (!comment) {
         if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
             entry.type = Config_String;
-            entry.value.string = g_strdup(yytext+1); /* drop the left quote */
-            if (entry.value.string[yyleng-2] != '"')
-                printf("warning: improperly terminated string on line %d\n",
-                       yylineno);
+            entry.value.string = g_strdup(cparsetext+1); /* drop the left quote */
+            if (entry.value.string[cparseleng-2] != '"')
+                g_warning("improperly terminated string on line %d",
+                          lineno);
             else
-                entry.value.string[yyleng-2] = '\0';
+                entry.value.string[cparseleng-2] = '\0';
         } else
             haserror = TRUE;
     }
@@ -55,7 +58,20 @@ static void numbervalue()
     if (!comment) {
         if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
             entry.type = Config_Integer;
-            entry.value.integer = atoi(yytext);
+            entry.value.integer = atoi(cparsetext);
+        } else
+            haserror = TRUE;
+    }
+}
+
+static void boolvalue()
+{
+    if (!comment) {
+        if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
+            entry.type = Config_Bool;
+            entry.value.bool = (!g_ascii_strcasecmp("true", cparsetext) ||
+                                !g_ascii_strcasecmp("yes", cparsetext) ||
+                                !g_ascii_strcasecmp("on", cparsetext));
         } else
             haserror = TRUE;
     }
@@ -64,7 +80,7 @@ static void numbervalue()
 static void identifier()
 {
     if (!comment) {
-        entry.name = g_strdup(yytext);
+        entry.name = g_strdup(cparsetext);
         entry.type = -1;
     }
 }
@@ -74,10 +90,10 @@ static void newline()
     if (!comment) {
         if (!haserror && entry.name != NULL && (signed)entry.type >= 0) {
             if (!config_set(entry.name, entry.type, entry.value))
-                g_warning("Invalid option in '%s': '%s'\n",
-                          yyfilename, entry.name);
-        } else {
-            printf("Parser error in '%s' on line %d\n", yyfilename, yylineno);
+                g_warning("Parser error in '%s' on line %d\n", filename,
+                          lineno);
+        } else if (haserror || entry.name != NULL || (signed)entry.type >= 0) {
+            g_warning("Parser error in '%s' on line %d", filename, lineno);
         }
         g_free(entry.name);
         entry.name = NULL;
@@ -87,10 +103,11 @@ static void newline()
 
         haserror = FALSE;
     }
-    ++yylineno;
+    comment = FALSE;
+    ++lineno;
 }
 
-static int yywrap()
+static int cparsewrap()
 {
     g_free(entry.name);
     entry.name = NULL;
@@ -99,9 +116,9 @@ static int yywrap()
     return 1;
 }
 
-void cparse_go(char *filename, FILE *file)
+void cparse_go(char *fname, FILE *file)
 {
-    yyfilename = filename;
-    yyin = file;
-    yylex();
+    filename = fname;
+    cparsein = file;
+    cparselex();
 }
This page took 0.026938 seconds and 4 git commands to generate.