-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.c
More file actions
47 lines (45 loc) · 1.55 KB
/
Copy pathmain.c
File metadata and controls
47 lines (45 loc) · 1.55 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
#include "libdclang.c"
// Where all the juicy fun begins...
int main(int argc, char **argv) {
dclang_initialize();
//setlocale(LC_ALL, "");
if (argc > 1) {
for(int opt = 1; opt < argc; opt++) {
if (strcmp(argv[opt], "-i") == 0) {
live_repl = 1;
} else if (strcmp(argv[opt], "-e") == 0) {
if (opt + 1 < argc) {
const char *code = argv[++opt];
FILE *f = fmemopen((void*)code, strlen(code), "r");
if (!f) {
perror("fmemopen failed to open input!");
return 1;
}
setinput(f);
repl();
fclose(f);
} else {
fprintf(stderr, "dclang: -e requires an argument\n");
return 1;
}
} else {
dclang_import(argv[opt]);
}
};
} else {
if (isatty(STDIN_FILENO)) {
live_repl = 1;
} else {
repl(); // run interpreter on piped stdin
return 0;
}
}
if (live_repl) {
setinput(stdin);
printf("Welcome to dclang! (v6.1.0) Aaron Krister Johnson, 2018-2026\n");
printf("Make sure to peruse README.md to get your bearings!\n");
printf("You can type 'primitives' to see a list of all the primitive (c-builtin) words.\n");
printf("You can type 'words' to see a list of words defined within dclang.\n");
repl();
}
}