src/config.c: Drop support for legacy color schemes

We used different naming schemes in versions prior to 1.8. Given that
calcurse 1.8 has been released more than 4.5 years ago, remove the
legacy code that still handles these. Users upgrading from <1.8 to 3.0.0
might need to convert the appropriate config file variable manually.

Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2011-12-12 01:45:45 +01:00
parent 27368d4ee6
commit a548660569

View File

@ -73,99 +73,44 @@ config_parse_int (int *dest, const char *val)
return 1; return 1;
} }
/*
* Load user color theme from file.
* Need to handle calcurse versions prior to 1.8, where colors where handled
* differently (number between 1 and 8).
*/
static int static int
config_parse_color (const char *val) config_parse_color (int *dest, const char *val)
{ {
#define AWAITED_COLORS 2 if (!strcmp (val, "black"))
*dest = COLOR_BLACK;
int i, len, color_num; else if (!strcmp (val, "red"))
char c[AWAITED_COLORS][BUFSIZ]; *dest = COLOR_RED;
int colr[AWAITED_COLORS]; else if (!strcmp (val, "green"))
*dest = COLOR_GREEN;
len = strlen (val); else if (!strcmp (val, "yellow"))
if (len > 1) *dest = COLOR_YELLOW;
{ else if (!strcmp (val, "blue"))
/* New version configuration */ *dest = COLOR_BLUE;
if (sscanf (val, "%s on %s", c[0], c[1]) != AWAITED_COLORS) else if (!strcmp (val, "magenta"))
return 0; *dest = COLOR_MAGENTA;
else if (!strcmp (val, "cyan"))
for (i = 0; i < AWAITED_COLORS; i++) *dest = COLOR_CYAN;
{ else if (!strcmp (val, "white"))
if (!strncmp (c[i], "black", 5)) *dest = COLOR_WHITE;
colr[i] = COLOR_BLACK; else if (!strcmp (val, "default"))
else if (!strncmp (c[i], "red", 3)) *dest = background;
colr[i] = COLOR_RED;
else if (!strncmp (c[i], "green", 5))
colr[i] = COLOR_GREEN;
else if (!strncmp (c[i], "yellow", 6))
colr[i] = COLOR_YELLOW;
else if (!strncmp (c[i], "blue", 4))
colr[i] = COLOR_BLUE;
else if (!strncmp (c[i], "magenta", 7))
colr[i] = COLOR_MAGENTA;
else if (!strncmp (c[i], "cyan", 4))
colr[i] = COLOR_CYAN;
else if (!strncmp (c[i], "white", 5))
colr[i] = COLOR_WHITE;
else if (!strncmp (c[i], "default", 7))
colr[i] = background;
else
return 0;
}
init_pair (COLR_CUSTOM, colr[0], colr[1]);
}
else if (len == 1)
{
/* Old version configuration */
if (isdigit (*val))
color_num = atoi (val);
else
return 0;
switch (color_num)
{
case 0:
colorize = 0;
break;
case 1:
init_pair (COLR_CUSTOM, COLOR_RED, background);
break;
case 2:
init_pair (COLR_CUSTOM, COLOR_GREEN, background);
break;
case 3:
init_pair (COLR_CUSTOM, COLOR_BLUE, background);
break;
case 4:
init_pair (COLR_CUSTOM, COLOR_CYAN, background);
break;
case 5:
init_pair (COLR_CUSTOM, COLOR_YELLOW, background);
break;
case 6:
init_pair (COLR_CUSTOM, COLOR_BLACK, COLR_GREEN);
break;
case 7:
init_pair (COLR_CUSTOM, COLOR_BLACK, COLR_YELLOW);
break;
case 8:
init_pair (COLR_CUSTOM, COLOR_RED, COLR_BLUE);
break;
default:
return 0;
}
}
else else
return 0; return 0;
return 1; return 1;
} }
static int
config_parse_color_pair (int *dest1, int *dest2, const char *val)
{
char s1[BUFSIZ], s2[BUFSIZ];
if (sscanf (val, "%s on %s", s1, s2) != 2)
return 0;
return (config_parse_color (dest1, s1) && config_parse_color (dest2, s2));
}
/* Set a configuration variable. */ /* Set a configuration variable. */
static int static int
config_set_conf (const char *key, const char *value) config_set_conf (const char *key, const char *value)
@ -213,7 +158,13 @@ config_set_conf (const char *key, const char *value)
} }
if (!strcmp(key, "color-theme")) if (!strcmp(key, "color-theme"))
return config_parse_color (value); {
int color1, color2;
if (!config_parse_color_pair (&color1, &color2, value))
return 0;
init_pair (COLR_CUSTOM, color1, color2);
return 1;
}
if (!strcmp(key, "layout")) { if (!strcmp(key, "layout")) {
wins_set_layout (atoi (value)); wins_set_layout (atoi (value));