From 92e2868f260cc58d5dbfbdb93102598ac7940a9f Mon Sep 17 00:00:00 2001 From: Pietro Cerutti Date: Mon, 24 Jul 2017 16:07:37 +0000 Subject: [PATCH] Convert AutoViewList to STailQ Issue #374 --- globals.h | 2 +- handler.c | 16 ++++++------ init.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ init.h | 8 ++++-- 4 files changed, 89 insertions(+), 10 deletions(-) diff --git a/globals.h b/globals.h index d0f632334..b08add825 100644 --- 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; diff --git a/handler.c b/handler.c index 4c1bd8f01..2396d4e1e 100644 --- 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 044e16765..71c3dded5 100644 --- 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 c48709caf..f7f86841a 100644 --- 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 }, -- 2.49.0