- arg = strdup (argv[i]);
- port = 1234;
-
- if (mode == 1)
- start_single (dirname (argv[0]));
- else
- printf ("Puerto: %d\n", port);
- /*
- if (fork () == 0)
- start_server ();
- else
- start_client ("localhost", 1234);
- */
+ mode = 2;
+ arg = strtok (argv[i], "=");
+ arg = strtok (NULL, "=");
+ if (arg != NULL)
+ port = atoi (arg);
+ }
+ else if (strncmp (argv[i], "--client", 8) == 0) {
+ mode = 3;
+ arg = strtok (argv[i], "=");
+ arg = strtok (NULL, "=");
+ if (arg != NULL) {
+ host = strtok (arg, ":");
+ arg = strtok (NULL, ":");
+ if (arg != NULL)
+ port = atoi (arg);
+ }
+ }
+ }
+
+ scm_init_guile ();
+
+ if (mode == 1) {
+ fd1 = scm_pipe ();
+ fd2 = scm_pipe ();
+ pid = fork ();
+
+ if (pid == 0) {
+ scm_close (SCM_CAR (fd1));
+ scm_close (SCM_CDR (fd2));
+ init_gacela (dirname (argv[0]));
+ start_local_server (scm_cons (SCM_CAR (fd2), SCM_CDR (fd1)));
+ }
+ else {
+ scm_close (SCM_CDR (fd1));
+ scm_close (SCM_CAR (fd2));
+ gacela_client (SCM_CAR (fd1), SCM_CDR (fd2));
+ kill (pid, SIGKILL);
+ }
+ }
+ else if (mode == 2 && port != 0) {
+ init_gacela (dirname (argv[0]));
+ start_server (port);
+ }
+ else if (mode == 3 && port != 0)
+ start_remote_client (host, port);
+ else {
+ init_gacela (dirname (argv[0]));
+ scm_shell (argc, argv);
+ SDL_Quit ();
+ }