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:51:29 +0100
committerJames Booth <boothj5@gmail.com>2017-04-07 00:51:29 +0100
commit2fafaec8a7dc9bc01ee894d83214590598b32914 (patch)
tree064ebb74c63ed0e6d532845c2136d873f1c45d7a /src/command/cmd_defs.c
parenta39440b61dc5ddb3df2d4989655f4050f193eab2 (diff)
downloadprofani-tty-2fafaec8a7dc9bc01ee894d83214590598b32914.tar.gz
Allow search_any and search_all for help
Diffstat (limited to 'src/command/cmd_defs.c')
-rw-r--r--src/command/cmd_defs.c40
1 files changed, 34 insertions, 6 deletions
diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c
index a9bc9771..ae77bf53 100644
--- a/src/command/cmd_defs.c
+++ b/src/command/cmd_defs.c
@@ -118,7 +118,7 @@ static struct cmd_t command_defs[] =
         CMD_MAINFUNC(cmd_help)
         CMD_NOTAGS
         CMD_SYN(
-            "/help [<area>|<command>|search] [<search_term>]")
+            "/help [<area>|<command>|search_all|search_any] [<search_terms>]")
         CMD_DESC(
             "Help on using Profanity. Passing no arguments list help areas. "
             "For command help, optional arguments are shown using square brackets, "
@@ -126,11 +126,12 @@ static struct cmd_t command_defs[] =
             "Arguments that may be one of a number of values are separated by a pipe "
             "e.g. val1|val2|val3.")
         CMD_ARGS(
-            { "<area>",                 "Summary help for commands in a certain area of functionality." },
-            { "<command>",              "Full help for a specific command, for example '/help connect'." },
-            { "search <search_term>",   "Search commands for search_term." })
+            { "<area>",                     "Summary help for commands in a certain area of functionality." },
+            { "<command>",                  "Full help for a specific command, for example '/help connect'." },
+            { "search_all <search_terms>",  "Search commands for returning matches that contain all of the search terms." },
+            { "search_any <search_terms>",  "Search commands for returning matches that contain any of the search terms." })
         CMD_EXAMPLES(
-            "/help search presence online",
+            "/help search_all presence online",
             "/help commands",
             "/help presence",
             "/help who")
@@ -2315,7 +2316,34 @@ _cmd_index(Command *cmd) {
 }
 
 GList*
-cmd_search_index(char *term)
+cmd_search_index_any(char *term)
+{
+    GList *results = NULL;
+
+    gchar **processed_terms = g_str_tokenize_and_fold(term, NULL, NULL);
+    int terms_len = g_strv_length(processed_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);
+            }
+            curr = g_list_next(curr);
+        }
+        g_list_free(index_keys);
+    }
+
+    g_strfreev(processed_terms);
+
+    return results;
+}
+
+GList*
+cmd_search_index_all(char *term)
 {
     GList *results = NULL;