From b133204cce5846139b9f5abf99e1ba90c007abc6 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 23 Oct 2019 23:30:09 +0100 Subject: [PATCH] tidy conditionals 2 - move true condition first - flatten 'else' clause when 'if' clause returns/breaks - compare int functions to zero --- copy.c | 12 ++++----- curs_lib.c | 6 ++--- handler.c | 20 +++++++------- hcache/serialize.c | 4 +-- imap/imap.c | 8 +++--- imap/message.c | 18 ++++++------- init.c | 8 +++--- mailcap.c | 6 ++--- maildir/shared.c | 6 ++--- mutt_mailbox.c | 12 ++++----- mutt_thread.c | 30 ++++++++++----------- ncrypt/crypt_gpgme.c | 64 +++++++++++++++++++++++--------------------- pager.c | 17 ++++++------ pop/pop.c | 8 +++--- postpone.c | 8 +++--- query.c | 10 +++---- recvattach.c | 8 +++--- recvcmd.c | 8 +++--- send.c | 12 ++++----- sidebar.c | 4 +-- 20 files changed, 139 insertions(+), 130 deletions(-) diff --git a/copy.c b/copy.c index 6e6dc0c83..db211b699 100644 --- a/copy.c +++ b/copy.c @@ -298,12 +298,7 @@ int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, if (!ignore) { mutt_debug(LL_DEBUG2, "Reorder: x = %d; hdr_count = %d\n", x, hdr_count); - if (!this_one) - { - this_one = mutt_str_strdup(buf); - this_one_len = mutt_str_strlen(this_one); - } - else + if (this_one) { size_t blen = mutt_str_strlen(buf); @@ -311,6 +306,11 @@ int mutt_copy_hdr(FILE *fp_in, FILE *fp_out, LOFF_T off_start, LOFF_T off_end, strcat(this_one + this_one_len, buf); this_one_len += blen; } + else + { + this_one = mutt_str_strdup(buf); + this_one_len = mutt_str_strlen(this_one); + } } } /* while (ftello (fp_in) < off_end) */ diff --git a/curs_lib.c b/curs_lib.c index 936bc87ae..7aaf00d49 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -280,10 +280,10 @@ int mutt_buffer_get_field_full(const char *field, struct Buffer *buf, Completion files, numfiles, es); } while (ret == 1); - if (ret != 0) - mutt_buffer_reset(buf); - else + if (ret == 0) mutt_buffer_fix_dptr(buf); + else + mutt_buffer_reset(buf); mutt_window_clearline(MuttMessageWindow, 0); mutt_enter_state_free(&es); diff --git a/handler.c b/handler.c index af01a9805..42959c9ed 100644 --- a/handler.c +++ b/handler.c @@ -573,12 +573,7 @@ static int autoview_handler(struct Body *a, struct State *s) mutt_file_copy_bytes(s->fp_in, fp_in, a->length); - if (!piped) - { - mutt_file_fclose(&fp_in); - pid = mutt_create_filter(mutt_b2s(cmd), NULL, &fp_out, &fp_err); - } - else + if (piped) { unlink(mutt_b2s(tempfile)); fflush(fp_in); @@ -586,6 +581,11 @@ static int autoview_handler(struct Body *a, struct State *s) pid = mutt_create_filter_fd(mutt_b2s(cmd), NULL, &fp_out, &fp_err, fileno(fp_in), -1, -1); } + else + { + mutt_file_fclose(&fp_in); + pid = mutt_create_filter(mutt_b2s(cmd), NULL, &fp_out, &fp_err); + } if (pid < 0) { @@ -1236,13 +1236,15 @@ static int multipart_handler(struct Body *a, struct State *s) else state_printf(s, _("[-- Attachment #%d --]\n"), count); print_part_line(s, p, 0); - if (!C_Weed) + if (C_Weed) + { + state_putc(s, '\n'); + } + else { fseeko(s->fp_in, p->hdr_offset, SEEK_SET); mutt_file_copy_bytes(s->fp_in, s->fp_out, p->offset - p->hdr_offset); } - else - state_putc(s, '\n'); } rc = mutt_body_handler(p, s); diff --git a/hcache/serialize.c b/hcache/serialize.c index 9f5d59e6d..37e0c14f6 100644 --- a/hcache/serialize.c +++ b/hcache/serialize.c @@ -311,8 +311,8 @@ unsigned char *serial_dump_buffer(struct Buffer *buf, unsigned char *d, int *off d = serial_dump_int(0, d, off); return d; } - else - d = serial_dump_int(1, d, off); + + d = serial_dump_int(1, d, off); d = serial_dump_char_size(buf->data, d, off, buf->dsize + 1, convert); d = serial_dump_int(buf->dptr - buf->data, d, off); diff --git a/imap/imap.c b/imap/imap.c index 0aac2d93c..fb85bc90d 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -238,13 +238,15 @@ static int make_msg_set(struct Mailbox *m, struct Buffer *buf, int flag, if (setstart == 0) { setstart = imap_edata_get(emails[n])->uid; - if (!started) + if (started) + { + mutt_buffer_add_printf(buf, ",%u", imap_edata_get(emails[n])->uid); + } + else { mutt_buffer_add_printf(buf, "%u", imap_edata_get(emails[n])->uid); started = true; } - else - mutt_buffer_add_printf(buf, ",%u", imap_edata_get(emails[n])->uid); } /* tie up if the last message also matches */ else if (n == (m->msg_count - 1)) diff --git a/imap/message.c b/imap/message.c index 6d926dcd0..17a5b489b 100644 --- a/imap/message.c +++ b/imap/message.c @@ -801,15 +801,7 @@ static int read_headers_normal_eval_cache(struct ImapAccountData *adata, * folders) */ m->emails[idx]->active = true; m->emails[idx]->changed = false; - if (!eval_condstore) - { - m->emails[idx]->read = h.edata->read; - m->emails[idx]->old = h.edata->old; - m->emails[idx]->deleted = h.edata->deleted; - m->emails[idx]->flagged = h.edata->flagged; - m->emails[idx]->replied = h.edata->replied; - } - else + if (eval_condstore) { h.edata->read = m->emails[idx]->read; h.edata->old = m->emails[idx]->old; @@ -817,6 +809,14 @@ static int read_headers_normal_eval_cache(struct ImapAccountData *adata, h.edata->flagged = m->emails[idx]->flagged; h.edata->replied = m->emails[idx]->replied; } + else + { + m->emails[idx]->read = h.edata->read; + m->emails[idx]->old = h.edata->old; + m->emails[idx]->deleted = h.edata->deleted; + m->emails[idx]->flagged = h.edata->flagged; + m->emails[idx]->replied = h.edata->replied; + } /* mailbox->emails[msgno]->received is restored from mutt_hcache_restore */ m->emails[idx]->edata = h.edata; diff --git a/init.c b/init.c index aa13633a3..484ead7a2 100644 --- a/init.c +++ b/init.c @@ -793,15 +793,13 @@ static int source_rc(const char *rcfile_path, struct Buffer *err) break; } } - if (!np) - { - mutt_list_insert_head(&MuttrcStack, mutt_str_strdup(rcfile)); - } - else + if (np) { mutt_error(_("Error: Cyclic sourcing of configuration file '%s'"), rcfile); return -1; } + + mutt_list_insert_head(&MuttrcStack, mutt_str_strdup(rcfile)); } mutt_debug(LL_DEBUG2, "Reading configuration file '%s'\n", rcfile); diff --git a/mailcap.c b/mailcap.c index e2e3d1743..14d91ef15 100644 --- a/mailcap.c +++ b/mailcap.c @@ -92,10 +92,10 @@ int mailcap_expand_command(struct Body *a, const char *filename, { const char *pvalue2 = NULL; - if (!param) - param = mutt_buffer_pool_get(); - else + if (param) mutt_buffer_reset(param); + else + param = mutt_buffer_pool_get(); /* Copy parameter name into param buffer */ cptr++; diff --git a/maildir/shared.c b/maildir/shared.c index 7e1cd73f4..6e7a75f65 100644 --- a/maildir/shared.c +++ b/maildir/shared.c @@ -712,10 +712,10 @@ void maildir_delayed_parsing(struct Mailbox *m, struct Maildir **md, struct Prog { mutt_debug(LL_DEBUG3, "maildir: need to sort %s by inode\n", mailbox_path(m)); p = maildir_sort(p, (size_t) -1, md_cmp_inode); - if (!last) - *md = p; - else + if (last) last->next = p; + else + *md = p; sort = true; p = skip_duplicates(p, &last); snprintf(fn, sizeof(fn), "%s/%s", mailbox_path(m), p->email->path); diff --git a/mutt_mailbox.c b/mutt_mailbox.c index 4aed73555..a1d71d664 100644 --- a/mutt_mailbox.c +++ b/mutt_mailbox.c @@ -255,13 +255,11 @@ bool mutt_mailbox_list(void) mutt_message("%s", mailboxlist); return true; } - else - { - /* there were no mailboxes needing to be notified, so clean up since - * MailboxNotify has somehow gotten out of sync */ - MailboxNotify = 0; - return false; - } + + /* there were no mailboxes needing to be notified, so clean up since + * MailboxNotify has somehow gotten out of sync */ + MailboxNotify = 0; + return false; } /** diff --git a/mutt_thread.c b/mutt_thread.c index 1ab4ee352..c2ff8fa97 100644 --- a/mutt_thread.c +++ b/mutt_thread.c @@ -239,8 +239,7 @@ static void calculate_visibility(struct Context *ctx, int *max_depth) } if (!tree) break; - else - tree = tree->prev; + tree = tree->prev; } } @@ -265,8 +264,7 @@ static void calculate_visibility(struct Context *ctx, int *max_depth) tree = tree->parent; if (!tree) break; - else - tree = tree->next; + tree = tree->next; } } } @@ -1013,18 +1011,18 @@ void mutt_sort_threads(struct Context *ctx, bool init) break; tnew = mutt_hash_find(ctx->thread_hash, ref->data); - if (!tnew) - { - tnew = mutt_mem_calloc(1, sizeof(struct MuttThread)); - mutt_hash_insert(ctx->thread_hash, ref->data, tnew); - } - else + if (tnew) { if (tnew->duplicate_thread) tnew = tnew->parent; if (is_descendant(tnew, thread)) /* no loops! */ continue; } + else + { + tnew = mutt_mem_calloc(1, sizeof(struct MuttThread)); + mutt_hash_insert(ctx->thread_hash, ref->data, tnew); + } if (thread->parent) unlink_message(&top.child, thread); @@ -1085,12 +1083,7 @@ int mutt_aside_thread(struct Email *e, bool forwards, bool subthreads) cur = e->thread; - if (!subthreads) - { - while (cur->parent) - cur = cur->parent; - } - else + if (subthreads) { if (forwards ^ ((C_Sort & SORT_REVERSE) != 0)) { @@ -1103,6 +1096,11 @@ int mutt_aside_thread(struct Email *e, bool forwards, bool subthreads) cur = cur->parent; } } + else + { + while (cur->parent) + cur = cur->parent; + } if (forwards ^ ((C_Sort & SORT_REVERSE) != 0)) { diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index b6abb8a7d..eb5c1b4af 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -333,12 +333,7 @@ static const char *parse_version_string(const char *s, int *major, int *minor, i s = parse_version_number(s, major); if (!s) return NULL; - if (!minor) - { - if (*s == '.') - s++; - } - else + if (minor) { if (*s != '.') return NULL; @@ -346,12 +341,7 @@ static const char *parse_version_string(const char *s, int *major, int *minor, i s = parse_version_number(s, minor); if (!s) return NULL; - if (!micro) - { - if (*s == '.') - s++; - } - else + if (micro) { if (*s != '.') return NULL; @@ -360,6 +350,16 @@ static const char *parse_version_string(const char *s, int *major, int *minor, i if (!s) return NULL; } + else + { + if (*s == '.') + s++; + } + } + else + { + if (*s == '.') + s++; } return s; /* patchlevel */ } @@ -829,13 +829,15 @@ static bool have_gpg_version(const char *version) engineinfo = gpgme_ctx_get_engine_info(ctx); while (engineinfo && (engineinfo->protocol != GPGME_PROTOCOL_OpenPGP)) engineinfo = engineinfo->next; - if (!engineinfo) + if (engineinfo) + { + engine_version = mutt_str_strdup(engineinfo->version); + } + else { mutt_debug(LL_DEBUG1, "Error finding GPGME PGP engine\n"); engine_version = mutt_str_strdup("0.0.0"); } - else - engine_version = mutt_str_strdup(engineinfo->version); gpgme_release(ctx); } @@ -2635,15 +2637,15 @@ static int pgp_gpgme_extract_keys(gpgme_data_t keydata, FILE **fp) tt = subkey->timestamp; mutt_date_localtime_format(date, sizeof(date), "%Y-%m-%d", tt); - if (!more) + if (more) { - fprintf(*fp, "pub %5.5s %u/%8s %s %s\n", gpgme_pubkey_algo_name(subkey->pubkey_algo), - subkey->length, shortid, date, uid->uid); + fprintf(*fp, "sub %5.5s %u/%8s %s\n", gpgme_pubkey_algo_name(subkey->pubkey_algo), + subkey->length, shortid, date); } else { - fprintf(*fp, "sub %5.5s %u/%8s %s\n", gpgme_pubkey_algo_name(subkey->pubkey_algo), - subkey->length, shortid, date); + fprintf(*fp, "pub %5.5s %u/%8s %s %s\n", gpgme_pubkey_algo_name(subkey->pubkey_algo), + subkey->length, shortid, date, uid->uid); } subkey = subkey->next; more = true; @@ -3090,15 +3092,15 @@ int pgp_gpgme_application_handler(struct Body *m, struct State *s) } tmpfname = data_object_to_tempfile(plaintext, &fp_out); - if (!tmpfname) + if (tmpfname) { - mutt_file_fclose(&fp_out); - state_puts(s, _("Error: copy data failed\n")); + unlink(tmpfname); + FREE(&tmpfname); } else { - unlink(tmpfname); - FREE(&tmpfname); + mutt_file_fclose(&fp_out); + state_puts(s, _("Error: copy data failed\n")); } } gpgme_data_release(plaintext); @@ -5712,12 +5714,7 @@ static bool verify_sender(struct Email *e) (uid_length == (sender_length + 2))) { const char *at_sign = strchr(uid->email + 1, '@'); - if (!at_sign) - { - if (strncmp(uid->email + 1, sender->mailbox, sender_length) == 0) - rc = false; - } - else + if (at_sign) { /* Assume address is 'mailbox@domainname'. * The mailbox part is case-sensitive, @@ -5737,6 +5734,11 @@ static bool verify_sender(struct Email *e) if (mailbox_match && domainname_match) rc = false; } + else + { + if (strncmp(uid->email + 1, sender->mailbox, sender_length) == 0) + rc = false; + } } } } diff --git a/pager.c b/pager.c index 70f6bd3b6..2474f54ee 100644 --- a/pager.c +++ b/pager.c @@ -2829,16 +2829,17 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P break; case OP_HELP: - /* don't let the user enter the help-menu from the help screen! */ - if (!InHelp) + if (InHelp) { - InHelp = true; - mutt_help(MENU_PAGER, MuttIndexWindow->cols); - pager_menu->redraw = REDRAW_FULL; - InHelp = false; - } - else + /* don't let the user enter the help-menu from the help screen! */ mutt_error(_("Help is currently being shown")); + break; + } + + InHelp = true; + mutt_help(MENU_PAGER, MuttIndexWindow->cols); + pager_menu->redraw = REDRAW_FULL; + InHelp = false; break; case OP_PAGER_HIDE_QUOTED: diff --git a/pop/pop.c b/pop/pop.c index dd7379b47..f69dcccf0 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -674,9 +674,7 @@ void pop_fetch_mail(void) for (int i = last + 1; i <= msgs; i++) { struct Message *msg = mx_msg_open_new(ctx->mailbox, NULL, MUTT_ADD_FROM); - if (!msg) - ret = -3; - else + if (msg) { snprintf(buf, sizeof(buf), "RETR %d\r\n", i); ret = pop_fetch_data(adata, buf, NULL, fetch_message, msg->fp); @@ -691,6 +689,10 @@ void pop_fetch_mail(void) mx_msg_close(ctx->mailbox, &msg); } + else + { + ret = -3; + } if ((ret == 0) && (delanswer == MUTT_YES)) { diff --git a/postpone.c b/postpone.c index 6d54c9874..cafe8428b 100644 --- a/postpone.c +++ b/postpone.c @@ -174,13 +174,15 @@ int mutt_num_postponed(struct Mailbox *m, bool force) #endif struct Mailbox *m_post = mx_path_resolve(C_Postponed); struct Context *ctx = mx_mbox_open(m_post, MUTT_NOSORT | MUTT_QUIET); - if (!ctx) + if (ctx) + { + PostCount = ctx->mailbox->msg_count; + } + else { mailbox_free(&m_post); PostCount = 0; } - else - PostCount = ctx->mailbox->msg_count; mx_fastclose_mailbox(m_post); ctx_free(&ctx); #ifdef USE_NNTP diff --git a/query.c b/query.c index f9d439cba..5e7523fed 100644 --- a/query.c +++ b/query.c @@ -185,15 +185,15 @@ static struct Query *run_query(char *s, int quiet) p = strtok(buf, "\t\n"); if (p) { - if (!first) + if (first) { - first = query_new(); - cur = first; + cur->next = query_new(); + cur = cur->next; } else { - cur->next = query_new(); - cur = cur->next; + first = query_new(); + cur = first; } mutt_addrlist_parse(&cur->addr, p); diff --git a/recvattach.c b/recvattach.c index 975fd980d..cd5fb851e 100644 --- a/recvattach.c +++ b/recvattach.c @@ -1041,7 +1041,11 @@ void mutt_print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, stru if (query_quadoption(C_Print, prompt) != MUTT_YES) return; - if (!C_AttachSplit) + if (C_AttachSplit) + { + print_attachment_list(actx, fp, tag, top, &state); + } + else { if (!can_print(actx, top, tag)) return; @@ -1052,8 +1056,6 @@ void mutt_print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, stru if ((mutt_wait_filter(pid) != 0) || C_WaitKey) mutt_any_key_to_continue(NULL); } - else - print_attachment_list(actx, fp, tag, top, &state); } /** diff --git a/recvcmd.c b/recvcmd.c index 102e0795f..3ef148a44 100644 --- a/recvcmd.c +++ b/recvcmd.c @@ -990,13 +990,15 @@ void mutt_attach_reply(FILE *fp, struct Email *e, struct AttachCtx *actx, memset(&st, 0, sizeof(struct State)); st.fp_out = fp_tmp; - if (!C_TextFlowed) + if (C_TextFlowed) + { + mutt_str_strfcpy(prefix, ">", sizeof(prefix)); + } + else { mutt_make_string(prefix, sizeof(prefix), 0, NONULL(C_IndentString), Context, Context->mailbox, e_parent); } - else - mutt_str_strfcpy(prefix, ">", sizeof(prefix)); st.prefix = prefix; st.flags = MUTT_CHARCONV; diff --git a/send.c b/send.c index dcae92b45..c749776de 100644 --- a/send.c +++ b/send.c @@ -2002,16 +2002,16 @@ int ci_send_message(SendFlags flags, struct Email *e_templ, const char *tempfile e_templ->content->use_disp = false; e_templ->content->disposition = DISP_INLINE; - if (!tempfile) + if (tempfile) { - mutt_mktemp(buf, sizeof(buf)); - fp_tmp = mutt_file_fopen(buf, "w+"); - e_templ->content->filename = mutt_str_strdup(buf); + fp_tmp = mutt_file_fopen(tempfile, "a+"); + e_templ->content->filename = mutt_str_strdup(tempfile); } else { - fp_tmp = mutt_file_fopen(tempfile, "a+"); - e_templ->content->filename = mutt_str_strdup(tempfile); + mutt_mktemp(buf, sizeof(buf)); + fp_tmp = mutt_file_fopen(buf, "w+"); + e_templ->content->filename = mutt_str_strdup(buf); } } else diff --git a/sidebar.c b/sidebar.c index fab2f9a46..0750f663c 100644 --- a/sidebar.c +++ b/sidebar.c @@ -912,8 +912,8 @@ static void draw_sidebar(int num_rows, int num_cols, int div_width) char *chars_after_delim = strpbrk(sidebar_folder_name, C_SidebarDelimChars); if (!chars_after_delim) break; - else - sidebar_folder_name = chars_after_delim + 1; + + sidebar_folder_name = chars_after_delim + 1; } } else -- 2.40.0