int *ColorQuote = NULL;
int ColorQuoteUsed;
int ColorDefs[MT_COLOR_MAX];
-struct ColorLine *ColorHdrList = NULL;
-struct ColorLine *ColorBodyList = NULL;
-struct ColorLine *ColorAttachList = NULL;
-struct ColorLine *ColorStatusList = NULL;
-struct ColorLine *ColorIndexList = NULL;
-struct ColorLine *ColorIndexAuthorList = NULL;
-struct ColorLine *ColorIndexFlagsList = NULL;
-struct ColorLine *ColorIndexSubjectList = NULL;
-struct ColorLine *ColorIndexTagList = NULL;
+struct ColorLineHead ColorHdrList = STAILQ_HEAD_INITIALIZER(ColorHdrList);
+struct ColorLineHead ColorBodyList = STAILQ_HEAD_INITIALIZER(ColorBodyList);
+struct ColorLineHead ColorAttachList = STAILQ_HEAD_INITIALIZER(ColorAttachList);
+struct ColorLineHead ColorStatusList = STAILQ_HEAD_INITIALIZER(ColorStatusList);
+struct ColorLineHead ColorIndexList = STAILQ_HEAD_INITIALIZER(ColorIndexList);
+struct ColorLineHead ColorIndexAuthorList = STAILQ_HEAD_INITIALIZER(ColorIndexAuthorList);
+struct ColorLineHead ColorIndexFlagsList = STAILQ_HEAD_INITIALIZER(ColorIndexFlagsList);
+struct ColorLineHead ColorIndexSubjectList = STAILQ_HEAD_INITIALIZER(ColorIndexSubjectList);
+struct ColorLineHead ColorIndexTagList = STAILQ_HEAD_INITIALIZER(ColorIndexTagList);
/* local to this file */
static int ColorQuoteSize;
return p;
}
-static void free_color_line(struct ColorLine **l, int free_colors)
+static void free_color_line(struct ColorLine *tmp, int free_colors)
{
- struct ColorLine *tmp = NULL;
-
- if (!l || !*l)
+ if (!tmp)
return;
- tmp = *l;
-
#ifdef HAVE_COLOR
if (free_colors && tmp->fg != -1 && tmp->bg != -1)
mutt_free_color(tmp->fg, tmp->bg);
regfree(&tmp->regex);
mutt_pattern_free(&tmp->color_pattern);
FREE(&tmp->pattern);
- FREE(l);
+ FREE(&tmp);
}
void ci_start_color(void)
#endif
static void do_uncolor(struct Buffer *buf, struct Buffer *s,
- struct ColorLine **cl, int *do_cache, bool parse_uncolor)
+ struct ColorLineHead *cl, int *do_cache, bool parse_uncolor)
{
- struct ColorLine *tmp = NULL, *last = NULL;
-
+ struct ColorLine *np = NULL, *tmp = NULL;
do
{
mutt_extract_token(buf, s, 0);
if (mutt_strcmp("*", buf->data) == 0)
{
- for (tmp = *cl; tmp;)
+ np = STAILQ_FIRST(cl);
+ while (np)
{
+ tmp = STAILQ_NEXT(np, entries);
if (!*do_cache)
{
*do_cache = 1;
}
- last = tmp;
- tmp = tmp->next;
- free_color_line(&last, parse_uncolor);
+ free_color_line(np, parse_uncolor);
+ np = tmp;
}
- *cl = NULL;
+ STAILQ_INIT(cl);
+ return;
}
else
{
- for (last = NULL, tmp = *cl; tmp; last = tmp, tmp = tmp->next)
+ tmp = NULL;
+ STAILQ_FOREACH(np, cl, entries)
{
- if (mutt_strcmp(buf->data, tmp->pattern) == 0)
+ if (mutt_strcmp(buf->data, np->pattern) == 0)
{
if (!*do_cache)
{
*do_cache = 1;
}
mutt_debug(1, "Freeing pattern \"%s\" from ColorList\n", tmp->pattern);
- if (last)
- {
- last->next = tmp->next;
- }
+ if (tmp)
+ STAILQ_REMOVE_AFTER(cl, tmp, entries);
else
- {
- *cl = tmp->next;
- }
- free_color_line(&tmp, parse_uncolor);
+ STAILQ_REMOVE_HEAD(cl, entries);
+ free_color_line(np, parse_uncolor);
break;
}
+ tmp = np;
}
}
} while (MoreArgs(s));
return _mutt_parse_uncolor(buf, s, data, err, 0);
}
-static int add_pattern(struct ColorLine **top, const char *s, int sensitive, int fg,
+static int add_pattern(struct ColorLineHead *top, const char *s, int sensitive, int fg,
int bg, int attr, struct Buffer *err, int is_index, int match)
{
/* is_index used to store compiled pattern
* only for `index' color object
* when called from mutt_parse_color() */
- struct ColorLine *tmp = *top;
+ struct ColorLine *tmp = NULL;
- while (tmp)
+ STAILQ_FOREACH(tmp, top, entries)
{
if (sensitive)
{
if (mutt_strcasecmp(s, tmp->pattern) == 0)
break;
}
- tmp = tmp->next;
}
if (tmp)
mutt_check_simple(buf, sizeof(buf), NONULL(SimpleSearch));
if ((tmp->color_pattern = mutt_pattern_comp(buf, MUTT_FULL_MSG, err)) == NULL)
{
- free_color_line(&tmp, 1);
+ free_color_line(tmp, 1);
return -1;
}
/* force re-caching of index colors */
else if ((r = REGCOMP(&tmp->regex, s, (sensitive ? mutt_which_case(s) : REG_ICASE))) != 0)
{
regerror(r, &tmp->regex, err->data, err->dsize);
- free_color_line(&tmp, 1);
+ free_color_line(tmp, 1);
return -1;
}
- tmp->next = *top;
tmp->pattern = safe_strdup(s);
tmp->match = match;
#ifdef HAVE_COLOR
}
#endif
tmp->pair = attr;
- *top = tmp;
+ STAILQ_INSERT_HEAD(top, tmp, entries);
}
return 0;
static int get_color(int index, unsigned char *s)
{
- struct ColorLine *color = NULL;
+ struct ColorLineHead *color = NULL;
+ struct ColorLine *np = NULL;
struct Header *hdr = Context->hdrs[Context->v2r[index]];
int type = *s;
switch (type)
{
case MT_COLOR_INDEX_AUTHOR:
- color = ColorIndexAuthorList;
+ color = &ColorIndexAuthorList;
break;
case MT_COLOR_INDEX_FLAGS:
- color = ColorIndexFlagsList;
+ color = &ColorIndexFlagsList;
break;
case MT_COLOR_INDEX_SUBJECT:
- color = ColorIndexSubjectList;
+ color = &ColorIndexSubjectList;
break;
case MT_COLOR_INDEX_TAG:
- for (color = ColorIndexTagList; color; color = color->next)
+ STAILQ_FOREACH(np, &ColorIndexTagList, entries)
{
- if (strncmp((const char *) (s + 1), color->pattern, strlen(color->pattern)) == 0)
- return color->pair;
- const char *transform = hash_find(TagTransforms, color->pattern);
+ if (strncmp((const char *) (s + 1), np->pattern, strlen(np->pattern)) == 0)
+ return np->pair;
+ const char *transform = hash_find(TagTransforms, np->pattern);
if (transform &&
(strncmp((const char *) (s + 1), transform, strlen(transform)) == 0))
- return color->pair;
+ return np->pair;
}
return 0;
default:
return ColorDefs[type];
}
- for (; color; color = color->next)
- if (mutt_pattern_exec(color->color_pattern, MUTT_MATCH_FULL_ADDRESS, Context, hdr, NULL))
- return color->pair;
+ STAILQ_FOREACH(np, color, entries)
+ {
+ if (mutt_pattern_exec(np->color_pattern, MUTT_MATCH_FULL_ADDRESS, Context, hdr, NULL))
+ return np->pair;
+ }
return 0;
}
#include <regex.h>
#include "lib/lib.h"
#include "options.h"
+#include "queue.h"
#ifdef USE_SLANG_CURSES
/**
* struct ColorLine - A regular expression and a color to highlight a line
*/
+STAILQ_HEAD(ColorLineHead, ColorLine);
struct ColorLine
{
regex_t regex;
short fg;
short bg;
int pair;
- struct ColorLine *next;
+ STAILQ_ENTRY(ColorLine) entries;
};
#define MUTT_PROGRESS_SIZE (1 << 0) /**< traffic-based progress */
extern int *ColorQuote;
extern int ColorQuoteUsed;
extern int ColorDefs[];
-extern struct ColorLine *ColorHdrList;
-extern struct ColorLine *ColorBodyList;
-extern struct ColorLine *ColorAttachList;
-extern struct ColorLine *ColorStatusList;
-extern struct ColorLine *ColorIndexList;
-extern struct ColorLine *ColorIndexAuthorList;
-extern struct ColorLine *ColorIndexFlagsList;
-extern struct ColorLine *ColorIndexSubjectList;
-extern struct ColorLine *ColorIndexTagList;
+extern struct ColorLineHead ColorHdrList;
+extern struct ColorLineHead ColorBodyList;
+extern struct ColorLineHead ColorAttachList;
+extern struct ColorLineHead ColorStatusList;
+extern struct ColorLineHead ColorIndexList;
+extern struct ColorLineHead ColorIndexAuthorList;
+extern struct ColorLineHead ColorIndexFlagsList;
+extern struct ColorLineHead ColorIndexSubjectList;
+extern struct ColorLineHead ColorIndexTagList;
void ci_start_color(void);
*/
if (!option(OPT_HEADER_COLOR_PARTIAL))
{
- for (color_line = ColorHdrList; color_line; color_line = color_line->next)
+ STAILQ_FOREACH(color_line, &ColorHdrList, entries)
{
if (REGEXEC(color_line->regex, buf) == 0)
{
found = false;
null_rx = false;
+ struct ColorLineHead *head = NULL;
if (line_info[n].type == MT_COLOR_HDEFAULT)
- color_line = ColorHdrList;
+ head = &ColorHdrList;
else
- color_line = ColorBodyList;
- while (color_line)
+ head = &ColorBodyList;
+ STAILQ_FOREACH(color_line, head, entries)
{
if (regexec(&color_line->regex, buf + offset, 1, pmatch,
(offset ? REG_NOTBOL : 0)) == 0)
else
null_rx = true; /* empty regex; don't add it, but keep looking */
}
- color_line = color_line->next;
}
if (null_rx)
found = false;
null_rx = false;
- for (color_line = ColorAttachList; color_line; color_line = color_line->next)
+ STAILQ_FOREACH(color_line, &ColorAttachList, entries)
{
if (regexec(&color_line->regex, buf + offset, 1, pmatch,
(offset ? REG_NOTBOL : 0)) == 0)