From 6818b362a776f0cc5a6068ed119dc2ebcbc5a9cc Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 24 Feb 2022 00:47:05 +0000 Subject: 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). --- src/gameinfo.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/gameinfo.c') 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 + * Copyright © 2022 Michael Smith * * 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; -- cgit v1.2.3-54-g00ecf