5 static int yylineno = 1;
6 static gboolean haserror = FALSE;
7 static ConfigEntry entry = { NULL, -1 };
9 static void stringvalue();
10 static void numbervalue();
11 static void identifier();
12 static void newline();
18 identifier [a-zA-Z][a-zA-Z0-9_]*
20 assign {white}={white}
24 {string}/{white}\n stringvalue();
25 {number}/{white}\n numbervalue();
26 ^{identifier}/{assign} identifier();
34 static void stringvalue()
36 if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
37 entry.type = Config_String;
38 entry.value.string = g_strdup(yytext+1); /* drop the left quote */
39 if (entry.value.string[yyleng-2] != '"')
40 printf("warning: improperly terminated string on line %d\n",
43 entry.value.string[yyleng-2] = '\0';
48 static void numbervalue()
50 if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
51 entry.type = Config_Integer;
52 entry.value.integer = atoi(yytext);
57 static void identifier()
59 g_print("identifier: %s\n", yytext);
60 entry.name = g_strdup(yytext);
66 if (!haserror && entry.name != NULL && (signed)entry.type >= 0) {
67 if (!config_set(entry.name, entry.type, entry.value))
68 g_warning("Invalid option in config file: '%s'\n", entry.name);
70 printf("Parser error in config file on line %d\n", yylineno);
74 if (entry.type == Config_String)
75 g_free(entry.value.string);
86 if (entry.type == Config_String)
87 g_free(entry.value.string);
91 void cparse_go(FILE *file)