#include <lib-lib/lib-lib.h>
-#include "lib/list.h"
-
WHERE void (*mutt_error) (const char *, ...);
WHERE void (*mutt_message) (const char *, ...);
WHERE string_list_t *MimeLookupList INITVAL (0);
WHERE string_list_t *UnIgnore 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 rx_t *Alternates INITVAL (0);
+WHERE rx_t *UnAlternates INITVAL (0);
+WHERE rx_t *MailLists INITVAL (0);
+WHERE rx_t *UnMailLists INITVAL (0);
+WHERE rx_t *SubscribedLists INITVAL (0);
+WHERE rx_t *UnSubscribedLists INITVAL (0);
WHERE SPAM_LIST *SpamList INITVAL (0);
-WHERE list2_t *NoSpamList INITVAL (0);
+WHERE rx_t *NoSpamList INITVAL (0);
/* bit vector for boolean variables */
#ifdef MAIN_C
}
}
-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,
}
}
-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,
/* "*" 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;
}
p_delete(p);
}
-int rx_list_match(list2_t *l, const char *pat)
+int rx_list_match(rx_t *l, const char *pat)
{
- int i;
-
- if (!pat || !*pat || list_empty(l))
+ if (!pat || !*pat)
return 0;
- for (i = 0; i < l->length; i++) {
- if (!REGEXEC(((rx_t*)l->data[i])->rx, pat))
+ while (l) {
+ if (!REGEXEC(l->rx, pat))
return 1;
+ l = l->next;
}
return 0;
}
-int rx_lookup (list2_t *l, const char *pat)
+rx_t **rx_lookup(rx_t **l, const char *pat)
{
- int i;
-
- if (!pat || !*pat || list_empty(l))
- return -1;
+ if (!pat || !*pat)
+ return NULL;
- for (i = 0; i < l->length; i++) {
- if (!strcmp(((rx_t*)l->data[i])->pattern, pat))
- return i;
+ while (*l) {
+ if (!strcmp((*l)->pattern, pat))
+ return l;
+ l = &(*l)->next;
}
- return -1;
+ return NULL;
}
int rx_sanitize_string(char *dst, ssize_t n, const char *src)
#ifndef MUTT_LIB_LIB_RX_H
#define MUTT_LIB_LIB_RX_H
-#include "../lib/list.h"
+#include <lib-lib/lib-lib.h>
/* this is a non-standard option supported by Solaris 2.5.x which allows
* patterns of the form \<...\>
#endif
typedef struct rx_t {
+ struct rx_t *next;
char *pattern; /* printable version */
regex_t *rx; /* compiled expression */
int not; /* do not match */
rx_t* rx_compile (const char*, int);
void rx_delete(rx_t **);
+DO_SLIST(rx_t, rx, rx_delete);
/* for handling lists */
-int rx_list_match(list2_t*, const char*); /* match all items list agains string */
-int rx_lookup(list2_t*, const char*); /* lookup pattern */
+int rx_list_match(rx_t *, const char*); /* match all items list agains string */
+rx_t **rx_lookup(rx_t**, const char*); /* lookup pattern */
int rx_sanitize_string(char *, ssize_t, const char *);
-
#define REGCOMP(X,Y,Z) regcomp(X, Y, REG_WORDS|REG_EXTENDED|(Z))
#define REGEXEC(X,Y) regexec(X, Y, 0, NULL, 0)
#include <lib-mime/mime.h>
#include <lib-ui/curses.h>
+#include <lib-crypt/crypt.h>
+
+#include "lib/list.h"
+
#include "mutt.h"
#include "handler.h"
#include "recvattach.h"
#include "copy.h"
#include "pager.h"
#include "charset.h"
-#include <lib-crypt/crypt.h>
#include "mutt_idna.h"
#ifdef USE_LIBESMTP