-
Notifications
You must be signed in to change notification settings - Fork 1
/
t_main.c
41 lines (36 loc) · 919 Bytes
/
t_main.c
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
#include <stdio.h>
#include <string.h>
#include "setup.h"
/* *
* this is the most basic scheme repl, compile it and run ./t_main
* and then input something like '(+ 3 12 (* 32 2))', it will output 79
*/
int main(int argc, char *argv[]) {
struct environ *base_env;
FILE *in;
int cont = 0;
int file_index;
if (argc == 2) {
in = fopen(argv[1], "r");
if (!in)
fatal(stderr, "Couldn't open %s\n", argv[1]);
} else if (argc == 3) {
if (!strcmp(argv[1], "-r")) {
file_index = 2;
cont = 1;
} else if (!strcmp(argv[2], "-r")) {
file_index = 1;
cont = 1;
} else
fatal(stderr, "Usage: %s -r file\n", argv[0]);
in = fopen(argv[file_index], "r");
if (!in)
fatal(stderr, "Couldn't open %s\n", argv[file_index]);
} else
in = stdin;
base_env = setup_builtin();
interpret_file(in, stdout, stderr, base_env);
if (cont)
interpret_file(stdin, stdout, stderr, base_env);
exit(0);
}