blob: c76980ce5c48ea23148864c57cf63ed9396362d0 (
plain) (
tree)
|
|
#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;
}
|