14 static int cmp(const void *a, const void *b)
16 const word *const *v = b;
17 const word *const *w = a;
18 return (strcmp(ATOM_NAME(ASSOC_ATOM(*w)), ATOM_NAME(ASSOC_ATOM(*v))));
29 atom_createtable(&at);
32 while (fgets(buf, sizeof(buf), stdin)) {
33 /* printf("+++ %s", buf); */
34 buf[strlen(buf) - 1] = 0;
37 if (strcmp(p, "set") == 0) {
38 char *k = strtok(0, " ");
39 int i = atoi(strtok(0, " "));
41 word *w = assoc_find(&t, atom_intern(&at, k), sizeof(word), &f);
45 } else if (strcmp(p, "get") == 0) {
46 char *k = strtok(0, " ");
47 word *w = assoc_find(&t, atom_intern(&at, k), 0, 0);
52 } else if (strcmp(p, "del") == 0) {
53 char *k = strtok(0, " ");
54 word *w = assoc_find(&t, atom_intern(&at, k), 0, 0);
60 } else if (strcmp(p, "count") == 0) {
62 } else if (strcmp(p, "show") == 0) {
70 v = malloc(n * sizeof(*v));
75 for (vv = v, assoc_mkiter(&i, &t), j = 0;
76 (w = assoc_next(&i)) != 0;
82 qsort(v, n, sizeof(*v), cmp);
83 printf("%s:%i", ATOM_NAME(ASSOC_ATOM(*v)), (*v)->i);
84 for (vv = v + 1; --j; vv++)
85 printf(" %s:%i", ATOM_NAME(ASSOC_ATOM(*vv)), (*vv)->i);
91 /* printf("--- %d\n", n); */
95 atom_destroytable(&at);