1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Reduce scope of GString in autocompleters

fixes #867
This commit is contained in:
James Booth 2016-10-03 21:44:40 +01:00
parent 96feb0e300
commit 3e7bb2293d

View File

@ -1565,9 +1565,9 @@ _bookmark_autocomplete(ProfWin *window, const char *const input)
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");
int num_args = g_strv_length(args);
if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) {
GString *beginning = g_string_new("/bookmark");
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);
@ -1578,6 +1578,7 @@ _bookmark_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/bookmark");
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);
@ -1587,6 +1588,7 @@ _bookmark_autocomplete(ProfWin *window, const char *const input)
}
}
if ((num_args == 4 && space_at_end) || (num_args == 5 && !space_at_end)) {
GString *beginning = g_string_new("/bookmark");
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);
@ -1597,6 +1599,7 @@ _bookmark_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/bookmark");
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);
@ -1606,6 +1609,7 @@ _bookmark_autocomplete(ProfWin *window, const char *const input)
}
}
if ((num_args == 6 && space_at_end) || (num_args == 7 && !space_at_end)) {
GString *beginning = g_string_new("/bookmark");
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);
@ -1616,6 +1620,7 @@ _bookmark_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/bookmark");
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);
@ -1624,7 +1629,6 @@ _bookmark_autocomplete(ProfWin *window, const char *const input)
return found;
}
}
g_string_free(beginning, TRUE);
}
g_strfreev(args);
@ -2540,9 +2544,9 @@ _connect_autocomplete(ProfWin *window, const char *const input)
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)) {
GString *beginning = g_string_new("/connect");
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);
@ -2553,6 +2557,7 @@ _connect_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/connect");
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);
@ -2562,6 +2567,7 @@ _connect_autocomplete(ProfWin *window, const char *const input)
}
}
if ((num_args == 3 && space_at_end) || (num_args == 4 && !space_at_end)) {
GString *beginning = g_string_new("/connect");
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);
@ -2572,6 +2578,7 @@ _connect_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/connect");
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);
@ -2581,6 +2588,7 @@ _connect_autocomplete(ProfWin *window, const char *const input)
}
}
if ((num_args == 5 && space_at_end) || (num_args == 6 && !space_at_end)) {
GString *beginning = g_string_new("/connect");
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);
@ -2591,6 +2599,7 @@ _connect_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/connect");
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);
@ -2599,8 +2608,6 @@ _connect_autocomplete(ProfWin *window, const char *const input)
return found;
}
}
g_string_free(beginning, TRUE);
}
g_strfreev(args);
@ -2779,9 +2786,9 @@ _account_autocomplete(ProfWin *window, const char *const input)
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)) {
GString *beginning = g_string_new("/account");
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);
@ -2792,6 +2799,7 @@ _account_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/account");
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);
@ -2802,6 +2810,7 @@ _account_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/account");
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);
@ -2812,6 +2821,7 @@ _account_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/account");
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);
@ -2822,6 +2832,7 @@ _account_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/account");
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);
@ -2832,6 +2843,7 @@ _account_autocomplete(ProfWin *window, const char *const input)
}
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)) {
GString *beginning = g_string_new("/account");
g_string_append_printf(beginning, " %s %s %s", args[0], args[1], args[2]);
if (theme_load_ac == NULL) {
theme_load_ac = autocomplete_new();
@ -2854,6 +2866,7 @@ _account_autocomplete(ProfWin *window, const char *const input)
#ifdef HAVE_LIBGPGME
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)) {
GString *beginning = g_string_new("/account");
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);