about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-04-14 23:01:57 +0100
committerJames Booth <boothj5@gmail.com>2014-04-14 23:01:57 +0100
commit241973700697abb60104c656a0aacfd182eb2316 (patch)
treea9aa0dcf7576a819a835e48d6c35c4c17de32552 /src
parent8d77930eceba6841673605f7df5083657a0ecd28 (diff)
downloadprofani-tty-241973700697abb60104c656a0aacfd182eb2316.tar.gz
Check for duplicate options in option parser
Diffstat (limited to 'src')
-rw-r--r--src/tools/parser.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/tools/parser.c b/src/tools/parser.c
index 375572e0..b4403d06 100644
--- a/src/tools/parser.c
+++ b/src/tools/parser.c
@@ -385,14 +385,31 @@ parse_options(gchar **args, int start, GList *keys, gboolean *res)
         return options;
     }
 
-    // check each option is valid and has value, failure if not
+    // validate options
     int curr;
+    GList *found_keys = NULL;
     for (curr = start; curr < g_strv_length(args); curr+= 2) {
-        if ((g_list_find(keys, args[curr]) == NULL) || (args[curr+1] == NULL)) {
+        // check if option valid
+        if (g_list_find(keys, args[curr]) == NULL) {
             *res = FALSE;
             return options;
         }
+
+        // check if duplicate
+        if (g_list_find(found_keys, args[curr]) != NULL) {
+            *res = FALSE;
+            return options;
+        }
+
+        // check value given
+        if (args[curr+1] == NULL) {
+            *res = FALSE;
+            return options;
+        }
+
+        found_keys = g_list_append(found_keys, args[curr]);
     }
+    g_list_free(found_keys);
 
     // create map
     options = g_hash_table_new(g_str_hash, g_str_equal);