]> granicus.if.org Git - neomutt/commitdiff
Convert MuttrcStack to STailQ
authorPietro Cerutti <gahr@gahr.ch>
Mon, 24 Jul 2017 14:49:06 +0000 (14:49 +0000)
committerRichard Russon <rich@flatcap.org>
Sat, 5 Aug 2017 17:53:06 +0000 (18:53 +0100)
Issue #374

init.c
mutt.h
muttlib.c

diff --git a/init.c b/init.c
index 0715a3551c48586cec0401100588da042066a53b..044e16765fe2ed951bdbfe74aeee1b6f0057ba3b 100644 (file)
--- 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 66bae4d34a28422e259f1a29c7a4d72029f77293..1bf4291a0d8309ed6714b4250fb1f1820d44de1b 100644 (file)
--- 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() */
index ec83acce3c16eae4f1ac323a8824e83539e889c5..e901a8157ed4ad09c4e65f446d24988630c5b25c 100644 (file)
--- 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;