Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Tue, 22 Mar 2005 22:05:38 +0000 (22:05 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Tue, 22 Mar 2005 22:05:38 +0000 (22:05 +0000)
- kick RX_LIST in favour of list2_t
- move internal regex abstraction to lib

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@226 e385b8ad-14ed-0310-8656-cc95a2468c6d

19 files changed:
Makefile.am
alias.c
globals.h
hdrline.c
hook.c
init.c
lib/Makefile.am
lib/list.c
lib/rx.c [new file with mode: 0644]
lib/rx.h [new file with mode: 0644]
mutt.h
mutt_menu.h
mutt_regex.h [deleted file]
mutt_ssl_gnutls.c
muttlib.c
pager.c
parse.c
protos.h
remailer.c

index 45bfa78..8a17ce3 100644 (file)
@@ -81,7 +81,7 @@ EXTRA_DIST = COPYRIGHT GPL OPS OPS.PGP OPS.CRYPT OPS.SMIME TODO \
        attach.h buffy.h charset.h copy.h crypthash.h dotlock.h functions.h gen_defs \
        globals.h hash.h history.h init.h keymap.h mutt_crypt.h \
        mailbox.h mapping.h md5.h mime.h mutt.h mutt_curses.h mutt_menu.h \
        attach.h buffy.h charset.h copy.h crypthash.h dotlock.h functions.h gen_defs \
        globals.h hash.h history.h init.h keymap.h mutt_crypt.h \
        mailbox.h mapping.h md5.h mime.h mutt.h mutt_curses.h mutt_menu.h \
-       mutt_regex.h mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \
+       mutt_sasl.h mutt_socket.h mutt_ssl.h mutt_tunnel.h \
        mx.h pager.h pgp.h protos.h reldate.h rfc1524.h rfc2047.h \
        rfc2231.h rfc822.h sha1.h sort.h mime.types VERSION prepare \
        _regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \
        mx.h pager.h pgp.h protos.h reldate.h rfc1524.h rfc2047.h \
        rfc2231.h rfc822.h sha1.h sort.h mime.types VERSION prepare \
        _regex.h OPS.MIX README.SECURITY remailer.c remailer.h browser.h \
diff --git a/alias.c b/alias.c
index 877add8..f092a8c 100644 (file)
--- a/alias.c
+++ b/alias.c
 #endif
 
 #include "mutt.h"
 #endif
 
 #include "mutt.h"
-#include "mutt_regex.h"
 #include "mutt_curses.h"
 #include "mutt_idna.h"
 
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
 #include "mutt_curses.h"
 #include "mutt_idna.h"
 
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
+#include "lib/rx.h"
 
 #include <string.h>
 #include <ctype.h>
 
 #include <string.h>
 #include <ctype.h>
@@ -527,11 +527,11 @@ int mutt_addr_is_user (ADDRESS * addr)
     return 1;
   }
 
     return 1;
   }
 
-  if (mutt_match_rx_list (addr->mailbox, Alternates)) {
+  if (rx_list_match (Alternates, addr->mailbox)) {
     dprint (5,
             (debugfile, "mail_addr_is_user: yes, %s matched by alternates.\n",
              addr->mailbox));
     dprint (5,
             (debugfile, "mail_addr_is_user: yes, %s matched by alternates.\n",
              addr->mailbox));
-    if (mutt_match_rx_list (addr->mailbox, UnAlternates))
+    if (rx_list_match (UnAlternates, addr->mailbox))
       dprint (5,
               (debugfile,
                "mail_addr_is_user: but, %s matched by unalternates.\n",
       dprint (5,
               (debugfile,
                "mail_addr_is_user: but, %s matched by unalternates.\n",
index b7ba1b8..d6819e3 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -10,6 +10,8 @@
 #define _GLOBALS_H
 
 #include "lib/str.h"
 #define _GLOBALS_H
 
 #include "lib/str.h"
+#include "lib/list.h"
+#include "lib/rx.h"
 
 WHERE void (*mutt_error) (const char *, ...);
 WHERE void (*mutt_message) (const char *, ...);
 
 WHERE void (*mutt_error) (const char *, ...);
 WHERE void (*mutt_message) (const char *, ...);
@@ -76,6 +78,13 @@ WHERE char *MhUnseen;
 WHERE char *MsgFmt;
 WHERE char *MsgIdFormat;
 
 WHERE char *MsgFmt;
 WHERE char *MsgIdFormat;
 
+WHERE rx_t Mask;
+WHERE rx_t QuoteRegexp;
+WHERE rx_t ReplyRegexp;
+WHERE rx_t Smileys;
+WHERE rx_t GecosMask;
+WHERE rx_t StripWasRegexp;
+
 #ifdef USE_SOCKET
 WHERE char *Preconnect INITVAL (NULL);
 WHERE char *Tunnel INITVAL (NULL);
 #ifdef USE_SOCKET
 WHERE char *Preconnect INITVAL (NULL);
 WHERE char *Tunnel INITVAL (NULL);
@@ -167,14 +176,14 @@ WHERE LIST *Ignore INITVAL (0);
 WHERE LIST *MimeLookupList INITVAL (0);
 WHERE LIST *UnIgnore INITVAL (0);
 
 WHERE LIST *MimeLookupList INITVAL (0);
 WHERE LIST *UnIgnore INITVAL (0);
 
-WHERE RX_LIST *Alternates INITVAL (0);
-WHERE RX_LIST *UnAlternates INITVAL (0);
-WHERE RX_LIST *MailLists INITVAL (0);
-WHERE RX_LIST *UnMailLists INITVAL (0);
-WHERE RX_LIST *SubscribedLists INITVAL (0);
-WHERE RX_LIST *UnSubscribedLists INITVAL (0);
+WHERE list2_t *Alternates INITVAL (0);
+WHERE list2_t *UnAlternates INITVAL (0);
+WHERE list2_t *MailLists INITVAL (0);
+WHERE list2_t *UnMailLists INITVAL (0);
+WHERE list2_t *SubscribedLists INITVAL (0);
+WHERE list2_t *UnSubscribedLists INITVAL (0);
 WHERE SPAM_LIST *SpamList INITVAL (0);
 WHERE SPAM_LIST *SpamList INITVAL (0);
-WHERE RX_LIST *NoSpamList INITVAL (0);
+WHERE list2_t *NoSpamList INITVAL (0);
 
 /* bit vector for boolean variables */
 #ifdef MAIN_C
 
 /* bit vector for boolean variables */
 #ifdef MAIN_C
@@ -234,7 +243,7 @@ WHERE ALIAS *Aliases INITVAL (0);
 WHERE LIST *UserHeader INITVAL (0);
 
 /*-- formerly in pgp.h --*/
 WHERE LIST *UserHeader INITVAL (0);
 
 /*-- formerly in pgp.h --*/
-WHERE REGEXP PgpGoodSign;
+WHERE rx_t PgpGoodSign;
 WHERE char *PgpSignAs;
 WHERE short PgpTimeout;
 WHERE char *PgpEntryFormat;
 WHERE char *PgpSignAs;
 WHERE short PgpTimeout;
 WHERE char *PgpEntryFormat;
@@ -297,9 +306,10 @@ extern const char *Months[];
 #endif
 
 #ifdef MAIN_C
 #endif
 
 #ifdef MAIN_C
-/* so that global vars get included */
+/* so that global vars get included
+ * FIXME WTF IS THIS?!?!???!?!??!?!??
+ */
 #include "mx.h"
 #include "mx.h"
-#include "mutt_regex.h"
 #include "buffy.h"
 #include "sort.h"
 #include "mutt_crypt.h"
 #include "buffy.h"
 #include "sort.h"
 #include "mutt_crypt.h"
index 5d84cb4..2ac88f1 100644 (file)
--- a/hdrline.c
+++ b/hdrline.c
@@ -19,6 +19,7 @@
 #include "mutt_idna.h"
 
 #include "lib/str.h"
 #include "mutt_idna.h"
 
 #include "lib/str.h"
+#include "lib/rx.h"
 
 #include <ctype.h>
 #include <stdlib.h>
 
 #include <ctype.h>
 #include <stdlib.h>
 
 int mutt_is_mail_list (ADDRESS * addr)
 {
 
 int mutt_is_mail_list (ADDRESS * addr)
 {
-  if (!mutt_match_rx_list (addr->mailbox, UnMailLists))
-    return mutt_match_rx_list (addr->mailbox, MailLists);
+  if (!rx_list_match (UnMailLists, addr->mailbox))
+    return rx_list_match (MailLists, addr->mailbox);
   return 0;
 }
 
 int mutt_is_subscribed_list (ADDRESS * addr)
 {
   return 0;
 }
 
 int mutt_is_subscribed_list (ADDRESS * addr)
 {
-  if (!mutt_match_rx_list (addr->mailbox, UnMailLists)
-      && !mutt_match_rx_list (addr->mailbox, UnSubscribedLists))
-    return mutt_match_rx_list (addr->mailbox, SubscribedLists);
+  if (!rx_list_match (UnMailLists, addr->mailbox)
+      && !rx_list_match (UnSubscribedLists, addr->mailbox))
+    return rx_list_match (SubscribedLists, addr->mailbox);
   return 0;
 }
 
   return 0;
 }
 
diff --git a/hook.c b/hook.c
index 6c4c83b..68a662e 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -22,6 +22,7 @@
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
+#include "lib/rx.h"
 
 #include <limits.h>
 #include <string.h>
 
 #include <limits.h>
 #include <string.h>
@@ -31,7 +32,7 @@
 
 typedef struct hook {
   int type;                     /* hook type */
 
 typedef struct hook {
   int type;                     /* hook type */
-  REGEXP rx;                    /* regular expression */
+  rx_t rx;                      /* regular expression */
   char *command;                /* filename, command or pattern to execute */
   pattern_t *pattern;           /* used for fcc,save,send-hook */
   struct hook *next;
   char *command;                /* filename, command or pattern to execute */
   pattern_t *pattern;           /* used for fcc,save,send-hook */
   struct hook *next;
diff --git a/init.c b/init.c
index a7e5cb9..35577a4 100644 (file)
--- a/init.c
+++ b/init.c
@@ -14,7 +14,6 @@
 #include "mutt.h"
 #include "mapping.h"
 #include "mutt_curses.h"
 #include "mutt.h"
 #include "mapping.h"
 #include "mutt_curses.h"
-#include "mutt_regex.h"
 #include "history.h"
 #include "keymap.h"
 #include "mbyte.h"
 #include "history.h"
 #include "keymap.h"
 #include "mbyte.h"
@@ -33,6 +32,7 @@
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
+#include "lib/rx.h"
 
 #include <ctype.h>
 #include <stdlib.h>
 
 #include <ctype.h>
 #include <stdlib.h>
@@ -301,44 +301,25 @@ static void add_to_list (LIST ** list, const char *str)
   }
 }
 
   }
 }
 
-static int add_to_rx_list (RX_LIST ** list, const char *s, int flags,
+static int add_to_rx_list (rx_t ** list, const char *s, int flags,
                            BUFFER * err)
 {
                            BUFFER * err)
 {
-  RX_LIST *t, *last = NULL;
-  REGEXP *rx;
+  rx_t* rx;
+  int i = 0;
 
   if (!s || !*s)
     return 0;
 
 
   if (!s || !*s)
     return 0;
 
-  if (!(rx = mutt_compile_regexp (s, flags))) {
+  if (!(rx = rx_compile (s, flags))) {
     snprintf (err->data, err->dsize, "Bad regexp: %s\n", s);
     return -1;
   }
 
     snprintf (err->data, err->dsize, "Bad regexp: %s\n", s);
     return -1;
   }
 
-  /* check to make sure the item is not already on this list */
-  for (last = *list; last; last = last->next) {
-    if (ascii_strcasecmp (rx->pattern, last->rx->pattern) == 0) {
-      /* already on the list, so just ignore it */
-      last = NULL;
-      break;
-    }
-    if (!last->next)
-      break;
-  }
-
-  if (!*list || last) {
-    t = mutt_new_rx_list ();
-    t->rx = rx;
-    if (last) {
-      last->next = t;
-      last = last->next;
-    }
-    else
-      *list = last = t;
-  }
-  else                          /* duplicate */
-    mutt_free_regexp (&rx);
-
+  i = rx_lookup ((*list), rx->pattern);
+  if (i >= 0)
+    rx_free (&rx);
+  else
+    list_push_back (list, rx);
   return 0;
 }
 
   return 0;
 }
 
@@ -346,14 +327,14 @@ static int add_to_spam_list (SPAM_LIST ** list, const char *pat,
                              const char *templ, BUFFER * err)
 {
   SPAM_LIST *t = NULL, *last = NULL;
                              const char *templ, BUFFER * err)
 {
   SPAM_LIST *t = NULL, *last = NULL;
-  REGEXP *rx;
+  rx_t* rx;
   int n;
   const char *p;
 
   if (!pat || !*pat || !templ)
     return 0;
 
   int n;
   const char *p;
 
   if (!pat || !*pat || !templ)
     return 0;
 
-  if (!(rx = mutt_compile_regexp (pat, REG_ICASE))) {
+  if (!(rx = rx_compile (pat, REG_ICASE))) {
     snprintf (err->data, err->dsize, _("Bad regexp: %s"), pat);
     return -1;
   }
     snprintf (err->data, err->dsize, _("Bad regexp: %s"), pat);
     return -1;
   }
@@ -417,7 +398,7 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat)
   spam = *list;
   if (spam->rx && !mutt_strcmp (spam->rx->pattern, pat)) {
     *list = spam->next;
   spam = *list;
   if (spam->rx && !mutt_strcmp (spam->rx->pattern, pat)) {
     *list = spam->next;
-    mutt_free_regexp (&spam->rx);
+    rx_free (&spam->rx);
     FREE(&spam->template);
     FREE(&spam);
     return 1;
     FREE(&spam->template);
     FREE(&spam);
     return 1;
@@ -427,7 +408,7 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat)
   for (spam = prev->next; spam;) {
     if (!mutt_strcmp (spam->rx->pattern, pat)) {
       prev->next = spam->next;
   for (spam = prev->next; spam;) {
     if (!mutt_strcmp (spam->rx->pattern, pat)) {
       prev->next = spam->next;
-      mutt_free_regexp (&spam->rx);
+      rx_free (&spam->rx);
       FREE(spam->template);
       FREE(spam);
       spam = prev->next;
       FREE(spam->template);
       FREE(spam);
       spam = prev->next;
@@ -467,35 +448,23 @@ static void remove_from_list (LIST ** l, const char *str)
   }
 }
 
   }
 }
 
-static int remove_from_rx_list (RX_LIST ** l, const char *str)
+static int remove_from_rx_list (list2_t** l, const char *str)
 {
 {
-  RX_LIST *p, *last = NULL;
-  int rv = -1;
+  int i = 0;
 
   if (mutt_strcmp ("*", str) == 0) {
 
   if (mutt_strcmp ("*", str) == 0) {
-    mutt_free_rx_list (l);      /* ``unCMD *'' means delete all current entries */
-    rv = 0;
+    list_del (l, rx_free);
+    return (0);
   }
   else {
   }
   else {
-    p = *l;
-    last = NULL;
-    while (p) {
-      if (ascii_strcasecmp (str, p->rx->pattern) == 0) {
-        mutt_free_regexp (&p->rx);
-        if (last)
-          last->next = p->next;
-        else
-          (*l) = p->next;
-        FREE (&p);
-        rv = 0;
-      }
-      else {
-        last = p;
-        p = p->next;
-      }
+    i = rx_lookup ((*l), str);
+    if (i >= 0) {
+      rx_t* r = list_pop_idx ((*l), i);
+      rx_free (&r);
+      return (0);
     }
   }
     }
   }
-  return (rv);
+  return (-1);
 }
 
 static int parse_ifdef (BUFFER * tmp, BUFFER * s, unsigned long data,
 }
 
 static int parse_ifdef (BUFFER * tmp, BUFFER * s, unsigned long data,
@@ -605,44 +574,6 @@ static int parse_list (BUFFER * buf, BUFFER * s, unsigned long data,
   return 0;
 }
 
   return 0;
 }
 
-#if 0
-static int _parse_rx_list (BUFFER * buf, BUFFER * s, unsigned long data,
-                           BUFFER * err, int flags)
-{
-  do {
-    mutt_extract_token (buf, s, 0);
-    if (add_to_rx_list ((RX_LIST **) data, buf->data, flags, err) != 0)
-      return -1;
-
-  }
-  while (MoreArgs (s));
-
-  return 0;
-}
-
-static int parse_rx_list (BUFFER * buf, BUFFER * s, unsigned long data,
-                          BUFFER * err)
-{
-  return _parse_rx_list (buf, s, data, err, REG_ICASE);
-}
-
-static int parse_rx_unlist (BUFFER * buf, BUFFER * s, unsigned long data,
-                            BUFFER * err)
-{
-  do {
-    mutt_extract_token (buf, s, 0);
-    if (mutt_strcmp (buf->data, "*") == 0) {
-      mutt_free_rx_list ((RX_LIST **) data);
-      break;
-    }
-    remove_from_rx_list ((RX_LIST **) data, buf->data);
-  }
-  while (MoreArgs (s));
-
-  return 0;
-}
-#endif
-
 static void _alternates_clean (void)
 {
   int i;
 static void _alternates_clean (void)
 {
   int i;
@@ -735,7 +666,7 @@ static int parse_spam_list (BUFFER * buf, BUFFER * s, unsigned long data,
     /* "*" is a special case. */
     if (!mutt_strcmp (buf->data, "*")) {
       mutt_free_spam_list (&SpamList);
     /* "*" is a special case. */
     if (!mutt_strcmp (buf->data, "*")) {
       mutt_free_spam_list (&SpamList);
-      mutt_free_rx_list (&NoSpamList);
+      list_del (&NoSpamList, rx_free);
       return 0;
     }
 
       return 0;
     }
 
@@ -1083,7 +1014,7 @@ static void mutt_set_default (struct option_t *p)
     break;
   case DT_RX:
     {
     break;
   case DT_RX:
     {
-      REGEXP *pp = (REGEXP *) p->data;
+      rx_t* pp = (rx_t*) p->data;
 
       if (!p->init && pp->pattern)
         p->init = (unsigned long) safe_strdup (pp->pattern);
 
       if (!p->init && pp->pattern)
         p->init = (unsigned long) safe_strdup (pp->pattern);
@@ -1130,7 +1061,7 @@ static void mutt_restore_default (struct option_t *p)
     break;
   case DT_RX:
     {
     break;
   case DT_RX:
     {
-      REGEXP *pp = (REGEXP *) p->data;
+      rx_t *pp = (rx_t *) p->data;
       int flags = 0;
 
       FREE (&pp->pattern);
       int flags = 0;
 
       FREE (&pp->pattern);
@@ -1323,7 +1254,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data,
       }
     }
     else if (DTYPE (MuttVars[idx].type) == DT_RX) {
       }
     }
     else if (DTYPE (MuttVars[idx].type) == DT_RX) {
-      REGEXP *ptr = (REGEXP *) MuttVars[idx].data;
+      rx_t *ptr = (rx_t *) MuttVars[idx].data;
       regex_t *rx;
       int e, flags = 0;
 
       regex_t *rx;
       int e, flags = 0;
 
index 7d2b12e..137b63e 100644 (file)
@@ -7,7 +7,7 @@ AUTOMAKE_OPTIONS = foreign
 INCLUDES = -I$(top_srcdir) -I../intl
 
 noinst_LIBRARIES = libsane.a
 INCLUDES = -I$(top_srcdir) -I../intl
 
 noinst_LIBRARIES = libsane.a
-noinst_HEADERS = mem.h str.h exit.h intl.h list.h
+noinst_HEADERS = mem.h str.h exit.h intl.h list.h rx.h
 
 
-libsane_a_SOURCES = mem.c exit.c str.c list.c \
-                   mem.h exit.h str.h list.h intl.h
+libsane_a_SOURCES = mem.c exit.c str.c list.c rx.h \
+                   mem.h exit.h str.h list.h rx.c intl.h
index bc8133f..7d233e7 100644 (file)
@@ -100,7 +100,7 @@ list2_t* list_dup (list2_t* l, void* (*dup) (void*)) {
   return (ret);
 }
 
   return (ret);
 }
 
-int _list_lookup (list2_t* l, int (*cmp) (const void*, const void*), const void* p) {
+int list_lookup (list2_t* l, int (*cmp) (const void*, const void*), const void* p) {
   int i = 0;
   if (list_empty(l) || !*cmp)
     return (-1);
   int i = 0;
   if (list_empty(l) || !*cmp)
     return (-1);
diff --git a/lib/rx.c b/lib/rx.c
new file mode 100644 (file)
index 0000000..1330af8
--- /dev/null
+++ b/lib/rx.c
@@ -0,0 +1,52 @@
+/*
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
+ */
+
+#include "rx.h"
+
+#include "mem.h"
+#include "str.h"
+
+rx_t *rx_compile (const char *s, int flags) {
+  rx_t *pp = safe_calloc (sizeof (rx_t), 1);
+
+  pp->pattern = safe_strdup (s);
+  pp->rx = safe_calloc (sizeof (regex_t), 1);
+  if (REGCOMP(pp->rx, NONULL (s), flags) != 0)
+    rx_free (&pp);
+
+  return pp;
+}
+
+void rx_free (rx_t** p) {
+  FREE(&(*p)->pattern);
+  regfree ((*p)->rx);
+  FREE(&(*p)->rx);
+  FREE(p);
+}
+
+int rx_compare (const rx_t* r1, const rx_t* r2) {
+  return (mutt_strcmp (r1->pattern, r2->pattern));
+}
+
+int rx_list_match (list2_t* l, const char* pat) {
+  int i = 0;
+  if (!pat || list_empty(l))
+    return (0);
+  for (i = 0; i < l->length; i++)
+    if (REGEXEC(((rx_t*) l->data[i])->rx, pat) == 0)
+      return (1);
+  return (0);
+}
+
+int rx_lookup (list2_t* l, const char* pat) {
+  int i = 0;
+  if (!pat || !*pat || list_empty(l))
+    return (-1);
+  for (i = 0; i < l->length; i++)
+    if (mutt_strcmp (((rx_t*) l->data[i])->pattern, pat) == 0)
+      return (i);
+  return (-1);
+}
diff --git a/lib/rx.h b/lib/rx.h
new file mode 100644 (file)
index 0000000..f098311
--- /dev/null
+++ b/lib/rx.h
@@ -0,0 +1,47 @@
+/*
+ * This file is part of mutt-ng, see http://www.muttng.org/.
+ * It's licensed under the GNU General Public License,
+ * please see the file GPL in the top level source directory.
+ */
+
+/*
+ * this is an internal abstraction layer for regular expressions
+ */
+
+#ifndef _LIB_RX_H
+#define _LIB_RX_H
+
+#include <sys/types.h>
+#ifdef USE_GNU_REGEX
+#include "_regex.h"
+#else
+#include <regex.h>
+#endif
+
+#include "list.h"
+
+/* this is a non-standard option supported by Solaris 2.5.x which allows
+ * patterns of the form \<...\>
+ */
+#ifndef REG_WORDS
+#define REG_WORDS 0
+#endif
+
+typedef struct rx_t {
+  char *pattern;                /* printable version */
+  regex_t *rx;                  /* compiled expression */
+  int not : 1;                  /* do not match */
+} rx_t;
+
+void rx_free (rx_t**);
+rx_t* rx_compile (const char*, int);
+
+/* for handling lists */
+int rx_compare (const rx_t*, const rx_t*);      /* compare two patterns */
+int rx_list_match (list2_t*, const char*);      /* match all items list agains string */
+int rx_lookup (list2_t*, const char*);          /* lookup pattern */
+
+#define REGCOMP(X,Y,Z) regcomp(X, Y, REG_WORDS|REG_EXTENDED|(Z))
+#define REGEXEC(X,Y) regexec(X, Y, (size_t)0, (regmatch_t *)0, (int)0)
+
+#endif /* !_LIB_RX_H */
diff --git a/mutt.h b/mutt.h
index 9875925..ec32499 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -8,8 +8,8 @@
  * please see the file GPL in the top level source directory.
  */
 
  * please see the file GPL in the top level source directory.
  */
 
-#ifndef MUTT_H
-#define MUTT_H
+#ifndef _MUTT_H
+#define _MUTT_H
 
 #include "config.h"
 
 
 #include "config.h"
 
@@ -44,6 +44,7 @@
 #include "rfc822.h"
 #include "hash.h"
 #include "charset.h"
 #include "rfc822.h"
 #include "hash.h"
 #include "charset.h"
+#include "lib/rx.h"
 
 #ifndef HAVE_WC_FUNCS
 # ifdef MB_LEN_MAX
 
 #ifndef HAVE_WC_FUNCS
 # ifdef MB_LEN_MAX
@@ -67,8 +68,6 @@
 #define INITVAL(x)
 #endif
 
 #define INITVAL(x)
 #endif
 
-#include "mutt_regex.h"
-
 /* flags for mutt_copy_header() */
 #define CH_UPDATE      1       /* update the status and x-status fields? */
 #define CH_WEED                (1<<1)  /* weed the headers? */
 /* flags for mutt_copy_header() */
 #define CH_UPDATE      1       /* update the status and x-status fields? */
 #define CH_WEED                (1<<1)  /* weed the headers? */
@@ -571,13 +570,8 @@ typedef struct list_t {
   struct list_t *next;
 } LIST;
 
   struct list_t *next;
 } LIST;
 
-typedef struct rx_list_t {
-  REGEXP *rx;
-  struct rx_list_t *next;
-} RX_LIST;
-
 typedef struct spam_list_t {
 typedef struct spam_list_t {
-  REGEXP *rx;
+  rx_t *rx;
   int nmatch;
   char *template;
   struct spam_list_t *next;
   int nmatch;
   char *template;
   struct spam_list_t *next;
@@ -586,9 +580,7 @@ typedef struct spam_list_t {
 
 #define mutt_new_list() safe_calloc (1, sizeof (LIST))
 #define mutt_new_spam_list() safe_calloc (1, sizeof (SPAM_LIST))
 
 #define mutt_new_list() safe_calloc (1, sizeof (LIST))
 #define mutt_new_spam_list() safe_calloc (1, sizeof (SPAM_LIST))
-#define mutt_new_rx_list() safe_calloc (1, sizeof (RX_LIST))
 void mutt_free_list (LIST **);
 void mutt_free_list (LIST **);
-void mutt_free_rx_list (RX_LIST **);
 void mutt_free_spam_list (SPAM_LIST **);
 LIST *mutt_copy_list (LIST *);
 int mutt_matches_ignore (const char *, LIST *);
 void mutt_free_spam_list (SPAM_LIST **);
 LIST *mutt_copy_list (LIST *);
 int mutt_matches_ignore (const char *, LIST *);
@@ -946,4 +938,4 @@ int state_printf (STATE *, const char *, ...);
 #include "lib.h"
 #include "globals.h"
 
 #include "lib.h"
 #include "globals.h"
 
-#endif /*MUTT_H */
+#endif /* !_MUTT_H */
index e6cb613..db7250a 100644 (file)
@@ -12,7 +12,8 @@
  */
 
 #include "keymap.h"
  */
 
 #include "keymap.h"
-#include "mutt_regex.h"
+
+#include "lib/rx.h"
 
 #define REDRAW_INDEX           (1)
 #define REDRAW_MOTION          (1<<1)
 
 #define REDRAW_INDEX           (1)
 #define REDRAW_MOTION          (1<<1)
diff --git a/mutt_regex.h b/mutt_regex.h
deleted file mode 100644 (file)
index 040778b..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright notice from original mutt:
- * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
- *
- * This file is part of mutt-ng, see http://www.muttng.org/.
- * It's licensed under the GNU General Public License,
- * please see the file GPL in the top level source directory.
- */
-
-/*
- * A (more) generic interface to regular expression matching
- */
-
-#ifndef MUTT_REGEX_H
-#define MUTT_REGEX_H
-
-#ifdef USE_GNU_REGEX
-#include "_regex.h"
-#else
-#include <regex.h>
-#endif
-
-/* this is a non-standard option supported by Solaris 2.5.x which allows
- * patterns of the form \<...\>
- */
-#ifndef REG_WORDS
-#define REG_WORDS 0
-#endif
-
-#define REGCOMP(X,Y,Z) regcomp(X, Y, REG_WORDS|REG_EXTENDED|(Z))
-#define REGEXEC(X,Y) regexec(&X, Y, (size_t)0, (regmatch_t *)0, (int)0)
-
-typedef struct {
-  char *pattern;                /* printable version */
-  regex_t *rx;                  /* compiled expression */
-  int not;                      /* do not match */
-} REGEXP;
-
-WHERE REGEXP Mask;
-WHERE REGEXP QuoteRegexp;
-WHERE REGEXP ReplyRegexp;
-WHERE REGEXP Smileys;
-WHERE REGEXP GecosMask;
-WHERE REGEXP StripWasRegexp;
-
-#endif /* MUTT_REGEX_H */
index 91cba18..7b6cb09 100644 (file)
 #include "mutt_curses.h"
 #include "mutt_menu.h"
 #include "mutt_ssl.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
 #include "mutt_ssl.h"
-#include "mutt_regex.h"
 
 #include "lib/mem.h"
 #include "lib/str.h"
 #include "lib/intl.h"
 
 #include "lib/mem.h"
 #include "lib/str.h"
 #include "lib/intl.h"
+#include "lib/rx.h"
 
 typedef struct _tlssockdata {
   gnutls_session state;
 
 typedef struct _tlssockdata {
   gnutls_session state;
index 67326c9..676b922 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -1437,40 +1437,6 @@ const char *mutt_make_version (void)
   return vstring;
 }
 
   return vstring;
 }
 
-REGEXP *mutt_compile_regexp (const char *s, int flags)
-{
-  REGEXP *pp = safe_calloc (sizeof (REGEXP), 1);
-
-  pp->pattern = safe_strdup (s);
-  pp->rx = safe_calloc (sizeof (regex_t), 1);
-  if (REGCOMP (pp->rx, NONULL (s), flags) != 0)
-    mutt_free_regexp (&pp);
-
-  return pp;
-}
-
-void mutt_free_regexp (REGEXP ** pp)
-{
-  FREE (&(*pp)->pattern);
-  regfree ((*pp)->rx);
-  FREE (&(*pp)->rx);
-  FREE (pp);
-}
-
-void mutt_free_rx_list (RX_LIST ** list)
-{
-  RX_LIST *p;
-
-  if (!list)
-    return;
-  while (*list) {
-    p = *list;
-    *list = (*list)->next;
-    mutt_free_regexp (&p->rx);
-    FREE (&p);
-  }
-}
-
 void mutt_free_spam_list (SPAM_LIST ** list)
 {
   SPAM_LIST *p;
 void mutt_free_spam_list (SPAM_LIST ** list)
 {
   SPAM_LIST *p;
@@ -1480,29 +1446,12 @@ void mutt_free_spam_list (SPAM_LIST ** list)
   while (*list) {
     p = *list;
     *list = (*list)->next;
   while (*list) {
     p = *list;
     *list = (*list)->next;
-    mutt_free_regexp (&p->rx);
+    rx_free (&p->rx);
     FREE(&p->template);
     FREE(&p);
   }
 }
 
     FREE(&p->template);
     FREE(&p);
   }
 }
 
-int mutt_match_rx_list (const char *s, RX_LIST * l)
-{
-  if (!s)
-    return 0;
-
-  for (; l; l = l->next) {
-    if (regexec (l->rx->rx, s, (size_t) 0, (regmatch_t *) 0, (int) 0) == 0) {
-      dprint (5,
-              (debugfile, "mutt_match_rx_list: %s matches %s\n", s,
-               l->rx->pattern));
-      return 1;
-    }
-  }
-
-  return 0;
-}
-
 int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
 {
   static regmatch_t *pmatch = NULL;
 int mutt_match_spam_list (const char *s, SPAM_LIST * l, char *text, int x)
 {
   static regmatch_t *pmatch = NULL;
diff --git a/pager.c b/pager.c
index 691d055..c7cd750 100644 (file)
--- a/pager.c
+++ b/pager.c
@@ -17,7 +17,6 @@
 
 #include "mutt.h"
 #include "mutt_curses.h"
 
 #include "mutt.h"
 #include "mutt_curses.h"
-#include "mutt_regex.h"
 #include "keymap.h"
 #include "mutt_menu.h"
 #include "mapping.h"
 #include "keymap.h"
 #include "mutt_menu.h"
 #include "mapping.h"
@@ -38,6 +37,7 @@
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
+#include "lib/rx.h"
 
 #include <sys/stat.h>
 #include <ctype.h>
 
 #include <sys/stat.h>
 #include <ctype.h>
@@ -672,7 +672,7 @@ resolve_types (char *buf, char *raw, struct line_t *lineInfo, int n, int last,
       lineInfo[n].type = MT_COLOR_HDEFAULT;
       color_line = ColorHdrList;
       while (color_line) {
       lineInfo[n].type = MT_COLOR_HDEFAULT;
       color_line = ColorHdrList;
       while (color_line) {
-        if (REGEXEC (color_line->rx, buf) == 0) {
+        if (REGEXEC (&color_line->rx, buf) == 0) {
           lineInfo[n].type = MT_COLOR_HEADER;
           lineInfo[n].syntax[0].color = color_line->pair;
           break;
           lineInfo[n].type = MT_COLOR_HEADER;
           lineInfo[n].syntax[0].color = color_line->pair;
           break;
diff --git a/parse.c b/parse.c
index a09d8dd..64b22f4 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -12,7 +12,6 @@
 #endif
 
 #include "mutt.h"
 #endif
 
 #include "mutt.h"
-#include "mutt_regex.h"
 #include "mailbox.h"
 #include "mime.h"
 #include "rfc2047.h"
 #include "mailbox.h"
 #include "mime.h"
 #include "rfc2047.h"
@@ -23,6 +22,7 @@
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
+#include "lib/rx.h"
 
 #include <string.h>
 #include <ctype.h>
 
 #include <string.h>
 #include <ctype.h>
@@ -1351,7 +1351,7 @@ ENVELOPE *mutt_read_rfc822_header (FILE * f, HEADER * hdr, short user_hdrs,
     *buf = '\0';
 
     if (mutt_match_spam_list (line, SpamList, buf, sizeof (buf))) {
     *buf = '\0';
 
     if (mutt_match_spam_list (line, SpamList, buf, sizeof (buf))) {
-      if (!mutt_match_rx_list (line, NoSpamList)) {
+      if (!rx_list_match (NoSpamList, line)) {
 
         /* if spam tag already exists, figure out how to amend it */
         if (e->spam && *buf) {
 
         /* if spam tag already exists, figure out how to amend it */
         if (e->spam && *buf) {
index e3aa631..b9edfc3 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -154,8 +154,6 @@ const char *mutt_make_version (void);
 
 const char *mutt_fqdn (short);
 
 
 const char *mutt_fqdn (short);
 
-REGEXP *mutt_compile_regexp (const char *, int);
-
 void mutt_account_hook (const char *url);
 void mutt_add_to_reference_headers (ENVELOPE * env, ENVELOPE * curenv,
                                     LIST *** pp, LIST *** qq);
 void mutt_account_hook (const char *url);
 void mutt_add_to_reference_headers (ENVELOPE * env, ENVELOPE * curenv,
                                     LIST *** pp, LIST *** qq);
@@ -204,7 +202,6 @@ void mutt_free_enter_state (ENTER_STATE **);
 void mutt_free_envelope (ENVELOPE **);
 void mutt_free_header (HEADER **);
 void mutt_free_parameter (PARAMETER **);
 void mutt_free_envelope (ENVELOPE **);
 void mutt_free_header (HEADER **);
 void mutt_free_parameter (PARAMETER **);
-void mutt_free_regexp (REGEXP **);
 void mutt_generate_header (char *, size_t, HEADER *, int);
 void mutt_help (int);
 void mutt_draw_tree (CONTEXT *);
 void mutt_generate_header (char *, size_t, HEADER *, int);
 void mutt_help (int);
 void mutt_draw_tree (CONTEXT *);
@@ -324,7 +321,6 @@ int mutt_is_text_part (BODY *);
 int mutt_is_valid_mailbox (const char *);
 int mutt_link_threads (HEADER *, HEADER *, CONTEXT *);
 int mutt_lookup_mime_type (BODY *, const char *);
 int mutt_is_valid_mailbox (const char *);
 int mutt_link_threads (HEADER *, HEADER *, CONTEXT *);
 int mutt_lookup_mime_type (BODY *, const char *);
-int mutt_match_rx_list (const char *, RX_LIST *);
 int mutt_match_spam_list (const char *, SPAM_LIST *, char *, int);
 int mutt_messages_in_thread (CONTEXT *, HEADER *, int);
 int mutt_multi_choice (char *prompt, char *letters);
 int mutt_match_spam_list (const char *, SPAM_LIST *, char *, int);
 int mutt_messages_in_thread (CONTEXT *, HEADER *, int);
 int mutt_multi_choice (char *prompt, char *letters);
index 927be73..68de837 100644 (file)
@@ -18,7 +18,6 @@
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
 #include "mutt.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
-#include "mutt_regex.h"
 #include "mapping.h"
 
 #include "remailer.h"
 #include "mapping.h"
 
 #include "remailer.h"
@@ -26,6 +25,7 @@
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
 #include "lib/mem.h"
 #include "lib/intl.h"
 #include "lib/str.h"
+#include "lib/rx.h"
 
 #include <stdio.h>
 #include <string.h>
 
 #include <stdio.h>
 #include <string.h>