Cleanup g_strfreev() to auto_gcharv

Include some additional minor cleanups
This commit is contained in:
John Hernandez
2023-07-13 16:31:31 +02:00
parent 029f1caa52
commit 865a056315
16 changed files with 165 additions and 234 deletions

View File

@@ -3210,14 +3210,14 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
return NULL;
}
gchar** split = g_strsplit(input, " ", 0);
auto_gcharv gchar** split = g_strsplit(input, " ", 0);
if (g_strv_length(split) == 3) {
char* field_tag = split[0] + 1;
if (form_tag_exists(form, field_tag)) {
form_field_type_t field_type = form_get_field_type(form, field_tag);
Autocomplete value_ac = form_get_value_ac(form, field_tag);
;
GString* beginning = g_string_new(split[0]);
g_string_append(beginning, " ");
g_string_append(beginning, split[1]);
@@ -3225,10 +3225,8 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
if (((g_strcmp0(split[1], "add") == 0) || (g_strcmp0(split[1], "remove") == 0))
&& field_type == FIELD_LIST_MULTI) {
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_TEXT_MULTI) {
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
} else if ((g_strcmp0(split[1], "remove") == 0) && field_type == FIELD_JID_MULTI) {
found = autocomplete_param_with_ac(input, beginning->str, value_ac, TRUE, previous);
}
@@ -3241,7 +3239,6 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
if (form_tag_exists(form, field_tag)) {
form_field_type_t field_type = form_get_field_type(form, field_tag);
Autocomplete value_ac = form_get_value_ac(form, field_tag);
;
switch (field_type) {
case FIELD_BOOLEAN:
@@ -3261,8 +3258,6 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
}
}
g_strfreev(split);
return found;
}

View File

@@ -2768,7 +2768,7 @@ _cmd_index(const Command* cmd)
index_source = g_string_append(index_source, " ");
}
gchar** tokens = g_str_tokenize_and_fold(index_source->str, NULL, NULL);
auto_gcharv gchar** tokens = g_str_tokenize_and_fold(index_source->str, NULL, NULL);
g_string_free(index_source, TRUE);
GString* index = g_string_new("");
@@ -2776,7 +2776,6 @@ _cmd_index(const Command* cmd)
index = g_string_append(index, tokens[i]);
index = g_string_append(index, " ");
}
g_strfreev(tokens);
return g_string_free(index, FALSE);
}
@@ -2786,7 +2785,7 @@ cmd_search_index_any(char* term)
{
GList* results = NULL;
gchar** processed_terms = g_str_tokenize_and_fold(term, NULL, NULL);
auto_gcharv gchar** processed_terms = g_str_tokenize_and_fold(term, NULL, NULL);
int terms_len = g_strv_length(processed_terms);
for (int i = 0; i < terms_len; i++) {
@@ -2802,8 +2801,6 @@ cmd_search_index_any(char* term)
g_list_free(index_keys);
}
g_strfreev(processed_terms);
return results;
}
@@ -2812,7 +2809,7 @@ cmd_search_index_all(char* term)
{
GList* results = NULL;
gchar** terms = g_str_tokenize_and_fold(term, NULL, NULL);
auto_gcharv gchar** terms = g_str_tokenize_and_fold(term, NULL, NULL);
int terms_len = g_strv_length(terms);
GList* commands = g_hash_table_get_keys(search_index);
@@ -2833,7 +2830,6 @@ cmd_search_index_all(char* term)
}
g_list_free(commands);
g_strfreev(terms);
return results;
}

View File

@@ -505,9 +505,8 @@ cmd_connect(ProfWin* window, const char* const command, gchar** args)
gboolean
cmd_account_list(ProfWin* window, const char* const command, gchar** args)
{
gchar** accounts = accounts_get_list();
auto_gcharv gchar** accounts = accounts_get_list();
cons_show_account_list(accounts);
g_strfreev(accounts);
return TRUE;
}
@@ -4839,9 +4838,8 @@ cmd_bookmark_ignore(ProfWin* window, const char* const command, gchar** args)
// `/bookmark ignore` lists them
if (args[1] == NULL) {
gsize len = 0;
gchar** list = bookmark_ignore_list(&len);
auto_gcharv gchar** list = bookmark_ignore_list(&len);
cons_show_bookmarks_ignore(list, len);
g_strfreev(list);
return TRUE;
}
@@ -8479,18 +8477,16 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
{
if (g_str_has_prefix(command, "/field") && window->type == WIN_CONFIG) {
gboolean result = FALSE;
gchar** args = parse_args_with_freetext(inp, 1, 2, &result);
auto_gcharv gchar** args = parse_args_with_freetext(inp, 1, 2, &result);
if (!result) {
win_println(window, THEME_DEFAULT, "!", "Invalid command, see /form help");
result = TRUE;
} else {
gchar** tokens = g_strsplit(inp, " ", 2);
auto_gcharv gchar** tokens = g_strsplit(inp, " ", 2);
char* field = tokens[0] + 1;
result = cmd_form_field(window, field, args);
g_strfreev(tokens);
}
g_strfreev(args);
return result;
}
@@ -8498,7 +8494,7 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
gboolean result = FALSE;
if (cmd) {
gchar** args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
auto_gcharv gchar** args = cmd->parser(inp, cmd->min_args, cmd->max_args, &result);
if (result == FALSE) {
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
return TRUE;
@@ -8507,20 +8503,17 @@ _cmd_execute(ProfWin* window, const char* const command, const char* const inp)
int i = 0;
while (cmd->sub_funcs[i].cmd) {
if (g_strcmp0(args[0], (char*)cmd->sub_funcs[i].cmd) == 0) {
result = cmd->sub_funcs[i].func(window, command, args);
goto out;
return cmd->sub_funcs[i].func(window, command, args);
}
i++;
}
}
if (!cmd->func) {
ui_invalid_command_usage(cmd->cmd, cmd->setting_func);
result = TRUE;
goto out;
return TRUE;
}
result = cmd->func(window, command, args);
out:
g_strfreev(args);
return result;
} else if (plugins_run_command(inp)) {
return TRUE;
@@ -9543,15 +9536,13 @@ _url_http_method(ProfWin* window, const char* cmd_template, gchar* url, gchar* p
void
_url_external_method(const char* cmd_template, const char* url, gchar* filename)
{
gchar** argv = format_call_external_argv(cmd_template, url, filename);
auto_gcharv gchar** argv = format_call_external_argv(cmd_template, url, filename);
if (!call_external(argv)) {
cons_show_error("Unable to call external executable for url: check the logs for more information.");
} else {
cons_show("URL '%s' has been called with '%s'.", url, cmd_template);
}
g_strfreev(argv);
}
gboolean