From: Pierre Habouzit Date: Sat, 11 Nov 2006 23:38:55 +0000 (+0100) Subject: move rx.[hc]. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=03fe827a7d4a7ad79ac235654414aa339a9a2c9a move rx.[hc]. those list2_t are really tasteless. Signed-off-by: Pierre Habouzit --- diff --git a/alias.c b/alias.c index cf4dc5e..cefe0ec 100644 --- a/alias.c +++ b/alias.c @@ -21,13 +21,12 @@ #include #include #include +#include #include #include #include -#include "lib/rx.h" - #include "mutt.h" #include "mutt_idna.h" #include "sort.h" diff --git a/globals.h b/globals.h index 8e690b8..96c439a 100644 --- a/globals.h +++ b/globals.h @@ -13,9 +13,9 @@ #include #include +#include #include "lib/list.h" -#include "lib/rx.h" WHERE void (*mutt_error) (const char *, ...); WHERE void (*mutt_message) (const char *, ...); diff --git a/hdrline.c b/hdrline.c index f50cc84..82ab690 100644 --- a/hdrline.c +++ b/hdrline.c @@ -11,6 +11,16 @@ # include "config.h" #endif +#include +#include +#include +#include + +#include +#include + +#include + #include #include "mutt.h" @@ -20,17 +30,6 @@ #include #include "mutt_idna.h" -#include - -#include - -#include "lib/rx.h" - -#include -#include -#include -#include - int mutt_is_mail_list (address_t * addr) { if (!rx_list_match (UnMailLists, addr->mailbox)) diff --git a/hook.c b/hook.c index e763f14..27f0afa 100644 --- a/hook.c +++ b/hook.c @@ -11,25 +11,24 @@ # include "config.h" #endif +#include +#include +#include +#include +#include + #include #include #include #include #include +#include #include "mutt.h" #include "mx.h" #include #include "compress.h" -#include "lib/rx.h" - -#include -#include -#include -#include -#include - #define ERROR_STOP 0 typedef struct hook { diff --git a/init.c b/init.c index d7eef24..96990c2 100644 --- a/init.c +++ b/init.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -45,7 +46,6 @@ #include "mx.h" #include "init.h" -#include "lib/rx.h" #include "lib/list.h" #include @@ -671,7 +671,7 @@ static int add_to_rx_list (list2_t** list, const char *s, int flags, i = rx_lookup ((*list), rx->pattern); if (i >= 0) - rx_free (&rx); + rx_delete(&rx); else list_push_back (list, rx); return 0; @@ -754,7 +754,7 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat) return 0; if (spam->rx && !m_strcmp(spam->rx->pattern, pat)) { *list = spam->next; - rx_free (&spam->rx); + rx_delete(&spam->rx); p_delete(&spam->template); p_delete(&spam); return 1; @@ -764,7 +764,7 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat) for (spam = prev->next; spam;) { if (!m_strcmp(spam->rx->pattern, pat)) { prev->next = spam->next; - rx_free (&spam->rx); + rx_delete(&spam->rx); p_delete(&spam->template); p_delete(&spam); spam = prev->next; @@ -809,14 +809,14 @@ static int remove_from_rx_list (list2_t** l, const char *str) int i = 0; if (m_strcmp("*", str) == 0) { - list_del (l, (list_del_t*) rx_free); + 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_free (&r); + rx_delete(&r); return (0); } } @@ -1026,7 +1026,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_free); + list_del (&NoSpamList, (list_del_t*) rx_delete); return 0; } diff --git a/lib-lib/Makefile.am b/lib-lib/Makefile.am index dd9b5b8..89120e3 100644 --- a/lib-lib/Makefile.am +++ b/lib-lib/Makefile.am @@ -3,10 +3,10 @@ noinst_LIBRARIES = liblib.a liblib_a_SOURCES = mem.h str.h ascii.h buffer.h hash.h list.h file.h mapping.h \ str.c ascii.c buffer.c hash.c list.c file.c mapping.c \ \ - date.h debug.h \ - date.c debug.c + date.h debug.h rx.h \ + date.c debug.c rx.c noinst_HEADERS = mem.h str.h ascii.h buffer.h hash.h list.h file.h mapping.h \ - date.c + date.h debug.h rx.h -include ../cflags.mk diff --git a/lib-lib/rx.c b/lib-lib/rx.c new file mode 100644 index 0000000..6413f69 --- /dev/null +++ b/lib-lib/rx.c @@ -0,0 +1,83 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * Copyright © 2006 Pierre Habouzit + */ +/* + * 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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +rx_t *rx_compile(const char *s, int flags) +{ + rx_t *pp = p_new(rx_t, 1); + + pp->pattern = m_strdup(s); + pp->rx = p_new(regex_t, 1); + + if (REGCOMP(pp->rx, NONULL(s), flags) != 0) { + rx_delete(&pp); + } + + return pp; +} + +void rx_delete(rx_t **p) +{ + p_delete(&(*p)->pattern); + regfree((*p)->rx); + p_delete(&(*p)->rx); + p_delete(p); +} + +int rx_list_match(list2_t *l, const char *pat) +{ + int i; + + if (!pat || !*pat || list_empty(l)) + return 0; + + for (i = 0; i < l->length; i++) { + if (!REGEXEC(((rx_t*)l->data[i])->rx, pat)) + return 1; + } + + return 0; +} + +int rx_lookup (list2_t *l, const char *pat) +{ + int i; + + if (!pat || !*pat || list_empty(l)) + return -1; + + for (i = 0; i < l->length; i++) { + if (!strcmp(((rx_t*)l->data[i])->pattern, pat)) + return i; + } + + return -1; +} diff --git a/lib-lib/rx.h b/lib-lib/rx.h new file mode 100644 index 0000000..48e295b --- /dev/null +++ b/lib-lib/rx.h @@ -0,0 +1,60 @@ +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + * + * Copyright © 2006 Pierre Habouzit + */ +/* + * 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 +#include + +#include "../lib/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; /* do not match */ +} rx_t; + +rx_t* rx_compile (const char*, int); +void rx_delete(rx_t **); + +/* 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 */ + +#define REGCOMP(X,Y,Z) regcomp(X, Y, REG_WORDS|REG_EXTENDED|(Z)) +#define REGEXEC(X,Y) regexec(X, Y, 0, NULL, 0) + +#endif /* !_LIB_RX_H */ diff --git a/lib-network/mutt_ssl_gnutls.c b/lib-network/mutt_ssl_gnutls.c index 9382054..a679048 100644 --- a/lib-network/mutt_ssl_gnutls.c +++ b/lib-network/mutt_ssl_gnutls.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -32,8 +33,6 @@ #include "mutt_socket.h" #include "mutt_ssl.h" -#include "lib/rx.h" - typedef struct _tlssockdata { gnutls_session state; gnutls_certificate_credentials xcred; diff --git a/lib-ui/menu.h b/lib-ui/menu.h index 96c2c53..5378541 100644 --- a/lib-ui/menu.h +++ b/lib-ui/menu.h @@ -12,9 +12,9 @@ * This file is named mutt_menu.h so it doesn't collide with ncurses menu.h */ -#include "keymap.h" +#include -#include "lib/rx.h" +#include "keymap.h" #define REDRAW_INDEX (1) #define REDRAW_MOTION (1<<1) diff --git a/lib/Makefile.am b/lib/Makefile.am index e76c232..8f21b15 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -5,8 +5,8 @@ AR=@AR@ AUTOMAKE_OPTIONS = foreign noinst_LIBRARIES = libsane.a -noinst_HEADERS = list.h rx.h +noinst_HEADERS = list.h -libsane_a_SOURCES = list.c rx.h list.h rx.c +libsane_a_SOURCES = list.c list.h -include ../cflags.mk diff --git a/lib/list.c b/lib/list.c index 8edcec2..7ef6e6c 100644 --- a/lib/list.c +++ b/lib/list.c @@ -21,7 +21,7 @@ list2_t* list_new (void) { } void list_del (list2_t** l, list_del_t* del) { - size_t i = 0; + ssize_t i = 0; if (!l || !*l) return; if (del) @@ -88,16 +88,16 @@ list2_t *list_cpy(list2_t *l) { return ret; } -list2_t* list_dup (list2_t* l, void* (*dup) (void*)) { +list2_t* list_dup (list2_t* l, void* (*dup_f) (void*)) { list2_t* ret = NULL; int i = 0; - if (list_empty(l) || !*dup) + if (list_empty(l) || !*dup_f) return (NULL); ret = list_new (); ret->length = l->length; ret->data = p_new(void*, l->length); for (i = 0; i < l->length; i++) - ret->data[i] = dup (l->data[i]); + ret->data[i] = dup_f (l->data[i]); return (ret); } diff --git a/lib/list.h b/lib/list.h index 0040c4d..a63b528 100644 --- a/lib/list.h +++ b/lib/list.h @@ -20,7 +20,7 @@ typedef struct list2_t { void** data; - size_t length; + ssize_t length; } list2_t; /* diff --git a/lib/rx.c b/lib/rx.c deleted file mode 100644 index 230bf3d..0000000 --- a/lib/rx.c +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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. - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include - -#include "rx.h" - - -rx_t *rx_compile (const char *s, int flags) { - rx_t *pp = p_new(rx_t, 1); - - pp->pattern = m_strdup(s); - pp->rx = p_new(regex_t, 1); - if (REGCOMP(pp->rx, NONULL (s), flags) != 0) - rx_free (&pp); - - return pp; -} - -void rx_free (rx_t** p) { - p_delete(&(*p)->pattern); - regfree ((*p)->rx); - p_delete(&(*p)->rx); - p_delete(p); -} - -int rx_compare (const rx_t* r1, const rx_t* r2) { - return (m_strcmp(r1->pattern, r2->pattern)); -} - -int rx_list_match (list2_t* l, const char* pat) { - int i = 0; - if (!pat || !*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 (m_strcmp(((rx_t*) l->data[i])->pattern, pat) == 0) - return (i); - return (-1); -} diff --git a/lib/rx.h b/lib/rx.h deleted file mode 100644 index 0eee105..0000000 --- a/lib/rx.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * 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 -#ifdef USE_GNU_REGEX -#include "_regex.h" -#else -#include -#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; /* 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/main.c b/main.c index 29197df..ab893ca 100644 --- a/main.c +++ b/main.c @@ -330,11 +330,6 @@ static void show_version (void) "+HAVE_REGCOMP " #else "-HAVE_REGCOMP " -#endif -#ifdef USE_GNU_REGEX - "+USE_GNU_REGEX " -#else - "-USE_GNU_REGEX " #endif "\n " #ifdef HAVE_COLOR diff --git a/mutt.h b/mutt.h index d418c38..490989d 100644 --- a/mutt.h +++ b/mutt.h @@ -44,11 +44,11 @@ #include #include #include +#include #include #include "charset.h" -#include "lib/rx.h" #ifndef HAVE_WC_FUNCS # ifdef MB_LEN_MAX diff --git a/muttlib.c b/muttlib.c index f901549..6d8b874 100644 --- a/muttlib.c +++ b/muttlib.c @@ -1236,7 +1236,7 @@ void mutt_free_spam_list (SPAM_LIST ** list) while (*list) { p = *list; *list = (*list)->next; - rx_free (&p->rx); + rx_delete(&p->rx); p_delete(&p->template); p_delete(&p); } diff --git a/pager.c b/pager.c index f0d366d..2a8d836 100644 --- a/pager.c +++ b/pager.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -49,7 +50,6 @@ #include -#include "lib/rx.h" #define ISHEADER(x) ((x) == MT_COLOR_HEADER || (x) == MT_COLOR_HDEFAULT) diff --git a/remailer.c b/remailer.c index d60048b..08b7a44 100644 --- a/remailer.c +++ b/remailer.c @@ -15,12 +15,20 @@ # include "config.h" #endif +#include +#include +#include +#include +#include +#include + #include #include #include #include #include #include +#include #include #include @@ -30,16 +38,6 @@ #include "remailer.h" -#include "lib/rx.h" - -#include -#include -#include - -#include -#include -#include - #define SW (option(OPTMBOXPANE)?SidebarWidth:0) #ifdef MIXMASTER