1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>

#include "ustr.h"

int
main(void)
{
    const struct UStr *kwIf = UStrAdd("if");
    const struct UStr *kwWhile = 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 = false;
        const struct UStr *ident = UStrAdd_(line, &added);

        if (ident == kwIf) {
            printf("keyword 'if'\n");
        } else if (ident == kwWhile) {
            printf("keyword 'while'\n");
        } else {
            printf("identifier '%s'\n", ident->cstr);
            if (added) {
                printf("this is new\n");
            }
        }
    }

    printf("Pool of UStr:\n");
    UStrPrintPool();
}