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

globals.h
handler.c
init.c
init.h

index d0f632334a8342d9e07172a427cb687d93af34cb..b08add8251310a470635c12301ecfe198ec8349c 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -202,7 +202,7 @@ WHERE struct Hash *TagTransforms;
 WHERE struct Hash *TagFormats;
 #endif
 
-WHERE struct List *AutoViewList;
+WHERE struct STailQHead AutoViewList INITVAL(STAILQ_HEAD_INITIALIZER(AutoViewList));
 WHERE struct List *AlternativeOrderList;
 WHERE struct List *AttachAllow;
 WHERE struct List *AttachExclude;
index 4c1bd8f01e949e033bd5b250e474fbfa7ebb3a29..2396d4e1e60235c1fd4ddba0475621e02ee11f9d 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -1016,16 +1016,18 @@ static int is_autoview(struct Body *b)
   else
   {
     /* determine if this type is on the user's auto_view list */
-    struct List *t = AutoViewList;
-
     mutt_check_lookup_list(b, type, sizeof(type));
-    for (; t; t = t->next)
+    struct STailQNode *np;
+    STAILQ_FOREACH(np, &AutoViewList, entries)
     {
-      int i = mutt_strlen(t->data) - 1;
-      if ((i > 0 && t->data[i - 1] == '/' && t->data[i] == '*' &&
-           (mutt_strncasecmp(type, t->data, i) == 0)) ||
-          (mutt_strcasecmp(type, t->data) == 0))
+      int i = mutt_strlen(np->data) - 1;
+      if ((i > 0 && np->data[i - 1] == '/' && np->data[i] == '*' &&
+           (mutt_strncasecmp(type, np->data, i) == 0)) ||
+          (mutt_strcasecmp(type, np->data) == 0))
+      {
         is_av = 1;
+        break;
+      }
     }
 
     if (is_mmnoask(type))
diff --git a/init.c b/init.c
index 044e16765fe2ed951bdbfe74aeee1b6f0057ba3b..71c3dded51bd02c5350427cae6f152d7af3164bb 100644 (file)
--- a/init.c
+++ b/init.c
@@ -783,6 +783,26 @@ static void add_to_list(struct List **list, const char *str)
   }
 }
 
+static void add_to_stailq(struct STailQHead *head, const char *str)
+{
+  /* don't add a NULL or empty string to the list */
+  if (!str || *str == '\0')
+    return;
+
+  /* check to make sure the item is not already on this list */
+  struct STailQNode *np;
+  STAILQ_FOREACH(np, head, entries)
+  {
+    if (mutt_strcasecmp(str, np->data) == 0)
+    {
+      return;
+    }
+  }
+  np = safe_calloc(1, sizeof(struct STailQNode));
+  np->data = safe_strdup(str);
+  STAILQ_INSERT_TAIL(head, np, entries);
+}
+
 static struct RxList *new_rx_list(void)
 {
   return safe_calloc(1, sizeof(struct RxList));
@@ -1149,6 +1169,59 @@ static int parse_list(struct Buffer *buf, struct Buffer *s, unsigned long data,
   return 0;
 }
 
+static int parse_stailq(struct Buffer *buf, struct Buffer *s, unsigned long data,
+                      struct Buffer *err)
+{
+
+  do
+  {
+    mutt_extract_token(buf, s, 0);
+    add_to_stailq((struct STailQHead *)data, buf->data);
+  } while (MoreArgs(s));
+
+  return 0;
+}
+
+static void remove_from_stailq(struct STailQHead *head, const char *str)
+{
+  if (mutt_strcmp("*", str) == 0)
+    mutt_free_stailq(head); /* ``unCMD *'' means delete all current entries */
+  else
+  {
+    struct STailQNode *np, *tmp;
+    STAILQ_FOREACH_SAFE(np, head, entries, tmp)
+    {
+      if (mutt_strcasecmp(str, np->data) == 0)
+      {
+        STAILQ_REMOVE(head, np, STailQNode, entries);
+        FREE(&np->data);
+        FREE(&np);
+        break;
+      }
+    }
+  }
+}
+
+static int parse_unstailq(struct Buffer *buf, struct Buffer *s,
+                        unsigned long data, struct Buffer *err)
+{
+  do
+  {
+    mutt_extract_token(buf, s, 0);
+    /*
+     * Check for deletion of entire list
+     */
+    if (mutt_strcmp(buf->data, "*") == 0)
+    {
+      mutt_free_stailq((struct STailQHead *)data);
+      break;
+    }
+    remove_from_stailq((struct STailQHead *)data, buf->data);
+  } while (MoreArgs(s));
+
+  return 0;
+}
+
 static void _alternates_clean(void)
 {
   int i;
diff --git a/init.h b/init.h
index c48709cafb18549e1c304f225a28b1b86805250a..f7f86841a77e7ad9bb69ddea89ce4905fb140d35 100644 (file)
--- a/init.h
+++ b/init.h
@@ -4493,10 +4493,14 @@ const struct Mapping SortSidebarMethods[] = {
 
 static int parse_list(struct Buffer *buf, struct Buffer *s, unsigned long data,
                       struct Buffer *err);
+static int parse_stailq(struct Buffer *buf, struct Buffer *s, unsigned long data,
+                      struct Buffer *err);
 static int parse_spam_list(struct Buffer *buf, struct Buffer *s,
                            unsigned long data, struct Buffer *err);
 static int parse_unlist(struct Buffer *buf, struct Buffer *s,
                         unsigned long data, struct Buffer *err);
+static int parse_unstailq(struct Buffer *buf, struct Buffer *s,
+                        unsigned long data, struct Buffer *err);
 #ifdef USE_SIDEBAR
 static int parse_path_list(struct Buffer *buf, struct Buffer *s,
                            unsigned long data, struct Buffer *err);
@@ -4576,7 +4580,7 @@ const struct Command Commands[] = {
   { "alias",            parse_alias,            0 },
   { "attachments",      parse_attachments,      0 },
   { "unattachments",parse_unattachments,0 },
-  { "auto_view",        parse_list,             UL &AutoViewList },
+  { "auto_view",        parse_stailq,           UL &AutoViewList },
   { "alternative_order",        parse_list,     UL &AlternativeOrderList },
   { "bind",             mutt_parse_bind,        0 },
   { "charset-hook",     mutt_parse_hook,        MUTT_CHARSETHOOK },
@@ -4650,7 +4654,7 @@ const struct Command Commands[] = {
   { "toggle",           parse_set,              MUTT_SET_INV },
   { "unalias",          parse_unalias,          0 },
   { "unalternative_order",parse_unlist,         UL &AlternativeOrderList },
-  { "unauto_view",      parse_unlist,           UL &AutoViewList },
+  { "unauto_view",      parse_unstailq,         UL &AutoViewList },
   { "unhdr_order",      parse_unlist,           UL &HeaderOrderList },
   { "unhook",           mutt_parse_unhook,      0 },
   { "unignore",         parse_unignore,         0 },