#include <stdlib.h>
#include <stdio.h>
#include "ustr.h"
int
main(void)
{
const struct UStr *kw[] = {
UStrAdd("if"),
UStrAdd("for"),
UStrAdd("while"),
};
char *line = 0;
size_t capacity = 0;
ssize_t len;
while ((len = getline(&line, &capacity, stdin)) > 0) {
line[len - 1] = 0;
bool added, error = false;
const struct UStr *identifier = UStrAdd_(line, &added);
for (size_t i = 0; i < sizeof(kw) / sizeof(kw[0]); ++i) {
if (kw[i] == identifier) {
printf("can not use keyword as identifier\n");
error = true;
}
}
if (error) {
continue;
}
if (added) {
printf("new ");
}
printf("identifier '%s'\n", identifier->cstr);
}
free(line); // ok even if line is null pointer
printf("List of unique strings:\n");
UStrPrintPool();
}