From 5a4df9d0e93209aeade80f632158036799f3e9bc Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sat, 18 Nov 2006 12:59:17 +0100 Subject: [PATCH] make rx_t be chaine-able so that we can get rid of list2_t (stage 1). Signed-off-by: Pierre Habouzit --- globals.h | 16 +++++++------- init.c | 59 +++++++++++++++++++++++++--------------------------- lib-lib/rx.c | 28 ++++++++++++------------- lib-lib/rx.h | 9 ++++---- sendlib.c | 5 ++++- 5 files changed, 57 insertions(+), 60 deletions(-) diff --git a/globals.h b/globals.h index aaca563..47bed4c 100644 --- a/globals.h +++ b/globals.h @@ -11,8 +11,6 @@ #include -#include "lib/list.h" - WHERE void (*mutt_error) (const char *, ...); WHERE void (*mutt_message) (const char *, ...); @@ -179,14 +177,14 @@ WHERE string_list_t *Ignore INITVAL (0); 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 diff --git a/init.c b/init.c index f71f363..ad55667 100644 --- 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; } diff --git a/lib-lib/rx.c b/lib-lib/rx.c index 521376f..d0a3942 100644 --- a/lib-lib/rx.c +++ b/lib-lib/rx.c @@ -46,34 +46,32 @@ void rx_delete(rx_t **p) 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) diff --git a/lib-lib/rx.h b/lib-lib/rx.h index d12fe85..14709d1 100644 --- a/lib-lib/rx.h +++ b/lib-lib/rx.h @@ -29,7 +29,7 @@ #ifndef MUTT_LIB_LIB_RX_H #define MUTT_LIB_LIB_RX_H -#include "../lib/list.h" +#include /* this is a non-standard option supported by Solaris 2.5.x which allows * patterns of the form \<...\> @@ -39,6 +39,7 @@ #endif typedef struct rx_t { + struct rx_t *next; char *pattern; /* printable version */ regex_t *rx; /* compiled expression */ int not; /* do not match */ @@ -46,13 +47,13 @@ typedef struct rx_t { 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) diff --git a/sendlib.c b/sendlib.c index 4dfca68..b024afc 100644 --- a/sendlib.c +++ b/sendlib.c @@ -19,6 +19,10 @@ #include #include +#include + +#include "lib/list.h" + #include "mutt.h" #include "handler.h" #include "recvattach.h" @@ -26,7 +30,6 @@ #include "copy.h" #include "pager.h" #include "charset.h" -#include #include "mutt_idna.h" #ifdef USE_LIBESMTP -- 2.20.1