diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2022-02-24 00:47:05 +0000 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2022-03-19 03:51:45 +0000 |
commit | 6818b362a776f0cc5a6068ed119dc2ebcbc5a9cc (patch) | |
tree | d2f32f226229cdfce0c61540396f4a7d3a4a8ced /src/gameinfo.c | |
parent | 98378138a521fa52758f1ed3501900e6c323c474 (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/gameinfo.c')
-rw-r--r-- | src/gameinfo.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/gameinfo.c b/src/gameinfo.c index a5f1a42..4af5df7 100644 --- a/src/gameinfo.c +++ b/src/gameinfo.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 @@ -228,6 +228,10 @@ static void kv_cb(enum kv_token type, const char *p, uint len, void *_ctxt) { break; case KV_NEST_END: if (ctxt->dontcarelvl) --ctxt->dontcarelvl; else --ctxt->nestlvl; + break; + case KV_COND_PREFIX: case KV_COND_SUFFIX: + con_warn("gameinfo: warning: just ignoring conditional \"%.*s\"", + len, p); } #undef MATCH } @@ -353,11 +357,9 @@ bool gameinfo_init(void) { strerror(errno)); goto e; } - kv_parser_feed(&kvp, buf, nread, &kv_cb, &ctxt); - if (kvp.state == KV_PARSER_ERROR) goto ep; + if (!kv_parser_feed(&kvp, buf, nread, &kv_cb, &ctxt)) goto ep; } - kv_parser_done(&kvp); - if (kvp.state == KV_PARSER_ERROR) goto ep; + if (!kv_parser_done(&kvp)) goto ep; close(fd); return true; |