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 identifier();
14 static void newline();
20 identifier [a-zA-Z][a-zA-Z0-9_.]*
22 assign {white}={white}
26 {string}/{white}\n stringvalue();
27 {number}/{white}\n numbervalue();
28 ^{identifier}/{assign} identifier();
37 static void stringvalue()
40 if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
41 entry.type = Config_String;
42 entry.value.string = g_strdup(yytext+1); /* drop the left quote */
43 if (entry.value.string[yyleng-2] != '"')
44 printf("warning: improperly terminated string on line %d\n",
47 entry.value.string[yyleng-2] = '\0';
53 static void numbervalue()
56 if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
57 entry.type = Config_Integer;
58 entry.value.integer = atoi(yytext);
64 static void identifier()
67 entry.name = g_strdup(yytext);
75 if (!haserror && entry.name != NULL && (signed)entry.type >= 0) {
76 if (!config_set(entry.name, entry.type, entry.value))
77 g_warning("Invalid option in '%s': '%s'\n",
78 yyfilename, entry.name);
80 printf("Parser error in '%s' on line %d\n", yyfilename, yylineno);
84 if (entry.type == Config_String)
85 g_free(entry.value.string);
97 if (entry.type == Config_String)
98 g_free(entry.value.string);
102 void cparse_go(char *filename, FILE *file)
104 yyfilename = filename;