about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-04-27 00:10:11 +0100
committerJames Booth <boothj5@gmail.com>2012-04-27 00:10:11 +0100
commit0c0a242972456e19a609b70cbbfc774cbfc1a91f (patch)
tree38ff16508add540e48aae8659595ef100263d9ca
parent887278b91bbb88f746e4dda2dff3a5ad78f8483c (diff)
downloadprofani-tty-0c0a242972456e19a609b70cbbfc774cbfc1a91f.tar.gz
Created command_t struct for command handling
-rw-r--r--command.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/command.c b/command.c
index 17c2dcb0..de36e732 100644
--- a/command.c
+++ b/command.c
@@ -34,6 +34,7 @@
 
 static gboolean _handle_command(const char * const command, 
     const char * const inp);
+static struct command_t _parse_command(char *str);
 static gboolean _cmd_quit(void);
 static gboolean _cmd_help(void);
 static gboolean _cmd_who(void);
@@ -45,6 +46,11 @@ static gboolean _cmd_set_beep(const char * const inp);
 static gboolean _cmd_set_flash(const char * const inp);
 static gboolean _cmd_default(const char * const inp);
 
+struct command_t {
+    char *command;
+    char **params;
+};
+
 gboolean process_input(char *inp)
 {
     gboolean result = FALSE;
@@ -57,10 +63,8 @@ gboolean process_input(char *inp)
     if (strlen(inp) == 0) {
         result = TRUE;
     } else if (inp[0] == '/') {
-        char inp_cpy[strlen(inp) + 1];
-        strcpy(inp_cpy, inp);
-        char *command = strtok(inp_cpy, " ");
-        result = _handle_command(command, inp);
+        struct command_t cmd = _parse_command(inp);
+        result = _handle_command(cmd.command, inp);
     } else {
         result = _cmd_default(inp);
     }
@@ -72,6 +76,16 @@ gboolean process_input(char *inp)
     return result;
 }
 
+static struct command_t _parse_command(char *str)
+{
+    struct command_t cmd;
+    char **split = g_strsplit(str, " ", 0);
+
+    cmd.command = split[0];
+    cmd.params = NULL;
+    return cmd;
+}
+
 static gboolean _handle_command(const char * const command, const char * const inp)
 {
     gboolean result = FALSE;