From cf0354eb8e043fcd9c6c17756701972f948a16f1 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Thu, 22 Aug 2024 00:02:48 +0100 Subject: Rewrite the gamedata and entprops systems entirely This removes the horrible janky old KeyValues parser and replaces it with a couple of trivial ad-hoc text parsers. In doing so, make the format of the actual gamedata files more human-friendly too. We also gain support for nested SendTables in mkentprops, which are required to get at various things like player velocity. And, the actual string matching is made more efficient (or, at least, more scalable) by way of a cool radix tree thing which generates a bunch of switch cases on distinct characters. --- test/kv.test.c | 55 ------------------------------------------------------- 1 file changed, 55 deletions(-) delete mode 100644 test/kv.test.c (limited to 'test') diff --git a/test/kv.test.c b/test/kv.test.c deleted file mode 100644 index 1bd1784..0000000 --- a/test/kv.test.c +++ /dev/null @@ -1,55 +0,0 @@ -/* This file is dedicated to the public domain. */ - -{.desc = "the KeyValues parser"}; - -// undef conflicting macros -#undef ERROR // windows.h -#undef OUT // " -#undef EOF // stdio.h -#include "../src/kv.c" - -#include "../src/intdefs.h" -#include "../src/langext.h" - -static noreturn die(const struct kv_parser *kvp) { - fprintf(stderr, "parse error: %d:%d: %s\n", kvp->line, kvp->col, - kvp->errmsg); - exit(1); -} - -static void tokcb(enum kv_token type, const char *p, uint len, - void *ctxt) { - // nop - we're just testing the tokeniser -} - -static const char data[] = -"KeyValues {\n\ - Key/1 Val1![conditional]\n\ - Key2\n\ -Val2// comment\n\ - \"String Key\" // also comment\n\ - Val3 Key4 [conditional!]{ Key5 \"Value Five\" } // one more\n\ -} \n\ -"; -static const int sz = sizeof(data) - 1; - -TEST("parsing should work with any buffer size") { - for (int chunksz = 3; chunksz <= sz; ++chunksz) { - struct kv_parser kvp = {0}; - // sending data in chunks to test reentrancy - for (int chunk = 0; chunk * chunksz < sz; ++chunk) { - int thischunk = chunksz; - if (chunk * chunksz + thischunk > sz) { - thischunk = sz - chunk * chunksz; - } - if (!kv_parser_feed(&kvp, data + chunk * chunksz, thischunk, - tokcb, 0)) { - die(&kvp); - } - } - if (!kv_parser_done(&kvp)) die(&kvp); - } - return true; -} - -// vi: sw=4 ts=4 noet tw=80 cc=80 -- cgit v1.2.3