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
```
* 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)
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 */
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++;
}
}
- 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;
}
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)
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()
*
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;
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)))
{
{
/* 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)))
{
(unsigned long) hfi, flags);
return src;
-#undef THREAD_NEW
-#undef THREAD_OLD
}
void _mutt_make_string(char *dest, size_t destlen, const char *s,
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)
{
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 */
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 */
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 */
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 */
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 */
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 */
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 */
{
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
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)
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 };
/* 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++;
*/
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);
}
return 0;
}
-#undef PREV
-
/**
* mbox_open_mailbox - open a mbox or mmdf style mailbox
*/
}
}
-#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
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 &&
{
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)
mutt_free_header(&ctx->hdrs[i]);
}
}
-#undef this_body
ctx->msgcount = j;
}
#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
* 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
*/
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;
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",
/* 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)
{
/* 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.
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 */
}
}
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;
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;
}
}
}
}
}
-#undef THIS_BODY
-
mutt_clear_error();
if (op == MUTT_LIMIT)
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;
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)
{
/* 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));
}
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));
}
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));
}
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));
}
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));
}
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));
}
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));
}
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
/* 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));
}
result = strcmp(aptr, bptr);
if (result == 0)
{
- AUXSORT(result, a, b);
+ result = perform_auxsort(result, a, 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));
}
#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
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;
hdr = tmp->message;
if (hdr)
{
- if (VISIBLE(hdr, ctx))
+ if (is_visible(hdr, ctx))
return 0;
else if (hdr->subject_changed)
return 1;
if (tree->message)
{
FREE(&tree->message->tree);
- if (VISIBLE(tree->message, ctx))
+ if (is_visible(tree->message, ctx))
{
tree->deep = true;
tree->visible = true;
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."));