make rx_t be chaine-able so that we can get rid of list2_t (stage 1).
[apps/madmutt.git] / init.c
diff --git a/init.c b/init.c
index f71f363..ad55667 100644 (file)
--- a/init.c
+++ b/init.c
@@ -625,26 +625,25 @@ static void add_to_list (string_list_t ** list, const char *str)
   }
 }
 
-static int add_to_rx_list (list2_t** list, const char *s, int flags,
-                           BUFFER * err)
+static int
+add_to_rx_list(rx_t **list, const char *s, int flags, BUFFER *err)
 {
-  rx_t* rx;
-  int i = 0;
+    rx_t* rx;
 
-  if (!s || !*s)
-    return 0;
+    if (!s || !*s)
+        return 0;
 
-  if (!(rx = rx_compile (s, flags))) {
-    snprintf (err->data, err->dsize, "Bad regexp: %s\n", s);
-    return -1;
-  }
+    if (rx_lookup(list, s))
+        return 0;
 
-  i = rx_lookup ((*list), rx->pattern);
-  if (i >= 0)
-    rx_delete(&rx);
-  else
-    list_push_back (list, rx);
-  return 0;
+    rx = rx_compile(s, flags);
+    if (!rx) {
+        snprintf(err->data, err->dsize, "Bad regexp: %s\n", s);
+        return -1;
+    }
+
+    rx_list_append(list, rx);
+    return 0;
 }
 
 static int add_to_spam_list (SPAM_LIST ** list, const char *pat,
@@ -774,23 +773,21 @@ static void remove_from_list (string_list_t ** l, const char *str)
   }
 }
 
-static int remove_from_rx_list (list2_t** l, const char *str)
+static int remove_from_rx_list(rx_t **l, const char *str)
 {
-  int i = 0;
+    if (m_strcmp("*", str) == 0) {
+        rx_list_wipe(l);
+        return 0;
+    }
 
-  if (m_strcmp("*", str) == 0) {
-    list_del (l, (list_del_t*) rx_delete);
-    return (0);
-  }
-  else {
-    i = rx_lookup ((*l), str);
-    if (i >= 0) {
-      rx_t* r = list_pop_idx ((*l), i);
-      rx_delete(&r);
-      return (0);
+    l = rx_lookup(l, str);
+    if (l) {
+        rx_t *r = rx_list_pop(l);
+        rx_delete(&r);
+        return 0;
     }
-  }
-  return (-1);
+
+    return -1;
 }
 
 static int parse_ifdef (BUFFER * tmp, BUFFER * s, unsigned long data,
@@ -996,7 +993,7 @@ static int parse_spam_list (BUFFER * buf, BUFFER * s, unsigned long data,
     /* "*" is a special case. */
     if (!m_strcmp(buf->data, "*")) {
       mutt_free_spam_list (&SpamList);
-      list_del (&NoSpamList, (list_del_t*) rx_delete);
+      rx_list_wipe(&NoSpamList);
       return 0;
     }