5 static char *yyfilename;
6 static int yylineno = 1;
7 static gboolean haserror = FALSE;
8 static ConfigEntry entry = { NULL, -1 };
10 static void stringvalue();
11 static void numbervalue();
12 static void identifier();
13 static void newline();
19 identifier [a-zA-Z][a-zA-Z0-9_]*
21 assign {white}={white}
25 {string}/{white}\n stringvalue();
26 {number}/{white}\n numbervalue();
27 ^{identifier}/{assign} identifier();
35 static void stringvalue()
37 if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
38 entry.type = Config_String;
39 entry.value.string = g_strdup(yytext+1); /* drop the left quote */
40 if (entry.value.string[yyleng-2] != '"')
41 printf("warning: improperly terminated string on line %d\n",
44 entry.value.string[yyleng-2] = '\0';
49 static void numbervalue()
51 if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
52 entry.type = Config_Integer;
53 entry.value.integer = atoi(yytext);
58 static void identifier()
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 '%s': '%s'\n",
69 yyfilename, entry.name);
71 printf("Parser error in '%s' on line %d\n", yyfilename, yylineno);
75 if (entry.type == Config_String)
76 g_free(entry.value.string);
87 if (entry.type == Config_String)
88 g_free(entry.value.string);
92 void cparse_go(char *filename, FILE *file)
94 yyfilename = filename;