13 static int cmp(const void *a, const void *b)
15 const word *const *v = b;
16 const word *const *w = a;
17 return (strcmp(ATOM_NAME(ASSOC_ATOM(*w)), ATOM_NAME(ASSOC_ATOM(*v))));
28 atom_createtable(&at);
31 while (fgets(buf, sizeof(buf), stdin)) {
32 buf[strlen(buf) - 1] = 0;
33 /* printf("# %s\n", buf); */
36 if (strcmp(p, "set") == 0) {
37 char *k = strtok(0, " ");
38 int i = atoi(strtok(0, " "));
40 word *w = assoc_find(&t, atom_intern(&at, k), sizeof(word), &f);
44 } else if (strcmp(p, "get") == 0) {
45 char *k = strtok(0, " ");
46 word *w = assoc_find(&t, atom_intern(&at, k), 0, 0);
51 } else if (strcmp(p, "del") == 0) {
52 char *k = strtok(0, " ");
53 word *w = assoc_find(&t, atom_intern(&at, k), 0, 0);
59 } else if (strcmp(p, "count") == 0) {
61 } else if (strcmp(p, "show") == 0) {
69 v = malloc(n * sizeof(*v));
74 for (vv = v, assoc_mkiter(&i, &t); (w = assoc_next(&i)) != 0; vv++)
76 qsort(v, n, sizeof(*v), cmp);
77 printf("%s:%i", ATOM_NAME(ASSOC_ATOM(*v)), (*v)->i);
78 for (vv = v + 1; --n; vv++)
79 printf(" %s:%i", ATOM_NAME(ASSOC_ATOM(*vv)), (*vv)->i);
88 atom_destroytable(&at);