From: Richard Russon Date: Thu, 24 Oct 2019 00:46:16 +0000 (+0100) Subject: tidy conditionals 4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ed199aa2476456be04bc5e81dcf8cd9ed89f0f8e;p=neomutt tidy conditionals 4 - move true condition first - flatten 'else' clause when 'if' clause returns/breaks - compare int functions to zero --- diff --git a/address/address.c b/address/address.c index cfaf0ae44..cb5b87723 100644 --- a/address/address.c +++ b/address/address.c @@ -1075,17 +1075,17 @@ size_t mutt_addr_write(char *buf, size_t buflen, struct Address *addr, bool disp { if (buflen == 0) goto done; - if (mutt_str_strcmp(addr->mailbox, "@") != 0) + if (mutt_str_strcmp(addr->mailbox, "@") == 0) + { + *pbuf = '\0'; + } + else { const char *a = display ? mutt_addr_for_display(addr) : addr->mailbox; len = mutt_str_strfcpy(pbuf, a, buflen + 1 /* strfcpy terminates */); pbuf += len; buflen -= len; } - else - { - *pbuf = '\0'; - } if (addr->personal || (addr->mailbox && (*addr->mailbox == '@'))) { diff --git a/curs_lib.c b/curs_lib.c index 7aaf00d49..25c5f020b 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -480,25 +480,27 @@ enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def) if (reno_ok) regfree(&reno); - if (MuttMessageWindow->rows != 1) + if (MuttMessageWindow->rows == 1) { - mutt_window_reflow_message_rows(1); - mutt_menu_current_redraw(); + mutt_window_clearline(MuttMessageWindow, 0); } else - mutt_window_clearline(MuttMessageWindow, 0); - - if (def != MUTT_ABORT) { - mutt_window_addstr((char *) ((def == MUTT_YES) ? yes : no)); - mutt_refresh(); + mutt_window_reflow_message_rows(1); + mutt_menu_current_redraw(); } - else + + if (def == MUTT_ABORT) { /* when the users cancels with ^G, clear the message stored with * mutt_message() so it isn't displayed when the screen is refreshed. */ mutt_clear_error(); } + else + { + mutt_window_addstr((char *) ((def == MUTT_YES) ? yes : no)); + mutt_refresh(); + } return def; } @@ -963,13 +965,15 @@ int mutt_multi_choice(const char *prompt, const char *letters) } mutt_beep(false); } - if (MuttMessageWindow->rows != 1) + if (MuttMessageWindow->rows == 1) + { + mutt_window_clearline(MuttMessageWindow, 0); + } + else { mutt_window_reflow_message_rows(1); mutt_menu_current_redraw(); } - else - mutt_window_clearline(MuttMessageWindow, 0); mutt_refresh(); return choice; } diff --git a/handler.c b/handler.c index 42959c9ed..79d8c5e6b 100644 --- a/handler.c +++ b/handler.c @@ -98,16 +98,16 @@ static void print_part_line(struct State *s, struct Body *b, int n) mutt_str_pretty_size(length, sizeof(length), b->length); state_mark_attach(s); char *charset = mutt_param_get(&b->parameter, "charset"); - if (n != 0) + if (n == 0) { - state_printf(s, _("[-- Alternative Type #%d: %s/%s%s%s, Encoding: %s, Size: %s --]\n"), - n, TYPE(b), b->subtype, charset ? "; charset=" : "", + state_printf(s, _("[-- Type: %s/%s%s%s, Encoding: %s, Size: %s --]\n"), + TYPE(b), b->subtype, charset ? "; charset=" : "", charset ? charset : "", ENCODING(b->encoding), length); } else { - state_printf(s, _("[-- Type: %s/%s%s%s, Encoding: %s, Size: %s --]\n"), - TYPE(b), b->subtype, charset ? "; charset=" : "", + state_printf(s, _("[-- Alternative Type #%d: %s/%s%s%s, Encoding: %s, Size: %s --]\n"), + n, TYPE(b), b->subtype, charset ? "; charset=" : "", charset ? charset : "", ENCODING(b->encoding), length); } } diff --git a/help.c b/help.c index a3b12115f..b39118181 100644 --- a/help.c +++ b/help.c @@ -348,17 +348,17 @@ static void format_line(FILE *fp, int ismacro, const char *t1, const char *t2, if (*t3) { - if (mutt_str_strcmp(C_Pager, "builtin") != 0) - { - fputc('\n', fp); - n = 0; - } - else + if (mutt_str_strcmp(C_Pager, "builtin") == 0) { n += col - wraplen; if (C_Markers) n++; } + else + { + fputc('\n', fp); + n = 0; + } col = pad(fp, n, col_b); } } diff --git a/imap/browse.c b/imap/browse.c index 44e6ac3b3..270c7ac1d 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -237,15 +237,15 @@ int imap_browse(const char *path, struct BrowserState *state) mutt_message(_("Getting folder list...")); /* skip check for parents when at the root */ - if (buf[0] != '\0') + if (buf[0] == '\0') { - imap_fix_path(adata->delim, buf, mbox, sizeof(mbox)); - n = mutt_str_strlen(mbox); + mbox[0] = '\0'; + n = 0; } else { - mbox[0] = '\0'; - n = 0; + imap_fix_path(adata->delim, buf, mbox, sizeof(mbox)); + n = mutt_str_strlen(mbox); } if (n) diff --git a/init.c b/init.c index 484ead7a2..5fc4cafe6 100644 --- a/init.c +++ b/init.c @@ -2108,22 +2108,18 @@ static enum CommandResult parse_subscribe_to(struct Buffer *buf, struct Buffer * if (buf->data && (*buf->data != '\0')) { /* Expand and subscribe */ - if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), true) != 0) - { - mutt_buffer_printf(err, _("Could not subscribe to %s"), buf->data); - return MUTT_CMD_ERROR; - } - else + if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), true) == 0) { mutt_message(_("Subscribed to %s"), buf->data); return MUTT_CMD_SUCCESS; } - } - else - { - mutt_debug(LL_DEBUG1, "Corrupted buffer"); + + mutt_buffer_printf(err, _("Could not subscribe to %s"), buf->data); return MUTT_CMD_ERROR; } + + mutt_debug(LL_DEBUG1, "Corrupted buffer"); + return MUTT_CMD_ERROR; } mutt_buffer_addstr(err, _("No folder specified")); @@ -2589,22 +2585,18 @@ static enum CommandResult parse_unsubscribe_from(struct Buffer *buf, struct Buff if (buf->data && (*buf->data != '\0')) { /* Expand and subscribe */ - if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), false) != 0) - { - mutt_buffer_printf(err, _("Could not unsubscribe from %s"), buf->data); - return MUTT_CMD_ERROR; - } - else + if (imap_subscribe(mutt_expand_path(buf->data, buf->dsize), false) == 0) { mutt_message(_("Unsubscribed from %s"), buf->data); return MUTT_CMD_SUCCESS; } - } - else - { - mutt_debug(LL_DEBUG1, "Corrupted buffer"); + + mutt_buffer_printf(err, _("Could not unsubscribe from %s"), buf->data); return MUTT_CMD_ERROR; } + + mutt_debug(LL_DEBUG1, "Corrupted buffer"); + return MUTT_CMD_ERROR; } mutt_buffer_addstr(err, _("No folder specified")); diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 850e930f9..c089182d5 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -1770,16 +1770,16 @@ char *nm_uri_from_query(struct Mailbox *m, char *buf, size_t buflen) nm_parse_type_from_query(mdata, buf); - if (get_limit(mdata) != C_NmDbLimit) + if (get_limit(mdata) == C_NmDbLimit) { - added = snprintf(uri, sizeof(uri), "%s%s?type=%s&limit=%d&query=", NmUriProtocol, - nm_db_get_filename(m), - query_type_to_string(mdata->query_type), get_limit(mdata)); + added = snprintf(uri, sizeof(uri), "%s%s?type=%s&query=", NmUriProtocol, + nm_db_get_filename(m), query_type_to_string(mdata->query_type)); } else { - added = snprintf(uri, sizeof(uri), "%s%s?type=%s&query=", NmUriProtocol, - nm_db_get_filename(m), query_type_to_string(mdata->query_type)); + added = snprintf(uri, sizeof(uri), "%s%s?type=%s&limit=%d&query=", NmUriProtocol, + nm_db_get_filename(m), + query_type_to_string(mdata->query_type), get_limit(mdata)); } if (added >= sizeof(uri)) diff --git a/pager.c b/pager.c index 2474f54ee..97faf40f3 100644 --- a/pager.c +++ b/pager.c @@ -2007,16 +2007,16 @@ static void pager_custom_redraw(struct Menu *pager_menu) { int flags = mutt_mb_is_lower(rd->searchbuf) ? REG_ICASE : 0; const int err = REG_COMP(&rd->search_re, rd->searchbuf, REG_NEWLINE | flags); - if (err != 0) + if (err == 0) { - regerror(err, &rd->search_re, buf, sizeof(buf)); - mutt_error("%s", buf); - rd->search_compiled = false; + rd->search_flag = MUTT_SEARCH; + rd->search_back = Resize->search_back; } else { - rd->search_flag = MUTT_SEARCH; - rd->search_back = Resize->search_back; + regerror(err, &rd->search_re, buf, sizeof(buf)); + mutt_error("%s", buf); + rd->search_compiled = false; } } rd->lines = Resize->line; @@ -2535,13 +2535,15 @@ int mutt_pager(const char *banner, const char *fname, PagerFlags flags, struct P break; case OP_PREV_PAGE: - if (rd.topline != 0) + if (rd.topline == 0) + { + mutt_message(_("Top of message is shown")); + } + else { rd.topline = up_n_lines(rd.pager_window->rows - C_PagerContext, rd.line_info, rd.topline, rd.hide_quoted); } - else - mutt_message(_("Top of message is shown")); break; case OP_NEXT_LINE: diff --git a/progress.c b/progress.c index 50692cea8..c05ca957f 100644 --- a/progress.c +++ b/progress.c @@ -183,13 +183,13 @@ void mutt_progress_init(struct Progress *progress, const char *msg, if (progress->inc == 0) { /* This progress bar does not increment - write the initial message */ - if (progress->size != 0) + if (progress->size == 0) { - mutt_message("%s (%s)", progress->msg, progress->sizestr); + mutt_message(progress->msg); } else { - mutt_message(progress->msg); + mutt_message("%s (%s)", progress->msg, progress->sizestr); } } else diff --git a/sendlib.c b/sendlib.c index 9df5a5cd3..5f2bf3df4 100644 --- a/sendlib.c +++ b/sendlib.c @@ -678,11 +678,7 @@ static void update_content_info(struct Content *info, struct ContentState *s, if (was_cr) { was_cr = false; - if (ch != '\n') - { - info->binary = true; - } - else + if (ch == '\n') { if (whitespace) info->space = true; @@ -695,6 +691,8 @@ static void update_content_info(struct Content *info, struct ContentState *s, linelen = 0; continue; } + + info->binary = true; } linelen++;