about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKristofer M White <me@kmwhite.net>2014-03-05 17:13:42 +0000
committerKristofer M White <me@kmwhite.net>2014-03-05 17:13:42 +0000
commit28425060bc5a759dead356e3ef49fc80a8c270d8 (patch)
tree5b9ba08e10fc9338b78e86e5056a65cc25165551
parentced6e7f411bb3e974344bdb72b7525bf63764b27 (diff)
downloadprofani-tty-28425060bc5a759dead356e3ef49fc80a8c270d8.tar.gz
Parsing optional args for cmd_join
-rw-r--r--src/command/command.c10
-rw-r--r--src/command/commands.c39
2 files changed, 37 insertions, 12 deletions
diff --git a/src/command/command.c b/src/command/command.c
index d7833433..5a1960ad 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -235,9 +235,9 @@ static struct cmd_t command_defs[] =
           NULL } } },
 
     { "/join",
-        cmd_join, parse_args_with_freetext, 1, 3, NULL,
-        { "/join room[@server] [nick] [password]", "Join a chat room.",
-        { "/join room[@server] [nick] [password]",
+        cmd_join, parse_args, 1, 5, NULL,
+        { "/join room[@server] [nick value] [passwd value]", "Join a chat room.",
+        { "/join room[@server] [nick value] [passwd value]",
           "--------------------------",
           "Join a chat room at the conference server.",
           "If nick is specified you will join with this nickname.",
@@ -246,8 +246,8 @@ static struct cmd_t command_defs[] =
           "If the room doesn't exist, and the server allows it, a new one will be created.",
           "",
           "Example : /join jdev@conference.jabber.org",
-          "Example : /join jdev@conference.jabber.org mynick",
-          "Example : /join private@conference.jabber.org mynick mypassword",
+          "Example : /join jdev@conference.jabber.org nick mynick",
+          "Example : /join private@conference.jabber.org nick mynick passwd mypassword",
           "Example : /join jdev (as user@jabber.org will join jdev@conference.jabber.org)",
           NULL } } },
 
diff --git a/src/command/commands.c b/src/command/commands.c
index 7b6fc0f0..2515a5bd 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -1610,20 +1610,45 @@ cmd_join(gchar **args, struct cmd_help_t help)
         room = room_str->str;
     }
 
-    // nick supplied
+    // Additional args supplied
     if (num_args > 1) {
+        char *opt1 = args[1];
+        char *opt1val = args[2];
+        char *opt2 = args[3];
+        char *opt2val = args[4];
+        if (opt1 != NULL) {
+            if (opt1val == NULL) {
+                cons_show("Usage: %s", help.usage);
+                cons_show("");
+                return TRUE;
+            }
+            if (strcmp(opt1, "nick") == 0) {
+                nick = strdup(opt1val);
+            } else if (strcmp(opt1, "passwd") == 0) {
+                passwd = strdup(opt1val);
+            } else {
+                cons_show("Usage: %s", help.usage);
+                cons_show("");
+                return TRUE;
+            }
+            if (opt2 != NULL) {
+                if (strcmp(opt2, "nick") == 0) {
+                    nick = strdup(opt2val);
+                } else if (strcmp(opt2, "passwd") == 0) {
+                    passwd = strdup(opt2val);
+                } else {
+                    cons_show("Usage: %s", help.usage);
+                    cons_show("");
+                    return TRUE;
+                }
+            }
+        }
         nick = args[1];
-
     // otherwise use account preference
     } else {
         nick = account->muc_nick;
     }
 
-    // pass supplied
-    if (num_args == 3) {
-        passwd = args[2];
-    }
-
     Jid *room_jid = jid_create_from_bare_and_resource(room, nick);
 
     if (!muc_room_is_active(room_jid)) {