From: Kevin McCarthy Date: Tue, 14 Aug 2018 01:56:37 +0000 (-0700) Subject: Refactor out mutt_is_quote_line(). X-Git-Tag: mutt-1-11-rel~91 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a1cf2012b0d65df64d2b93c1d1d30990609268f8;p=mutt 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 ab3d4ade..398e768c 100644 --- a/pager.c +++ b/pager.c @@ -707,13 +707,51 @@ static int brailleCol = -1; static int check_attachment_marker (char *); +/* Checks if buf matches the QuoteRegexp and doesn't match Smileys. + * pmatch, if non-null, is populated with the regexec match against + * QuoteRegexp. 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 (QuoteRegexp.rx && + regexec ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) + { + if (Smileys.rx && + regexec ((regex_t *) Smileys.rx, 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 ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) + is_quote = 1; + + buf[smatch[0].rm_so] = c; + } + } + else + is_quote = 1; + } + + return is_quote; +} + static void resolve_types (char *buf, char *raw, struct line_t *lineInfo, int n, int last, struct q_class_t **QuoteList, int *q_level, int *force_redraw, int q_classify) { COLOR_LINE *color_line; - regmatch_t pmatch[1], smatch[1]; + regmatch_t pmatch[1]; int found, offset, null_rx, i; if (n == 0 || ISHEADER (lineInfo[n-1].type)) @@ -807,43 +845,13 @@ resolve_types (char *buf, char *raw, struct line_t *lineInfo, int n, int last, } else if (check_sig (buf, lineInfo, n - 1) == 0) lineInfo[n].type = MT_COLOR_SIGNATURE; - else if (regexec ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) + else if (mutt_is_quote_line (buf, pmatch)) { - if (regexec ((regex_t *) Smileys.rx, 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 ((regex_t *) QuoteRegexp.rx, buf, 1, pmatch, 0) == 0) - { - if (q_classify && lineInfo[n].quote == NULL) - lineInfo[n].quote = classify_quote (QuoteList, - buf + pmatch[0].rm_so, - pmatch[0].rm_eo - pmatch[0].rm_so, - force_redraw, q_level); - lineInfo[n].type = MT_COLOR_QUOTED; - } - else - lineInfo[n].type = MT_COLOR_NORMAL; - - buf[smatch[0].rm_so] = c; - } - else - lineInfo[n].type = MT_COLOR_NORMAL; - } - else - { - if (q_classify && lineInfo[n].quote == NULL) - lineInfo[n].quote = classify_quote (QuoteList, buf + pmatch[0].rm_so, - pmatch[0].rm_eo - pmatch[0].rm_so, - force_redraw, q_level); - lineInfo[n].type = MT_COLOR_QUOTED; - } + if (q_classify && lineInfo[n].quote == NULL) + lineInfo[n].quote = classify_quote (QuoteList, buf + pmatch[0].rm_so, + pmatch[0].rm_eo - pmatch[0].rm_so, + force_redraw, q_level); + lineInfo[n].type = MT_COLOR_QUOTED; } else lineInfo[n].type = MT_COLOR_NORMAL; diff --git a/protos.h b/protos.h index c112d888..1b38563e 100644 --- a/protos.h +++ b/protos.h @@ -336,6 +336,7 @@ int mutt_is_mail_list (ADDRESS *); int mutt_is_message_type(int, const char *); int mutt_is_list_cc (int, ADDRESS *, ADDRESS *); int mutt_is_list_recipient (int, ADDRESS *, ADDRESS *); +int mutt_is_quote_line (char *, regmatch_t *); int mutt_is_subscribed_list (ADDRESS *); int mutt_is_text_part (BODY *); int mutt_is_valid_mailbox (const char *);