]> git.jsancho.org Git - gacela.git/blobdiff - src/gacela.c
(no commit message)
[gacela.git] / src / gacela.c
index 8c36b4eda218d2f91a890d01a0d6c54d74b95445..737766aa3cc8818c94b760826d7ff2e37b8b2136 100644 (file)
@@ -15,6 +15,8 @@
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
+#include <stdio.h>
+#include <string.h>
 #include <libguile.h>
 #include <libgen.h>
 #include <readline/readline.h>
@@ -229,16 +231,42 @@ start_client (char *hostname, int port)
 int
 main (int argc, char *argv[])
 {
-  int shell_mode = 0;
-  int port;
+  char *arg;
+  int mode = 0;   // shell: 1, server: 2, client: 3
+  char *host;
+  int port = 0;
   int i;
 
-  for (i = 1; i < argc; i++)
+  // Checking arguments
+  for (i = 1; i < argc; i++) {
     if (strcmp (argv[i], "--shell-mode") == 0)
-      shell_mode = 1;
+      mode = 1;
+    else if (strncmp (argv[i], "--server", 8) == 0) {
+      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);
+      }
+    }
+  }
 
-  if (shell_mode == 1)
+  if (mode == 1)
     start_single (dirname (argv[0]));
+  else if (mode == 2 && port != 0)
+    start_server (dirname (argv[0]), port);
+  else if (mode == 3 && port != 0)
+    start_client (host, port);
   /*
   if (fork () == 0)
     start_server ();