X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=openbox%2Fcparse.l;h=70524007b91f1628ec461e3bcb07f3d08b5e9be4;hb=83508a2ad227464b84e9cd84f7172ac69bf85230;hp=5e4b6d3ef75b969e962edc78caa77474410d5eca;hpb=56dc0446cd8a9a2685e1ffadb58b781e52e1a95a;p=chaz%2Fopenbox diff --git a/openbox/cparse.l b/openbox/cparse.l index 5e4b6d3e..70524007 100644 --- a/openbox/cparse.l +++ b/openbox/cparse.l @@ -2,84 +2,112 @@ #include #include "config.h" -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]+ string \"[^"\n]*\" -identifier [a-zA-Z][a-zA-Z0-9_]* +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(); = [ \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(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[cparseleng-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(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; + } } static void identifier() { - g_print("identifier: %s\n", yytext); - entry.name = g_strdup(yytext); - entry.type = -1; + if (!comment) { + entry.name = g_strdup(cparsetext); + 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 config file: '%s'\n", entry.name); - } else { - printf("Parser error in config file on line %d\n", 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("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; + if (entry.type == Config_String) + g_free(entry.value.string); + entry.type = -1; - haserror = FALSE; - ++yylineno; + haserror = FALSE; + } + comment = FALSE; + ++lineno; } -static int yywrap() +static int cparsewrap() { g_free(entry.name); entry.name = NULL; @@ -88,8 +116,9 @@ static int yywrap() return 1; } -void cparse_go(FILE *file) +void cparse_go(char *fname, FILE *file) { - yyin = file; - yylex(); + filename = fname; + cparsein = file; + cparselex(); }