diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/command/cmd_ac.c | 123 | ||||
-rw-r--r-- | src/tools/autocomplete.c | 6 |
2 files changed, 72 insertions, 57 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 7e2b3164..951bc136 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1534,57 +1534,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 == 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; + } } - - 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 == 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 > 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 ((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 (autojoin) { + 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); - } else { + 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; + } } - 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; + } } } @@ -1709,13 +1720,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; } @@ -1767,12 +1776,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); @@ -1855,7 +1866,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(); @@ -1883,7 +1894,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(); @@ -1930,14 +1941,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; @@ -2270,13 +2281,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); @@ -2318,13 +2331,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); 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 |