X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fgacela.c;h=737766aa3cc8818c94b760826d7ff2e37b8b2136;hb=a6e0eb4c5e06bb6107acf40eb9f6a89e691d585e;hp=8c36b4eda218d2f91a890d01a0d6c54d74b95445;hpb=73ed7bc4800eff475715461ac8c9c26a8531d4f6;p=gacela.git diff --git a/src/gacela.c b/src/gacela.c index 8c36b4e..737766a 100644 --- a/src/gacela.c +++ b/src/gacela.c @@ -15,6 +15,8 @@ along with this program. If not, see . */ +#include +#include #include #include #include @@ -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 ();