]> granicus.if.org Git - neomutt/commitdiff
Convert AlternativeOrderList and (Attach|Inline)(Allow|Exclude) to STailQ
authorPietro Cerutti <gahr@gahr.ch>
Tue, 25 Jul 2017 13:33:34 +0000 (13:33 +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
parse.c

index 33f23c3ae7f04e5f5ff7a7cd8c969fdd6c1bbdf9..51566e1fa8aed772baaa3290e46d961de8251589 100644 (file)
--- a/globals.h
+++ b/globals.h
@@ -203,11 +203,11 @@ WHERE struct Hash *TagFormats;
 #endif
 
 WHERE struct STailQHead AutoViewList INITVAL(STAILQ_HEAD_INITIALIZER(AutoViewList));
-WHERE struct List *AlternativeOrderList;
-WHERE struct List *AttachAllow;
-WHERE struct List *AttachExclude;
-WHERE struct List *InlineAllow;
-WHERE struct List *InlineExclude;
+WHERE struct STailQHead AlternativeOrderList INITVAL(STAILQ_HEAD_INITIALIZER(AlternativeOrderList));
+WHERE struct STailQHead AttachAllow INITVAL(STAILQ_HEAD_INITIALIZER(AttachAllow));
+WHERE struct STailQHead AttachExclude INITVAL(STAILQ_HEAD_INITIALIZER(AttachExclude));
+WHERE struct STailQHead InlineAllow INITVAL(STAILQ_HEAD_INITIALIZER(InlineAllow));
+WHERE struct STailQHead InlineExclude INITVAL(STAILQ_HEAD_INITIALIZER(InlineExclude));
 WHERE struct List *HeaderOrderList;
 WHERE struct List *Ignore;
 WHERE struct List *MailToAllow;
index 2396d4e1e60235c1fd4ddba0475621e02ee11f9d..bf3c1dc5d4e0f39d31b8427520ebe0c309eb088d 100644 (file)
--- a/handler.c
+++ b/handler.c
@@ -1051,7 +1051,6 @@ static int alternative_handler(struct Body *a, struct State *s)
 {
   struct Body *choice = NULL;
   struct Body *b = NULL;
-  struct List *t = NULL;
   int type = 0;
   bool mustfree = false;
   int rc = 0;
@@ -1074,23 +1073,23 @@ static int alternative_handler(struct Body *a, struct State *s)
   a = b;
 
   /* First, search list of preferred types */
-  t = AlternativeOrderList;
-  while (t && !choice)
+  struct STailQNode *np;
+  STAILQ_FOREACH(np, &AlternativeOrderList, entries)
   {
     char *c = NULL;
     int btlen; /* length of basetype */
     bool wild; /* do we have a wildcard to match all subtypes? */
 
-    c = strchr(t->data, '/');
+    c = strchr(np->data, '/');
     if (c)
     {
       wild = (c[1] == '*' && c[2] == 0);
-      btlen = c - t->data;
+      btlen = c - np->data;
     }
     else
     {
       wild = true;
-      btlen = mutt_strlen(t->data);
+      btlen = mutt_strlen(np->data);
     }
 
     if (a->parts)
@@ -1100,17 +1099,19 @@ static int alternative_handler(struct Body *a, struct State *s)
     while (b)
     {
       const char *bt = TYPE(b);
-      if ((mutt_strncasecmp(bt, t->data, btlen) == 0) && (bt[btlen] == 0))
+      if ((mutt_strncasecmp(bt, np->data, btlen) == 0) && (bt[btlen] == 0))
       {
         /* the basetype matches */
-        if (wild || (mutt_strcasecmp(t->data + btlen + 1, b->subtype) == 0))
+        if (wild || (mutt_strcasecmp(np->data + btlen + 1, b->subtype) == 0))
         {
           choice = b;
         }
       }
       b = b->next;
     }
-    t = t->next;
+
+    if (choice)
+      break;
   }
 
   /* Next, look for an autoviewable type */
diff --git a/init.c b/init.c
index d3410ca7c7f34aa5a416270d5d3335760af79306..900de882ebdc21effb61a896bd09d6f9cd14dea2 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1632,26 +1632,14 @@ static void _attachments_clean(void)
 }
 
 static int parse_attach_list(struct Buffer *buf, struct Buffer *s,
-                             struct List **ldata, struct Buffer *err)
+                             struct STailQHead *head, struct Buffer *err)
 {
   struct AttachMatch *a = NULL;
-  struct List *listp = NULL, *lastp = NULL;
   char *p = NULL;
   char *tmpminor = NULL;
   int len;
   int ret;
 
-  /* Find the last item in the list that data points to. */
-  lastp = NULL;
-  mutt_debug(5, "parse_attach_list: ldata = %p, *ldata = %p\n", (void *) ldata,
-             (void *) *ldata);
-  for (listp = *ldata; listp; listp = listp->next)
-  {
-    a = (struct AttachMatch *) listp->data;
-    mutt_debug(5, "parse_attach_list: skipping %s/%s\n", a->major, a->minor);
-    lastp = listp;
-  }
-
   do
   {
     mutt_extract_token(buf, s, 0);
@@ -1702,18 +1690,7 @@ static int parse_attach_list(struct Buffer *buf, struct Buffer *s,
 
     mutt_debug(5, "parse_attach_list: added %s/%s [%d]\n", a->major, a->minor, a->major_int);
 
-    listp = safe_malloc(sizeof(struct List));
-    listp->data = (char *) a;
-    listp->next = NULL;
-    if (lastp)
-    {
-      lastp->next = listp;
-    }
-    else
-    {
-      *ldata = listp;
-    }
-    lastp = listp;
+    mutt_stailq_insert_tail(head, (char *)a);
   } while (MoreArgs(s));
 
   _attachments_clean();
@@ -1721,10 +1698,9 @@ static int parse_attach_list(struct Buffer *buf, struct Buffer *s,
 }
 
 static int parse_unattach_list(struct Buffer *buf, struct Buffer *s,
-                               struct List **ldata, struct Buffer *err)
+                               struct STailQHead *head, struct Buffer *err)
 {
   struct AttachMatch *a = NULL;
-  struct List *lp = NULL, *lastp = NULL, *newlp = NULL;
   char *tmp = NULL;
   int major;
   char *minor = NULL;
@@ -1752,12 +1728,10 @@ static int parse_unattach_list(struct Buffer *buf, struct Buffer *s,
     }
     major = mutt_check_mime_type(tmp);
 
-    /* We must do our own walk here because remove_from_list() will only
-     * remove the List->data, not anything pointed to by the List->data. */
-    lastp = NULL;
-    for (lp = *ldata; lp;)
+    struct STailQNode *np, *tmp2;
+    STAILQ_FOREACH_SAFE(np, head, entries, tmp2)
     {
-      a = (struct AttachMatch *) lp->data;
+      a = (struct AttachMatch *) np->data;
       mutt_debug(5, "parse_unattach_list: check %s/%s [%d] : %s/%s [%d]\n",
                  a->major, a->minor, a->major_int, tmp, minor, major);
       if (a->major_int == major && (mutt_strcasecmp(minor, a->minor) == 0))
@@ -1766,22 +1740,10 @@ static int parse_unattach_list(struct Buffer *buf, struct Buffer *s,
                    a->minor, a->major_int);
         regfree(&a->minor_rx);
         FREE(&a->major);
-
-        /* Relink backward */
-        if (lastp)
-          lastp->next = lp->next;
-        else
-          *ldata = lp->next;
-
-        newlp = lp->next;
-        FREE(&lp->data); /* same as a */
-        FREE(&lp);
-        lp = newlp;
-        continue;
+        STAILQ_REMOVE(head, np, STailQNode, entries);
+        FREE(&np->data);
+        FREE(&np);
       }
-
-      lastp = lp;
-      lp = lp->next;
     }
 
   } while (MoreArgs(s));
@@ -1791,14 +1753,14 @@ static int parse_unattach_list(struct Buffer *buf, struct Buffer *s,
   return 0;
 }
 
-static int print_attach_list(struct List *lp, char op, char *name)
+static int print_attach_list(struct STailQHead *h, char op, char *name)
 {
-  while (lp)
+  struct STailQNode *np;
+  STAILQ_FOREACH(np, h, entries)
   {
     printf("attachments %c%s %s/%s\n", op, name,
-           ((struct AttachMatch *) lp->data)->major,
-           ((struct AttachMatch *) lp->data)->minor);
-    lp = lp->next;
+           ((struct AttachMatch *) np->data)->major,
+           ((struct AttachMatch *) np->data)->minor);
   }
 
   return 0;
@@ -1808,7 +1770,7 @@ static int parse_attachments(struct Buffer *buf, struct Buffer *s,
                              unsigned long data, struct Buffer *err)
 {
   char op, *category = NULL;
-  struct List **listp = NULL;
+  struct STailQHead *headp = NULL;
 
   mutt_extract_token(buf, s, 0);
   if (!buf->data || *buf->data == '\0')
@@ -1825,10 +1787,10 @@ static int parse_attachments(struct Buffer *buf, struct Buffer *s,
     mutt_endwin(NULL);
     fflush(stdout);
     printf(_("\nCurrent attachments settings:\n\n"));
-    print_attach_list(AttachAllow, '+', "A");
-    print_attach_list(AttachExclude, '-', "A");
-    print_attach_list(InlineAllow, '+', "I");
-    print_attach_list(InlineExclude, '-', "I");
+    print_attach_list(&AttachAllow, '+', "A");
+    print_attach_list(&AttachExclude, '-', "A");
+    print_attach_list(&InlineAllow, '+', "I");
+    print_attach_list(&InlineExclude, '-', "I");
     mutt_any_key_to_continue(NULL);
     return 0;
   }
@@ -1841,16 +1803,16 @@ static int parse_attachments(struct Buffer *buf, struct Buffer *s,
   if (mutt_strncasecmp(category, "attachment", strlen(category)) == 0)
   {
     if (op == '+')
-      listp = &AttachAllow;
+      headp = &AttachAllow;
     else
-      listp = &AttachExclude;
+      headp = &AttachExclude;
   }
   else if (mutt_strncasecmp(category, "inline", strlen(category)) == 0)
   {
     if (op == '+')
-      listp = &InlineAllow;
+      headp = &InlineAllow;
     else
-      listp = &InlineExclude;
+      headp = &InlineExclude;
   }
   else
   {
@@ -1858,14 +1820,14 @@ static int parse_attachments(struct Buffer *buf, struct Buffer *s,
     return -1;
   }
 
-  return parse_attach_list(buf, s, listp, err);
+  return parse_attach_list(buf, s, headp, err);
 }
 
 static int parse_unattachments(struct Buffer *buf, struct Buffer *s,
                                unsigned long data, struct Buffer *err)
 {
   char op, *p = NULL;
-  struct List **listp = NULL;
+  struct STailQHead *head = NULL;
 
   mutt_extract_token(buf, s, 0);
   if (!buf->data || *buf->data == '\0')
@@ -1884,16 +1846,16 @@ static int parse_unattachments(struct Buffer *buf, struct Buffer *s,
   if (mutt_strncasecmp(p, "attachment", strlen(p)) == 0)
   {
     if (op == '+')
-      listp = &AttachAllow;
+      head = &AttachAllow;
     else
-      listp = &AttachExclude;
+      head = &AttachExclude;
   }
   else if (mutt_strncasecmp(p, "inline", strlen(p)) == 0)
   {
     if (op == '+')
-      listp = &InlineAllow;
+      head = &InlineAllow;
     else
-      listp = &InlineExclude;
+      head = &InlineExclude;
   }
   else
   {
@@ -1901,7 +1863,7 @@ static int parse_unattachments(struct Buffer *buf, struct Buffer *s,
     return -1;
   }
 
-  return parse_unattach_list(buf, s, listp, err);
+  return parse_unattach_list(buf, s, head, err);
 }
 
 static int parse_unlists(struct Buffer *buf, struct Buffer *s,
diff --git a/init.h b/init.h
index f7f86841a77e7ad9bb69ddea89ce4905fb140d35..869c9e7ba59de8cbee59d5302bbc00c3b165bac5 100644 (file)
--- a/init.h
+++ b/init.h
@@ -4581,7 +4581,7 @@ const struct Command Commands[] = {
   { "attachments",      parse_attachments,      0 },
   { "unattachments",parse_unattachments,0 },
   { "auto_view",        parse_stailq,           UL &AutoViewList },
-  { "alternative_order",        parse_list,     UL &AlternativeOrderList },
+  { "alternative_order",parse_stailq,           UL &AlternativeOrderList },
   { "bind",             mutt_parse_bind,        0 },
   { "charset-hook",     mutt_parse_hook,        MUTT_CHARSETHOOK },
 #ifdef HAVE_COLOR
@@ -4653,7 +4653,7 @@ const struct Command Commands[] = {
   { "timeout-hook",     mutt_parse_hook,        MUTT_TIMEOUTHOOK | MUTT_GLOBALHOOK },
   { "toggle",           parse_set,              MUTT_SET_INV },
   { "unalias",          parse_unalias,          0 },
-  { "unalternative_order",parse_unlist,         UL &AlternativeOrderList },
+  { "unalternative_order",parse_unstailq,       UL &AlternativeOrderList },
   { "unauto_view",      parse_unstailq,         UL &AutoViewList },
   { "unhdr_order",      parse_unlist,           UL &HeaderOrderList },
   { "unhook",           mutt_parse_unhook,      0 },
diff --git a/parse.c b/parse.c
index bf1a726d9e9245a0c8b46edc474c5c4bc65734f0..c6e3e188562a1d6926996f2ba72db62879be6f3a 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -1538,20 +1538,20 @@ struct Address *mutt_parse_adrlist(struct Address *p, const char *s)
 /**
  * count_body_parts_check - Compares mime types to the ok and except lists
  */
-static bool count_body_parts_check(struct List **checklist, struct Body *b, bool dflt)
+static bool count_body_parts_check(struct STailQHead *checklist, struct Body *b, bool dflt)
 {
-  struct List *type = NULL;
   struct AttachMatch *a = NULL;
 
   /* If list is null, use default behavior. */
-  if (!*checklist)
+  if (!checklist || STAILQ_EMPTY(checklist))
   {
     return false;
   }
 
-  for (type = *checklist; type; type = type->next)
+  struct STailQNode *np;
+  STAILQ_FOREACH(np, checklist, entries)
   {
-    a = (struct AttachMatch *) type->data;
+    a = (struct AttachMatch *) np->data;
     mutt_debug(5, "cbpc: %s %d/%s ?? %s/%s [%d]... ",
                dflt ? "[OK]   " : "[EXCL] ", b->type,
                b->subtype ? b->subtype : "*", a->major, a->minor, a->major_int);
@@ -1684,8 +1684,11 @@ int mutt_count_body_parts(struct Context *ctx, struct Header *hdr)
   else
     mutt_parse_mime_message(ctx, hdr);
 
-  if (AttachAllow || AttachExclude || InlineAllow || InlineExclude)
+  if (!STAILQ_EMPTY(&AttachAllow) || !STAILQ_EMPTY(&AttachExclude) ||
+      !STAILQ_EMPTY(&InlineAllow) || !STAILQ_EMPTY(&InlineExclude))
+  {
     hdr->attach_total = count_body_parts(hdr->content, MUTT_PARTS_TOPLEVEL);
+  }
   else
     hdr->attach_total = 0;