15 static int cmp(const void *a, const void *b)
17 const word *const *v = b;
18 const word *const *w = a;
19 return (strcmp(ATOM_NAME(ASSOC_ATOM(*w)), ATOM_NAME(ASSOC_ATOM(*v))));
30 atom_createtable(&at);
33 while (fgets(buf, sizeof(buf), stdin)) {
34 /* printf("+++ %s", buf); */
35 buf[strlen(buf) - 1] = 0;
38 if (STRCMP(p, ==, "set")) {
39 char *k = strtok(0, " ");
40 int i = atoi(strtok(0, " "));
42 word *w = assoc_find(&t, atom_intern(&at, k), sizeof(word), &f);
46 } else if (STRCMP(p, ==, "get")) {
47 char *k = strtok(0, " ");
48 word *w = assoc_find(&t, atom_intern(&at, k), 0, 0);
53 } else if (STRCMP(p, ==, "del")) {
54 char *k = strtok(0, " ");
55 word *w = assoc_find(&t, atom_intern(&at, k), 0, 0);
61 } else if (STRCMP(p, ==, "count")) {
62 printf("%lu\n", (unsigned long)n);
63 } else if (STRCMP(p, ==, "show")) {
71 v = malloc(n * sizeof(*v));
76 for (vv = v, assoc_mkiter(&i, &t), j = 0;
77 (w = assoc_next(&i)) != 0;
83 qsort(v, n, sizeof(*v), cmp);
84 printf("%s:%i", ATOM_NAME(ASSOC_ATOM(*v)), (*v)->i);
85 for (vv = v + 1; --j; vv++)
86 printf(" %s:%i", ATOM_NAME(ASSOC_ATOM(*vv)), (*vv)->i);
92 /* printf("--- %d\n", n); */
96 atom_destroytable(&at);