From: Pietro Cerutti Date: Mon, 24 Jul 2017 14:49:06 +0000 (+0000) Subject: Convert MuttrcStack to STailQ X-Git-Tag: neomutt-20170907~35^2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4399aa9f30d32c625fb8da72f21f0296b24539b3;p=neomutt Convert MuttrcStack to STailQ Issue #374 --- diff --git a/init.c b/init.c index 0715a3551..044e16765 100644 --- a/init.c +++ b/init.c @@ -3168,10 +3168,9 @@ static int parse_set(struct Buffer *tmp, struct Buffer *s, unsigned long data, return r; } -/* Stack structure - * FILO designed to contain the list of config files that have been sourced - * and avoid cyclic sourcing */ -static struct List *MuttrcStack; +/* FILO designed to contain the list of config files that have been sourced and + * avoid cyclic sourcing */ +static struct STailQHead MuttrcStack = STAILQ_HEAD_INITIALIZER(MuttrcStack); /** * to_absolute_path - Convert relative filepath to an absolute path @@ -3245,15 +3244,25 @@ static int source_rc(const char *rcfile_path, struct Buffer *err) if (rcfile[rcfilelen - 1] != '|') { - if (!to_absolute_path(rcfile, mutt_front_list(MuttrcStack))) + struct STailQNode *np = STAILQ_FIRST(&MuttrcStack); + if (!to_absolute_path(rcfile, np ? NONULL(np->data) : "")) { mutt_error("Error: impossible to build path of '%s'.", rcfile_path); return -1; } - if (!MuttrcStack || mutt_find_list(MuttrcStack, rcfile) == NULL) + STAILQ_FOREACH(np, &MuttrcStack, entries) { - mutt_push_list(&MuttrcStack, rcfile); + if (mutt_strcmp(np->data, rcfile) == 0) + { + break; + } + } + if (!np) + { + np = safe_calloc(1, sizeof(struct STailQNode)); + np->data = safe_strdup(rcfile); + STAILQ_INSERT_HEAD(&MuttrcStack, np, entries); } else { @@ -3338,7 +3347,10 @@ static int source_rc(const char *rcfile_path, struct Buffer *err) } } - mutt_pop_list(&MuttrcStack); + if (!STAILQ_EMPTY(&MuttrcStack)) + { + STAILQ_REMOVE_HEAD(&MuttrcStack, entries); + } return rc; } diff --git a/mutt.h b/mutt.h index 66bae4d34..1bf4291a0 100644 --- a/mutt.h +++ b/mutt.h @@ -327,11 +327,6 @@ struct List *mutt_find_list(struct List *l, const char *data); struct STailQNode *mutt_find_stailq(struct STailQHead *h, const char *data); int mutt_remove_from_rx_list(struct RxList **l, const char *str); -/* handle stack */ -void mutt_push_list(struct List **head, const char *data); -bool mutt_pop_list(struct List **head); -const char *mutt_front_list(struct List *head); - void mutt_init(int skip_sys_rc, struct List *commands); /* flag to mutt_pattern_comp() */ diff --git a/muttlib.c b/muttlib.c index ec83acce3..e901a8157 100644 --- a/muttlib.c +++ b/muttlib.c @@ -300,33 +300,6 @@ struct STailQNode *mutt_find_stailq(struct STailQHead *h, const char *data) return NULL; } -void mutt_push_list(struct List **head, const char *data) -{ - struct List *tmp = NULL; - tmp = safe_malloc(sizeof(struct List)); - tmp->data = safe_strdup(data); - tmp->next = *head; - *head = tmp; -} - -bool mutt_pop_list(struct List **head) -{ - struct List *elt = *head; - if (!elt) - return false; - *head = elt->next; - FREE(&elt->data); - FREE(&elt); - return true; -} - -const char *mutt_front_list(struct List *head) -{ - if (!head || !head->data) - return ""; - return head->data; -} - int mutt_remove_from_rx_list(struct RxList **l, const char *str) { struct RxList *p = NULL, *last = NULL;