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 \
#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 "lib/rx.h"
#include <string.h>
#include <ctype.h>
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));
- 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",
#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 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);
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 RX_LIST *NoSpamList INITVAL (0);
+WHERE list2_t *NoSpamList INITVAL (0);
/* bit vector for boolean variables */
#ifdef MAIN_C
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;
#endif
#ifdef MAIN_C
-/* so that global vars get included */
+/* so that global vars get included
+ * FIXME WTF IS THIS?!?!???!?!??!?!??
+ */
#include "mx.h"
-#include "mutt_regex.h"
#include "buffy.h"
#include "sort.h"
#include "mutt_crypt.h"
#include "mutt_idna.h"
#include "lib/str.h"
+#include "lib/rx.h"
#include <ctype.h>
#include <stdlib.h>
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)
{
- 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;
}
#include "lib/mem.h"
#include "lib/intl.h"
#include "lib/str.h"
+#include "lib/rx.h"
#include <limits.h>
#include <string.h>
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;
#include "mutt.h"
#include "mapping.h"
#include "mutt_curses.h"
-#include "mutt_regex.h"
#include "history.h"
#include "keymap.h"
#include "mbyte.h"
#include "lib/mem.h"
#include "lib/intl.h"
#include "lib/str.h"
+#include "lib/rx.h"
#include <ctype.h>
#include <stdlib.h>
}
}
-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)
{
- RX_LIST *t, *last = NULL;
- REGEXP *rx;
+ rx_t* rx;
+ int i = 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;
}
- /* 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;
}
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;
- 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;
}
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;
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;
}
}
-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) {
- mutt_free_rx_list (l); /* ``unCMD *'' means delete all current entries */
- rv = 0;
+ list_del (l, rx_free);
+ return (0);
}
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,
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;
/* "*" 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;
}
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);
break;
case DT_RX:
{
- REGEXP *pp = (REGEXP *) p->data;
+ rx_t *pp = (rx_t *) p->data;
int flags = 0;
FREE (&pp->pattern);
}
}
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;
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
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);
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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 */
* 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 "rfc822.h"
#include "hash.h"
#include "charset.h"
+#include "lib/rx.h"
#ifndef HAVE_WC_FUNCS
# ifdef MB_LEN_MAX
#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? */
struct list_t *next;
} LIST;
-typedef struct rx_list_t {
- REGEXP *rx;
- struct rx_list_t *next;
-} RX_LIST;
-
typedef struct spam_list_t {
- REGEXP *rx;
+ rx_t *rx;
int nmatch;
char *template;
struct spam_list_t *next;
#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_rx_list (RX_LIST **);
void mutt_free_spam_list (SPAM_LIST **);
LIST *mutt_copy_list (LIST *);
int mutt_matches_ignore (const char *, LIST *);
#include "lib.h"
#include "globals.h"
-#endif /*MUTT_H */
+#endif /* !_MUTT_H */
*/
#include "keymap.h"
-#include "mutt_regex.h"
+
+#include "lib/rx.h"
#define REDRAW_INDEX (1)
#define REDRAW_MOTION (1<<1)
+++ /dev/null
-/*
- * 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 */
#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/rx.h"
typedef struct _tlssockdata {
gnutls_session state;
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;
while (*list) {
p = *list;
*list = (*list)->next;
- mutt_free_regexp (&p->rx);
+ rx_free (&p->rx);
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;
#include "mutt.h"
#include "mutt_curses.h"
-#include "mutt_regex.h"
#include "keymap.h"
#include "mutt_menu.h"
#include "mapping.h"
#include "lib/mem.h"
#include "lib/intl.h"
#include "lib/str.h"
+#include "lib/rx.h"
#include <sys/stat.h>
#include <ctype.h>
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;
#endif
#include "mutt.h"
-#include "mutt_regex.h"
#include "mailbox.h"
#include "mime.h"
#include "rfc2047.h"
#include "lib/mem.h"
#include "lib/intl.h"
#include "lib/str.h"
+#include "lib/rx.h"
#include <string.h>
#include <ctype.h>
*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) {
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_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 *);
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);
#include "mutt.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
-#include "mutt_regex.h"
#include "mapping.h"
#include "remailer.h"
#include "lib/mem.h"
#include "lib/intl.h"
#include "lib/str.h"
+#include "lib/rx.h"
#include <stdio.h>
#include <string.h>