]> granicus.if.org Git - neomutt/commitdiff
Refactor out mutt_is_quote_line()
authorKevin McCarthy <kevin@8t8.us>
Tue, 14 Aug 2018 01:56:37 +0000 (18:56 -0700)
committerRichard Russon <rich@flatcap.org>
Sat, 1 Sep 2018 17:06:08 +0000 (18:06 +0100)
This makes resolve_types() a tiny bit clearer, and will be usable by
$abort_noattach.

pager.c
protos.h

diff --git a/pager.c b/pager.c
index 9c1d360dd8f66ec7a7fddce3f88a2d6a9c2b0886..36edda1147cb7933de57856dfdfb51a9053b9167 100644 (file)
--- 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;
index dcff4cb8697ae3449c43a69da7667dc8e6a60a65..d3514d7a2b3a7f55a06f87908a7b879d03ef902b 100644 (file)
--- 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);