From: Pierre Habouzit Date: Mon, 4 Dec 2006 00:18:21 +0000 (+0100) Subject: more strings simplifications. X-Git-Url: http://git.madism.org/?a=commitdiff_plain;h=79b870584c9a4fca6f6bf34b9b95dcff3b76dc29;p=apps%2Fmadmutt.git more strings simplifications. Signed-off-by: Pierre Habouzit --- diff --git a/init.c b/init.c index 2be929e..82636f1 100644 --- a/init.c +++ b/init.c @@ -1183,142 +1183,118 @@ static int parse_unalias (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ ((unused)), BUFFER * err __attribute__ ((unused))) { - alias_t *tmp, *last = NULL; - - do { - mutt_extract_token (buf, s, 0); - - if (m_strcmp("*", buf->data) == 0) { - if (CurrentMenu == MENU_ALIAS) { - for (tmp = Aliases; tmp; tmp = tmp->next) - tmp->del = 1; - set_option (OPTFORCEREDRAWINDEX); - } - else - alias_list_wipe(&Aliases); - break; - } - else - for (tmp = Aliases; tmp; tmp = tmp->next) { - if (m_strcasecmp(buf->data, tmp->name) == 0) { - if (CurrentMenu == MENU_ALIAS) { - tmp->del = 1; - set_option (OPTFORCEREDRAWINDEX); + alias_t *tmp, **last; + + do { + mutt_extract_token (buf, s, 0); + + if (!m_strcmp("*", buf->data) == 0) { + if (CurrentMenu == MENU_ALIAS) { + for (tmp = Aliases; tmp; tmp = tmp->next) + tmp->del = 1; + set_option(OPTFORCEREDRAWINDEX); + } else { + alias_list_wipe(&Aliases); + } break; - } + } - if (last) - last->next = tmp->next; - else - Aliases = tmp->next; - tmp->next = NULL; - alias_list_wipe(&tmp); - break; + last = &Aliases; + for (last = &Aliases; *last; last = &(*last)->next) { + if (!m_strcasecmp(buf->data, (*last)->name)) { + if (CurrentMenu == MENU_ALIAS) { + (*last)->del = 1; + set_option (OPTFORCEREDRAWINDEX); + } else { + tmp = alias_list_pop(last); + alias_delete(&tmp); + } + break; + } } - last = tmp; - } - } - while (MoreArgs (s)); - return 0; + } while (MoreArgs(s)); + + return 0; } static int parse_alias (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ ((unused)), BUFFER * err) { - alias_t *tmp = Aliases; - alias_t *last = NULL; - char *estr = NULL; + alias_t **last; + char *estr = NULL; - if (!MoreArgs (s)) { - m_strcpy(err->data, err->dsize, _("alias: no address")); - return (-1); - } + if (!MoreArgs (s)) { + m_strcpy(err->data, err->dsize, _("alias: no address")); + return (-1); + } - mutt_extract_token (buf, s, 0); + mutt_extract_token (buf, s, 0); - /* check to see if an alias with this name already exists */ - for (; tmp; tmp = tmp->next) { - if (!m_strcasecmp(tmp->name, buf->data)) - break; - last = tmp; - } + /* check to see if an alias with this name already exists */ + for (last = &Aliases; *last; last = &(*last)->next) { + if (!m_strcasecmp((*last)->name, buf->data)) + break; + } - if (!tmp) { - /* create a new alias */ - tmp = alias_new(); - tmp->name = m_strdup(buf->data); - /* give the main addressbook code a chance */ - if (CurrentMenu == MENU_ALIAS) - set_option (OPTMENUCALLER); - } - else { - /* override the previous value */ - address_list_wipe(&tmp->addr); - if (CurrentMenu == MENU_ALIAS) - set_option (OPTFORCEREDRAWINDEX); - } + if (!*last) { + /* create a new alias */ + *last = alias_new(); + (*last)->name = m_strdup(buf->data); + /* give the main addressbook code a chance */ + if (CurrentMenu == MENU_ALIAS) + set_option (OPTMENUCALLER); + } else { + /* override the previous value */ + address_list_wipe(&(*last)->addr); + if (CurrentMenu == MENU_ALIAS) + set_option (OPTFORCEREDRAWINDEX); + } - mutt_extract_token (buf, s, - M_TOKEN_QUOTE | M_TOKEN_SPACE | M_TOKEN_SEMICOLON); - tmp->addr = mutt_parse_adrlist (tmp->addr, buf->data); - if (last) - last->next = tmp; - else - Aliases = tmp; - if (mutt_addrlist_to_idna (tmp->addr, &estr)) { - snprintf (err->data, err->dsize, - _("Warning: Bad IDN '%s' in alias '%s'.\n"), estr, tmp->name); - p_delete(&estr); - return -1; - } + mutt_extract_token(buf, s, + M_TOKEN_QUOTE | M_TOKEN_SPACE | M_TOKEN_SEMICOLON); + (*last)->addr = mutt_parse_adrlist((*last)->addr, buf->data); + if (mutt_addrlist_to_idna((*last)->addr, &estr)) { + snprintf (err->data, err->dsize, + _("Warning: Bad IDN '%s' in alias '%s'.\n"), estr, (*last)->name); + p_delete(&estr); + return -1; + } - return 0; + return 0; } static int -parse_unmy_hdr (BUFFER * buf, BUFFER * s, - unsigned long data __attribute__ ((unused)), - BUFFER * err __attribute__ ((unused))) +parse_unmy_hdr(BUFFER * buf, BUFFER * s, + unsigned long data __attribute__ ((unused)), + BUFFER * err __attribute__ ((unused))) { - string_list_t *last = NULL; - string_list_t *tmp = UserHeader; - string_list_t *ptr; - ssize_t l; + do { + mutt_extract_token (buf, s, 0); - do { - mutt_extract_token (buf, s, 0); - if (m_strcmp("*", buf->data) == 0) - string_list_wipe(&UserHeader); - else { - tmp = UserHeader; - last = NULL; - - l = m_strlen(buf->data); - if (buf->data[l - 1] == ':') - l--; - - while (tmp) { - if (ascii_strncasecmp (buf->data, tmp->data, l) == 0 - && tmp->data[l] == ':') { - ptr = tmp; - if (last) - last->next = tmp->next; - else - UserHeader = tmp->next; - tmp = tmp->next; - ptr->next = NULL; - string_list_wipe(&ptr); - } - else { - last = tmp; - tmp = tmp->next; + if (!m_strcmp("*", buf->data)) { + string_list_wipe(&UserHeader); + } else { + string_list_t **last = &UserHeader; + ssize_t l = m_strlen(buf->data); + + if (buf->data[l - 1] == ':') + l--; + + while (*last) { + if (!ascii_strncasecmp(buf->data, (*last)->data, l) + && (*last)->data[l] == ':') + { + string_list_t *tmp = string_list_pop(last); + string_item_delete(&tmp); + } else { + last = &(*last)->next; + } + } } - } - } - } - while (MoreArgs (s)); - return 0; + } while (MoreArgs(s)); + + return 0; } static int parse_my_hdr (BUFFER * buf, BUFFER * s, unsigned long data __attribute__ ((unused)),