]> git.jsancho.org Git - gacela.git/blob - gacela.c
(no commit message)
[gacela.git] / gacela.c
1 #include <stdio.h>
2 #include <readline/readline.h>
3 #include <sys/types.h>
4 #include <unistd.h>
5 #include <libguile.h>
6
7 /* Read-Send-Print-Loop */
8 void rspl(int pin, int pout)
9 {
10   static char *line = (char *)NULL;
11   int exit = 0;
12
13   while (!exit) {
14     if (line) {
15       free(line);
16       line = (char *)NULL;
17     }
18     
19     line = readline("gacela>");
20     
21     if (line && *line) {
22       add_history(line);
23       if (strcmp(line, "(quit)") == 0)
24         exit = 1;
25       else {
26         write(pout, line, strlen(line));
27         write(pout, "\n", 1);
28       }
29     }
30   }
31 }
32
33 int main (int argc, char *argv[])
34 {
35   pid_t cpid;
36   int pfd[2];
37
38   pipe(pfd);
39   cpid = fork();
40   if (cpid != 0) {
41     rspl(pfd[0], pfd[1]);
42     return 0;
43   }
44   else {
45     char buf;
46     static char *line = (char *)NULL;
47
48     dup2(pfd[0], 0);
49     close(pfd[0]);
50
51     while (1) {
52       if (line) {
53         free(line);
54         line = (char *)NULL;
55       }
56
57       line = readline("");
58       if (line && *line) {
59         printf("%s-\n", line);
60       }
61     }
62   }
63 }