From 01748cc2548aa19c160ddbb8d18e28dddc1efd9f Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Mon, 4 Dec 2006 01:03:58 +0100 Subject: [PATCH] impressive how mutt upstream don't get how list work. simplify lots of code, more to come. Signed-off-by: Pierre Habouzit --- init.c | 109 +++++++++++++++++++++++---------------------------------- 1 file changed, 43 insertions(+), 66 deletions(-) diff --git a/init.c b/init.c index 94c82b2..2be929e 100644 --- a/init.c +++ b/init.c @@ -585,41 +585,27 @@ int query_quadoption (int opt, const char *prompt) /* not reached */ } -static void add_to_list (string_list_t ** list, const char *str) +static void add_to_list(string_list_t **list, const char *str) { - string_list_t *t, *last = NULL; - - /* don't add a NULL or empty string to the list */ - if (!str || *str == '\0') - return; + /* don't add a NULL or empty string to the list */ + if (m_strisempty(str)) + return; - /* check to make sure the item is not already on this list */ - for (last = *list; last; last = last->next) { - if (ascii_strcasecmp (str, last->data) == 0) { - /* already on the list, so just ignore it */ - last = NULL; - break; + /* check to make sure the item is not already on this list */ + while (*list) { + if (!ascii_strcasecmp(str, (*list)->data)) + return; + list = &(*list)->next; } - if (!last->next) - break; - } - if (!*list || last) { - t = p_new(string_list_t, 1); - t->data = m_strdup(str); - if (last) { - last->next = t; - last = last->next; - } - else - *list = last = t; - } + *list = p_new(string_list_t, 1); + (*list)->data = m_strdup(str); } static int add_to_rx_list(rx_t **list, const char *s, int flags, BUFFER *err) { - rx_t* rx; + rx_t *rx; if (m_strisempty(s)) return 0; @@ -640,7 +626,7 @@ add_to_rx_list(rx_t **list, const char *s, int flags, BUFFER *err) static int add_to_spam_list(rx_t **list, const char *pat, const char *templ, BUFFER * err) { - rx_t **last, *rx; + rx_t *rx; if (m_strisempty(pat) || !templ) return 0; @@ -651,62 +637,53 @@ static int add_to_spam_list(rx_t **list, const char *pat, } /* 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)->pattern) == 0) { - rx_t *tmp = rx_list_pop(last); + while (*list) { + if (!ascii_strcasecmp(rx->pattern, (*list)->pattern)) { + rx_t *tmp = rx_list_pop(list); rx_delete(&tmp); - last = rx_list_last(last); - break; + } else { + list = &(*list)->next; } } - *last = rx; + *list = rx; rx_set_template(rx, templ); return 0; } static int remove_from_spam_list (rx_t ** list, const char *pat) { - int nremoved = 0; - - while (*list) { - if (!m_strcmp((*list)->pattern, pat)) { - rx_t *spam = rx_list_pop(list); - rx_delete(&spam); - nremoved++; - } else { - list = &(*list)->next; - } - } + int nremoved = 0; + + while (*list) { + if (!m_strcmp((*list)->pattern, pat)) { + rx_t *spam = rx_list_pop(list); + rx_delete(&spam); + nremoved++; + } else { + list = &(*list)->next; + } + } - return nremoved; + return nremoved; } -static void remove_from_list (string_list_t ** l, const char *str) +static void remove_from_list(string_list_t **l, const char *str) { - string_list_t *p, *last = NULL; + if (!m_strcmp("*", str)) { + string_list_wipe(l); /* ``unCMD *'' means delete all current entries */ + return; + } - if (m_strcmp("*", str) == 0) - string_list_wipe(l); /* ``unCMD *'' means delete all current entries */ - else { - p = *l; - last = NULL; - while (p) { - if (ascii_strcasecmp (str, p->data) == 0) { - p_delete(&p->data); - if (last) - last->next = p->next; - else - (*l) = p->next; - p_delete(&p); - } - else { - last = p; - p = p->next; - } + while (*l) { + if (!ascii_strcasecmp(str, (*l)->data)) { + string_list_t *it = string_list_pop(l); + string_item_delete(&it); + } else { + l = &(*l)->next; + } } - } } static int remove_from_rx_list(rx_t **l, const char *str) -- 2.20.1