about summary refs log tree commit diff stats
path: root/command.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-02-18 23:09:21 +0000
committerJames Booth <boothj5@gmail.com>2012-02-18 23:09:21 +0000
commit34fba754ea5122575b0a3ea1f3a76de96e973e81 (patch)
tree2f47c03b40580241e545ae999fa572f56abbdfdd /command.c
parent547704b65aae6771e984a28e214db43a578785e7 (diff)
downloadprofani-tty-34fba754ea5122575b0a3ea1f3a76de96e973e81.tar.gz
Tidy start commands
Diffstat (limited to 'command.c')
-rw-r--r--command.c87
1 files changed, 55 insertions, 32 deletions
diff --git a/command.c b/command.c
index 076187de..9022fd9f 100644
--- a/command.c
+++ b/command.c
@@ -5,6 +5,11 @@
 #include "windows.h"
 #include "util.h"
 
+static int _cmd_start_quit(void);
+static int _cmd_start_help(void);
+static int _cmd_start_connect(char *inp);
+static int _cmd_start_default(char *inp);
+
 static int _cmd_quit(void);
 static int _cmd_help(void);
 static int _cmd_who(void);
@@ -31,46 +36,18 @@ int handle_start_command(char *inp)
     // get the command "/command"
     char *command = strtok(inp_cpy, " ");
 
-    // handle invalid commands
     if (!_valid_start_command(command)) {
         cons_bad_command(command);
         gui_refresh();
         result = AWAIT_COMMAND;
-
-    // quit
     } else if (strcmp(command, "/quit") == 0) {
-        result = QUIT_PROF;
-
-    // help
+        result = _cmd_start_quit();
     } else if (strcmp(command, "/help") == 0) {
-        cons_help();
-        gui_refresh();
-        result = AWAIT_COMMAND;
-
-    // connect
+        result = _cmd_start_help();
     } else if (strcmp(command, "/connect") == 0) {
-        if (strlen(inp) < 10) {
-            cons_bad_connect();
-            gui_refresh();
-            result = AWAIT_COMMAND;
-        } else {
-            char *user;
-            user = strndup(inp+9, strlen(inp)-9);
-
-            status_bar_get_password();
-            status_bar_refresh();
-            char passwd[20];
-            inp_get_password(passwd);
-            int connect_status = jabber_connect(user, passwd);
-            if (connect_status == CONNECTING)
-                result = START_MAIN;
-            else
-                result = AWAIT_COMMAND;
-            }
+        result = _cmd_start_connect(inp);
     } else {
-        cons_bad_command(inp);
-        gui_refresh();
-        result = AWAIT_COMMAND;
+        result = _cmd_start_default(inp);
     }
 
     inp_clear();
@@ -101,6 +78,52 @@ int handle_command(char *cmd)
 
 }
 
+static int _cmd_start_quit(void)
+{
+    return QUIT_PROF;
+}
+
+static int _cmd_start_help(void)
+{
+    cons_help();
+    gui_refresh();
+    return AWAIT_COMMAND;
+}
+
+static int _cmd_start_connect(char *inp)
+{
+    int result = AWAIT_COMMAND;
+
+    if (strlen(inp) < 10) {
+        cons_bad_connect();
+        gui_refresh();
+        result = AWAIT_COMMAND;
+    } else {
+        char *user;
+        user = strndup(inp+9, strlen(inp)-9);
+
+        status_bar_get_password();
+        status_bar_refresh();
+        char passwd[20];
+        inp_get_password(passwd);
+        int connect_status = jabber_connect(user, passwd);
+        if (connect_status == CONNECTING)
+            result = START_MAIN;
+        else
+            result = AWAIT_COMMAND;
+    }
+    
+    return result;
+}
+
+static int _cmd_start_default(char *inp)
+{
+    cons_bad_command(inp);
+    gui_refresh();
+
+    return AWAIT_COMMAND;
+}
+
 static int _cmd_quit(void)
 {
     return FALSE;