X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela.c;h=0493d8fd63621c90534f89946970c574eceb17e4;hb=a807d13b26724e7219b3e7e82915a43ff9d327cc;hp=1cd7412806fe013cbb22fced8232b5e54fcd6bf9;hpb=d4cff32858a9ff65b06f1430810699a91fbcc2b9;p=gacela.git diff --git a/gacela.c b/gacela.c index 1cd7412..0493d8f 100644 --- a/gacela.c +++ b/gacela.c @@ -1,11 +1,63 @@ #include +#include +#include +#include +#include + +/* Read-Send-Print-Loop */ +void rspl(int pin, int pout) +{ + static char *line = (char *)NULL; + int exit = 0; + + while (!exit) { + if (line) { + free(line); + line = (char *)NULL; + } + + line = readline("gacela>"); + + if (line && *line) { + add_history(line); + if (strcmp(line, "(quit)") == 0) + exit = 1; + else { + write(pout, line, strlen(line)); + write(pout, "\n", 1); + } + } + } +} int main (int argc, char *argv[]) { - char exp[1024]; + pid_t cpid; + int pfd[2]; + + pipe(pfd); + cpid = fork(); + if (cpid != 0) { + rspl(pfd[0], pfd[1]); + return 0; + } + else { + char buf; + static char *line = (char *)NULL; + + dup2(pfd[0], 0); + close(pfd[0]); - printf("gacela>"); - scanf("%s", exp); + while (1) { + if (line) { + free(line); + line = (char *)NULL; + } - return 0; + line = readline(""); + if (line && *line) { + printf("%s-\n", line); + } + } + } }