#include #include #include #include "basic.h" int main(int argc, char **argv) { char *p_buf; srand(0); // not very usefull... readline_history hist; hist.str = 0; hist.max = 10; 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) { printf("KBASIC 0.1\n" "Press ^D to quit interpreter.\n\n"); for (;;) { printf("> "); char *l = freadline(stdin, &hist); if (l == NULL) break; if (!strcmp(l, "exit")) { free(l); break; } prog_ip = l; get_token(); if (token_type == NUMBER) { // label. insert line. insert_line(l, atoi(token)); } else { // directly execute start(l); } free(l); } } else { printf("usage:\n\t%s \trun BASIC file\n", argv[0]); printf("\n\t%s\t\t\tinteractive BASIC interpreter\n", argv[0]); exit(1); } return 0; }