From 53ad34084c4f4d6378f71ac04c2aa0c0e6b40e18 Mon Sep 17 00:00:00 2001 From: jsancho Date: Fri, 22 Apr 2011 08:04:07 +0000 Subject: [PATCH] --- gacela.c | 60 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/gacela.c b/gacela.c index 343f1ba..dee7659 100644 --- a/gacela.c +++ b/gacela.c @@ -1,33 +1,55 @@ #include #include +#include +#include /* Read-Send-Print-Loop */ -void rspl () +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; - } + 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[]) { - rspl (); - return 0; + pid_t cpid; + int pfd[2]; + + pipe(pfd); + cpid = fork(); + if (cpid != 0) { + rspl(pfd[0], pfd[1]); + return 0; + } + else { + char buf; + + while (1) { + while (read(pfd[0], &buf, 1) > 0) { + if (buf == '\n') + write(STDOUT_FILENO, "-\n", 2); + else + write(STDOUT_FILENO, &buf, 1); + } + } + } } -- 2.39.2