From: Kevin McCarthy Date: Tue, 14 Aug 2018 01:56:37 +0000 (-0700) Subject: Refactor out mutt_is_quote_line() X-Git-Tag: 2019-10-25~671^2~9 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1054c950d4442423b05d19d3da6d9c684b4ceb22;p=neomutt Refactor out mutt_is_quote_line() This makes resolve_types() a tiny bit clearer, and will be usable by $abort_noattach. --- diff --git a/pager.c b/pager.c index 9c1d360dd..36edda114 100644 --- a/pager.c +++ b/pager.c @@ -823,6 +823,41 @@ static int check_attachment_marker(char *p) return (int) (*p - *q); } +/* Checks if buf matches the QuoteRegex and doesn't match Smileys. + * pmatch, if non-null, is populated with the regexec match against + * QuoteRegex. This is used by the pager for calling classify_quote. + */ +int mutt_is_quote_line(char *buf, regmatch_t *pmatch) +{ + int is_quote = 0; + regmatch_t pmatch_internal[1], smatch[1]; + char c; + + if (!pmatch) + pmatch = pmatch_internal; + + if (QuoteRegex && QuoteRegex->regex && regexec(QuoteRegex->regex, buf, 1, pmatch, 0) == 0) + { + if (Smileys && Smileys->regex && regexec(Smileys->regex, buf, 1, smatch, 0) == 0) + { + if (smatch[0].rm_so > 0) + { + c = buf[smatch[0].rm_so]; + buf[smatch[0].rm_so] = 0; + + if (regexec(QuoteRegex->regex, buf, 1, pmatch, 0) == 0) + is_quote = 1; + + buf[smatch[0].rm_so] = c; + } + } + else + is_quote = 1; + } + + return is_quote; +} + /** * resolve_types - Determine the style for a line of text * @param buf Formatted text @@ -840,7 +875,7 @@ static void resolve_types(char *buf, char *raw, struct Line *line_info, int n, bool *force_redraw, bool q_classify) { struct ColorLine *color_line = NULL; - regmatch_t pmatch[1], smatch[1]; + regmatch_t pmatch[1]; bool found; bool null_rx; int offset, i = 0; @@ -929,47 +964,16 @@ static void resolve_types(char *buf, char *raw, struct Line *line_info, int n, } else if (check_sig(buf, line_info, n - 1) == 0) line_info[n].type = MT_COLOR_SIGNATURE; - else if (QuoteRegex && QuoteRegex->regex && - regexec(QuoteRegex->regex, buf, 1, pmatch, 0) == 0) - { - if (Smileys && Smileys->regex && (regexec(Smileys->regex, buf, 1, smatch, 0) == 0)) - { - if (smatch[0].rm_so > 0) - { - char c; - - /* hack to avoid making an extra copy of buf */ - c = buf[smatch[0].rm_so]; - buf[smatch[0].rm_so] = 0; - - if (regexec(QuoteRegex->regex, buf, 1, pmatch, 0) == 0) - { - if (q_classify && !line_info[n].quote) - { - line_info[n].quote = classify_quote(quote_list, buf + pmatch[0].rm_so, - pmatch[0].rm_eo - pmatch[0].rm_so, - force_redraw, q_level); - } - line_info[n].type = MT_COLOR_QUOTED; - } - else - line_info[n].type = MT_COLOR_NORMAL; + else if (mutt_is_quote_line(buf, pmatch)) - buf[smatch[0].rm_so] = c; - } - else - line_info[n].type = MT_COLOR_NORMAL; - } - else + { + if (q_classify && line_info[n].quote == NULL) { - if (q_classify && !line_info[n].quote) - { - line_info[n].quote = classify_quote(quote_list, buf + pmatch[0].rm_so, - pmatch[0].rm_eo - pmatch[0].rm_so, - force_redraw, q_level); - } - line_info[n].type = MT_COLOR_QUOTED; + line_info[n].quote = classify_quote(quote_list, buf + pmatch[0].rm_so, + pmatch[0].rm_eo - pmatch[0].rm_so, + force_redraw, q_level); } + line_info[n].type = MT_COLOR_QUOTED; } else line_info[n].type = MT_COLOR_NORMAL; diff --git a/protos.h b/protos.h index dcff4cb86..d3514d7a2 100644 --- a/protos.h +++ b/protos.h @@ -68,6 +68,7 @@ int mutt_num_postponed(bool force); int mutt_thread_set_flag(struct Header *hdr, int flag, int bf, int subthread); void mutt_update_num_postponed(void); int url_parse_mailto(struct Envelope *e, char **body, const char *src); +int mutt_is_quote_line(char *buf, regmatch_t *pmatch); #ifndef HAVE_WCSCASECMP int wcscasecmp(const wchar_t *a, const wchar_t *b);