blob: c76980ce5c48ea23148864c57cf63ed9396362d0 (
plain) (
blame)
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
|
#include <stdio.h>
#include <stdlib.h>
#include <readline.h>
#include "basic.h"
int main(int argc, char **argv) {
char *p_buf;
srand(1); // not very usefull...
interp_name = argv[0];
init();
if(argc == 2) {
/* load the program to execute */
if(!(p_buf = load_file(argv[1]))) exit(1);
load_program(p_buf);
start(p_buf);
} else if (argc == 1) {
readline_history hist;
hist.str = 0; hist.max = 10;
printf("KBASIC 0.1\n"
"Press ^D to quit interpreter.\n\n");
for (;;) {
printf("\x1b[0m\x1b[32m> \x1b[1m");
char *l = freadline(stdin, &hist);
set_color();
if (l == NULL) break;
if (!strcmp(l, "exit")) break;
prog_ip = l;
get_token();
if (token_type == NUMBER) { // label. insert line.
insert_line(l, atoi(token));
} else { // directly execute
start(l);
}
}
} else {
printf("usage:\n");
printf(" %s <filename> run BASIC file\n", argv[0]);
printf(" %s interactive BASIC interpreter\n", argv[0]);
exit(1);
}
return 0;
}
|