]> granicus.if.org Git - neomutt/commitdiff
kill preproc expansion laziness
authorRichard Russon <rich@flatcap.org>
Sat, 7 Oct 2017 01:19:56 +0000 (02:19 +0100)
committerRichard Russon <rich@flatcap.org>
Sat, 14 Oct 2017 14:01:43 +0000 (15:01 +0100)
Replace macros which were shortcuts for code, e.g.

```
  #define CUR_ENV Context->hdrs[i]->env
  function(CUR_ENV);
  CUR_ENV->from = "user";
  #undef CUR_ENV
```

13 files changed:
curs_main.c
hdrline.c
history.c
init.c
mbox.c
mx.c
ncrypt/crypt_gpgme.c
parse.c
pattern.c
rfc2047.c
sendlib.c
sort.c
thread.c

index 7742d8ca638e41970533268874a97f03d712df96..5b5d12c2a42c82d1a80598f962fefe3358218cdf 100644 (file)
@@ -357,7 +357,6 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun
    * they will be visible in the limited view */
   if (ctx->pattern)
   {
-#define THIS_BODY ctx->hdrs[j]->content
     for (j = (check == MUTT_REOPENED) ? 0 : oldcount; j < ctx->msgcount; j++)
     {
       if (!j)
@@ -371,10 +370,10 @@ void update_index(struct Menu *menu, struct Context *ctx, int check, int oldcoun
         ctx->v2r[ctx->vcount] = j;
         ctx->hdrs[j]->limited = true;
         ctx->vcount++;
-        ctx->vsize += THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
+        struct Body *b = ctx->hdrs[j]->content;
+        ctx->vsize += b->length + b->offset - b->hdr_offset;
       }
     }
-#undef THIS_BODY
   }
 
   /* save the list of new messages */
@@ -2441,7 +2440,6 @@ int mutt_index_menu(void)
         menu->current = -1;
         for (j = 0; j != Context->vcount; j++)
         {
-#define CURHDRi Context->hdrs[Context->v2r[i]]
           if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_NEXT_NEW_THEN_UNREAD)
           {
             i++;
@@ -2461,18 +2459,19 @@ int mutt_index_menu(void)
             }
           }
 
-          if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS)
+          struct Header *h = Context->hdrs[Context->v2r[i]];
+          if (h->collapsed && (Sort & SORT_MASK) == SORT_THREADS)
           {
-            if (UNREAD(CURHDRi) && first_unread == -1)
+            if (UNREAD(h) && first_unread == -1)
               first_unread = i;
-            if (UNREAD(CURHDRi) == 1 && first_new == -1)
+            if (UNREAD(h) == 1 && first_new == -1)
               first_new = i;
           }
-          else if ((!CURHDRi->deleted && !CURHDRi->read))
+          else if ((!h->deleted && !h->read))
           {
             if (first_unread == -1)
               first_unread = i;
-            if ((!CURHDRi->old) && first_new == -1)
+            if ((!h->old) && first_new == -1)
               first_new = i;
           }
 
@@ -2483,7 +2482,6 @@ int mutt_index_menu(void)
               first_new != -1)
             break;
         }
-#undef CURHDRi
         if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
              op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD) &&
             first_new != -1)
index 29de2834f8e4c2bdc52d1208f01b3efbffb5dcf9..1ddba45e1b21a0ac862ba36199ef6e174d9d9b35 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -453,6 +453,18 @@ static char *apply_subject_mods(struct Envelope *env)
   return env->disp_subj;
 }
 
+static bool thread_is_new(struct Context *ctx, struct Header *hdr)
+{
+  return (hdr->collapsed && (hdr->num_hidden > 1) &&
+          (mutt_thread_contains_unread(ctx, hdr) == 1));
+}
+
+static bool thread_is_old(struct Context *ctx, struct Header *hdr)
+{
+  return (hdr->collapsed && (hdr->num_hidden > 1) &&
+          (mutt_thread_contains_unread(ctx, hdr) == 2));
+}
+
 /**
  * hdr_format_str - Format a string, like printf()
  *
@@ -516,12 +528,6 @@ static const char *hdr_format_str(char *dest, size_t destlen, size_t col, int co
   int optional = (flags & MUTT_FORMAT_OPTIONAL);
   int threads = ((Sort & SORT_MASK) == SORT_THREADS);
   int is_index = (flags & MUTT_FORMAT_INDEX);
-#define THREAD_NEW                                                             \
-  (threads && hdr->collapsed && hdr->num_hidden > 1 &&                         \
-   mutt_thread_contains_unread(ctx, hdr) == 1)
-#define THREAD_OLD                                                             \
-  (threads && hdr->collapsed && hdr->num_hidden > 1 &&                         \
-   mutt_thread_contains_unread(ctx, hdr) == 2)
   size_t len;
   size_t colorlen;
 
@@ -1247,9 +1253,9 @@ static const char *hdr_format_str(char *dest, size_t destlen, size_t col, int co
           ch = get_nth_wchar(FlagChars, FlagCharDeleted);
         else if (hdr->attach_del)
           ch = get_nth_wchar(FlagChars, FlagCharDeletedAttach);
-        else if (THREAD_NEW)
+        else if (threads && thread_is_new(ctx, hdr))
           ch = get_nth_wchar(FlagChars, FlagCharNewThread);
-        else if (THREAD_OLD)
+        else if (threads && thread_is_old(ctx, hdr))
           ch = get_nth_wchar(FlagChars, FlagCharOldThread);
         else if (hdr->read && (ctx && (ctx->msgnotreadyet != hdr->msgno)))
         {
@@ -1311,9 +1317,9 @@ static const char *hdr_format_str(char *dest, size_t destlen, size_t col, int co
     {
       /* New/Old for threads; replied; New/Old for messages */
       char *first = NULL;
-      if (THREAD_NEW)
+      if (threads && thread_is_new(ctx, hdr))
         first = get_nth_wchar(FlagChars, FlagCharNewThread);
-      else if (THREAD_OLD)
+      else if (threads && thread_is_old(ctx, hdr))
         first = get_nth_wchar(FlagChars, FlagCharOldThread);
       else if (hdr->read && (ctx && (ctx->msgnotreadyet != hdr->msgno)))
       {
@@ -1377,8 +1383,6 @@ static const char *hdr_format_str(char *dest, size_t destlen, size_t col, int co
                         (unsigned long) hfi, flags);
 
   return src;
-#undef THREAD_NEW
-#undef THREAD_OLD
 }
 
 void _mutt_make_string(char *dest, size_t destlen, const char *s,
index 52fedee7c9839c0157f0840f28e106b71783aad4..5e09e003d78c6da8f25d7ec8e3bae0e58c617ad5 100644 (file)
--- a/history.c
+++ b/history.c
@@ -86,7 +86,13 @@ struct History
 static struct History Histories[HC_LAST];
 static int OldSize = 0;
 
-#define GET_HISTORY(CLASS) ((CLASS >= HC_LAST) ? NULL : &Histories[CLASS])
+static struct History *get_history(enum HistoryClass hclass)
+{
+  if (hclass >= HC_LAST)
+    return NULL;
+
+  return &Histories[hclass];
+}
 
 static void init_history(struct History *h)
 {
@@ -332,7 +338,7 @@ static void save_history(enum HistoryClass hclass, const char *s)
 static void remove_history_dups(enum HistoryClass hclass, const char *s)
 {
   int source, dest, old_last;
-  struct History *h = GET_HISTORY(hclass);
+  struct History *h = get_history(hclass);
 
   if (!History || !h)
     return; /* disabled */
@@ -385,7 +391,7 @@ void mutt_init_history(void)
 void mutt_history_add(enum HistoryClass hclass, const char *s, bool save)
 {
   int prev;
-  struct History *h = GET_HISTORY(hclass);
+  struct History *h = get_history(hclass);
 
   if (!History || !h)
     return; /* disabled */
@@ -417,7 +423,7 @@ void mutt_history_add(enum HistoryClass hclass, const char *s, bool save)
 char *mutt_history_next(enum HistoryClass hclass)
 {
   int next;
-  struct History *h = GET_HISTORY(hclass);
+  struct History *h = get_history(hclass);
 
   if (!History || !h)
     return ""; /* disabled */
@@ -439,7 +445,7 @@ char *mutt_history_next(enum HistoryClass hclass)
 char *mutt_history_prev(enum HistoryClass hclass)
 {
   int prev;
-  struct History *h = GET_HISTORY(hclass);
+  struct History *h = get_history(hclass);
 
   if (!History || !h)
     return ""; /* disabled */
@@ -460,7 +466,7 @@ char *mutt_history_prev(enum HistoryClass hclass)
 
 void mutt_reset_history_state(enum HistoryClass hclass)
 {
-  struct History *h = GET_HISTORY(hclass);
+  struct History *h = get_history(hclass);
 
   if (!History || !h)
     return; /* disabled */
@@ -470,7 +476,7 @@ void mutt_reset_history_state(enum HistoryClass hclass)
 
 bool mutt_history_at_scratch(enum HistoryClass hclass)
 {
-  struct History *h = GET_HISTORY(hclass);
+  struct History *h = get_history(hclass);
 
   if (!History || !h)
     return false; /* disabled */
@@ -480,7 +486,7 @@ bool mutt_history_at_scratch(enum HistoryClass hclass)
 
 void mutt_history_save_scratch(enum HistoryClass hclass, const char *s)
 {
-  struct History *h = GET_HISTORY(hclass);
+  struct History *h = get_history(hclass);
 
   if (!History || !h)
     return; /* disabled */
diff --git a/init.c b/init.c
index d2496e845ba39601b20a003d08ca817a10cdf282..826899895657885c7bd8e87d348defcd892a5909 100644 (file)
--- a/init.c
+++ b/init.c
@@ -391,18 +391,17 @@ int mutt_option_set(const struct Option *val, struct Buffer *err)
           {
             regmatch_t pmatch[1];
 
-#define CUR_ENV Context->hdrs[i]->env
             for (int i = 0; i < Context->msgcount; i++)
             {
-              if (CUR_ENV && CUR_ENV->subject)
+              struct Envelope *e = Context->hdrs[i]->env;
+              if (e && e->subject)
               {
-                CUR_ENV->real_subj =
-                    (regexec(ReplyRegexp.regex, CUR_ENV->subject, 1, pmatch, 0)) ?
-                        CUR_ENV->subject :
-                        CUR_ENV->subject + pmatch[0].rm_eo;
+                e->real_subj =
+                    (regexec(ReplyRegexp.regex, e->subject, 1, pmatch, 0)) ?
+                        e->subject :
+                        e->subject + pmatch[0].rm_eo;
               }
             }
-#undef CUR_ENV
           }
         }
         else
@@ -2812,18 +2811,17 @@ static int parse_set(struct Buffer *tmp, struct Buffer *s, unsigned long data,
           regmatch_t pmatch[1];
           int i;
 
-#define CUR_ENV Context->hdrs[i]->env
           for (i = 0; i < Context->msgcount; i++)
           {
-            if (CUR_ENV && CUR_ENV->subject)
+            struct Envelope *e = Context->hdrs[i]->env;
+            if (e && e->subject)
             {
-              CUR_ENV->real_subj =
-                  (regexec(ReplyRegexp.regex, CUR_ENV->subject, 1, pmatch, 0)) ?
-                      CUR_ENV->subject :
-                      CUR_ENV->subject + pmatch[0].rm_eo;
+              e->real_subj =
+                  (regexec(ReplyRegexp.regex, e->subject, 1, pmatch, 0)) ?
+                      e->subject :
+                      e->subject + pmatch[0].rm_eo;
             }
           }
-#undef CUR_ENV
         }
     }
     else if (DTYPE(MuttVars[idx].type) == DT_MAGIC)
@@ -3380,8 +3378,9 @@ finish:
   return r;
 }
 
-#define NUMVARS (sizeof(MuttVars) / sizeof(MuttVars[0]))
-#define NUMCOMMANDS (sizeof(Commands) / sizeof(Commands[0]))
+#define NUMVARS mutt_array_size(MuttVars)
+#define NUMCOMMANDS mutt_array_size(Commands)
+
 /* initial string that starts completion. No telling how much crap
  * the user has typed so far. Allocate LONG_STRING just to be sure! */
 static char User_typed[LONG_STRING] = { 0 };
diff --git a/mbox.c b/mbox.c
index 1d55224fdfb68e9503598f210d018e4c67aac750..55df64cf9fa9a51f9154007130fe680291bf095c 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -292,16 +292,15 @@ static int mbox_parse_mailbox(struct Context *ctx)
       /* Save the Content-Length of the previous message */
       if (count > 0)
       {
-#define PREV ctx->hdrs[ctx->msgcount - 1]
-
-        if (PREV->content->length < 0)
+        struct Header *h = ctx->hdrs[ctx->msgcount - 1];
+        if (h->content->length < 0)
         {
-          PREV->content->length = loc - PREV->content->offset - 1;
-          if (PREV->content->length < 0)
-            PREV->content->length = 0;
+          h->content->length = loc - h->content->offset - 1;
+          if (h->content->length < 0)
+            h->content->length = 0;
         }
-        if (!PREV->lines)
-          PREV->lines = lines ? lines - 1 : 0;
+        if (!h->lines)
+          h->lines = lines ? lines - 1 : 0;
       }
 
       count++;
@@ -411,15 +410,16 @@ static int mbox_parse_mailbox(struct Context *ctx)
    */
   if (count > 0)
   {
-    if (PREV->content->length < 0)
+    struct Header *h = ctx->hdrs[ctx->msgcount - 1];
+    if (h->content->length < 0)
     {
-      PREV->content->length = ftello(ctx->fp) - PREV->content->offset - 1;
-      if (PREV->content->length < 0)
-        PREV->content->length = 0;
+      h->content->length = ftello(ctx->fp) - h->content->offset - 1;
+      if (h->content->length < 0)
+        h->content->length = 0;
     }
 
-    if (!PREV->lines)
-      PREV->lines = lines ? lines - 1 : 0;
+    if (!h->lines)
+      h->lines = lines ? lines - 1 : 0;
 
     mx_update_context(ctx, count);
   }
@@ -433,8 +433,6 @@ static int mbox_parse_mailbox(struct Context *ctx)
   return 0;
 }
 
-#undef PREV
-
 /**
  * mbox_open_mailbox - open a mbox or mmdf style mailbox
  */
diff --git a/mx.c b/mx.c
index e04994d93557ec32ee1e34d7d6c66d4634129206..7cb0a3ce51e6cfb5bc14e1cbe2a91a22a4655667 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -109,7 +109,10 @@ struct MxOps *mx_get_ops(int magic)
   }
 }
 
-#define mutt_is_spool(s) (mutt_strcmp(SpoolFile, s) == 0)
+static bool mutt_is_spool(const char *str)
+{
+  return (mutt_strcmp(SpoolFile, str) == 0);
+}
 
 #ifdef USE_IMAP
 
@@ -906,7 +909,6 @@ void mx_update_tables(struct Context *ctx, int committing)
   ctx->unread = 0;
   ctx->changed = false;
   ctx->flagged = 0;
-#define this_body ctx->hdrs[j]->content
   for (i = 0, j = 0; i < ctx->msgcount; i++)
   {
     if (!ctx->hdrs[i]->quasi_deleted &&
@@ -924,7 +926,8 @@ void mx_update_tables(struct Context *ctx, int committing)
       {
         ctx->v2r[ctx->vcount] = j;
         ctx->hdrs[j]->virtual = ctx->vcount++;
-        ctx->vsize += this_body->length + this_body->offset - this_body->hdr_offset;
+        struct Body *b = ctx->hdrs[j]->content;
+        ctx->vsize += b->length + b->offset - b->hdr_offset;
       }
 
       if (committing)
@@ -972,7 +975,6 @@ void mx_update_tables(struct Context *ctx, int committing)
       mutt_free_header(&ctx->hdrs[i]);
     }
   }
-#undef this_body
   ctx->msgcount = j;
 }
 
index 9b45ea480a94b4088b296d049425875ee5c87250..de3e32d53dfcf8aff6c179d627f020404ac2a47e 100644 (file)
 #include "sort.h"
 #include "state.h"
 
-#define PKA_NOTATION_NAME "pka-address@gnupg.org"
-#define is_pka_notation(notation)                                              \
-  ((notation)->name && (strcmp((notation)->name, PKA_NOTATION_NAME) == 0))
-
 /* Values used for comparing addresses. */
 #define CRYPT_KV_VALID 1
 #define CRYPT_KV_ADDR 2
@@ -133,6 +129,13 @@ static char *current_sender = NULL;
  * General helper functions.
  */
 
+#define PKA_NOTATION_NAME "pka-address@gnupg.org"
+
+static bool is_pka_notation(gpgme_sig_notation_t notation)
+{
+  return (mutt_strcmp(notation->name, PKA_NOTATION_NAME) == 0);
+}
+
 /**
  * redraw_if_needed - accommodate for a redraw if needed
  */
diff --git a/parse.c b/parse.c
index a0fa2410117cff1d4e4bd915299b646b430221e5..d23a509629250f70237b283a6d67c824001261b5 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -1351,15 +1351,6 @@ static bool count_body_parts_check(struct ListHead *checklist, struct Body *b, b
   return false;
 }
 
-#define AT_COUNT(why)                                                          \
-  {                                                                            \
-    shallcount = true;                                                         \
-  }
-#define AT_NOCOUNT(why)                                                        \
-  {                                                                            \
-    shallcount = false;                                                        \
-  }
-
 static int count_body_parts(struct Body *body, int flags)
 {
   int count = 0;
@@ -1372,7 +1363,7 @@ static int count_body_parts(struct Body *body, int flags)
   for (bp = body; bp != NULL; bp = bp->next)
   {
     /* Initial disposition is to count and not to recurse this part. */
-    AT_COUNT("default");
+    shallcount = true; /* default */
     shallrecurse = false;
 
     mutt_debug(5, "bp: desc=\"%s\"; fn=\"%s\", type=\"%d/%s\"\n",
@@ -1390,7 +1381,7 @@ static int count_body_parts(struct Body *body, int flags)
 
       /* Don't count containers if they're top-level. */
       if (flags & MUTT_PARTS_TOPLEVEL)
-        AT_NOCOUNT("top-level message/*");
+        shallcount = false; // top-level message/*
     }
     else if (bp->type == TYPEMULTIPART)
     {
@@ -1401,12 +1392,12 @@ static int count_body_parts(struct Body *body, int flags)
 
       /* Don't count containers if they're top-level. */
       if (flags & MUTT_PARTS_TOPLEVEL)
-        AT_NOCOUNT("top-level multipart");
+        shallcount = false; /* top-level multipart */
     }
 
     if (bp->disposition == DISPINLINE && bp->type != TYPEMULTIPART &&
         bp->type != TYPEMESSAGE && bp == body)
-      AT_NOCOUNT("ignore fundamental inlines");
+      shallcount = false; /* ignore fundamental inlines */
 
     /* If this body isn't scheduled for enumeration already, don't bother
      * profiling it further.
@@ -1421,16 +1412,16 @@ static int count_body_parts(struct Body *body, int flags)
       if (bp->disposition == DISPATTACH)
       {
         if (!count_body_parts_check(&AttachAllow, bp, true))
-          AT_NOCOUNT("attach not allowed");
+          shallcount = false; /* attach not allowed */
         if (count_body_parts_check(&AttachExclude, bp, false))
-          AT_NOCOUNT("attach excluded");
+          shallcount = false; /* attach excluded */
       }
       else
       {
         if (!count_body_parts_check(&InlineAllow, bp, true))
-          AT_NOCOUNT("inline not allowed");
+          shallcount = false; /* inline not allowed */
         if (count_body_parts_check(&InlineExclude, bp, false))
-          AT_NOCOUNT("excluded");
+          shallcount = false; /* excluded */
       }
     }
 
index 4aeafb80c3cb88b0f903bdc9eb4519caa48c4499..f467640215c2131d41b5c4f95777ce1691847516 100644 (file)
--- a/pattern.c
+++ b/pattern.c
@@ -1914,8 +1914,6 @@ int mutt_pattern_func(int op, char *prompt)
                      MUTT_PROGRESS_MSG, ReadInc,
                      (op == MUTT_LIMIT) ? Context->msgcount : Context->vcount);
 
-#define THIS_BODY Context->hdrs[i]->content
-
   if (op == MUTT_LIMIT)
   {
     Context->vcount = 0;
@@ -1936,7 +1934,8 @@ int mutt_pattern_func(int op, char *prompt)
         Context->hdrs[i]->limited = true;
         Context->v2r[Context->vcount] = i;
         Context->vcount++;
-        Context->vsize += THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
+        struct Body *b = Context->hdrs[i]->content;
+        Context->vsize += b->length + b->offset - b->hdr_offset;
       }
     }
   }
@@ -1966,8 +1965,6 @@ int mutt_pattern_func(int op, char *prompt)
     }
   }
 
-#undef THIS_BODY
-
   mutt_clear_error();
 
   if (op == MUTT_LIMIT)
index feedb182d53ec1b190c1dc9f5705a2278d1895f4..eaf12042c64133b35329143b66be7f536026532d 100644 (file)
--- a/rfc2047.c
+++ b/rfc2047.c
@@ -573,19 +573,20 @@ static int rfc2047_encode(ICONV_CONST char *d, size_t dlen, int col, const char
       n = choose_block(t, n, col, icode, tocode, &encoder, &wlen);
     }
 
-/* Add to output buffer. */
-#define LINEBREAK "\n\t"
-    if (bufpos + wlen + strlen(LINEBREAK) > buflen)
+    /* Add to output buffer. */
+    const char *line_break = "\n\t";
+    const int lb_len = 2; /* strlen(line_break) */
+      
+    if ((bufpos + wlen + lb_len) > buflen)
     {
-      buflen = bufpos + wlen + strlen(LINEBREAK);
+      buflen = bufpos + wlen + lb_len;
       safe_realloc(&buf, buflen);
     }
     r = encode_block(buf + bufpos, t, n, icode, tocode, encoder);
     assert(r == wlen);
     bufpos += wlen;
-    memcpy(buf + bufpos, LINEBREAK, strlen(LINEBREAK));
-    bufpos += strlen(LINEBREAK);
-#undef LINEBREAK
+    memcpy(buf + bufpos, line_break, lb_len);
+    bufpos += lb_len;
 
     col = 1;
 
index 2764273cd682fe3a2a0297c721d3454463828035..da896aae43d575a3ddf46aab2febb7348f26d1a8 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -422,8 +422,10 @@ int mutt_write_mime_header(struct Body *a, FILE *f)
   return (ferror(f) ? -1 : 0);
 }
 
-#define write_as_text_part(a)                                                  \
-  (mutt_is_text_part(a) || ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp(a)))
+static bool write_as_text_part(struct Body *b)
+{
+  return (mutt_is_text_part(b) || ((WithCrypto & APPLICATION_PGP) && mutt_is_application_pgp(b)));
+}
 
 int mutt_write_mime_body(struct Body *a, FILE *f)
 {
diff --git a/sort.c b/sort.c
index b76a66ff0dbdf9848f3e5902a2c230ea99daf00d..96060dce6ce2530b3409ad6bb17cccadb207439a 100644 (file)
--- a/sort.c
+++ b/sort.c
 /* function to use as discriminator when normal sort method is equal */
 static sort_t *AuxSort = NULL;
 
-#define AUXSORT(code, a, b)                                                    \
-  if (!code && AuxSort && !option(OPT_AUX_SORT))                               \
-  {                                                                            \
-    set_option(OPT_AUX_SORT);                                                  \
-    code = AuxSort(a, b);                                                      \
-    unset_option(OPT_AUX_SORT);                                                \
-  }                                                                            \
-  if (!code)                                                                   \
-    code = (*((struct Header **) a))->index - (*((struct Header **) b))->index;
+static int perform_auxsort(int retval, const void *a, const void *b)
+{
+  /* If the items compared equal by the main sort
+   * and we're not already doing an 'aux' sort...  */
+  if ((retval == 0) && AuxSort && !option(OPT_AUX_SORT))
+  {
+    set_option(OPT_AUX_SORT);
+    retval = AuxSort(a, b);
+    unset_option(OPT_AUX_SORT);
+  }
+  /* If the items still match, use their index positions
+   * to maintain a stable sort order */
+  if (retval == 0)
+    retval = (*((struct Header **) a))->index - (*((struct Header **) b))->index;
+  return retval;
+}
 
 static int compare_score(const void *a, const void *b)
 {
   struct Header **pa = (struct Header **) a;
   struct Header **pb = (struct Header **) b;
   int result = (*pb)->score - (*pa)->score; /* note that this is reverse */
-  AUXSORT(result, a, b);
+  result = perform_auxsort(result, a, b);
   return (SORTCODE(result));
 }
 
@@ -70,7 +77,7 @@ static int compare_size(const void *a, const void *b)
   struct Header **pa = (struct Header **) a;
   struct Header **pb = (struct Header **) b;
   int result = (*pa)->content->length - (*pb)->content->length;
-  AUXSORT(result, a, b);
+  result = perform_auxsort(result, a, b);
   return (SORTCODE(result));
 }
 
@@ -79,7 +86,7 @@ static int compare_date_sent(const void *a, const void *b)
   struct Header **pa = (struct Header **) a;
   struct Header **pb = (struct Header **) b;
   int result = (*pa)->date_sent - (*pb)->date_sent;
-  AUXSORT(result, a, b);
+  result = perform_auxsort(result, a, b);
   return (SORTCODE(result));
 }
 
@@ -100,7 +107,7 @@ static int compare_subject(const void *a, const void *b)
     rc = 1;
   else
     rc = mutt_strcasecmp((*pa)->env->real_subj, (*pb)->env->real_subj);
-  AUXSORT(rc, a, b);
+  rc = perform_auxsort(rc, a, b);
   return (SORTCODE(rc));
 }
 
@@ -132,7 +139,7 @@ static int compare_to(const void *a, const void *b)
   strfcpy(fa, mutt_get_name((*ppa)->env->to), SHORT_STRING);
   fb = mutt_get_name((*ppb)->env->to);
   result = mutt_strncasecmp(fa, fb, SHORT_STRING);
-  AUXSORT(result, a, b);
+  result = perform_auxsort(result, a, b);
   return (SORTCODE(result));
 }
 
@@ -147,7 +154,7 @@ static int compare_from(const void *a, const void *b)
   strfcpy(fa, mutt_get_name((*ppa)->env->from), SHORT_STRING);
   fb = mutt_get_name((*ppb)->env->from);
   result = mutt_strncasecmp(fa, fb, SHORT_STRING);
-  AUXSORT(result, a, b);
+  result = perform_auxsort(result, a, b);
   return (SORTCODE(result));
 }
 
@@ -156,7 +163,7 @@ static int compare_date_received(const void *a, const void *b)
   struct Header **pa = (struct Header **) a;
   struct Header **pb = (struct Header **) b;
   int result = (*pa)->received - (*pb)->received;
-  AUXSORT(result, a, b);
+  result = perform_auxsort(result, a, b);
   return (SORTCODE(result));
 }
 
@@ -171,7 +178,7 @@ static int compare_order(const void *a, const void *b)
     anum_t na = NHDR(*ha)->article_num;
     anum_t nb = NHDR(*hb)->article_num;
     int result = na == nb ? 0 : na > nb ? 1 : -1;
-    AUXSORT(result, a, b);
+    result = perform_auxsort(result, a, b);
     return (SORTCODE(result));
   }
   else
@@ -203,7 +210,7 @@ static int compare_spam(const void *a, const void *b)
   /* Else, if neither has a spam attr, presume equality. Fall back on aux. */
   if (!ahas && !bhas)
   {
-    AUXSORT(result, a, b);
+    result = perform_auxsort(result, a, b);
     return (SORTCODE(result));
   }
 
@@ -229,7 +236,7 @@ static int compare_spam(const void *a, const void *b)
     result = strcmp(aptr, bptr);
     if (result == 0)
     {
-      AUXSORT(result, a, b);
+      result = perform_auxsort(result, a, b);
     }
   }
 
@@ -257,7 +264,7 @@ static int compare_label(const void *a, const void *b)
   /* If neither has a label, use aux sort. */
   if (!ahas && !bhas)
   {
-    AUXSORT(result, a, b);
+    result = perform_auxsort(result, a, b);
     return (SORTCODE(result));
   }
 
index e57e35138dbd68dfb000a0667774967c9af7c419..7a0fd560b39d2a07c0622dd6a95a07b46b30caf3 100644 (file)
--- a/thread.c
+++ b/thread.c
 #include "protos.h"
 #include "sort.h"
 
-#define VISIBLE(hdr, ctx)                                                      \
-  (hdr->virtual >= 0 || (hdr->collapsed && (!ctx->pattern || hdr->limited)))
+static bool is_visible(struct Header *hdr, struct Context *ctx)
+{
+  return (hdr->virtual >= 0 || (hdr->collapsed && (!ctx->pattern || hdr->limited)));
+}
 
 /**
  * is_descendant - Is one thread a descendant of another
@@ -75,7 +77,7 @@ static int need_display_subject(struct Context *ctx, struct Header *hdr)
   for (tmp = tree->prev; tmp; tmp = tmp->prev)
   {
     hdr = tmp->message;
-    if (hdr && VISIBLE(hdr, ctx))
+    if (hdr && is_visible(hdr, ctx))
     {
       if (hdr->subject_changed)
         return 1;
@@ -91,7 +93,7 @@ static int need_display_subject(struct Context *ctx, struct Header *hdr)
     hdr = tmp->message;
     if (hdr)
     {
-      if (VISIBLE(hdr, ctx))
+      if (is_visible(hdr, ctx))
         return 0;
       else if (hdr->subject_changed)
         return 1;
@@ -164,7 +166,7 @@ static void calculate_visibility(struct Context *ctx, int *max_depth)
     if (tree->message)
     {
       FREE(&tree->message->tree);
-      if (VISIBLE(tree->message, ctx))
+      if (is_visible(tree->message, ctx))
       {
         tree->deep = true;
         tree->visible = true;
@@ -1139,7 +1141,7 @@ int mutt_parent_message(struct Context *ctx, struct Header *hdr, int find_root)
     mutt_error(_("Parent message is not available."));
     return -1;
   }
-  if (!VISIBLE(parent, ctx))
+  if (!is_visible(parent, ctx))
   {
     if (find_root)
       mutt_error(_("Root message is not visible in this limited view."));