summaryrefslogtreecommitdiffhomepage
path: root/src/build/mkgamedata.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2022-02-24 00:47:05 +0000
committerMichael Smith <mikesmiffy128@gmail.com>2022-03-19 03:51:45 +0000
commit6818b362a776f0cc5a6068ed119dc2ebcbc5a9cc (patch)
treed2f32f226229cdfce0c61540396f4a7d3a4a8ced /src/build/mkgamedata.c
parent98378138a521fa52758f1ed3501900e6c323c474 (diff)
Fix some old KV parser issues
- Implement conditionals in the lexer and reject or ignore them in callbacks. This will allow something to use them later if needed. - Make error handling less stupid (return a bool instead of using the state struct).
Diffstat (limited to 'src/build/mkgamedata.c')
-rw-r--r--src/build/mkgamedata.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/build/mkgamedata.c b/src/build/mkgamedata.c
index ca2e130..e2e59ff 100644
--- a/src/build/mkgamedata.c
+++ b/src/build/mkgamedata.c
@@ -1,5 +1,5 @@
/*
- * Copyright © 2021 Michael Smith <mikesmiffy128@gmail.com>
+ * Copyright © 2022 Michael Smith <mikesmiffy128@gmail.com>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -144,6 +144,9 @@ static void kv_cb(enum kv_token type, const char *p, uint len, void *ctxt) {
*ents_tail = e;
ents_tail = &e->next;
}
+ break;
+ case KV_COND_PREFIX: case KV_COND_SUFFIX:
+ badparse(state, "unexpected conditional");
}
}
@@ -165,11 +168,9 @@ int OS_MAIN(int argc, os_char *argv[]) {
int nread;
while (nread = read(fd, buf, sizeof(buf))) {
if (nread == -1) die("couldn't read file");
- kv_parser_feed(&kv, buf, nread, &kv_cb, &state);
- if (kv.state == KV_PARSER_ERROR) goto ep;
+ if (!kv_parser_feed(&kv, buf, nread, &kv_cb, &state)) goto ep;
}
- kv_parser_done(&kv);
- if (kv.state == KV_PARSER_ERROR) {
+ if (!kv_parser_done(&kv)) {
ep: fprintf(stderr, "mkgamedata: %" fS ":%d:%d: bad syntax: %s\n",
*argv, kv.line, kv.col, kv.errmsg);
exit(1);