diff options
Diffstat (limited to 'src/user/app/kbasic/control.c')
-rw-r--r-- | src/user/app/kbasic/control.c | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/src/user/app/kbasic/control.c b/src/user/app/kbasic/control.c index 1ab22ff..87731c4 100644 --- a/src/user/app/kbasic/control.c +++ b/src/user/app/kbasic/control.c @@ -1,7 +1,7 @@ +#include <tce/syscall.h> + #include <stdio.h> #include <string.h> -// #include <sys/wait.h> -// #include <unistd.h> #include <ctype.h> #include <stdlib.h> #include <setjmp.h> @@ -94,18 +94,25 @@ void insert_line(char *l, int n) { } } - p = malloc(prog_l + strlen(l) + 3); + p = malloc(prog_l + strlen(l) + 4); strncpy(p, program, (a - program)); // copy [0, a[ - p[a - program] = 0; + + char *p2 = p + (a - program); + if (*(p2-1) != '\n') *(p2++) = '\n'; + *p2 = 0; + // if l is an empty line, do not copy. for (i_n = 0; l[i_n]; i_n++) { if (!isdigit(l[i_n]) && l[i_n] != '\n' && l[i_n] != '\r') { - strcpy(p + (a - program), l); // copy l + strcpy(p2, l); // copy l break; } } - strcat(p + (a - program), b); // copy [b, end[ + if (p2[strlen(p2)-1] != '\n') strcat(p2, "\n"); + + strcat(p2, b); // copy [b, end[ + if (p2[strlen(p2)-1] != '\n') strcat(p2, "\n"); load_program(p); // reparse labels } @@ -140,6 +147,9 @@ int start(char *entry) { case PRINT: exec_print(); break; + case COLOR: + color(); + break; case GOTO: exec_goto(); break; @@ -455,30 +465,25 @@ char *gpop() Forks and runs another instance of the interpreter */ void exec_exec() { - - /* TODO int pid; get_token(); if (token_type==QUOTE) { - pid = fork(); - if (pid < 0) { - printf("Error: could not fork.\n"); + char *args[2]; + args[0] = token; + args[1] = 0; + + pid = run(interp_name, args, term.fd); + if (pid <= 0) { + printf("Error: could not run '%s'.\n", interp_name); } else { - if (pid == 0) { - execlp(interp_name, interp_name, token, 0); - printf("Error: could not exec.\n"); - exit(0); - } else { - wait(0); - } + int ret = waitpid(pid, 1); + printf("[exited: %i]\n", ret); } get_token(); } else { serror(0); } - */ - printf("EXEC not available.\n"); } /* LOAD function |