5 static char *yyfilename;
6 static int yylineno = 1;
7 static gboolean haserror = FALSE;
8 static gboolean comment = FALSE;
9 static ConfigEntry entry = { NULL, -1 };
11 static void stringvalue();
12 static void numbervalue();
13 static void boolvalue();
14 static void identifier();
15 static void newline();
21 identifier [a-zA-Z][a-zA-Z0-9_.]*
23 assign {white}={white}
24 bool ([tT][rR][uU][eE]|[fF][aA][lL][sS][eE]|[yY][eE][sS]|[nN][oO]|[oO][nN]|[oO][fF][fF])
29 {bool}/{white}\n boolvalue();
30 {string}/{white}\n stringvalue();
31 {number}/{white}\n numbervalue();
32 ^{identifier}/{assign} identifier();
36 . if (!comment) haserror = TRUE;
40 static void stringvalue()
43 if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
44 entry.type = Config_String;
45 entry.value.string = g_strdup(yytext+1); /* drop the left quote */
46 if (entry.value.string[yyleng-2] != '"')
47 printf("warning: improperly terminated string on line %d\n",
50 entry.value.string[yyleng-2] = '\0';
56 static void numbervalue()
59 if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
60 entry.type = Config_Integer;
61 entry.value.integer = atoi(yytext);
67 static void boolvalue()
70 if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
71 entry.type = Config_Bool;
72 entry.value.bool = (!g_ascii_strcasecmp("true", yytext) ||
73 !g_ascii_strcasecmp("yes", yytext) ||
74 !g_ascii_strcasecmp("on", yytext));
80 static void identifier()
83 entry.name = g_strdup(yytext);
91 if (!haserror && entry.name != NULL && (signed)entry.type >= 0) {
92 if (!config_set(entry.name, entry.type, entry.value))
93 g_warning("Parser error in '%s' on line %d\n", yyfilename,
96 g_warning("Parser error in '%s' on line %d", yyfilename, yylineno);
100 if (entry.type == Config_String)
101 g_free(entry.value.string);
114 if (entry.type == Config_String)
115 g_free(entry.value.string);
119 void cparse_go(char *filename, FILE *file)
121 yyfilename = filename;