/*
+ * Copyright notice from original mutt:
* Copyright (C) 1996-2002 Michael R. Elkins <me@mutt.org>
- *
- * 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., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
+ *
+ * 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 "mutt.h"
#include "mapping.h"
#include "mutt_curses.h"
-#include "mutt_regex.h"
#include "history.h"
#include "keymap.h"
#include "mbyte.h"
#include "mutt_ssl.h"
#endif
-
-
#include "mx.h"
#include "init.h"
#include "mailbox.h"
+#include "lib/mem.h"
+#include "lib/intl.h"
+#include "lib/str.h"
+#include "lib/rx.h"
+
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
}
}
-static int add_to_rx_list (RX_LIST ** list, const char *s, int flags,
+static int add_to_rx_list (list2_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;
}
* the template, and leaving t pointed at the current item.
*/
t = last;
- safe_free (&t->template);
+ FREE(t->template);
break;
}
if (!last->next)
spam = *list;
if (spam->rx && !mutt_strcmp (spam->rx->pattern, pat)) {
*list = spam->next;
- mutt_free_regexp (&spam->rx);
- safe_free (&spam->template);
- safe_free (&spam);
+ 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);
- safe_free (&spam->template);
- safe_free (&spam);
+ rx_free (&spam->rx);
+ FREE(spam->template);
+ FREE(spam);
spam = prev->next;
++nremoved;
}
}
}
-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;
if ((f = safe_fopen (SYSCONFDIR "/nntpserver", "r"))) {
buffer[0] = '\0';
fgets (buffer, sizeof (buffer), f);
- p = &buffer;
+ p = (char*) &buffer;
SKIPWS (p);
i = p;
while (*i && (*i != ' ') && (*i != '\t') && (*i != '\r')