about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-04-15 00:27:55 +0100
committerJames Booth <boothj5@gmail.com>2014-04-15 00:27:55 +0100
commit40759eddbf2804cf43b9b73004609a92a7ff055c (patch)
tree33c996667bbed120e364797359e9e27c7d552b4b /src
parent4425aba1f218cdaeacc607a69287db4ad951b2d0 (diff)
downloadprofani-tty-40759eddbf2804cf43b9b73004609a92a7ff055c.tar.gz
Simplified parse_options to take first option as argument
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c4
-rw-r--r--src/tools/parser.c8
-rw-r--r--src/tools/parser.h2
3 files changed, 7 insertions, 7 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index 2daa82d1..1a05de4e 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -71,7 +71,7 @@ cmd_connect(gchar **args, struct cmd_help_t help)
         gchar *opt_keys[] = { "server", "port", NULL };
         gboolean parsed;
 
-        GHashTable *options = parse_options(args, 1, opt_keys, &parsed);
+        GHashTable *options = parse_options(&args[1], opt_keys, &parsed);
         if (!parsed) {
             cons_show("Usage: %s", help.usage);
             cons_show("");
@@ -1572,7 +1572,7 @@ cmd_join(gchar **args, struct cmd_help_t help)
     gchar *opt_keys[] = { "nick", "password", NULL };
     gboolean parsed;
 
-    GHashTable *options = parse_options(args, 1, opt_keys, &parsed);
+    GHashTable *options = parse_options(&args[1], opt_keys, &parsed);
     if (!parsed) {
         cons_show("Usage: %s", help.usage);
         cons_show("");
diff --git a/src/tools/parser.c b/src/tools/parser.c
index ff00b1e8..aafbf576 100644
--- a/src/tools/parser.c
+++ b/src/tools/parser.c
@@ -374,7 +374,7 @@ get_start(char *string, int tokens)
 }
 
 GHashTable *
-parse_options(gchar **args, int start, gchar **opt_keys, gboolean *res)
+parse_options(gchar **args, gchar **opt_keys, gboolean *res)
 {
     GList *keys = NULL;
     int i;
@@ -385,7 +385,7 @@ parse_options(gchar **args, int start, gchar **opt_keys, gboolean *res)
     GHashTable *options = NULL;
 
     // no options found, success
-    if (args[start] == NULL) {
+    if (args[0] == NULL) {
         options = g_hash_table_new(g_str_hash, g_str_equal);
         *res = TRUE;
         g_list_free(keys);
@@ -395,7 +395,7 @@ parse_options(gchar **args, int start, gchar **opt_keys, gboolean *res)
     // validate options
     int curr;
     GList *found_keys = NULL;
-    for (curr = start; curr < g_strv_length(args); curr+= 2) {
+    for (curr = 0; curr < g_strv_length(args); curr+= 2) {
         // check if option valid
         if (g_list_find_custom(keys, args[curr], (GCompareFunc)g_strcmp0) == NULL) {
             *res = FALSE;
@@ -425,7 +425,7 @@ parse_options(gchar **args, int start, gchar **opt_keys, gboolean *res)
     // create map
     options = g_hash_table_new(g_str_hash, g_str_equal);
     *res = TRUE;
-    for (curr = start; curr < g_strv_length(args); curr+=2) {
+    for (curr = 0; curr < g_strv_length(args); curr+=2) {
         g_hash_table_insert(options, args[curr], args[curr+1]);
     }
 
diff --git a/src/tools/parser.h b/src/tools/parser.h
index 10ee627c..2ca92d85 100644
--- a/src/tools/parser.h
+++ b/src/tools/parser.h
@@ -29,7 +29,7 @@ gchar** parse_args(const char * const inp, int min, int max, gboolean *result);
 gchar** parse_args_with_freetext(const char * const inp, int min, int max, gboolean *result);
 int count_tokens(char *string);
 char* get_start(char *string, int tokens);
-GHashTable* parse_options(gchar **args, int start, gchar **keys, gboolean *res);
+GHashTable* parse_options(gchar **args, gchar **keys, gboolean *res);
 void options_destroy(GHashTable *options);
 
 #endif
\ No newline at end of file