From f377e0329efe9f2b20a95c286a867c36cab0fce0 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 May 2016 00:32:53 +0100 Subject: [PATCH 01/12] Allow autocomplete for basic compelters when no input --- src/tools/autocomplete.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index dc071357..2484a6e1 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -224,7 +224,7 @@ autocomplete_param_with_func(const char *const input, char *command, autocomplet sprintf(command_cpy, "%s ", command); int len = strlen(command_cpy); - if ((strncmp(input, command_cpy, len) == 0) && (strlen(input) > len)) { + if (strncmp(input, command_cpy, len) == 0) { int i; int inp_len = strlen(input); char prefix[inp_len]; @@ -255,7 +255,7 @@ autocomplete_param_with_ac(const char *const input, char *command, Autocomplete sprintf(command_cpy, "%s ", command); int len = strlen(command_cpy); int inp_len = strlen(input); - if ((strncmp(input, command_cpy, len) == 0) && (strlen(input) > len)) { + if (strncmp(input, command_cpy, len) == 0) { int i; char prefix[inp_len]; for(i = len; i < inp_len; i++) { @@ -280,7 +280,7 @@ autocomplete_param_with_ac(const char *const input, char *command, Autocomplete char* autocomplete_param_no_with_func(const char *const input, char *command, int arg_number, autocomplete_func func) { - if (strncmp(input, command, strlen(command)) == 0 && (strlen(input) > strlen(command))) { + if (strncmp(input, command, strlen(command)) == 0) { GString *result_str = NULL; // count tokens properly From e183fd918614dcbecfc10203d660d2607d1f4f27 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 May 2016 01:28:04 +0100 Subject: [PATCH 02/12] Allow empty autocomplete for /otr policy --- src/command/cmd_ac.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index e43bcdb1..5cc0405a 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1707,13 +1707,11 @@ _log_autocomplete(ProfWin *window, const char *const input) { char *result = NULL; - result = autocomplete_param_with_func(input, "/log rotate", - prefs_autocomplete_boolean_choice); + result = autocomplete_param_with_func(input, "/log rotate", prefs_autocomplete_boolean_choice); if (result) { return result; } - result = autocomplete_param_with_func(input, "/log shared", - prefs_autocomplete_boolean_choice); + result = autocomplete_param_with_func(input, "/log shared", prefs_autocomplete_boolean_choice); if (result) { return result; } @@ -1765,12 +1763,14 @@ _otr_autocomplete(ProfWin *window, const char *const input) // /otr policy always user@server.com if (conn_status == JABBER_CONNECTED) { gboolean result; - gchar **args = parse_args(input, 3, 3, &result); + gchar **args = parse_args(input, 2, 3, &result); if (result && (strcmp(args[0], "policy") == 0)) { GString *beginning = g_string_new("/otr "); g_string_append(beginning, args[0]); g_string_append(beginning, " "); - g_string_append(beginning, args[1]); + if (args[1]) { + g_string_append(beginning, args[1]); + } found = autocomplete_param_with_func(input, beginning->str, roster_contact_autocomplete); g_string_free(beginning, TRUE); From d1ece21b5f581f39b97262e981a7d68e2a82f0bb Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 May 2016 01:36:21 +0100 Subject: [PATCH 03/12] Complete no arg for /plugins load --- src/command/cmd_ac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 5cc0405a..ab62fa3a 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1853,7 +1853,7 @@ static char* _plugins_autocomplete(ProfWin *window, const char *const input) { char *result = NULL; - if ((strncmp(input, "/plugins load ", 14) == 0) && (strlen(input) > 14)) { + if (strncmp(input, "/plugins load ", 14) == 0) { if (plugins_load_ac == NULL) { plugins_load_ac = autocomplete_new(); GSList *plugins = plugins_unloaded_list(); From 78c23dce5894e9a9688d204ea5271be7f64dff4d Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 May 2016 01:37:25 +0100 Subject: [PATCH 04/12] Complete no arg for /theme load --- src/command/cmd_ac.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index ab62fa3a..df53b322 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1881,7 +1881,7 @@ static char* _theme_autocomplete(ProfWin *window, const char *const input) { char *result = NULL; - if ((strncmp(input, "/theme load ", 12) == 0) && (strlen(input) > 12)) { + if (strncmp(input, "/theme load ", 12) == 0) { if (theme_load_ac == NULL) { theme_load_ac = autocomplete_new(); GSList *themes = theme_list(); From 492c1bfa14cc4c67777bf9473d6f2f678dbe3f4f Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 May 2016 01:39:16 +0100 Subject: [PATCH 05/12] Complete no arg for /script run|show --- src/command/cmd_ac.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index df53b322..534afc0f 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1928,14 +1928,14 @@ static char* _script_autocomplete(ProfWin *window, const char *const input) { char *result = NULL; - if ((strncmp(input, "/script show ", 13) == 0) && (strlen(input) > 13)) { + if (strncmp(input, "/script show ", 13) == 0) { result = autocomplete_param_with_func(input, "/script show", _script_autocomplete_func); if (result) { return result; } } - if ((strncmp(input, "/script run ", 12) == 0) && (strlen(input) > 12)) { + if (strncmp(input, "/script run ", 12) == 0) { result = autocomplete_param_with_func(input, "/script run", _script_autocomplete_func); if (result) { return result; From e8b25780399dda78a3f5ee0dfa94017316c9d7e6 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 May 2016 01:43:45 +0100 Subject: [PATCH 06/12] Complete no arg for /affiliation set --- src/command/cmd_ac.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 534afc0f..8b902c34 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2268,13 +2268,15 @@ _affiliation_autocomplete(ProfWin *window, const char *const input) gboolean parse_result; Autocomplete jid_ac = muc_roster_jid_ac(mucwin->roomjid); - gchar **args = parse_args(input, 3, 3, &parse_result); + gchar **args = parse_args(input, 2, 3, &parse_result); if ((strncmp(input, "/affiliation", 12) == 0) && (parse_result == TRUE)) { GString *beginning = g_string_new("/affiliation "); g_string_append(beginning, args[0]); g_string_append(beginning, " "); - g_string_append(beginning, args[1]); + if (args[1]) { + g_string_append(beginning, args[1]); + } result = autocomplete_param_with_ac(input, beginning->str, jid_ac, TRUE); g_string_free(beginning, TRUE); From 8699510408030201fb3ea432a63441ad73e65324 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 May 2016 01:44:56 +0100 Subject: [PATCH 07/12] Complete no arg for /role set --- src/command/cmd_ac.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 8b902c34..6db2995f 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2318,13 +2318,15 @@ _role_autocomplete(ProfWin *window, const char *const input) gboolean parse_result; Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid); - gchar **args = parse_args(input, 3, 3, &parse_result); + gchar **args = parse_args(input, 2, 3, &parse_result); if ((strncmp(input, "/role", 5) == 0) && (parse_result == TRUE)) { GString *beginning = g_string_new("/role "); g_string_append(beginning, args[0]); g_string_append(beginning, " "); - g_string_append(beginning, args[1]); + if (args[1]) { + g_string_append(beginning, args[1]); + } result = autocomplete_param_with_ac(input, beginning->str, nick_ac, TRUE); g_string_free(beginning, TRUE); From b5749197385f9cff9a495a977dd70f027ff421b9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 May 2016 01:44:56 +0100 Subject: [PATCH 08/12] Complete no arg for /role set --- src/command/cmd_ac.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 8b902c34..6db2995f 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2318,13 +2318,15 @@ _role_autocomplete(ProfWin *window, const char *const input) gboolean parse_result; Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid); - gchar **args = parse_args(input, 3, 3, &parse_result); + gchar **args = parse_args(input, 2, 3, &parse_result); if ((strncmp(input, "/role", 5) == 0) && (parse_result == TRUE)) { GString *beginning = g_string_new("/role "); g_string_append(beginning, args[0]); g_string_append(beginning, " "); - g_string_append(beginning, args[1]); + if (args[1]) { + g_string_append(beginning, args[1]); + } result = autocomplete_param_with_ac(input, beginning->str, nick_ac, TRUE); g_string_free(beginning, TRUE); From 5c15f95646767aaf5df705b658a22ef4fb91f693 Mon Sep 17 00:00:00 2001 From: James Booth Date: Tue, 24 May 2016 23:39:27 +0100 Subject: [PATCH 09/12] Complete no arg for /bookmark properties --- src/command/cmd_ac.c | 103 ++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 46 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 6db2995f..641b3291 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1532,57 +1532,68 @@ _bookmark_autocomplete(ProfWin *window, const char *const input) char *found = NULL; gboolean result; - gchar **args = parse_args(input, 3, 8, &result); - gboolean handle_options = result && (g_strv_length(args) > 2); + gchar **args = parse_args(input, 2, 8, &result); - if (handle_options && ((strcmp(args[0], "add") == 0) || (strcmp(args[0], "update") == 0)) ) { + if (result && ((strcmp(args[0], "add") == 0) || (strcmp(args[0], "update") == 0)) ) { + gboolean space_at_end = g_str_has_suffix(input, " "); GString *beginning = g_string_new("/bookmark"); - gboolean autojoin = FALSE; int num_args = g_strv_length(args); - - g_string_append(beginning, " "); - g_string_append(beginning, args[0]); - g_string_append(beginning, " "); - g_string_append(beginning, args[1]); - if (num_args == 4 && g_strcmp0(args[2], "autojoin") == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); - autojoin = TRUE; - } - - if (num_args > 4) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); - g_string_append(beginning, " "); - g_string_append(beginning, args[3]); - if (num_args == 6 && g_strcmp0(args[4], "autojoin") == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[4]); - autojoin = TRUE; - } - } - - if (num_args > 6) { - g_string_append(beginning, " "); - g_string_append(beginning, args[4]); - g_string_append(beginning, " "); - g_string_append(beginning, args[5]); - if (num_args == 8 && g_strcmp0(args[6], "autojoin") == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[6]); - autojoin = TRUE; - } - } - - if (autojoin) { - found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice); - } else { + if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) { + g_string_append_printf(beginning, " %s %s", args[0], args[1]); found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } } - g_string_free(beginning, TRUE); - if (found) { - g_strfreev(args); - return found; + if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "autojoin") == 0)) + || (num_args == 4 && (g_strcmp0(args[2], "autojoin") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); + found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 4 && space_at_end) || (num_args == 5 && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s %s", args[0], args[1], args[2], args[3]); + found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 5 && space_at_end && (g_strcmp0(args[4], "autojoin") == 0)) + || (num_args == 6 && (g_strcmp0(args[4], "autojoin") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4]); + found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 6 && space_at_end) || (num_args == 7 && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5]); + found = autocomplete_param_with_ac(input, beginning->str, bookmark_property_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 7 && space_at_end && (g_strcmp0(args[6], "autojoin") == 0)) + || (num_args == 8 && (g_strcmp0(args[6], "autojoin") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + found = autocomplete_param_with_func(input, beginning->str, prefs_autocomplete_boolean_choice); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } } } From 28cc04ca7d994e408cac3ca29a8d6ce6d4f1e8e2 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 1 Jun 2016 00:04:35 +0100 Subject: [PATCH 10/12] Complete no arg for /connect properties --- src/command/cmd_ac.c | 105 +++++++++++++++++++++---------------------- 1 file changed, 52 insertions(+), 53 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 951bc136..6b85b6a1 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1527,7 +1527,6 @@ _blocked_autocomplete(ProfWin *window, const char *const input) return NULL; } - static char* _bookmark_autocomplete(ProfWin *window, const char *const input) { @@ -2468,68 +2467,68 @@ _connect_autocomplete(ProfWin *window, const char *const input) char *found = NULL; gboolean result = FALSE; - gchar **args = parse_args(input, 2, 6, &result); + gchar **args = parse_args(input, 1, 7, &result); - if ((strncmp(input, "/connect", 8) == 0) && (result == TRUE)) { - GString *beginning = g_string_new("/connect "); - g_string_append(beginning, args[0]); - if (args[1] && args[2]) { - g_string_append(beginning, " "); - g_string_append(beginning, args[1]); - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); - if (args[3] && args[4]) { - g_string_append(beginning, " "); - g_string_append(beginning, args[3]); - g_string_append(beginning, " "); - g_string_append(beginning, args[4]); + if (result) { + gboolean space_at_end = g_str_has_suffix(input, " "); + GString *beginning = g_string_new("/connect"); + int num_args = g_strv_length(args); + if ((num_args == 1 && space_at_end) || (num_args == 2 && !space_at_end)) { + g_string_append_printf(beginning, " %s", args[0]); + found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; } } - found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE); - g_string_free(beginning, TRUE); - if (found) { - g_strfreev(args); - return found; - } - } - - g_strfreev(args); - - result = FALSE; - args = parse_args(input, 2, 7, &result); - - if ((strncmp(input, "/connect", 8) == 0) && (result == TRUE)) { - GString *beginning = g_string_new("/connect "); - g_string_append(beginning, args[0]); - int curr = 0; - if (args[1]) { - g_string_append(beginning, " "); - g_string_append(beginning, args[1]); - curr = 1; - if (args[2] && args[3]) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); - g_string_append(beginning, " "); - g_string_append(beginning, args[3]); - curr = 3; - if (args[4] && args[5]) { - g_string_append(beginning, " "); - g_string_append(beginning, args[4]); - g_string_append(beginning, " "); - g_string_append(beginning, args[5]); - curr = 5; - } - } - } - if (curr != 0 && (g_strcmp0(args[curr], "tls") == 0)) { + if ((num_args == 2 && space_at_end && (g_strcmp0(args[1], "tls") == 0)) + || (num_args == 3 && (g_strcmp0(args[1], "tls") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s", args[0], args[1]); found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE); g_string_free(beginning, TRUE); if (found) { g_strfreev(args); return found; } - } else { + } + if ((num_args == 3 && space_at_end) || (num_args == 4 && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); + found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE); g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 4 && space_at_end && (g_strcmp0(args[3], "tls") == 0)) + || (num_args == 5 && (g_strcmp0(args[3], "tls") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s %s", args[0], args[1], args[2], args[3]); + found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 5 && space_at_end) || (num_args == 6 && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4]); + found = autocomplete_param_with_ac(input, beginning->str, connect_property_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 6 && space_at_end && (g_strcmp0(args[5], "tls") == 0)) + || (num_args == 7 && (g_strcmp0(args[5], "tls") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s %s %s %s", args[0], args[1], args[2], args[3], args[4], args[5]); + found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } } } From 78785fa7e62eb6f8c30a015a180b4b33805d7317 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 1 Jun 2016 00:15:01 +0100 Subject: [PATCH 11/12] Complete no arg for /join properties --- src/command/cmd_ac.c | 45 +++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 6b85b6a1..63ad4fbc 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2566,32 +2566,39 @@ _join_autocomplete(ProfWin *window, const char *const input) char *found = NULL; gboolean result = FALSE; - found = autocomplete_param_with_func(input, "/join", bookmark_find); - if (found) { - return found; - } + gchar **args = parse_args(input, 1, 5, &result); - gchar **args = parse_args(input, 2, 4, &result); - - if ((strncmp(input, "/join", 5) == 0) && (result == TRUE)) { - GString *beginning = g_string_new("/join "); - g_string_append(beginning, args[0]); - if (args[1] && args[2]) { - g_string_append(beginning, " "); - g_string_append(beginning, args[1]); - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); + if (result) { + gboolean space_at_end = g_str_has_suffix(input, " "); + GString *beginning = g_string_new("/join"); + int num_args = g_strv_length(args); + if ((num_args == 1 && space_at_end) || (num_args == 2 && !space_at_end)) { + g_string_append_printf(beginning, " %s", args[0]); + found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } } - found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE); - g_string_free(beginning, TRUE); - if (found) { - g_strfreev(args); - return found; + if ((num_args == 3 && space_at_end) || (num_args == 4 && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); + found = autocomplete_param_with_ac(input, beginning->str, join_property_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } } } g_strfreev(args); + found = autocomplete_param_with_func(input, "/join", bookmark_find); + if (found) { + return found; + } + return NULL; } From 784d9642bc56c9d88f3d9a0df87b3e29614d2054 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 1 Jun 2016 00:41:27 +0100 Subject: [PATCH 12/12] Complete no arg for /account properties --- src/command/cmd_ac.c | 70 ++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 31 deletions(-) diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 63ad4fbc..fca3326a 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -2802,50 +2802,63 @@ _account_autocomplete(ProfWin *window, const char *const input) char *found = NULL; gboolean result = FALSE; - gchar **args = parse_args(input, 3, 4, &result); - - if ((strncmp(input, "/account set", 12) == 0) && (result == TRUE)) { - GString *beginning = g_string_new("/account set "); - g_string_append(beginning, args[1]); - if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "otr")) == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); + gchar **args = parse_args(input, 2, 4, &result); + if (result && (strcmp(args[0], "set") == 0)) { + gboolean space_at_end = g_str_has_suffix(input, " "); + GString *beginning = g_string_new("/account"); + int num_args = g_strv_length(args); + if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) { + g_string_append_printf(beginning, " %s %s", args[0], args[1]); + found = autocomplete_param_with_ac(input, beginning->str, account_set_ac, TRUE); + g_string_free(beginning, TRUE); + if (found) { + g_strfreev(args); + return found; + } + } + if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "otr") == 0)) + || (num_args == 4 && (g_strcmp0(args[2], "otr") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); found = autocomplete_param_with_ac(input, beginning->str, otr_policy_ac, TRUE); g_string_free(beginning, TRUE); if (found) { g_strfreev(args); return found; } - } else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "status")) == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); + } + if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "status") == 0)) + || (num_args == 4 && (g_strcmp0(args[2], "status") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); found = autocomplete_param_with_ac(input, beginning->str, account_status_ac, TRUE); g_string_free(beginning, TRUE); if (found) { g_strfreev(args); return found; } - } else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "tls")) == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); + } + if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "tls") == 0)) + || (num_args == 4 && (g_strcmp0(args[2], "tls") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); found = autocomplete_param_with_ac(input, beginning->str, tls_property_ac, TRUE); g_string_free(beginning, TRUE); if (found) { g_strfreev(args); return found; } - } else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "startscript")) == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); + } + if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "startscript") == 0)) + || (num_args == 4 && (g_strcmp0(args[2], "startscript") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); found = autocomplete_param_with_func(input, beginning->str, _script_autocomplete_func); g_string_free(beginning, TRUE); if (found) { g_strfreev(args); return found; } - } else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "theme")) == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); + } + if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "theme") == 0)) + || (num_args == 4 && (g_strcmp0(args[2], "theme") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); if (theme_load_ac == NULL) { theme_load_ac = autocomplete_new(); GSList *themes = theme_list(); @@ -2860,27 +2873,22 @@ _account_autocomplete(ProfWin *window, const char *const input) found = autocomplete_param_with_ac(input, beginning->str, theme_load_ac, TRUE); g_string_free(beginning, TRUE); if (found) { + g_strfreev(args); return found; } + } #ifdef HAVE_LIBGPGME - } else if ((g_strv_length(args) > 3) && (g_strcmp0(args[2], "pgpkeyid")) == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); + if ((num_args == 3 && space_at_end && (g_strcmp0(args[2], "pgpkeyid") == 0)) + || (num_args == 4 && (g_strcmp0(args[2], "pgpkeyid") == 0) && !space_at_end)) { + g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]); found = autocomplete_param_with_func(input, beginning->str, p_gpg_autocomplete_key); g_string_free(beginning, TRUE); if (found) { g_strfreev(args); return found; } -#endif - } else { - found = autocomplete_param_with_ac(input, beginning->str, account_set_ac, TRUE); - g_string_free(beginning, TRUE); - if (found) { - g_strfreev(args); - return found; - } } +#endif } if ((strncmp(input, "/account clear", 14) == 0) && (result == TRUE)) {