+#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char buf[256];
char *p;
sym_table t;
- size_t n = 0;
+ size_t n = 0, j;
sym_create(&t);
while (fgets(buf, sizeof(buf), stdin)) {
+/* printf("+++ %s", buf); */
buf[strlen(buf) - 1] = 0;
-/* printf("# %s\n", buf); */
p = strtok(buf, " ");
if (strcmp(p, "set") == 0) {
puts("*NOMEM*");
continue;
}
- for (vv = v, sym_mkiter(&i, &t); (w = sym_next(&i)) != 0; vv++)
+ for (vv = v, sym_mkiter(&i, &t), j = 0;
+ (w = sym_next(&i)) != 0;
+ vv++, j++) {
+ assert(j < n);
*vv = w;
+ }
+ assert(j == n);
qsort(v, n, sizeof(*v), cmp);
printf("%s:%i", SYM_NAME(*v), (*v)->i);
- for (vv = v + 1; --n; vv++)
+ for (vv = v + 1; --j; vv++)
printf(" %s:%i", SYM_NAME(*vv), (*vv)->i);
free(v);
putchar('\n');
}
} else
puts("*BAD*");
+/* printf("--- %d\n", n); */
}
sym_destroy(&t);