Merge branch '1858_segfault_in_search'
[midnight-commander.git] / src / skin / colors-old.c
blob165bfe0457ebe4c7bf698347b2f3f9226388e381
1 /*
2 Skins engine.
3 Work with colors - backward compability
5 Copyright (C) 2009 The Free Software Foundation, Inc.
7 Written by:
8 Slava Zanko <slavazanko@gmail.com>, 2009.
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software; you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be
18 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25 MA 02110-1301, USA.
28 #include <config.h>
29 #include <stdlib.h>
30 #include <sys/types.h> /* size_t */
31 #include "../src/tty/color.h"
33 #include "../src/global.h"
34 #include "../src/setup.h"
35 #include "skin.h"
36 #include "internal.h"
39 /*** global variables ****************************************************************************/
41 /*** file scope macro definitions ****************************************************************/
43 /*** file scope type declarations ****************************************************************/
45 typedef struct mc_skin_colors_old_struct {
46 const char *old_color;
47 const char *group;
48 const char *key;
49 } mc_skin_colors_old_t;
51 /*** file scope variables ************************************************************************/
53 mc_skin_colors_old_t old_colors[] = {
54 {"normal", "core", "_default_"},
55 {"marked", "core", "marked"},
56 {"selected", "core", "selected"},
57 {"markselect", "core", "markselect"},
58 {"reverse", "core", "reverse"},
59 {"dnormal", "dialog", "_default_"},
60 {"dfocus", "dialog", "dfocus"},
61 {"dhotnormal", "dialog", "dhotnormal"},
62 {"dhotfocus", "dialog", "dhotfocus"},
63 {"errors", "error", "_default_"},
64 {"errdhotnormal", "error", "errdhotnormal"},
65 {"errdhotfocus", "error", "errdhotfocus"},
66 {"menu", "menu", "_default_"},
67 {"menuhot", "menu", "menuhot"},
68 {"menusel", "menu", "menusel"},
69 {"menuhotsel", "menu", "menuhotsel"},
70 {"gauge", "core", "gauge"},
71 {"input", "core", "input"},
72 {"helpnormal", "help", "_default_"},
73 {"helpitalic", "help", "helpitalic"},
74 {"helpbold", "help", "helpbold"},
75 {"helplink", "help", "helplink"},
76 {"helpslink", "help", "helpslink"},
77 {"viewunderline", "viewer", "viewunderline"},
78 {"editnormal", "editor", "_default_"},
79 {"editbold", "editor", "editbold"},
80 {"editmarked", "editor", "editmarked"},
81 {"editwhitespace", "editor", "editwhitespace"},
82 {"editlinestate", "editor", "linestate"},
83 {NULL, NULL, NULL}
87 /*** file scope functions ************************************************************************/
88 /* --------------------------------------------------------------------------------------------- */
90 static gboolean
91 mc_skin_colors_old_transform (const char *old_color, const char **group, const char **key)
93 int lc_index;
95 if (old_color != NULL)
96 for (lc_index = 0; old_colors[lc_index].old_color; lc_index++) {
97 if (strcasecmp (old_color, old_colors[lc_index].old_color) == 0) {
98 if (group != NULL)
99 *group = old_colors[lc_index].group;
100 if (key != NULL)
101 *key = old_colors[lc_index].key;
102 return TRUE;
105 return FALSE;
108 /* --------------------------------------------------------------------------------------------- */
110 static void
111 mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_string)
113 gchar **colors, **orig_colors;
114 gchar **key_val;
115 const gchar *skin_group, *skin_key;
116 gchar *skin_val;
118 if (the_color_string == NULL)
119 return;
121 orig_colors = colors = g_strsplit (the_color_string, ":", -1);
122 if (colors == NULL)
123 return;
125 for (; *colors; colors++) {
126 key_val = g_strsplit_set (*colors, "=,", 3);
128 if (!key_val)
129 continue;
131 if (key_val[1] == NULL
132 || !mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key)) {
133 g_strfreev (key_val);
134 continue;
136 if (key_val[2] != NULL)
137 skin_val = g_strdup_printf ("%s;%s", key_val[1], key_val[2]);
138 else
139 skin_val = g_strdup_printf ("%s;", key_val[1]);
140 mc_config_set_string (mc_skin->config, skin_group, skin_key, skin_val);
142 g_free (skin_val);
144 g_strfreev (key_val);
146 g_strfreev (orig_colors);
149 /* --------------------------------------------------------------------------------------------- */
150 /*** public functions ****************************************************************************/
151 /* --------------------------------------------------------------------------------------------- */
153 void
154 mc_skin_colors_old_configure (mc_skin_t * mc_skin)
156 mc_skin_colors_old_configure_one (mc_skin, setup_color_string);
157 mc_skin_colors_old_configure_one (mc_skin, term_color_string);
158 mc_skin_colors_old_configure_one (mc_skin, getenv ("MC_COLOR_TABLE"));
159 mc_skin_colors_old_configure_one (mc_skin, command_line_colors);
162 /* --------------------------------------------------------------------------------------------- */