]> git.jsancho.org Git - gacela.git/blobdiff - gacela.c
(no commit message)
[gacela.git] / gacela.c
index 80d4abc79b24b11efe7f810741a1b653d39de16b..0493d8fd63621c90534f89946970c574eceb17e4 100644 (file)
--- a/gacela.c
+++ b/gacela.c
@@ -1,75 +1,63 @@
-#include <SDL/SDL.h>
-#include <GL/gl.h>
+#include <stdio.h>
+#include <readline/readline.h>
+#include <sys/types.h>
+#include <unistd.h>
 #include <libguile.h>
-#include <pthread.h>
 
-int contador = 0;
-int incremento = 1;
-
-SCM prueba () {
-       int flags;
-
-       SDL_Init (SDL_INIT_EVERYTHING);
-
-       SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
-
-       flags = SDL_OPENGL | SDL_GL_DOUBLEBUFFER | SDL_HWPALETTE | SDL_RESIZABLE | SDL_SWSURFACE;
-       SDL_SetVideoMode (200, 200, 32, flags);
-
-       glShadeModel (GL_SMOOTH);
-       glClearColor (0, 0, 0, 0);
-       glHint (GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
-       glViewport (0, 0, 200, 200);
-       glMatrixMode (GL_PROJECTION);
-       glLoadIdentity ();
-       glOrtho (-200, 200, -200, 200, 0, 1);
-       glMatrixMode (GL_MODELVIEW);
-       glLoadIdentity ();
-
-       return SCM_UNSPECIFIED;
-}
-
-void *bucle () {
-       while (1) {
-               contador = contador + incremento;
-               if (contador > 1000) incremento = -1;
-               else if (contador < 0) incremento = 1;
-       }
-       pthread_exit(NULL);
-}
-
-SCM lanzar_bucle () {
-       pthread_t t;
-
-       pthread_create(&t, NULL, bucle, NULL);
-       return SCM_UNSPECIFIED;
-}
-
-SCM ver_contador () {
-       return scm_from_int(contador);
-}
-
-static void*
-register_functions (void* data)
+/* Read-Send-Print-Loop */
+void rspl(int pin, int pout)
 {
-       scm_c_define_gsubr ("prueba", 0, 0, 0, &prueba);
-       scm_c_define_gsubr ("ver-contador", 0, 0, 0, &ver_contador);
-       scm_c_define_gsubr ("lanzar-bucle", 0, 0, 0, &lanzar_bucle);
-       return NULL;
+  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[]) {
-/*     GSCM_status status;
-       GSCM_top_level toplev;
-
-       status = gscm_eval_str(NULL, toplev, "(use-modules (ice-9 readline))");
-       status = gscm_eval_str(NULL, toplev, "(activate-readline)");
-*/
-       scm_with_guile (&register_functions, NULL);
-       scm_c_eval_string("(set-repl-prompt! \"gacela>\")");
-       scm_c_eval_string("(use-modules (ice-9 readline))");
-       scm_c_eval_string("(activate-readline)");
-       scm_shell (argc, argv);
+int main (int argc, char *argv[])
+{
+  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]);
+
+    while (1) {
+      if (line) {
+       free(line);
+       line = (char *)NULL;
+      }
+
+      line = readline("");
+      if (line && *line) {
+       printf("%s-\n", line);
+      }
+    }
+  }
 }
-