From 506ce9cb136c4c82114cd6b863f6362b53fa22ba Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 14 May 2014 20:49:25 +0100 Subject: [PATCH 1/4] Added autocomplete for bookmark autojoin --- src/command/command.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 65c56ab3..afc8bf05 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1664,31 +1664,52 @@ _bookmark_autocomplete(char *input, int *size) char *found = NULL; gboolean result; - gchar **args = parse_args(input, 3, 7, &result); + gchar **args = parse_args(input, 3, 8, &result); if (result && ((strcmp(args[0], "add") == 0) || (strcmp(args[0], "update") == 0)) ) { GString *beginning = g_string_new("/bookmark "); + gboolean autojoin = FALSE; + int num_args = g_strv_length(args); - if (g_strv_length(args) > 2) { + if (num_args > 2) { 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 (g_strv_length(args) > 4) { + 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 (g_strv_length(args) > 6) { + 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; + } } } - found = autocomplete_param_with_ac(input, size, beginning->str, bookmark_property_ac); + if (autojoin) { + found = autocomplete_param_with_func(input, size, beginning->str, prefs_autocomplete_boolean_choice); + } else { + found = autocomplete_param_with_ac(input, size, beginning->str, bookmark_property_ac); + } g_string_free(beginning, TRUE); if (found != NULL) { return found; From bd55e7a9783eb51cfd05ba4b9a689acada64b262 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 14 May 2014 20:53:31 +0100 Subject: [PATCH 2/4] Tidied bookmark autocompleter --- src/command/command.c | 44 ++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index afc8bf05..c2a6091e 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1680,31 +1680,33 @@ _bookmark_autocomplete(char *input, int *size) g_string_append(beginning, args[2]); autojoin = TRUE; } + } - if (num_args > 4) { + 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[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; - } - } + 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 (num_args > 2) { if (autojoin) { found = autocomplete_param_with_func(input, size, beginning->str, prefs_autocomplete_boolean_choice); } else { From 75898a777ae6d5132311df2640ed46969301b946 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 14 May 2014 21:01:54 +0100 Subject: [PATCH 3/4] More tidy of bookmark autocomplete --- src/command/command.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index c2a6091e..6dadcb64 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1665,21 +1665,21 @@ _bookmark_autocomplete(char *input, int *size) gboolean result; gchar **args = parse_args(input, 3, 8, &result); + gboolean handle_options = result && (g_strv_length(args) > 2); - if (result && ((strcmp(args[0], "add") == 0) || (strcmp(args[0], "update") == 0)) ) { - GString *beginning = g_string_new("/bookmark "); + if (handle_options && ((strcmp(args[0], "add") == 0) || (strcmp(args[0], "update") == 0)) ) { + GString *beginning = g_string_new("/bookmark"); gboolean autojoin = FALSE; int num_args = g_strv_length(args); - if (num_args > 2) { - g_string_append(beginning, args[0]); + 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[1]); - if (num_args == 4 && g_strcmp0(args[2], "autojoin") == 0) { - g_string_append(beginning, " "); - g_string_append(beginning, args[2]); - autojoin = TRUE; - } + g_string_append(beginning, args[2]); + autojoin = TRUE; } if (num_args > 4) { @@ -1706,16 +1706,14 @@ _bookmark_autocomplete(char *input, int *size) } } - if (num_args > 2) { - if (autojoin) { - found = autocomplete_param_with_func(input, size, beginning->str, prefs_autocomplete_boolean_choice); - } else { - found = autocomplete_param_with_ac(input, size, beginning->str, bookmark_property_ac); - } - g_string_free(beginning, TRUE); - if (found != NULL) { - return found; - } + if (autojoin) { + found = autocomplete_param_with_func(input, size, beginning->str, prefs_autocomplete_boolean_choice); + } else { + found = autocomplete_param_with_ac(input, size, beginning->str, bookmark_property_ac); + } + g_string_free(beginning, TRUE); + if (found != NULL) { + return found; } } From e762d80b68cf9377ba26d8781b6c87eaf11f84e8 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 14 May 2014 21:54:38 +0100 Subject: [PATCH 4/4] Use hash table for autocomplete functions --- src/command/command.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/src/command/command.c b/src/command/command.c index 6dadcb64..211f7b4f 100644 --- a/src/command/command.c +++ b/src/command/command.c @@ -1538,15 +1538,39 @@ _cmd_complete_parameters(char *input, int *size) } } - autocompleter acs[] = { _who_autocomplete, _sub_autocomplete, _notify_autocomplete, - _autoaway_autocomplete, _theme_autocomplete, _log_autocomplete, - _account_autocomplete, _roster_autocomplete, _group_autocomplete, - _bookmark_autocomplete, _autoconnect_autocomplete, _otr_autocomplete, - _connect_autocomplete, _statuses_autocomplete, _alias_autocomplete, - _join_autocomplete }; + GHashTable *ac_funcs = g_hash_table_new(g_str_hash, g_str_equal); + g_hash_table_insert(ac_funcs, "/who", _who_autocomplete); + g_hash_table_insert(ac_funcs, "/sub", _sub_autocomplete); + g_hash_table_insert(ac_funcs, "/notify", _notify_autocomplete); + g_hash_table_insert(ac_funcs, "/autoaway", _autoaway_autocomplete); + g_hash_table_insert(ac_funcs, "/theme", _theme_autocomplete); + g_hash_table_insert(ac_funcs, "/log", _log_autocomplete); + g_hash_table_insert(ac_funcs, "/account", _account_autocomplete); + g_hash_table_insert(ac_funcs, "/roster", _roster_autocomplete); + g_hash_table_insert(ac_funcs, "/group", _group_autocomplete); + g_hash_table_insert(ac_funcs, "/bookmark", _bookmark_autocomplete); + g_hash_table_insert(ac_funcs, "/autoconnect", _autoconnect_autocomplete); + g_hash_table_insert(ac_funcs, "/otr", _otr_autocomplete); + g_hash_table_insert(ac_funcs, "/connect", _connect_autocomplete); + g_hash_table_insert(ac_funcs, "/statuses", _statuses_autocomplete); + g_hash_table_insert(ac_funcs, "/alias", _alias_autocomplete); + g_hash_table_insert(ac_funcs, "/join", _join_autocomplete); - for (i = 0; i < ARRAY_SIZE(acs); i++) { - result = acs[i](input, size); + char parsed[*size+1]; + i = 0; + while (i < *size) { + if (input[i] == ' ') { + break; + } else { + parsed[i] = input[i]; + } + i++; + } + parsed[i] = '\0'; + + char * (*ac_func)(char *, int *) = g_hash_table_lookup(ac_funcs, parsed); + if (ac_func != NULL) { + result = ac_func(input, size); if (result != NULL) { ui_replace_input(input, result, size); g_free(result);