From: Richard Russon Date: Sat, 26 Mar 2016 03:44:41 +0000 (+0000) Subject: tidy code X-Git-Tag: neomutt-20160404~8^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=df6d5a2aef0ba0dd9be12a722a8ff81f47bd7452;p=neomutt tidy code --- diff --git a/curs_main.c b/curs_main.c index 92ac49efb..c709d4bce 100644 --- a/curs_main.c +++ b/curs_main.c @@ -910,8 +910,8 @@ int mutt_index_menu (void) CHECK_IN_MAILBOX; menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? CURHDR->index : -1; - if ((op == OP_LIMIT_CURRENT_THREAD && mutt_limit_current_thread(CURHDR)) - || (op == OP_MAIN_LIMIT && mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)) + if (((op == OP_LIMIT_CURRENT_THREAD) && mutt_limit_current_thread(CURHDR)) + || ((op == OP_MAIN_LIMIT) && (mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0))) { if (menu->oldcurrent >= 0) { diff --git a/pattern.c b/pattern.c index c6abc1dca..87305886a 100644 --- a/pattern.c +++ b/pattern.c @@ -1294,49 +1294,72 @@ void mutt_check_simple (char *s, size_t len, const char *simple) } } -static THREAD* top_of_thread(HEADER *h) +/** + * top_of_thread - Find the first email in the current thread + * @h: Header of current email + * + * Returns: + * THREAD*: success, email found + * NULL: on error + */ +static THREAD * +top_of_thread (HEADER *h) { - THREAD *t = h->thread; + THREAD *t; - while (t && t->parent) t = t->parent; - return t; -} + if (!h) + return NULL; -int mutt_limit_current_thread (HEADER *h) -{ - int i; - THREAD *me; + t = h->thread; - me = top_of_thread(h); + while (t && t->parent) + t = t->parent; - if (!me) { - /* NOP */ - return 0; - } - - Context->vcount = 0; - Context->vsize = 0; - Context->collapsed = 0; + return t; +} - for (i = 0; i < Context->msgcount; i++) - { - Context->hdrs[i]->virtual = -1; - Context->hdrs[i]->limited = 0; - Context->hdrs[i]->collapsed = 0; - Context->hdrs[i]->num_hidden = 0; - if (top_of_thread(Context->hdrs[i]) == me) - { - BODY *body = Context->hdrs[i]->content; - - Context->hdrs[i]->virtual = Context->vcount; - Context->hdrs[i]->limited = 1; - Context->v2r[Context->vcount] = i; - Context->vcount++; - Context->vsize += body->length + body->offset - - body->hdr_offset; - } - } - return 1; +/** + * mutt_limit_current_thread - Limit the email view to the current thread + * @h: Header of current email + * + * Returns: + * 1: Success + * 0: Failure + */ +int +mutt_limit_current_thread (HEADER *h) +{ + int i; + THREAD *me; + + if (!h) + return 0; + + me = top_of_thread (h); + if (!me) + return 0; + + Context->vcount = 0; + Context->vsize = 0; + Context->collapsed = 0; + + for (i = 0; i < Context->msgcount; i++) { + Context->hdrs[i]->virtual = -1; + Context->hdrs[i]->limited = 0; + Context->hdrs[i]->collapsed = 0; + Context->hdrs[i]->num_hidden = 0; + + if (top_of_thread (Context->hdrs[i]) == me) { + BODY *body = Context->hdrs[i]->content; + + Context->hdrs[i]->virtual = Context->vcount; + Context->hdrs[i]->limited = 1; + Context->v2r[Context->vcount] = i; + Context->vcount++; + Context->vsize += (body->length + body->offset - body->hdr_offset); + } + } + return 1; } int mutt_pattern_func (int op, char *prompt)