X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=init.c;h=35577a40ff641cf94c7929604dc9a5d139bb6ef6;hp=818a6bd45bfaeda647e6f36e4985742db3391ac0;hb=fa7f733a61a6fe3143198791ab470ddf4d08fdbe;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281 diff --git a/init.c b/init.c index 818a6bd..35577a4 100644 --- a/init.c +++ b/init.c @@ -1,19 +1,10 @@ /* + * Copyright notice from original mutt: * Copyright (C) 1996-2002 Michael R. Elkins - * - * 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 @@ -23,7 +14,6 @@ #include "mutt.h" #include "mapping.h" #include "mutt_curses.h" -#include "mutt_regex.h" #include "history.h" #include "keymap.h" #include "mbyte.h" @@ -35,12 +25,15 @@ #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 #include #include @@ -308,44 +301,25 @@ static void add_to_list (LIST ** list, const char *str) } } -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; } @@ -353,14 +327,14 @@ static int add_to_spam_list (SPAM_LIST ** list, const char *pat, 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; } @@ -375,7 +349,7 @@ static int add_to_spam_list (SPAM_LIST ** list, const char *pat, * the template, and leaving t pointed at the current item. */ t = last; - safe_free (&t->template); + FREE(t->template); break; } if (!last->next) @@ -424,9 +398,9 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat) 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; } @@ -434,9 +408,9 @@ static int remove_from_spam_list (SPAM_LIST ** list, const char *pat) 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; } @@ -474,35 +448,23 @@ static void remove_from_list (LIST ** l, const char *str) } } -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, @@ -612,44 +574,6 @@ static int parse_list (BUFFER * buf, 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; @@ -742,7 +666,7 @@ static int parse_spam_list (BUFFER * buf, BUFFER * s, unsigned long data, /* "*" 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; } @@ -1090,7 +1014,7 @@ static void mutt_set_default (struct option_t *p) 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); @@ -1137,7 +1061,7 @@ static void mutt_restore_default (struct option_t *p) break; case DT_RX: { - REGEXP *pp = (REGEXP *) p->data; + rx_t *pp = (rx_t *) p->data; int flags = 0; FREE (&pp->pattern); @@ -1330,7 +1254,7 @@ static int parse_set (BUFFER * tmp, BUFFER * s, unsigned long data, } } 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; @@ -2184,7 +2108,7 @@ void mutt_init (int skip_sys_rc, LIST * commands) 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')