X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=src%2Fgacela.c;h=9503f4146a1c66ea56725cd49615570ad0aea1b1;hb=a9ac7797c7eca236ee5b3114d9a6ab859c00b0b3;hp=10aee8d38a58c38ac485c2a015357c46c588a874;hpb=5529af7c3a48a6231247ae8d472f359b6c75e938;p=gacela.git diff --git a/src/gacela.c b/src/gacela.c index 10aee8d..9503f41 100644 --- a/src/gacela.c +++ b/src/gacela.c @@ -154,9 +154,10 @@ gacela_client (SCM rec_channel, SCM send_channel) if (line && *line) { add_history (line); - scm_write (scm_from_locale_string ("("), send_channel); + //scm_write (scm_from_locale_string ("("), send_channel); scm_write (scm_from_locale_string (line), send_channel); - scm_write (scm_from_locale_string (")"), send_channel); + //scm_write (scm_from_locale_string (")"), send_channel); + scm_force_output (send_channel); while (scm_char_ready_p (rec_channel) == SCM_BOOL_F) { if (ctrl_c) break; @@ -165,7 +166,7 @@ gacela_client (SCM rec_channel, SCM send_channel) if (ctrl_c) ctrl_c = 0; else { - buffer = scm_read_line (rec_channel); + buffer = scm_read (rec_channel); printf ("%s\n", scm_to_locale_string (buffer)); } } @@ -267,13 +268,9 @@ main (int argc, char *argv[]) char *host; int port = 0; int i; - SCM pipes; + SCM fd1, fd2; int pid; - char *string = "prueba\n"; - int p[2]; - char buffer[150]; - // Checking arguments for (i = 1; i < argc; i++) { if (strcmp (argv[i], "--shell-mode") == 0) @@ -308,46 +305,36 @@ main (int argc, char *argv[]) //start_remote_client (host, port); return; else { - /* - pipes = scm_pipe (); + fd1 = scm_pipe (); + fd2 = scm_pipe (); pid = fork (); - if (pid == 0) - start_local_server (dirname (argv[0]), pipes); - else - gacela_client (SCM_CAR (pipes), SCM_CDR (pipes)); - */ - /* if (pid == 0) { - scm_write (scm_from_locale_string ("prueba"), SCM_CDR (pipes)); - sleep (10); + scm_close (SCM_CAR (fd1)); + scm_close (SCM_CDR (fd2)); + start_local_server (dirname (argv[0]), scm_cons (SCM_CAR (fd2), SCM_CDR (fd1))); } else { - while (scm_char_ready_p (SCM_CAR (pipes)) == SCM_BOOL_F) { - sleep (1); - printf ("1\n"); - } - SCM buffer; - buffer = scm_read_line (SCM_CAR (pipes)); - printf ("%s\n", scm_to_locale_string (buffer)); + scm_close (SCM_CDR (fd1)); + scm_close (SCM_CAR (fd2)); + gacela_client (SCM_CAR (fd1), SCM_CDR (fd2)); + kill (pid, SIGKILL); } - */ - FILE *stream; - pipe (p); + + /* + SCM buffer; if (pid == 0) { - close (p[1]); - stream = fdopen (p[0], "w"); - fprintf (stream, "prueba\n"); - fclose (stream); - printf ("1\n"); - sleep (10); + printf ("Hijo: 0\n"); + scm_write (scm_from_locale_string ("Hola mundo\n"), SCM_CDR (pipes)); + scm_force_output (SCM_CDR (pipes)); + printf ("Hijo: 1\n"); } else { - int c; - close (p[0]); - stream = fdopen (p[1], "r"); - while ((c = fgetc (stream)) != EOF) - putchar (c); + printf ("Padre: 0\n"); + buffer = scm_read (SCM_CAR (pipes)); + printf ("%s\n", scm_to_locale_string (buffer)); + printf ("Padre: 1\n"); } + */ } }