parse lines that start with '#' as comments
This commit is contained in:
parent
2b1a11c69d
commit
93783c2a04
1 changed files with 40 additions and 30 deletions
|
@ -5,6 +5,7 @@
|
||||||
static char *yyfilename;
|
static char *yyfilename;
|
||||||
static int yylineno = 1;
|
static int yylineno = 1;
|
||||||
static gboolean haserror = FALSE;
|
static gboolean haserror = FALSE;
|
||||||
|
static gboolean comment = FALSE;
|
||||||
static ConfigEntry entry = { NULL, -1 };
|
static ConfigEntry entry = { NULL, -1 };
|
||||||
|
|
||||||
static void stringvalue();
|
static void stringvalue();
|
||||||
|
@ -26,6 +27,7 @@ assign {white}={white}
|
||||||
{number}/{white}\n numbervalue();
|
{number}/{white}\n numbervalue();
|
||||||
^{identifier}/{assign} identifier();
|
^{identifier}/{assign} identifier();
|
||||||
\n newline();
|
\n newline();
|
||||||
|
^# comment = TRUE;
|
||||||
=
|
=
|
||||||
[ \t]
|
[ \t]
|
||||||
. haserror = TRUE;
|
. haserror = TRUE;
|
||||||
|
@ -34,49 +36,57 @@ assign {white}={white}
|
||||||
|
|
||||||
static void stringvalue()
|
static void stringvalue()
|
||||||
{
|
{
|
||||||
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
|
if (!comment) {
|
||||||
entry.type = Config_String;
|
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
|
||||||
entry.value.string = g_strdup(yytext+1); /* drop the left quote */
|
entry.type = Config_String;
|
||||||
if (entry.value.string[yyleng-2] != '"')
|
entry.value.string = g_strdup(yytext+1); /* drop the left quote */
|
||||||
printf("warning: improperly terminated string on line %d\n",
|
if (entry.value.string[yyleng-2] != '"')
|
||||||
yylineno);
|
printf("warning: improperly terminated string on line %d\n",
|
||||||
else
|
yylineno);
|
||||||
entry.value.string[yyleng-2] = '\0';
|
else
|
||||||
} else
|
entry.value.string[yyleng-2] = '\0';
|
||||||
haserror = TRUE;
|
} else
|
||||||
|
haserror = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void numbervalue()
|
static void numbervalue()
|
||||||
{
|
{
|
||||||
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
|
if (!comment) {
|
||||||
entry.type = Config_Integer;
|
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
|
||||||
entry.value.integer = atoi(yytext);
|
entry.type = Config_Integer;
|
||||||
} else
|
entry.value.integer = atoi(yytext);
|
||||||
haserror = TRUE;
|
} else
|
||||||
|
haserror = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void identifier()
|
static void identifier()
|
||||||
{
|
{
|
||||||
entry.name = g_strdup(yytext);
|
if (!comment) {
|
||||||
entry.type = -1;
|
entry.name = g_strdup(yytext);
|
||||||
|
entry.type = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void newline()
|
static void newline()
|
||||||
{
|
{
|
||||||
if (!haserror && entry.name != NULL && (signed)entry.type >= 0) {
|
if (!comment) {
|
||||||
if (!config_set(entry.name, entry.type, entry.value))
|
if (!haserror && entry.name != NULL && (signed)entry.type >= 0) {
|
||||||
g_warning("Invalid option in '%s': '%s'\n",
|
if (!config_set(entry.name, entry.type, entry.value))
|
||||||
yyfilename, entry.name);
|
g_warning("Invalid option in '%s': '%s'\n",
|
||||||
} else {
|
yyfilename, entry.name);
|
||||||
printf("Parser error in '%s' on line %d\n", yyfilename, yylineno);
|
} else {
|
||||||
}
|
printf("Parser error in '%s' on line %d\n", yyfilename, yylineno);
|
||||||
g_free(entry.name);
|
}
|
||||||
entry.name = NULL;
|
g_free(entry.name);
|
||||||
if (entry.type == Config_String)
|
entry.name = NULL;
|
||||||
g_free(entry.value.string);
|
if (entry.type == Config_String)
|
||||||
entry.type = -1;
|
g_free(entry.value.string);
|
||||||
|
entry.type = -1;
|
||||||
|
|
||||||
haserror = FALSE;
|
haserror = FALSE;
|
||||||
|
}
|
||||||
++yylineno;
|
++yylineno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue