X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/mLib/blobdiff_plain/7cf5c72a6d353ed5a7e340562c11e54c21c85e5e..9a5e5808ff09935b8562d7bf93b3ada040d96669:/struct/t/sym-test.c diff --git a/struct/t/sym-test.c b/struct/t/sym-test.c index 264d6a9..5bbbff8 100644 --- a/struct/t/sym-test.c +++ b/struct/t/sym-test.c @@ -3,7 +3,9 @@ #include #include +#include "macros.h" #include "sym.h" +#include "unihash.h" typedef struct word { sym_base _b; @@ -31,7 +33,7 @@ int main(void) buf[strlen(buf) - 1] = 0; p = strtok(buf, " "); - if (strcmp(p, "set") == 0) { + if (STRCMP(p, ==, "set")) { char *k = strtok(0, " "); int i = atoi(strtok(0, " ")); unsigned f; @@ -39,14 +41,14 @@ int main(void) w->i = i; if (!f) n++; - } else if (strcmp(p, "get") == 0) { + } else if (STRCMP(p, ==, "get")) { char *k = strtok(0, " "); word *w = sym_find(&t, k, -1, 0, 0); if (w) printf("%i\n", w->i); else puts("*MISSING*"); - } else if (strcmp(p, "del") == 0) { + } else if (STRCMP(p, ==, "del")) { char *k = strtok(0, " "); word *w = sym_find(&t, k, -1, 0, 0); if (w) { @@ -54,9 +56,12 @@ int main(void) n--; } else puts("*MISSING*"); - } else if (strcmp(p, "count") == 0) { - printf("%i\n", n); - } else if (strcmp(p, "show") == 0) { + } else if (STRCMP(p, ==, "count")) { + printf("%lu\n", (unsigned long)n); + } else if (STRCMP(p, ==, "seed")) { + char *k = strtok(0, " "); + unihash_setkey(&unihash_global, strtoul(k, 0, 0)); + } else if (STRCMP(p, ==, "show")) { sym_iter i; word *w; word **v, **vv; @@ -64,7 +69,7 @@ int main(void) if (!n) puts("*EMPTY*"); else { - v = malloc(n * sizeof(*v)); + v = calloc(n, sizeof(*v)); if (!v) { puts("*NOMEM*"); continue;