summaryrefslogtreecommitdiff
path: root/core/cescal.c
blob: c41f7cd3ca935e193205a501fb851bed987210b2 (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
 * Copyright (c) 2026, Chloe M.
 * Provided under the BSD-3 clause
 */

#include <stdio.h>
#include <unistd.h>
#include "cescal/state.h"
#include "cescal/parser.h"
#include "cescal/log.h"

static void
help(void)
{
    printf("usage: ./cescal [flags]\n");
    printf("[-h]    Display this help menu\n");
}

static int
compile(const char *pathname)
{
    struct cescal_state st;

    if (pathname == NULL) {
        return -1;
    }

    if (state_init(&st, pathname) < 0) {
        return -1;
    }

    for (int i = 0; i < 2; ++i) {
        if (parser_parse(&st) < 0) {
            return -1;
        }
    }

    state_close(&st);
    return 0;
}

int
main(int argc, char **argv)
{
    int opt;

    if (argc < 2) {
        cc_error("too few arguments\n");
        help();
        return -1;
    }

    while ((opt = getopt(argc, argv, "h")) != -1) {
        switch (opt) {
        case 'h':
            help();
            return -1;
        }
    }

    while (optind < argc) {
        if (compile(argv[optind++]) < 0) {
            break;
        }
    }

    return 0;
}