X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fcparse.l;h=3f362668d48520f0e25a9cb7321499030856b4e1;hb=ddb5d43edc8bb35dadaa83fc3b516a43c1674cc9;hp=c2bd008ca1b849e758c426905ee73635fd7cce7b;hpb=2b1a11c69dd6dd1fce86279bb12f6206d09bc5e5;p=chaz%2Fopenbox diff --git a/openbox/cparse.l b/openbox/cparse.l index c2bd008c..3f362668 100644 --- a/openbox/cparse.l +++ b/openbox/cparse.l @@ -5,10 +5,12 @@ static char *yyfilename; static int yylineno = 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(); @@ -19,64 +21,89 @@ 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]) %% +^# comment = TRUE; +{bool}/{white}\n boolvalue(); {string}/{white}\n stringvalue(); {number}/{white}\n numbervalue(); ^{identifier}/{assign} identifier(); \n newline(); = [ \t] -. haserror = TRUE; +. if (!comment) haserror = TRUE; %% static void stringvalue() { - 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); - else - entry.value.string[yyleng-2] = '\0'; - } else - haserror = TRUE; + 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); + else + entry.value.string[yyleng-2] = '\0'; + } else + haserror = TRUE; + } } static void numbervalue() { - if (!haserror && entry.name != NULL && (signed)entry.type < 0) { - entry.type = Config_Integer; - entry.value.integer = atoi(yytext); - } else - haserror = TRUE; + if (!comment) { + if (!haserror && entry.name != NULL && (signed)entry.type < 0) { + entry.type = Config_Integer; + entry.value.integer = atoi(yytext); + } 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", yytext) || + !g_ascii_strcasecmp("yes", yytext) || + !g_ascii_strcasecmp("on", yytext)); + } else + haserror = TRUE; + } } static void identifier() { - entry.name = g_strdup(yytext); - entry.type = -1; + if (!comment) { + entry.name = g_strdup(yytext); + entry.type = -1; + } } static void newline() { - 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_free(entry.name); - entry.name = NULL; - if (entry.type == Config_String) - g_free(entry.value.string); - entry.type = -1; + 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_free(entry.name); + entry.name = NULL; + if (entry.type == Config_String) + g_free(entry.value.string); + entry.type = -1; - haserror = FALSE; + haserror = FALSE; + } + comment = FALSE; ++yylineno; }