exit SPAM_LIST, just extend rx_t with the needed informations.
[apps/madmutt.git] / lib-lib / rx.c
index d0a3942..8604ad5 100644 (file)
@@ -38,11 +38,32 @@ rx_t *rx_compile(const char *s, int flags)
     return pp;
 }
 
+void rx_set_template(rx_t *rx, const char *tpl)
+{
+    const char *p = tpl;
+
+    m_strreplace(&rx->template, tpl);
+    rx->nmatch = 0;
+
+    while ((p = strchr(p, '%'))) {
+        if (isdigit(*++p)) {
+            int n = strtol(p, (char **)&p, 10);
+            rx->nmatch = MAX(n, rx->nmatch);
+        } else {
+            if (*p == '%')
+                p++;
+        }
+    }
+
+    rx->nmatch++;     /* match 0 is always the whole expr */
+}
+
 void rx_delete(rx_t **p)
 {
     p_delete(&(*p)->pattern);
     regfree((*p)->rx);
     p_delete(&(*p)->rx);
+    p_delete(&(*p)->template);
     p_delete(p);
 }