Skip to content

Commit

Permalink
Merge pull request #1858 from H3rnand3zzz/cleanup/auto_char
Browse files Browse the repository at this point in the history
Major cleanup
  • Loading branch information
jubalh authored Jul 14, 2023
2 parents 9451ea7 + 09f217d commit 4814887
Show file tree
Hide file tree
Showing 57 changed files with 579 additions and 775 deletions.
2 changes: 1 addition & 1 deletion src/chatlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ _get_log_filename(const char* const other, const char* const login, GDateTime* d
{
auto_gchar gchar* chatlogs_dir = files_file_in_account_data_path(DIR_CHATLOGS, login, is_room ? "rooms" : NULL);
auto_gchar gchar* logfile_name = g_date_time_format(dt, "%Y_%m_%d.log");
auto_gchar gchar* other_ = str_replace(other, "@", "_at_");
auto_char char* other_ = str_replace(other, "@", "_at_");
auto_gchar gchar* logs_path = g_strdup_printf("%s/%s", chatlogs_dir, other_);
gchar* logfile_path = NULL;

Expand Down
12 changes: 3 additions & 9 deletions src/command/cmd_ac.c
Original file line number Diff line number Diff line change
Expand Up @@ -3210,25 +3210,23 @@ _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]);

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);
}
Expand All @@ -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:
Expand All @@ -3261,8 +3258,6 @@ _form_field_autocomplete(ProfWin* window, const char* const input, gboolean prev
}
}

g_strfreev(split);

return found;
}

Expand Down Expand Up @@ -4387,9 +4382,8 @@ _url_autocomplete(ProfWin* window, const char* const input, gboolean previous)
if ((num_args == 1 && space_at_end) || (num_args == 2 && !space_at_end)) {
result = autocomplete_param_with_func(input, "/url save", wins_get_url, previous, window);
} else if ((num_args == 2 && space_at_end) || (num_args == 3 && !space_at_end)) {
gchar* cmd = g_strdup_printf("/url save %s", args[1]);
auto_gchar gchar* cmd = g_strdup_printf("/url save %s", args[1]);
result = cmd_ac_complete_filepath(input, cmd, previous);
g_free(cmd);
}
}
}
Expand Down
16 changes: 5 additions & 11 deletions src/command/cmd_defs.c
Original file line number Diff line number Diff line change
Expand Up @@ -2768,15 +2768,14 @@ _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("");
for (int i = 0; i < g_strv_length(tokens); i++) {
index = g_string_append(index, tokens[i]);
index = g_string_append(index, " ");
}
g_strfreev(tokens);

return g_string_free(index, FALSE);
}
Expand All @@ -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++) {
Expand All @@ -2802,8 +2801,6 @@ cmd_search_index_any(char* term)
g_list_free(index_keys);
}

g_strfreev(processed_terms);

return results;
}

Expand All @@ -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);
Expand All @@ -2833,7 +2830,6 @@ cmd_search_index_all(char* term)
}

g_list_free(commands);
g_strfreev(terms);

return results;
}
Expand Down Expand Up @@ -3039,14 +3035,13 @@ command_mangen(void)
create_dir("docs");

GDateTime* now = g_date_time_new_now_local();
gchar* date = g_date_time_format(now, "%F");
gchar* header = g_strdup_printf(".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date);
auto_gchar gchar* date = g_date_time_format(now, "%F");
auto_gchar gchar* header = g_strdup_printf(".TH man 1 \"%s\" \"" PACKAGE_VERSION "\" \"Profanity XMPP client\"\n", date);
if (!header) {
log_error("command_mangen(): could not allocate memory");
return;
}
g_date_time_unref(now);
g_free(date);

GList* curr = cmds;
while (curr) {
Expand Down Expand Up @@ -3098,6 +3093,5 @@ command_mangen(void)

printf("\nProcessed %d commands.\n\n", g_list_length(cmds));

g_free(header);
g_list_free(cmds);
}
Loading

0 comments on commit 4814887

Please sign in to comment.