<<< Date Index >>>     <<< Thread Index >>>

parent_match patch (was: [PATCH] pattern groups)



On 2006-01-10 17:21:49 +0100, Vincent Lefevre wrote:
> On 2006-01-09 19:55:10 +0100, Thomas Roessler wrote:
> > On 2006-01-09 14:47:00 +0100, Thomas Roessler wrote:
> > 
> > > To match against a pattern group, use '$' instead of '~'
> > > (better character suggestions would be much appreciated.)
> > 
> > The attached version uses '%' instead.
> 
> This is annoying because '%' was already used by the parent_match patch.
> Now, the special character for the parent_match patch could be changed,
> e.g. to '<'.

If you're interested, I've updated Aaron Schrab's parent_match patch
for the CVS version (thus now using the '<' modifier). Attached.

-- 
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / SPACES project at LORIA
diff -Naurd mutt-cvs/PATCHES mutt-new/PATCHES
--- mutt-cvs/PATCHES    2002-12-09 17:44:54.000000000 +0000
+++ mutt-new/PATCHES    2006-01-10 16:27:50.000000000 +0000
@@ -0,0 +1 @@
+patch-1.5.11.ats.parent_match.vl.1
diff -Naurd mutt-cvs/doc/manual.xml.head mutt-new/doc/manual.xml.head
--- mutt-cvs/doc/manual.xml.head        2005-10-06 22:08:25.000000000 +0000
+++ mutt-new/doc/manual.xml.head        2006-01-10 16:23:06.000000000 +0000
@@ -3343,7 +3343,7 @@
 </para>
 
 <sect3>
-<title>Pattern Modifier</title>
+<title>Pattern Modifiers</title>
 
 <para>
 Note that patterns matching 'lists' of addresses (notably c,C,p,P and t)
@@ -3361,6 +3361,12 @@
 
 </para>
 
+<para>
+Normally patterns are compared with the message that is being created.
+If you want a pattern to match against a message that you are replying to,
+you can prefix the pattern with &lt;.
+</para>
+
 </sect3>
 
 <sect3>
diff -Naurd mutt-cvs/mutt.h mutt-new/mutt.h
--- mutt-cvs/mutt.h     2006-01-10 04:39:32.000000000 +0000
+++ mutt-new/mutt.h     2006-01-10 16:23:46.000000000 +0000
@@ -818,6 +818,7 @@
   unsigned int alladdr : 1;
   unsigned int stringmatch : 1;
   unsigned int groupmatch : 1;
+  unsigned int parent : 1;
   int min;
   int max;
   struct pattern_t *next;
diff -Naurd mutt-cvs/pattern.c mutt-new/pattern.c
--- mutt-cvs/pattern.c  2006-01-10 04:39:32.000000000 +0000
+++ mutt-new/pattern.c  2006-01-10 16:26:25.000000000 +0000
@@ -769,6 +769,7 @@
   pattern_t *last = NULL;
   int not = 0;
   int alladdr = 0;
+  int parent = 0;
   int or = 0;
   int implicit = 1;    /* used to detect logical AND operator */
   struct pattern_flags *entry;
@@ -789,6 +790,10 @@
        ps.dptr++;
        alladdr = !alladdr;
        break;
+      case '<':
+       ps.dptr++;
+       parent = !parent;
+       break;
       case '!':
        ps.dptr++;
        not = !not;
@@ -818,6 +823,7 @@
        implicit = 0;
        not = 0;
        alladdr = 0;
+       parent = 0;
        break;
       case '%':
       case '=':
@@ -838,8 +844,10 @@
        tmp->alladdr = alladdr;
         tmp->stringmatch = (*ps.dptr == '=') ? 1 : 0;
         tmp->groupmatch  = (*ps.dptr == '%') ? 1 : 0;
+       tmp->parent = parent;
        not = 0;
        alladdr = 0;
+       parent = 0;
 
        if (last)
          last->next = tmp;
@@ -905,8 +913,10 @@
        last = tmp;
        tmp->not ^= not;
        tmp->alladdr |= alladdr;
+       tmp->parent |= parent;
        not = 0;
        alladdr = 0;
+       parent = 0;
        ps.dptr = p + 1; /* restore location */
        break;
       default:
@@ -1024,12 +1034,24 @@
 int
 mutt_pattern_exec (struct pattern_t *pat, pattern_exec_flag flags, CONTEXT 
*ctx, HEADER *h)
 {
+  HEADER *cur_head;
+
+  cur_head = h;
+
+  if (pat->parent)
+  {
+    if (h->thread && h->thread->parent && h->thread->parent->message )
+      h = h->thread->parent->message;
+    else
+      return pat->not;
+  }
+ 
   switch (pat->op)
   {
     case M_AND:
-      return (pat->not ^ (perform_and (pat->child, flags, ctx, h) > 0));
+      return (pat->not ^ (perform_and (pat->child, flags, ctx, cur_head) > 0));
     case M_OR:
-      return (pat->not ^ (perform_or (pat->child, flags, ctx, h) > 0));
+      return (pat->not ^ (perform_or (pat->child, flags, ctx, cur_head) > 0));
     case M_ALL:
       return (!pat->not);
     case M_EXPIRED:
diff -Naurd mutt-cvs/send.c mutt-new/send.c
--- mutt-cvs/send.c     2006-01-10 04:39:33.000000000 +0000
+++ mutt-new/send.c     2006-01-10 16:27:20.000000000 +0000
@@ -1172,6 +1172,13 @@
     }
   }
 
+  /* set parent, for use by < flag in send-hooks */
+  if (cur && !(flags & (SENDPOSTPONED|SENDRESEND)))
+  {
+    msg->thread = safe_calloc (1, sizeof (THREAD));
+    msg->thread->parent = cur->thread;
+  }
+
   /* this is handled here so that the user can match ~f in send-hook */
   if (cur && option (OPTREVNAME) && !(flags & (SENDPOSTPONED|SENDRESEND)))
   {