X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=init.c;h=2889e5ea068b2cbf210b75404019020696c41ede;hp=94c82b2e6fb6e4fa5110eaea3e5b33906a549d1f;hb=76f757084ec84861326ef36977c6e116da9a1432;hpb=b218f5706bf6bf15bd59a58d9d8d18df17f0b7c9 diff --git a/init.c b/init.c index 94c82b2..2889e5e 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) @@ -755,9 +732,8 @@ static int parse_ignore (BUFFER * buf, BUFFER * s, return 0; } -static int parse_list (BUFFER * buf, BUFFER * s, - unsigned long data __attribute__ ((unused)), - BUFFER * err __attribute__ ((unused))) +static int parse_list(BUFFER * buf, BUFFER * s, unsigned long data, + BUFFER * err __attribute__ ((unused))) { do { mutt_extract_token (buf, s, 0); @@ -1206,142 +1182,117 @@ 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); + (*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); - 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); + do { + mutt_extract_token (buf, s, 0); + + 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; + } + } } - else { - last = tmp; - tmp = tmp->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)), @@ -1975,7 +1926,7 @@ static int parse_source (BUFFER * tmp, BUFFER * s, every call to this function. err where to write error messages */ -int mutt_parse_rc_line ( /* const */ char *line, BUFFER * token, BUFFER * err) +int mutt_parse_rc_line (const char *line, BUFFER * token, BUFFER * err) { int i, r = -1; BUFFER expn; @@ -2353,6 +2304,9 @@ static int mutt_execute_commands (string_list_t * p) return 0; } +#include "parse.h" +#include "rcparser.h" + void mutt_init (int skip_sys_rc, string_list_t * commands) { struct passwd *pw; @@ -2565,6 +2519,40 @@ void mutt_init (int skip_sys_rc, string_list_t * commands) } } +#if 0 + { + void *parser = rcparseAlloc(malloc); + struct rcstate state; + segment s1 = {" ", 1}; + segment s2 = {"toto", 4 }; + segment s3 = {"titi", 4 }; + segment s4 = {"\"", 1 }; + segment s5 = {"index_format", 12 }; + + mutt_endwin(NULL); + + p_clear(&state, 1); + + rcparseTrace(stderr, "> "); + rcparse(parser, RCTK_ALTERNATIVE_ORDER, s1, &state); + rcparse(parser, RCTK_SPACE, s1, &state); + rcparse(parser, RCTK_ATOM, s2, &state); + rcparse(parser, RCTK_SPACE, s1, &state); + rcparse(parser, RCTK_DQUOTE, s4, &state); + rcparse(parser, RCTK_ATOM, s3, &state); + rcparse(parser, RCTK_SPACE, s1, &state); + rcparse(parser, RCTK_ATOM, s3, &state); + rcparse(parser, RCTK_DQUOTE, s4, &state); + rcparse(parser, RCTK_SPACE, s1, &state); + rcparse(parser, RCTK_DOLLAR, s1, &state); + rcparse(parser, RCTK_ATOM, s5, &state); + rcparse(parser, RCTK_NL, s1, &state); + rcparse(parser, 0, s1, &state); + + exit(0); + } +#endif + /* Read the user's initialization file. */ if (access (Muttrc, F_OK) != -1) { if (!option (OPTNOCURSES))