]> granicus.if.org Git - mutt/commitdiff
Refactor out mutt_is_quote_line().
authorKevin McCarthy <kevin@8t8.us>
Tue, 14 Aug 2018 01:56:37 +0000 (18:56 -0700)
committerKevin McCarthy <kevin@8t8.us>
Tue, 14 Aug 2018 02:03:31 +0000 (19:03 -0700)
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 ab3d4ade4088018e81e76efd2be4ecd7e6cf14d6..398e768c38230c4d968d0f1bf3186870916d533e 100644 (file)
--- 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;
index c112d888201ca23199c4a71358df8464d7eefc49..1b38563eb90aecf2e71968060da1c55064d018c7 100644 (file)
--- 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 *);