/*
* Copyright (C) 1996-2002,2012 Michael R. Elkins <me@mutt.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include "mutt.h"
#include "mutt_curses.h"
#include "mutt_menu.h"
#include "mapping.h"
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
/* globals */
int *ColorQuote;
int ColorQuoteUsed;
int ColorDefs[MT_COLOR_MAX];
COLOR_LINE *ColorHdrList = NULL;
COLOR_LINE *ColorBodyList = NULL;
COLOR_LINE *ColorIndexList = NULL;
/* local to this file */
static int ColorQuoteSize;
#ifdef HAVE_COLOR
#define COLOR_DEFAULT (-2)
typedef struct color_list
{
int pair;
short fg;
short bg;
short index;
short count;
struct color_list *next;
} COLOR_LIST;
static COLOR_LIST *ColorList = NULL;
static int UserColors = 0;
static const struct mapping_t Colors[] =
{
{ "black", COLOR_BLACK },
{ "blue", COLOR_BLUE },
{ "cyan", COLOR_CYAN },
{ "green", COLOR_GREEN },
{ "magenta", COLOR_MAGENTA },
{ "red", COLOR_RED },
{ "white", COLOR_WHITE },
{ "yellow", COLOR_YELLOW },
#if defined (USE_SLANG_CURSES) || defined (HAVE_USE_DEFAULT_COLORS)
{ "default", COLOR_DEFAULT },
#endif
{ 0, 0 }
};
#endif /* HAVE_COLOR */
static const struct mapping_t Fields[] =
{
{ "hdrdefault", MT_COLOR_HDEFAULT },
{ "quoted", MT_COLOR_QUOTED },
{ "signature", MT_COLOR_SIGNATURE },
{ "indicator", MT_COLOR_INDICATOR },
{ "status", MT_COLOR_STATUS },
{ "tree", MT_COLOR_TREE },
{ "error", MT_COLOR_ERROR },
{ "normal", MT_COLOR_NORMAL },
{ "tilde", MT_COLOR_TILDE },
{ "markers", MT_COLOR_MARKERS },
{ "header", MT_COLOR_HEADER },
{ "body", MT_COLOR_BODY },
{ "message", MT_COLOR_MESSAGE },
{ "attachment", MT_COLOR_ATTACHMENT },
{ "search", MT_COLOR_SEARCH },
{ "bold", MT_COLOR_BOLD },
{ "underline", MT_COLOR_UNDERLINE },
{ "index", MT_COLOR_INDEX },
{ "prompt", MT_COLOR_PROMPT },
#ifdef USE_SIDEBAR
{ "sidebar_divider", MT_COLOR_DIVIDER },
{ "sidebar_flagged", MT_COLOR_FLAGGED },
{ "sidebar_highlight",MT_COLOR_HIGHLIGHT },
{ "sidebar_indicator",MT_COLOR_SB_INDICATOR },
{ "sidebar_new", MT_COLOR_NEW },
{ "sidebar_spoolfile",MT_COLOR_SB_SPOOLFILE },
#endif
{ NULL, 0 }
};
static const struct mapping_t ComposeFields[] =
{
{ "header", MT_COLOR_COMPOSE_HEADER },
{ "security_encrypt", MT_COLOR_COMPOSE_SECURITY_ENCRYPT },
{ "security_sign", MT_COLOR_COMPOSE_SECURITY_SIGN },
{ "security_both", MT_COLOR_COMPOSE_SECURITY_BOTH },
{ "security_none", MT_COLOR_COMPOSE_SECURITY_NONE },
{ NULL, 0 }
};
#define COLOR_QUOTE_INIT 8
#ifdef NCURSES_VERSION
#define ATTR_MASK (A_ATTRIBUTES ^ A_COLOR)
#elif defined (USE_SLANG_CURSES)
#define ATTR_MASK (~(unsigned int)A_NORMAL ^ (A_CHARTEXT | A_UNUSED | A_COLOR))
#endif
static COLOR_LINE *mutt_new_color_line (void)
{
COLOR_LINE *p = safe_calloc (1, sizeof (COLOR_LINE));
p->fg = p->bg = -1;
return (p);
}
static void mutt_free_color_line(COLOR_LINE **l,
int free_colors)
{
COLOR_LINE *tmp;
if (!l || !*l)
return;
tmp = *l;
#ifdef HAVE_COLOR
if (free_colors && tmp->fg != -1 && tmp->bg != -1)
mutt_free_color(tmp->fg, tmp->bg);
#endif
/* we should really introduce a container
* type for regular expressions.
*/
regfree(&tmp->rx);
mutt_pattern_free(&tmp->color_pattern);
FREE (&tmp->pattern);
FREE (l); /* __FREE_CHECKED__ */
}
void ci_start_color (void)
{
memset (ColorDefs, A_NORMAL, sizeof (int) * MT_COLOR_MAX);
ColorQuote = (int *) safe_malloc (COLOR_QUOTE_INIT * sizeof (int));
memset (ColorQuote, A_NORMAL, sizeof (int) * COLOR_QUOTE_INIT);
ColorQuoteSize =