about summary refs log tree commit diff stats
path: root/src/command/cmd_defs.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2017-04-07 00:36:36 +0100
committerJames Booth <boothj5@gmail.com>2017-04-07 00:36:36 +0100
commita39440b61dc5ddb3df2d4989655f4050f193eab2 (patch)
tree02d51da2a7893ce6239895a621b94de64f8a50da /src/command/cmd_defs.c
parent6cba96fdd1fd6aeec2af1bfe69d7c6805d0234a2 (diff)
downloadprofani-tty-a39440b61dc5ddb3df2d4989655f4050f193eab2.tar.gz
Match all terms on help search
Diffstat (limited to 'src/command/cmd_defs.c')
-rw-r--r--src/command/cmd_defs.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index 59d1323a..a9bc9771 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -2319,24 +2319,29 @@ cmd_search_index(char *term)
 {
     GList *results = NULL;
 
-    gchar **processed_terms = g_str_tokenize_and_fold(term, NULL, NULL);
-    int terms_len = g_strv_length(processed_terms);
+    gchar **terms = g_str_tokenize_and_fold(term, NULL, NULL);
+    int terms_len = g_strv_length(terms);
 
-    int i = 0;
-    for (i = 0; i < terms_len; i++) {
-        GList *index_keys = g_hash_table_get_keys(search_index);
-        GList *curr = index_keys;
-        while (curr) {
-            char *index_entry = g_hash_table_lookup(search_index, curr->data);
-            if (g_str_match_string(processed_terms[i], index_entry, FALSE)) {
-                results = g_list_append(results, curr->data);
+    GList *commands = g_hash_table_get_keys(search_index);
+    GList *curr = commands;
+    while (curr) {
+        char *command = curr->data;
+        int matches = 0;
+        int i = 0;
+        for (i = 0; i < terms_len; i++) {
+            char *command_index = g_hash_table_lookup(search_index, command);
+            if (g_str_match_string(terms[i], command_index, FALSE)) {
+                matches++;
             }
-            curr = g_list_next(curr);
         }
-        g_list_free(index_keys);
+        if (matches == terms_len) {
+            results = g_list_append(results, command);
+        }
+        curr = g_list_next(curr);
     }
 
-    g_strfreev(processed_terms);
+    g_list_free(commands);
+    g_strfreev(terms);
 
     return results;
 }