config: "line ends early" is now a fatal error

This commit is contained in:
snow flurry 2020-11-16 20:31:42 -08:00
parent 50f3806f15
commit 6e9a68711d

View file

@ -25,7 +25,7 @@ config_t *
parse_config(char *path) parse_config(char *path)
{ {
FILE *fd; FILE *fd;
int res, state, line, ws, comment, err, i, col; int state, line, ws, comment, err, i, col;
#define ST_FILENAME 0 #define ST_FILENAME 0
#define ST_EXT 1 #define ST_EXT 1
#define ST_START 2 #define ST_START 2
@ -58,11 +58,13 @@ parse_config(char *path)
switch (ch) { switch (ch) {
case '\t': case '\t':
case ' ': case ' ':
if (comment) if (comment) {
continue; continue;
}
/* only run on the first whitespace */ /* only run on the first whitespace */
if (!ws) { if (!ws) {
DPRINTF(("i = %d\n", i));
i = 0; i = 0;
ws = 1; ws = 1;
state++; state++;
@ -106,25 +108,30 @@ parse_config(char *path)
err = 1; err = 1;
break; break;
} }
if (state != ST_OPTS) { if (state != ST_OPTS) {
PMSG("warn", "line ends early"); PMSG("error", "line ends early");
err = 1;
break;
} }
memset(cur->next, 0, sizeof(config_t));
cur = cur->next; cur = cur->next;
memset(cur, 0, sizeof(config_t));
} }
/* reset state for next line */ /* reset state for next line */
state = ST_FILENAME; state = ST_FILENAME;
ws = col = i = comment = 0; ws = col = i = 0;
comment = 0;
line++; line++;
break; break;
case '#': case '#':
comment = 1; comment = 1;
break; break;
default: default:
if (comment) if (comment) {
continue; continue;
}
ws = 0; ws = 0;
@ -136,6 +143,7 @@ parse_config(char *path)
err = 1; err = 1;
} else { } else {
cur->filename[i] = toupper(ch); cur->filename[i] = toupper(ch);
DPRINTF(("%c", cur->filename[i]));
i++; i++;
} }
break; break;
@ -145,6 +153,7 @@ parse_config(char *path)
err = 1; err = 1;
} else { } else {
cur->ext[i] = toupper(ch); cur->ext[i] = toupper(ch);
DPRINTF(("%c", cur->ext[i]));
i++; i++;
} }
break; break;