]> granicus.if.org Git - neomutt/commitdiff
tidy conditionals 4
authorRichard Russon <rich@flatcap.org>
Thu, 24 Oct 2019 00:46:16 +0000 (01:46 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 27 Oct 2019 01:22:41 +0000 (01:22 +0000)
- move true condition first
- flatten 'else' clause when 'if' clause returns/breaks
- compare int functions to zero

address/address.c
curs_lib.c
handler.c
help.c
imap/browse.c
init.c
notmuch/mutt_notmuch.c
pager.c
progress.c
sendlib.c

index cfaf0ae443a66ccb955cea1b211ef85df095bc85..cb5b877238381cd3adecd212195ac17fb02f2ac4 100644 (file)
@@ -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 == '@')))
     {
index 7aaf00d49b8be50259b3d1d6c0abdf170a580131..25c5f020b394c1f46ff3f7f402937c73efbdc7cc 100644 (file)
@@ -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;
 }
index 42959c9edf86df70e66ac67f3e41caf47a5edfc7..79d8c5e6bf6f0fc7e38e2fe8f67a243f58b9894b 100644 (file)
--- 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 a3b12115f3efe3cedace83afefe0a5a2fd47b685..b3911818174683a876d4f0a75aca39e23f50f275 100644 (file)
--- 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);
       }
     }
index 44e6ac3b3a75f325f81891e62b1a68cf5fb59318..270c7ac1da77d6e7c0cb9cb29e3fbc04b94d9cd6 100644 (file)
@@ -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 484ead7a273b12cf1c67315a57e317992a3b6535..5fc4cafe661d2db7b848bc25966a21ec43ba6284 100644 (file)
--- 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"));
index 850e930f91990e6819aa4cbb920af63e40295ef7..c089182d5e6e766dd0c1091423d891336b8f78fe 100644 (file)
@@ -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 2474f54ee75a4a30862d135eb9d41e4375243d9a..97faf40f34cfbdce602e2e6894c3d939794b3396 100644 (file)
--- 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:
index 50692cea88ddf7e756c6490c402aca093c4564af..c05ca957f0ead4b7671ee53c4221c53942f19ce8 100644 (file)
@@ -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
index 9df5a5cd3ccede83634dc807dd1b1825b11ea6e3..5f2bf3df45dc3caa8919e78af9a1a470abf602a7 100644 (file)
--- 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++;