-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpuncta.c
More file actions
53 lines (52 loc) · 1.69 KB
/
puncta.c
File metadata and controls
53 lines (52 loc) · 1.69 KB
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
#define COC_IMPLEMENTATION
#include "puncta.h"
int main(int argc, char *argv[]) {
if (argc < 2) {
coc_log_raw(COC_FATAL, "Usage: %s <file name> [-option]", argv[0]);
return 1;
}
Coc_Log_Config cfg = {
.min_level = COC_LOG_MIN_LEVEL,
.use_date = true,
.use_time = true,
.use_ms = true,
.use_color = true
};
const char *filename = NULL;
const char *log_file = NULL;
for (int i = 1; i < argc; i++) {
const char *arg = argv[i];
const char *value = NULL;
size_t len = coc_kv_split(arg, &value);
if (len > 2 && arg[0] == '-' && arg[1] == '-') {
if (coc_kv_match(arg, len, "--version")) {
coc_log_raw(COC_INFO,
"Puncta %d.%d.%d",
PUNCTA_VERSION_MAJOR, PUNCTA_VERSION_MINOR, PUNCTA_VERSION_PATCH);
return 0;
} else if (coc_kv_match(arg, len, "--log-level")) {
cfg.min_level = coc_log_level_from_cstr(value);
} else if (coc_kv_match(arg, len, "--log-file")) {
log_file = value;
} else {
coc_log_raw(COC_ERROR, "%s: unknown option %.*s", argv[0], (int)len, arg);
return 1;
}
} else {
if (!filename) filename = arg;
else {
coc_log_raw(COC_ERROR, "%s: extra argument: %s", argv[0], arg);
return 1;
}
}
}
coc_log_init(cfg , log_file);
if (filename == NULL) {
coc_log_raw(COC_FATAL, "%s: no input file", argv[0]);
return 1;
}
VM *vm = run_file(filename, NULL);
vm_free(vm);
coc_log_close();
return 0;
}