diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c index 6e22e90e..3aeedc60 100644 --- a/src/command/cmd_ac.c +++ b/src/command/cmd_ac.c @@ -1635,7 +1635,6 @@ cmd_ac_complete_filepath(const char* const input, char* const startstr, gboolean static char* _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previous) { - int i; char* result = NULL; jabber_conn_status_t conn_status = connection_get_status(); @@ -1644,7 +1643,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ gchar* boolean_choices[] = { "/beep", "/intype", "/states", "/outtype", "/flash", "/splash", "/history", "/vercheck", "/privileges", "/wrap", "/carbons", "/os", "/slashguard" }; - for (i = 0; i < ARRAY_SIZE(boolean_choices); i++) { + for (int i = 0; i < ARRAY_SIZE(boolean_choices); i++) { result = autocomplete_param_with_func(input, boolean_choices[i], prefs_autocomplete_boolean_choice, previous, NULL); if (result) { return result; @@ -1661,7 +1660,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ // Remove quote character before and after names when doing autocomplete char* unquoted = strip_arg_quotes(input); - for (i = 0; i < ARRAY_SIZE(nick_choices); i++) { + for (int i = 0; i < ARRAY_SIZE(nick_choices); i++) { result = autocomplete_param_with_ac(unquoted, nick_choices[i], nick_ac, TRUE, previous); if (result) { free(unquoted); @@ -1676,7 +1675,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ gchar* contact_choices[] = { "/msg", "/info" }; // Remove quote character before and after names when doing autocomplete char* unquoted = strip_arg_quotes(input); - for (i = 0; i < ARRAY_SIZE(contact_choices); i++) { + for (int i = 0; i < ARRAY_SIZE(contact_choices); i++) { result = autocomplete_param_with_func(unquoted, contact_choices[i], roster_contact_autocomplete, previous, NULL); if (result) { free(unquoted); @@ -1686,7 +1685,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ free(unquoted); gchar* resource_choices[] = { "/caps", "/ping" }; - for (i = 0; i < ARRAY_SIZE(resource_choices); i++) { + for (int i = 0; i < ARRAY_SIZE(resource_choices); i++) { result = autocomplete_param_with_func(input, resource_choices[i], roster_fulljid_autocomplete, previous, NULL); if (result) { return result; @@ -1695,7 +1694,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ } gchar* invite_choices[] = { "/join" }; - for (i = 0; i < ARRAY_SIZE(invite_choices); i++) { + for (int i = 0; i < ARRAY_SIZE(invite_choices); i++) { result = autocomplete_param_with_func(input, invite_choices[i], muc_invites_find, previous, NULL); if (result) { return result; @@ -1705,7 +1704,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ gchar* cmds[] = { "/prefs", "/disco", "/room", "/autoping", "/mainwin", "/inputwin" }; Autocomplete completers[] = { prefs_ac, disco_ac, room_ac, autoping_ac, winpos_ac, winpos_ac }; - for (i = 0; i < ARRAY_SIZE(cmds); i++) { + for (int i = 0; i < ARRAY_SIZE(cmds); i++) { result = autocomplete_param_with_ac(input, cmds[i], completers[i], TRUE, previous); if (result) { return result; @@ -1778,7 +1777,7 @@ _cmd_ac_complete_params(ProfWin* window, const char* const input, gboolean previ int len = strlen(input); char parsed[len + 1]; - i = 0; + int i = 0; while (i < len) { if (input[i] == ' ') { break; @@ -1856,12 +1855,11 @@ _who_autocomplete(ProfWin* window, const char* const input, gboolean previous) } else { jabber_conn_status_t conn_status = connection_get_status(); if (conn_status == JABBER_CONNECTED) { - int i = 0; gchar* group_commands[] = { "/who any", "/who online", "/who offline", "/who chat", "/who away", "/who xa", "/who dnd", "/who available", "/who unavailable" }; - for (i = 0; i < ARRAY_SIZE(group_commands); i++) { + for (int i = 0; i < ARRAY_SIZE(group_commands); i++) { result = autocomplete_param_with_func(input, group_commands[i], roster_group_autocomplete, previous, NULL); if (result) { return result; @@ -2186,7 +2184,6 @@ _bookmark_autocomplete(ProfWin* window, const char* const input, gboolean previo static char* _notify_autocomplete(ProfWin* window, const char* const input, gboolean previous) { - int i = 0; char* result = NULL; result = autocomplete_param_with_func(input, "/notify room trigger remove", prefs_autocomplete_room_trigger, previous, NULL); @@ -2196,7 +2193,7 @@ _notify_autocomplete(ProfWin* window, const char* const input, gboolean previous gchar* boolean_choices1[] = { "/notify room current", "/notify chat current", "/notify typing current", "/notify room text", "/notify chat text" }; - for (i = 0; i < ARRAY_SIZE(boolean_choices1); i++) { + for (int i = 0; i < ARRAY_SIZE(boolean_choices1); i++) { result = autocomplete_param_with_func(input, boolean_choices1[i], prefs_autocomplete_boolean_choice, previous, NULL); if (result) { return result; @@ -2229,7 +2226,7 @@ _notify_autocomplete(ProfWin* window, const char* const input, gboolean previous } gchar* boolean_choices2[] = { "/notify invite", "/notify sub", "/notify mention", "/notify trigger" }; - for (i = 0; i < ARRAY_SIZE(boolean_choices2); i++) { + for (int i = 0; i < ARRAY_SIZE(boolean_choices2); i++) { result = autocomplete_param_with_func(input, boolean_choices2[i], prefs_autocomplete_boolean_choice, previous, NULL); if (result) { return result; @@ -3713,12 +3710,11 @@ _account_autocomplete(ProfWin* window, const char* const input, gboolean previou return found; } - int i = 0; gchar* account_choice[] = { "/account set", "/account show", "/account enable", "/account disable", "/account rename", "/account clear", "/account remove", "/account default set" }; - for (i = 0; i < ARRAY_SIZE(account_choice); i++) { + for (int i = 0; i < ARRAY_SIZE(account_choice); i++) { found = autocomplete_param_with_func(input, account_choice[i], accounts_find_all, previous, NULL); if (found) { return found; diff --git a/src/command/cmd_defs.c b/src/command/cmd_defs.c index 8bfd33d3..53c42bae 100644 --- a/src/command/cmd_defs.c +++ b/src/command/cmd_defs.c @@ -2557,17 +2557,16 @@ _cmd_index(Command* cmd) index_source = g_string_append(index_source, " "); int len = g_strv_length(cmd->help.tags); - int i = 0; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { index_source = g_string_append(index_source, cmd->help.tags[i]); index_source = g_string_append(index_source, " "); } len = g_strv_length(cmd->help.synopsis); - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { index_source = g_string_append(index_source, cmd->help.synopsis[i]); index_source = g_string_append(index_source, " "); } - for (i = 0; cmd->help.args[i][0] != NULL; i++) { + for (int i = 0; cmd->help.args[i][0] != NULL; i++) { index_source = g_string_append(index_source, cmd->help.args[i][0]); index_source = g_string_append(index_source, " "); index_source = g_string_append(index_source, cmd->help.args[i][1]); @@ -2578,7 +2577,7 @@ _cmd_index(Command* cmd) g_string_free(index_source, TRUE); GString* index = g_string_new(""); - for (i = 0; i < g_strv_length(tokens); i++) { + for (int i = 0; i < g_strv_length(tokens); i++) { index = g_string_append(index, tokens[i]); index = g_string_append(index, " "); } @@ -2598,8 +2597,7 @@ cmd_search_index_any(char* term) gchar** processed_terms = g_str_tokenize_and_fold(term, NULL, NULL); int terms_len = g_strv_length(processed_terms); - int i = 0; - for (i = 0; i < terms_len; i++) { + for (int i = 0; i < terms_len; i++) { GList* index_keys = g_hash_table_get_keys(search_index); GList* curr = index_keys; while (curr) { @@ -2630,8 +2628,7 @@ cmd_search_index_all(char* term) while (curr) { char* command = curr->data; int matches = 0; - int i = 0; - for (i = 0; i < terms_len; i++) { + for (int i = 0; i < terms_len; i++) { char* command_index = g_hash_table_lookup(search_index, command); if (g_str_match_string(terms[i], command_index, FALSE)) { matches++; @@ -2663,8 +2660,7 @@ cmd_init(void) // load command defs into hash table commands = g_hash_table_new(g_str_hash, g_str_equal); - unsigned int i; - for (i = 0; i < ARRAY_SIZE(command_defs); i++) { + for (unsigned int i = 0; i < ARRAY_SIZE(command_defs); i++) { Command* pcmd = command_defs + i; // add to hash @@ -2738,8 +2734,7 @@ cmd_get_ordered(const char* const tag) static gboolean _cmd_has_tag(Command* pcmd, const char* const tag) { - int i = 0; - for (i = 0; pcmd->help.tags[i] != NULL; i++) { + for (int i = 0; pcmd->help.tags[i] != NULL; i++) { if (g_strcmp0(tag, pcmd->help.tags[i]) == 0) { return TRUE; } @@ -2758,8 +2753,8 @@ void command_docgen(void) { GList* cmds = NULL; - unsigned int i; - for (i = 0; i < ARRAY_SIZE(command_defs); i++) { + + for (unsigned int i = 0; i < ARRAY_SIZE(command_defs); i++) { Command* pcmd = command_defs + i; cmds = g_list_insert_sorted(cmds, pcmd, (GCompareFunc)_cmp_command); } diff --git a/src/command/cmd_funcs.c b/src/command/cmd_funcs.c index 56a68297..0837f630 100644 --- a/src/command/cmd_funcs.c +++ b/src/command/cmd_funcs.c @@ -1086,8 +1086,7 @@ _writecsv(int fd, const char* const str) size_t len = strlen(str); char* s = malloc(2 * len * sizeof(char)); char* c = s; - int i = 0; - for (; i < strlen(str); i++) { + for (int i =0; i < strlen(str); i++) { if (str[i] != '"') *c++ = str[i]; else { @@ -1415,8 +1414,7 @@ cmd_close(ProfWin* window, const char* const command, gchar** args) gboolean is_num = TRUE; int index = 0; if (args[0] != NULL) { - int i = 0; - for (i = 0; i < strlen(args[0]); i++) { + for (int i = 0; i < strlen(args[0]); i++) { if (!isdigit((int)args[0][i])) { is_num = FALSE; break; @@ -1503,8 +1501,7 @@ gboolean cmd_win(ProfWin* window, const char* const command, gchar** args) { gboolean is_num = TRUE; - int i = 0; - for (i = 0; i < strlen(args[0]); i++) { + for (int i = 0; i < strlen(args[0]); i++) { if (!isdigit((int)args[0][i])) { is_num = FALSE; break; @@ -8567,14 +8564,13 @@ cmd_omemo_fingerprint(ProfWin* window, const char* const command, gchar** args) } GList* fingerprints = omemo_known_device_identities(jid->barejid); - GList* fingerprint; if (!fingerprints) { win_println(window, THEME_DEFAULT, "-", "There is no known fingerprints for %s", jid->barejid); return TRUE; } - for (fingerprint = fingerprints; fingerprint != NULL; fingerprint = fingerprint->next) { + for (GList* fingerprint = fingerprints; fingerprint != NULL; fingerprint = fingerprint->next) { char* formatted_fingerprint = omemo_format_fingerprint(fingerprint->data); gboolean trusted = omemo_is_trusted_identity(jid->barejid, fingerprint->data); @@ -8710,8 +8706,7 @@ cmd_omemo_untrust(ProfWin* window, const char* const command, gchar** args) omemo_untrust(barejid, fingerprint); char* unformatted_fingerprint = malloc(strlen(fingerprint)); - int i; - int j; + int i, j; for (i = 0, j = 0; fingerprint[i] != '\0'; i++) { if (!g_ascii_isxdigit(fingerprint[i])) { continue; diff --git a/src/common.c b/src/common.c index f05bc3ba..c0bd6525 100644 --- a/src/common.c +++ b/src/common.c @@ -91,10 +91,9 @@ create_dir(char* name) gboolean mkdir_recursive(const char* dir) { - int i; gboolean result = TRUE; - for (i = 1; i <= strlen(dir); i++) { + for (int i = 1; i <= strlen(dir); i++) { if (dir[i] == '/' || dir[i] == '\0') { gchar* next_dir = g_strndup(dir, i); result = create_dir(next_dir); @@ -446,8 +445,7 @@ get_random_string(int length) prng = g_rand_new(); - int i; - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { rand[i] = alphabet[g_rand_int_range(prng, 0, sizeof(alphabet))]; } g_rand_free(prng); diff --git a/src/config/accounts.c b/src/config/accounts.c index 3787d889..88828da9 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -77,8 +77,7 @@ accounts_load(void) gsize naccounts; gchar** account_names = g_key_file_get_groups(accounts, &naccounts); - gsize i; - for (i = 0; i < naccounts; i++) { + for (gsize i = 0; i < naccounts; i++) { autocomplete_add(all_ac, account_names[i]); if (g_key_file_get_boolean(accounts, account_names[i], "enabled", NULL)) { autocomplete_add(enabled_ac, account_names[i]); @@ -252,8 +251,7 @@ accounts_get_account(const char* const name) GList* otr_manual = NULL; gchar** manual = g_key_file_get_string_list(accounts, name, "otr.manual", &length, NULL); if (manual) { - int i; - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { otr_manual = g_list_append(otr_manual, strdup(manual[i])); } g_strfreev(manual); @@ -262,8 +260,7 @@ accounts_get_account(const char* const name) GList* otr_opportunistic = NULL; gchar** opportunistic = g_key_file_get_string_list(accounts, name, "otr.opportunistic", &length, NULL); if (opportunistic) { - int i; - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { otr_opportunistic = g_list_append(otr_opportunistic, strdup(opportunistic[i])); } g_strfreev(opportunistic); @@ -272,8 +269,7 @@ accounts_get_account(const char* const name) GList* otr_always = NULL; gchar** always = g_key_file_get_string_list(accounts, name, "otr.always", &length, NULL); if (always) { - int i; - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { otr_always = g_list_append(otr_always, strdup(always[i])); } g_strfreev(always); @@ -287,8 +283,7 @@ accounts_get_account(const char* const name) GList* omemo_enabled = NULL; gchar** enabled_list = g_key_file_get_string_list(accounts, name, "omemo.enabled", &length, NULL); if (enabled_list) { - int i; - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { omemo_enabled = g_list_append(omemo_enabled, strdup(enabled_list[i])); } g_strfreev(enabled_list); @@ -297,8 +292,7 @@ accounts_get_account(const char* const name) GList* omemo_disabled = NULL; gchar** disabled_list = g_key_file_get_string_list(accounts, name, "omemo.disabled", &length, NULL); if (disabled_list) { - int i; - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { omemo_disabled = g_list_append(omemo_disabled, strdup(disabled_list[i])); } g_strfreev(disabled_list); @@ -425,8 +419,7 @@ accounts_rename(const char* const account_name, const char* const new_name) "tls.policy" }; - int i; - for (i = 0; i < ARRAY_SIZE(string_keys); i++) { + for (int i = 0; i < ARRAY_SIZE(string_keys); i++) { char* value = g_key_file_get_string(accounts, account_name, string_keys[i], NULL); if (value) { g_key_file_set_string(accounts, new_name, string_keys[i], value); diff --git a/src/config/color.c b/src/config/color.c index 63089fd8..7fca0d1a 100644 --- a/src/config/color.c +++ b/src/config/color.c @@ -343,12 +343,11 @@ color_distance(const struct color_def* a, const struct color_def* b) static int find_closest_col(int h, int s, int l) { - int i; struct color_def a = { h, s, l }; int min = 0; int dmin = color_distance(&a, &color_names[0]); - for (i = 1; i < COLOR_NAME_SIZE; i++) { + for (int i = 1; i < COLOR_NAME_SIZE; i++) { int d = color_distance(&a, &color_names[i]); if (d < dmin) { dmin = d; @@ -361,7 +360,6 @@ find_closest_col(int h, int s, int l) static int find_col(const char* col_name, int n) { - int i; char name[32] = { 0 }; /* @@ -381,7 +379,7 @@ find_col(const char* col_name, int n) return -1; } - for (i = 0; i < COLOR_NAME_SIZE; i++) { + for (int i = 0; i < COLOR_NAME_SIZE; i++) { if (g_ascii_strcasecmp(name, color_names[i].name) == 0) { return i; } @@ -462,8 +460,6 @@ color_pair_cache_reset(void) static int _color_pair_cache_get(int fg, int bg) { - int i; - if (COLORS < 256) { if (fg > 7 || bg > 7) { log_error("Color: trying to load 256 colour theme without capable terminal"); @@ -472,7 +468,7 @@ _color_pair_cache_get(int fg, int bg) } /* try to find pair in cache */ - for (i = 0; i < cache.size; i++) { + for (int i = 0; i < cache.size; i++) { if (fg == cache.pairs[i].fg && bg == cache.pairs[i].bg) { return i; } @@ -486,7 +482,7 @@ _color_pair_cache_get(int fg, int bg) return -1; } - i = cache.size; + int i = cache.size; cache.pairs[i].fg = fg; cache.pairs[i].bg = bg; /* (re-)define the new pair in curses */ diff --git a/src/config/preferences.c b/src/config/preferences.c index 00a1e5ce..e4aebdb5 100644 --- a/src/config/preferences.c +++ b/src/config/preferences.c @@ -194,8 +194,7 @@ _prefs_load(void) gsize len = 0; gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); - int i = 0; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { autocomplete_add(room_trigger_ac, triggers[i]); } g_strfreev(triggers); @@ -312,14 +311,15 @@ prefs_message_get_triggers(const char* const message) char* message_lower = g_utf8_strdown(message, -1); gsize len = 0; gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); - int i; - for (i = 0; i < len; i++) { + + for (int i = 0; i < len; i++) { char* trigger_lower = g_utf8_strdown(triggers[i], -1); if (g_strrstr(message_lower, trigger_lower)) { result = g_list_append(result, strdup(triggers[i])); } g_free(trigger_lower); } + g_strfreev(triggers); g_free(message_lower); @@ -1384,8 +1384,7 @@ prefs_get_room_notify_triggers(void) gsize len = 0; gchar** triggers = g_key_file_get_string_list(prefs, PREF_GROUP_NOTIFICATIONS, "room.trigger.list", &len, NULL); - int i; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { result = g_list_append(result, strdup(triggers[i])); } @@ -1476,8 +1475,7 @@ prefs_titlebar_pos_up(void) { ProfWinPlacement* placement = prefs_get_win_placement(); - int pos = 2; - for (pos = 2; pos < 5; pos++) { + for (int pos = 2; pos < 5; pos++) { if (placement->titlebar_pos == pos) { placement->titlebar_pos = pos - 1; @@ -1504,8 +1502,7 @@ prefs_mainwin_pos_up(void) { ProfWinPlacement* placement = prefs_get_win_placement(); - int pos = 2; - for (pos = 2; pos < 5; pos++) { + for (int pos = 2; pos < 5; pos++) { if (placement->mainwin_pos == pos) { placement->mainwin_pos = pos - 1; @@ -1532,8 +1529,7 @@ prefs_statusbar_pos_up(void) { ProfWinPlacement* placement = prefs_get_win_placement(); - int pos = 2; - for (pos = 2; pos < 5; pos++) { + for (int pos = 2; pos < 5; pos++) { if (placement->statusbar_pos == pos) { placement->statusbar_pos = pos - 1; @@ -1560,8 +1556,7 @@ prefs_inputwin_pos_up(void) { ProfWinPlacement* placement = prefs_get_win_placement(); - int pos = 2; - for (pos = 2; pos < 5; pos++) { + for (int pos = 2; pos < 5; pos++) { if (placement->inputwin_pos == pos) { placement->inputwin_pos = pos - 1; @@ -1588,8 +1583,7 @@ prefs_titlebar_pos_down(void) { ProfWinPlacement* placement = prefs_get_win_placement(); - int pos = 1; - for (pos = 1; pos < 4; pos++) { + for (int pos = 1; pos < 4; pos++) { if (placement->titlebar_pos == pos) { placement->titlebar_pos = pos + 1; @@ -1616,8 +1610,7 @@ prefs_mainwin_pos_down(void) { ProfWinPlacement* placement = prefs_get_win_placement(); - int pos = 1; - for (pos = 1; pos < 4; pos++) { + for (int pos = 1; pos < 4; pos++) { if (placement->mainwin_pos == pos) { placement->mainwin_pos = pos + 1; @@ -1644,8 +1637,7 @@ prefs_statusbar_pos_down(void) { ProfWinPlacement* placement = prefs_get_win_placement(); - int pos = 1; - for (pos = 1; pos < 4; pos++) { + for (int pos = 1; pos < 4; pos++) { if (placement->statusbar_pos == pos) { placement->statusbar_pos = pos + 1; @@ -1672,8 +1664,7 @@ prefs_inputwin_pos_down(void) { ProfWinPlacement* placement = prefs_get_win_placement(); - int pos = 1; - for (pos = 1; pos < 4; pos++) { + for (int pos = 1; pos < 4; pos++) { if (placement->inputwin_pos == pos) { placement->inputwin_pos = pos + 1; @@ -1741,8 +1732,8 @@ prefs_get_aliases(void) GList* result = NULL; gsize len; gchar** keys = g_key_file_get_keys(prefs, PREF_GROUP_ALIAS, &len, NULL); - int i; - for (i = 0; i < len; i++) { + + for (int i = 0; i < len; i++) { char* name = keys[i]; char* value = g_key_file_get_string(prefs, PREF_GROUP_ALIAS, name, NULL); diff --git a/src/config/tlscerts.c b/src/config/tlscerts.c index 6b4d759f..55a3fa1b 100644 --- a/src/config/tlscerts.c +++ b/src/config/tlscerts.c @@ -71,8 +71,7 @@ tlscerts_init(void) gsize len = 0; gchar** groups = g_key_file_get_groups(tlscerts, &len); - int i = 0; - for (i = 0; i < g_strv_length(groups); i++) { + for (int i = 0; i < g_strv_length(groups); i++) { autocomplete_add(certs_ac, groups[i]); } g_strfreev(groups); @@ -117,8 +116,7 @@ tlscerts_list(void) gsize len = 0; gchar** groups = g_key_file_get_groups(tlscerts, &len); - int i = 0; - for (i = 0; i < g_strv_length(groups); i++) { + for (int i = 0; i < g_strv_length(groups); i++) { char* fingerprint = strdup(groups[i]); int version = g_key_file_get_integer(tlscerts, fingerprint, "version", NULL); char* serialnumber = g_key_file_get_string(tlscerts, fingerprint, "serialnumber", NULL); @@ -209,8 +207,7 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria cert->subject_organisation_unit = NULL; cert->subject_email = NULL; gchar** fields = g_strsplit(subjectname, "/", 0); - int i = 0; - for (i = 0; i < g_strv_length(fields); i++) { + for (int i = 0; i < g_strv_length(fields); i++) { gchar** keyval = g_strsplit(fields[i], "=", 2); if (g_strv_length(keyval) == 2) { if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) { @@ -251,7 +248,7 @@ tlscerts_new(const char* const fingerprint, int version, const char* const seria cert->issuer_organisation_unit = NULL; cert->issuer_email = NULL; fields = g_strsplit(issuername, "/", 0); - for (i = 0; i < g_strv_length(fields); i++) { + for (int i = 0; i < g_strv_length(fields); i++) { gchar** keyval = g_strsplit(fields[i], "=", 2); if (g_strv_length(keyval) == 2) { if ((g_strcmp0(keyval[0], "C") == 0) || (g_strcmp0(keyval[0], "countryName") == 0)) { diff --git a/src/log.c b/src/log.c index 38971f26..541a263f 100644 --- a/src/log.c +++ b/src/log.c @@ -244,10 +244,9 @@ _rotate_log_file(void) gchar* log_file = g_strdup(mainlogfile); size_t len = strlen(log_file); gchar* log_file_new = malloc(len + 4); - int i = 1; // find an empty name. from .log -> log.01 -> log.99 - for (; i < 100; i++) { + for (int i=1; i < 100; i++) { g_sprintf(log_file_new, "%s.%02d", log_file, i); if (!g_file_test(log_file_new, G_FILE_TEST_EXISTS)) break; @@ -780,7 +779,6 @@ log_stderr_handler(void) char* const buf = stderr_buf; ssize_t size; int retry = 0; - int i; if (!stderr_inited) return; @@ -792,7 +790,7 @@ log_stderr_handler(void) if (size <= 0 || retry++ >= STDERR_RETRY_NR) break; - for (i = 0; i < size; ++i) { + for (int i = 0; i < size; ++i) { if (buf[i] == '\n') { log_msg(stderr_level, "stderr", s->str); g_string_assign(s, ""); diff --git a/src/omemo/crypto.c b/src/omemo/crypto.c index 316f6f63..380551ad 100644 --- a/src/omemo/crypto.c +++ b/src/omemo/crypto.c @@ -287,8 +287,7 @@ omemo_decrypt_func(signal_buffer** output, int cipher, const uint8_t* key, size_ assert(FALSE); } - int i; - for (i = 0; i < padding; i++) { + for (int i = 0; i < padding; i++) { if (plaintext[plaintext_len - 1 - i] != padding) { ret = SG_ERR_UNKNOWN; goto out; diff --git a/src/pgp/gpg.c b/src/pgp/gpg.c index 1c2d2aca..73b985fb 100644 --- a/src/pgp/gpg.c +++ b/src/pgp/gpg.c @@ -202,8 +202,7 @@ p_gpg_on_connect(const char* const barejid) return; } - int i = 0; - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { GError* gerr = NULL; gchar* jid = jids[i]; gchar* keyid = g_key_file_get_string(pubkeyfile, jid, "keyid", &gerr); @@ -777,9 +776,8 @@ p_gpg_format_fp_str(char* fp) } GString* format = g_string_new(""); - int i; int len = strlen(fp); - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { g_string_append_c(format, fp[i]); if (((i + 1) % 4 == 0) && (i + 1 < len)) { g_string_append_c(format, ' '); diff --git a/src/plugins/api.c b/src/plugins/api.c index cbf30dd1..26d78a6e 100644 --- a/src/plugins/api.c +++ b/src/plugins/api.c @@ -123,7 +123,7 @@ api_register_command(const char* const plugin_name, const char* command_name, in help->tags[0] = NULL; - int i = 0; + int i; for (i = 0; synopsis[i] != NULL; i++) { help->synopsis[i] = strdup(synopsis[i]); } diff --git a/src/plugins/plugins.c b/src/plugins/plugins.c index a225c78a..580f98f0 100644 --- a/src/plugins/plugins.c +++ b/src/plugins/plugins.c @@ -84,8 +84,7 @@ plugins_init(void) // load plugins gchar** plugins_pref = prefs_get_plugins(); if (plugins_pref) { - int i; - for (i = 0; i < g_strv_length(plugins_pref); i++) { + for (int i = 0; i < g_strv_length(plugins_pref); i++) { gboolean loaded = FALSE; gchar* filename = plugins_pref[i]; #ifdef HAVE_PYTHON diff --git a/src/tools/autocomplete.c b/src/tools/autocomplete.c index a3763bfb..bd766e52 100644 --- a/src/tools/autocomplete.c +++ b/src/tools/autocomplete.c @@ -171,8 +171,7 @@ autocomplete_add(Autocomplete ac, const char* item) void autocomplete_add_all(Autocomplete ac, char** items) { - int i = 0; - for (i = 0; i < g_strv_length(items); i++) { + for (int i = 0; i < g_strv_length(items); i++) { autocomplete_add(ac, items[i]); } } @@ -202,8 +201,7 @@ autocomplete_remove(Autocomplete ac, const char* const item) void autocomplete_remove_all(Autocomplete ac, char** items) { - int i = 0; - for (i = 0; i < g_strv_length(items); i++) { + for (int i = 0; i < g_strv_length(items); i++) { autocomplete_remove(ac, items[i]); } } @@ -310,10 +308,9 @@ autocomplete_param_with_func(const char* const input, char* command, autocomplet int len = strlen(command_cpy); if (strncmp(input, command_cpy, len) == 0) { - int i; int inp_len = strlen(input); char prefix[inp_len]; - for (i = len; i < inp_len; i++) { + for (int i = len; i < inp_len; i++) { prefix[i - len] = input[i]; } prefix[inp_len - len] = '\0'; @@ -341,9 +338,8 @@ autocomplete_param_with_ac(const char* const input, char* command, Autocomplete int len = strlen(command_cpy); int inp_len = strlen(input); if (strncmp(input, command_cpy, len) == 0) { - int i; char prefix[inp_len]; - for (i = len; i < inp_len; i++) { + for (int i = len; i < inp_len; i++) { prefix[i - len] = input[i]; } prefix[inp_len - len] = '\0'; diff --git a/src/tools/parser.c b/src/tools/parser.c index 364dd436..c251c13a 100644 --- a/src/tools/parser.c +++ b/src/tools/parser.c @@ -62,8 +62,7 @@ _parse_args_helper(const char* const inp, int min, int max, gboolean* result, gb GSList* tokens = NULL; // add tokens to GSList - int i; - for (i = 0; i < inp_size; i++) { + for (int i = 0; i < inp_size; i++) { gchar* curr_ch = g_utf8_offset_to_pointer(copy, i); gunichar curr_uni = g_utf8_get_char(curr_ch); @@ -255,12 +254,11 @@ count_tokens(const char* const string) int length = g_utf8_strlen(string, -1); gboolean in_quotes = FALSE; int num_tokens = 0; - int i = 0; // include first token num_tokens++; - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { gchar* curr_ch = g_utf8_offset_to_pointer(string, i); gunichar curr_uni = g_utf8_get_char(curr_ch); @@ -288,12 +286,11 @@ get_start(const char* const string, int tokens) gboolean in_quotes = FALSE; char* result_str = NULL; int num_tokens = 0; - int i = 0; // include first token num_tokens++; - for (i = 0; i < length; i++) { + for (int i = 0; i < length; i++) { gchar* curr_ch = g_utf8_offset_to_pointer(string, i); gunichar curr_uni = g_utf8_get_char(curr_ch); @@ -327,8 +324,7 @@ GHashTable* parse_options(gchar** args, gchar** opt_keys, gboolean* res) { GList* keys = NULL; - int i; - for (i = 0; i < g_strv_length(opt_keys); i++) { + for (int i = 0; i < g_strv_length(opt_keys); i++) { keys = g_list_append(keys, opt_keys[i]); } @@ -343,9 +339,8 @@ parse_options(gchar** args, gchar** opt_keys, gboolean* res) } // validate options - int curr; GList* found_keys = NULL; - for (curr = 0; curr < g_strv_length(args); curr += 2) { + for (int curr = 0; curr < g_strv_length(args); curr += 2) { // check if option valid if (g_list_find_custom(keys, args[curr], (GCompareFunc)g_strcmp0) == NULL) { *res = FALSE; @@ -378,7 +373,7 @@ parse_options(gchar** args, gchar** opt_keys, gboolean* res) // create map options = g_hash_table_new(g_str_hash, g_str_equal); *res = TRUE; - for (curr = 0; curr < g_strv_length(args); curr += 2) { + for (int curr = 0; curr < g_strv_length(args); curr += 2) { g_hash_table_insert(options, args[curr], args[curr + 1]); } diff --git a/src/ui/console.c b/src/ui/console.c index a3797963..cb2bb888 100644 --- a/src/ui/console.c +++ b/src/ui/console.c @@ -859,8 +859,7 @@ cons_show_account_list(gchar** accounts) int size = g_strv_length(accounts); if (size > 0) { cons_show("Accounts:"); - int i = 0; - for (i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { if ((connection_get_status() == JABBER_CONNECTED) && (g_strcmp0(session_get_account_name(), accounts[i]) == 0)) { resource_presence_t presence = accounts_get_last_presence(accounts[i]); theme_item_t presence_colour = theme_main_presence_attrs(string_from_resource_presence(presence)); @@ -2718,13 +2717,12 @@ cons_show_bookmarks_ignore(gchar** list, gsize len) return; } - int i; ProfWin* console = wins_get_console(); cons_show(""); cons_show("Ignored bookmarks:"); - for (i = 0; i < len; i++) { + for (int i = 0; i < len; i++) { win_print(console, THEME_DEFAULT, "-", " %s", list[i]); win_newline(console); } diff --git a/src/ui/core.c b/src/ui/core.c index 4bbb23de..aad6d387 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -1222,8 +1222,7 @@ void ui_show_lines(ProfWin* window, gchar** lines) { if (lines) { - int i; - for (i = 0; lines[i] != NULL; i++) { + for (int i = 0; lines[i] != NULL; i++) { win_println(window, THEME_DEFAULT, "-", "%s", lines[i]); } } diff --git a/src/ui/statusbar.c b/src/ui/statusbar.c index 3dfdf086..9997755b 100644 --- a/src/ui/statusbar.c +++ b/src/ui/statusbar.c @@ -296,8 +296,7 @@ status_bar_draw(void) pos = 0; } gint max_tabs = prefs_get_statusbartabs(); - int i = 1; - for (i = 1; i <= max_tabs; i++) { + for (int i = 1; i <= max_tabs; i++) { StatusBarTab* tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); if (tab) { pos = _status_bar_draw_tab(tab, pos, i); @@ -319,8 +318,7 @@ _extended_new(void) return FALSE; } - int i = 0; - for (i = max_tabs + 1; i <= tabs_count; i++) { + for (int i = max_tabs + 1; i <= tabs_count; i++) { StatusBarTab* tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); if (tab && tab->highlight) { return TRUE; @@ -527,8 +525,7 @@ _tabs_width(void) if (show_name && show_number) { int width = g_hash_table_size(statusbar->tabs) > max_tabs ? 4 : 1; - int i = 0; - for (i = 1; i <= max_tabs; i++) { + for (int i = 1; i <= max_tabs; i++) { StatusBarTab* tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); if (tab) { gboolean is_current = i == statusbar->current_tab; @@ -547,8 +544,7 @@ _tabs_width(void) if (show_name && !show_number) { int width = g_hash_table_size(statusbar->tabs) > max_tabs ? 4 : 1; - int i = 0; - for (i = 1; i <= max_tabs; i++) { + for (int i = 1; i <= max_tabs; i++) { StatusBarTab* tab = g_hash_table_lookup(statusbar->tabs, GINT_TO_POINTER(i)); if (tab) { gboolean is_current = i == statusbar->current_tab; diff --git a/src/ui/titlebar.c b/src/ui/titlebar.c index e587bab0..a22abaeb 100644 --- a/src/ui/titlebar.c +++ b/src/ui/titlebar.c @@ -190,8 +190,7 @@ _title_bar_draw(void) werase(win); wmove(win, 0, 0); - int i; - for (i = 0; i < 45; i++) { + for (int i = 0; i < 45; i++) { waddch(win, ' '); } diff --git a/src/ui/window.c b/src/ui/window.c index 5a1a90dc..687af3b2 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -1613,8 +1613,7 @@ _win_print_internal(ProfWin* window, const char* show_char, int pad_indent, GDat static void _win_indent(WINDOW* win, int size) { - int i = 0; - for (i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { waddch(win, ' '); } } @@ -1743,8 +1742,7 @@ win_print_trackbar(ProfWin* window) wbkgdset(window->layout->win, theme_attrs(THEME_TRACKBAR)); wattron(window->layout->win, theme_attrs(THEME_TRACKBAR)); - int i; - for (i = 1; i < cols; i++) { + for (int i = 1; i < cols; i++) { wprintw(window->layout->win, "-"); } @@ -1756,11 +1754,11 @@ win_print_trackbar(ProfWin* window) void win_redraw(ProfWin* window) { - int i, size; + int size; werase(window->layout->win); size = buffer_size(window->layout->buffer); - for (i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { ProfBuffEntry* e = buffer_get_entry(window->layout->buffer, i); if (e->display_from == NULL && e->message && e->message[0] == '-') { @@ -1935,12 +1933,12 @@ win_handle_command_exec_result_note(ProfWin* window, const char* const type, con void win_insert_last_read_position_marker(ProfWin* window, char* id) { - int i, size; + int size; size = buffer_size(window->layout->buffer); // TODO: this is somewhat costly. We should improve this later. // check if we already have a separator present - for (i = 0; i < size; i++) { + for (int i = 0; i < size; i++) { ProfBuffEntry* e = buffer_get_entry(window->layout->buffer, i); // if yes, don't print a new one diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index f3788a41..98a5c399 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -387,8 +387,7 @@ _caps_by_ver(const char* const ver) gchar** features_list = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL); GSList* features = NULL; if (features_list && features_len > 0) { - int i; - for (i = 0; i < features_len; i++) { + for (int i = 0; i < features_len; i++) { features = g_slist_append(features, features_list[i]); } } diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 48c09953..fbbbfc9c 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -237,8 +237,7 @@ stanza_create_http_upload_request(xmpp_ctx_t* ctx, const char* const id, xmpp_stanza_t* filename_txt = xmpp_stanza_new(ctx); char* filename_cpy = strdup(upload->filename); // strip spaces from filename (servers don't spaces) - int i; - for (i = 0; i < strlen(filename_cpy); i++) { + for (int i = 0; i < strlen(filename_cpy); i++) { if (filename_cpy[i] == ' ') { filename_cpy[i] = '_'; } @@ -1826,8 +1825,7 @@ stanza_create_caps_from_query_element(xmpp_stanza_t* query) xmpp_stanza_t* id_stanza = curr_identity->data; const char* stanza_lang = xmpp_stanza_get_attribute(id_stanza, "xml:lang"); if (stanza_lang) { - int i = 0; - for (i = 0; i < num_langs; i++) { + for (int i = 0; i < num_langs; i++) { if (g_strcmp0(langs[i], stanza_lang) == 0) { found = id_stanza; break; @@ -1929,8 +1927,7 @@ stanza_get_error_message(xmpp_stanza_t* stanza) STANZA_NAME_UNEXPECTED_REQUEST }; - int i; - for (i = 0; i < ARRAY_SIZE(defined_conditions); i++) { + for (int i = 0; i < ARRAY_SIZE(defined_conditions); i++) { xmpp_stanza_t* cond_stanza = xmpp_stanza_get_child_by_name(error_stanza, defined_conditions[i]); if (cond_stanza) { char* result = strdup(xmpp_stanza_get_name(cond_stanza)); @@ -2334,8 +2331,7 @@ stanza_create_omemo_devicelist_publish(xmpp_ctx_t* ctx, GList* const ids) xmpp_stanza_set_name(list, "list"); xmpp_stanza_set_ns(list, "eu.siacs.conversations.axolotl"); - GList* i; - for (i = ids; i != NULL; i = i->next) { + for (GList *i = ids; i != NULL; i = i->next) { xmpp_stanza_t* device = xmpp_stanza_new(ctx); xmpp_stanza_set_name(device, "device"); char* id = g_strdup_printf("%d", GPOINTER_TO_INT(i->data));