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,6 +36,7 @@ assign {white}={white}
|
||||||
|
|
||||||
static void stringvalue()
|
static void stringvalue()
|
||||||
{
|
{
|
||||||
|
if (!comment) {
|
||||||
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
|
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
|
||||||
entry.type = Config_String;
|
entry.type = Config_String;
|
||||||
entry.value.string = g_strdup(yytext+1); /* drop the left quote */
|
entry.value.string = g_strdup(yytext+1); /* drop the left quote */
|
||||||
|
@ -44,25 +47,31 @@ static void stringvalue()
|
||||||
entry.value.string[yyleng-2] = '\0';
|
entry.value.string[yyleng-2] = '\0';
|
||||||
} else
|
} else
|
||||||
haserror = TRUE;
|
haserror = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void numbervalue()
|
static void numbervalue()
|
||||||
{
|
{
|
||||||
|
if (!comment) {
|
||||||
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
|
if (!haserror && entry.name != NULL && (signed)entry.type < 0) {
|
||||||
entry.type = Config_Integer;
|
entry.type = Config_Integer;
|
||||||
entry.value.integer = atoi(yytext);
|
entry.value.integer = atoi(yytext);
|
||||||
} else
|
} else
|
||||||
haserror = TRUE;
|
haserror = TRUE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void identifier()
|
static void identifier()
|
||||||
{
|
{
|
||||||
|
if (!comment) {
|
||||||
entry.name = g_strdup(yytext);
|
entry.name = g_strdup(yytext);
|
||||||
entry.type = -1;
|
entry.type = -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void newline()
|
static void newline()
|
||||||
{
|
{
|
||||||
|
if (!comment) {
|
||||||
if (!haserror && entry.name != NULL && (signed)entry.type >= 0) {
|
if (!haserror && entry.name != NULL && (signed)entry.type >= 0) {
|
||||||
if (!config_set(entry.name, entry.type, entry.value))
|
if (!config_set(entry.name, entry.type, entry.value))
|
||||||
g_warning("Invalid option in '%s': '%s'\n",
|
g_warning("Invalid option in '%s': '%s'\n",
|
||||||
|
@ -77,6 +86,7 @@ static void newline()
|
||||||
entry.type = -1;
|
entry.type = -1;
|
||||||
|
|
||||||
haserror = FALSE;
|
haserror = FALSE;
|
||||||
|
}
|
||||||
++yylineno;
|
++yylineno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue