]> granicus.if.org Git - neomutt/commitdiff
Convert MailtoAllow, MimeLookupList and SidebarWhitelist to STailQ
authorPietro Cerutti <gahr@gahr.ch>
Tue, 25 Jul 2017 14:21:01 +0000 (14:21 +0000)
committerRichard Russon <rich@flatcap.org>
Sat, 5 Aug 2017 17:53:06 +0000 (18:53 +0100)
Issue #374

attach.c
globals.h
init.c
init.h
sidebar.c
url.c

index 9a5f72b367d170a014c2f81327018f7c8e08a51a..71a60c5cb847d718cbf63d6e99b0f349bb6243b4 100644 (file)
--- a/attach.c
+++ b/attach.c
@@ -307,15 +307,15 @@ bailout:
  */
 void mutt_check_lookup_list(struct Body *b, char *type, int len)
 {
-  struct List *t = MimeLookupList;
   int i;
 
-  for (; t; t = t->next)
+  struct STailQNode *np;
+  STAILQ_FOREACH(np, &MimeLookupList, entries)
   {
-    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))
+    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))
     {
       struct Body tmp = { 0 };
       int n;
index 7118f5b41320e03981b3a1793d47875a2bc89288..8dd728bce5dddf29d48a5c36bb3cb8533c3659cd 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -210,8 +210,8 @@ WHERE struct STailQHead InlineAllow INITVAL(STAILQ_HEAD_INITIALIZER(InlineAllow)
 WHERE struct STailQHead InlineExclude INITVAL(STAILQ_HEAD_INITIALIZER(InlineExclude));
 WHERE struct STailQHead HeaderOrderList INITVAL(STAILQ_HEAD_INITIALIZER(HeaderOrderList));
 WHERE struct STailQHead Ignore INITVAL(STAILQ_HEAD_INITIALIZER(Ignore));
-WHERE struct List *MailToAllow;
-WHERE struct List *MimeLookupList;
+WHERE struct STailQHead MailToAllow INITVAL(STAILQ_HEAD_INITIALIZER(MailToAllow));
+WHERE struct STailQHead MimeLookupList INITVAL(STAILQ_HEAD_INITIALIZER(MimeLookupList));
 WHERE struct STailQHead UnIgnore INITVAL(STAILQ_HEAD_INITIALIZER(UnIgnore));
 
 WHERE struct RxList *Alternates;
@@ -266,7 +266,7 @@ WHERE short ScoreThresholdFlag;
 
 #ifdef USE_SIDEBAR
 WHERE short SidebarWidth;
-WHERE struct List *SidebarWhitelist;
+WHERE struct STailQHead SidebarWhitelist INITVAL(STAILQ_HEAD_INITIALIZER(SidebarWhitelist));
 #endif
 
 #ifdef USE_IMAP
diff --git a/init.c b/init.c
index 95ae3f57b6c1140a7d39ae39a94ebecfb528539e..9fbcff9184eb3bc5e516ca87bd19347a52b2a82a 100644 (file)
--- a/init.c
+++ b/init.c
@@ -748,41 +748,6 @@ void mutt_free_opts(void)
   mutt_free_rx_list(&NoSpamList);
 }
 
-static void add_to_list(struct List **list, const char *str)
-{
-  struct List *t = NULL, *last = NULL;
-
-  /* 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 */
-  for (last = *list; last; last = last->next)
-  {
-    if (mutt_strcasecmp(str, last->data) == 0)
-    {
-      /* already on the list, so just ignore it */
-      last = NULL;
-      break;
-    }
-    if (!last->next)
-      break;
-  }
-
-  if (!*list || last)
-  {
-    t = safe_calloc(1, sizeof(struct List));
-    t->data = safe_strdup(str);
-    if (last)
-    {
-      last->next = t;
-      last = last->next;
-    }
-    else
-      *list = last = t;
-  }
-}
-
 static void add_to_stailq(struct STailQHead *head, const char *str)
 {
   /* don't add a NULL or empty string to the list */
@@ -977,36 +942,6 @@ static int add_to_replace_list(struct ReplaceList **list, const char *pat,
   return 0;
 }
 
-static void remove_from_list(struct List **l, const char *str)
-{
-  struct List *p = NULL, *last = NULL;
-
-  if (mutt_strcmp("*", str) == 0)
-    mutt_free_list(l); /* ``unCMD *'' means delete all current entries */
-  else
-  {
-    p = *l;
-    last = NULL;
-    while (p)
-    {
-      if (mutt_strcasecmp(str, p->data) == 0)
-      {
-        FREE(&p->data);
-        if (last)
-          last->next = p->next;
-        else
-          (*l) = p->next;
-        FREE(&p);
-      }
-      else
-      {
-        last = p;
-        p = p->next;
-      }
-    }
-  }
-}
-
 /**
  * finish_source - 'finish' command: stop processing current config file
  * @param tmp  Temporary space shared by all command handlers
@@ -1175,18 +1110,6 @@ static int parse_ignore(struct Buffer *buf, struct Buffer *s,
   return 0;
 }
 
-static int parse_list(struct Buffer *buf, struct Buffer *s, unsigned long data,
-                      struct Buffer *err)
-{
-  do
-  {
-    mutt_extract_token(buf, s, 0);
-    add_to_list((struct List **) data, buf->data);
-  } while (MoreArgs(s));
-
-  return 0;
-}
-
 static int parse_stailq(struct Buffer *buf, struct Buffer *s, unsigned long data,
                       struct Buffer *err)
 {
@@ -1445,26 +1368,6 @@ static int parse_spam_list(struct Buffer *buf, struct Buffer *s,
   return -1;
 }
 
-static int parse_unlist(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_list((struct List **) data);
-      break;
-    }
-    remove_from_list((struct List **) data, buf->data);
-  } while (MoreArgs(s));
-
-  return 0;
-}
-
 #ifdef USE_SIDEBAR
 static int parse_path_list(struct Buffer *buf, struct Buffer *s,
                            unsigned long data, struct Buffer *err)
@@ -1476,7 +1379,7 @@ static int parse_path_list(struct Buffer *buf, struct Buffer *s,
     mutt_extract_token(buf, s, 0);
     strfcpy(path, buf->data, sizeof(path));
     mutt_expand_path(path, sizeof(path));
-    add_to_list((struct List **) data, path);
+    add_to_stailq((struct STailQHead *) data, path);
   } while (MoreArgs(s));
 
   return 0;
@@ -1495,12 +1398,12 @@ static int parse_path_unlist(struct Buffer *buf, struct Buffer *s,
      */
     if (mutt_strcmp(buf->data, "*") == 0)
     {
-      mutt_free_list((struct List **) data);
+      mutt_stailq_free((struct STailQHead *) data);
       break;
     }
     strfcpy(path, buf->data, sizeof(path));
     mutt_expand_path(path, sizeof(path));
-    remove_from_list((struct List **) data, path);
+    remove_from_stailq((struct STailQHead *) data, path);
   } while (MoreArgs(s));
 
   return 0;
@@ -4430,13 +4333,13 @@ void mutt_init(int skip_sys_rc, struct List *commands)
    * create RFC822-compliant mail messages using the "subject" and "body"
    * headers.
    */
-  add_to_list(&MailToAllow, "body");
-  add_to_list(&MailToAllow, "subject");
+  add_to_stailq(&MailToAllow, "body");
+  add_to_stailq(&MailToAllow, "subject");
   /* Cc, In-Reply-To, and References help with not breaking threading on
    * mailing lists, see https://github.com/neomutt/neomutt/issues/115 */
-  add_to_list(&MailToAllow, "cc");
-  add_to_list(&MailToAllow, "in-reply-to");
-  add_to_list(&MailToAllow, "references");
+  add_to_stailq(&MailToAllow, "cc");
+  add_to_stailq(&MailToAllow, "in-reply-to");
+  add_to_stailq(&MailToAllow, "references");
 
   struct STailQNode *np = NULL;
   if (STAILQ_EMPTY(&Muttrc))
diff --git a/init.h b/init.h
index 0bc4be694f4db9edc64ad5de7e3c0b5f678d1279..727aa3d8e210bc243cd12a4448c13a4079c011db 100644 (file)
--- a/init.h
+++ b/init.h
@@ -4491,14 +4491,10 @@ const struct Mapping SortSidebarMethods[] = {
 
 /* functions used to parse commands in a rc file */
 
-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
@@ -4619,12 +4615,12 @@ const struct Command Commands[] = {
   { "tag-transforms",   parse_tag_transforms,   0 },
   { "tag-formats",      parse_tag_formats,      0 },
 #endif
-  { "mailto_allow",     parse_list,             UL &MailToAllow },
-  { "unmailto_allow",   parse_unlist,           UL &MailToAllow },
+  { "mailto_allow",     parse_stailq,           UL &MailToAllow },
+  { "unmailto_allow",   parse_unstailq,         UL &MailToAllow },
   { "message-hook",     mutt_parse_hook,        MUTT_MESSAGEHOOK },
   { "mbox-hook",        mutt_parse_hook,        MUTT_MBOXHOOK },
-  { "mime_lookup",      parse_list,     UL &MimeLookupList },
-  { "unmime_lookup",    parse_unlist,   UL &MimeLookupList },
+  { "mime_lookup",      parse_stailq,           UL &MimeLookupList },
+  { "unmime_lookup",    parse_unstailq,         UL &MimeLookupList },
   { "mono",             mutt_parse_mono,        0 },
   { "my_hdr",           parse_my_hdr,           0 },
   { "pgp-hook",         mutt_parse_hook,        MUTT_CRYPTHOOK },
index 438a137ca8ef317a1ea84cc0809190ca9500bef6..9949539f801b17dccd58f819f0a88a6a077ec65a 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -369,8 +369,8 @@ static void update_entries_visibility(void)
       /* Spool directory */
       continue;
 
-    if (mutt_find_list(SidebarWhitelist, sbe->buffy->path) ||
-        mutt_find_list(SidebarWhitelist, sbe->buffy->desc))
+    if (mutt_stailq_find(&SidebarWhitelist, sbe->buffy->path) ||
+        mutt_stailq_find(&SidebarWhitelist, sbe->buffy->desc))
       /* Explicitly asked to be visible */
       continue;
 
diff --git a/url.c b/url.c
index 02c208be36a954c1ffe34657ab22e837a5a02b1d..580f211169c5962f078e27501c4310ca7653f9d6 100644 (file)
--- a/url.c
+++ b/url.c
@@ -313,7 +313,7 @@ int url_parse_mailto(struct Envelope *e, char **body, const char *src)
      * choose to create a message with only a subset of the headers given in
      * the URL.
      */
-    if (mutt_matches_list(tag, MailToAllow))
+    if (mutt_stailq_match(tag, &MailToAllow))
     {
       if (mutt_strcasecmp(tag, "body") == 0)
       {