3 Work with colors - backward compability
5 Copyright (C) 2009, 2010, 2011, 2012
6 The Free Software Foundation, Inc.
9 Slava Zanko <slavazanko@gmail.com>, 2009
10 Egmont Koblinger <egmont@gmail.com>, 2010
11 Andrew Borodin <aborodin@vmail.ru>, 2012
13 This file is part of the Midnight Commander.
15 The Midnight Commander is free software: you can redistribute it
16 and/or modify it under the terms of the GNU General Public License as
17 published by the Free Software Foundation, either version 3 of the License,
18 or (at your option) any later version.
20 The Midnight Commander is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program. If not, see <http://www.gnu.org/licenses/>.
31 #include <string.h> /* strcmp() */
32 #include <sys/types.h> /* size_t */
36 #include "lib/tty/color.h"
38 /*** global variables ****************************************************************************/
40 /*** file scope macro definitions ****************************************************************/
42 /*** file scope type declarations ****************************************************************/
44 typedef struct mc_skin_colors_old_struct
46 const char *old_color
;
49 } mc_skin_colors_old_t
;
51 /*** file scope variables ************************************************************************/
53 /* keep this table alphabetically sorted */
54 static const mc_skin_colors_old_t old_colors
[] = {
55 {"bbarbutton", "buttonbar", "button"},
56 {"bbarhotkey", "buttonbar", "hotkey"},
57 {"commandlinemark", "core", "commandlinemark"},
58 {"dfocus", "dialog", "dfocus"},
59 {"dhotfocus", "dialog", "dhotfocus"},
60 {"dhotnormal", "dialog", "dhotnormal"},
61 {"disabled", "core", "disabled"},
62 {"dnormal", "dialog", "_default_"},
63 {"editbg", "editor", "editbg"},
64 {"editbold", "editor", "editbold"},
65 {"editframe", "editor", "editframe"},
66 {"editframeactive", "editor", "editframeactive"},
67 {"editframedrag", "editor", "editframedrag"},
68 {"editlinestate", "editor", "editlinestate"},
69 {"editmarked", "editor", "editmarked"},
70 {"editnormal", "editor", "_default_"},
71 {"editwhitespace", "editor", "editwhitespace"},
72 {"errdhotfocus", "error", "errdhotfocus"},
73 {"errdhotnormal", "error", "errdhotnormal"},
74 {"errors", "error", "_default_"},
75 {"gauge", "core", "gauge"},
76 {"header", "core", "header"},
77 {"helpbold", "help", "helpbold"},
78 {"helpitalic", "help", "helpitalic"},
79 {"helplink", "help", "helplink"},
80 {"helpnormal", "help", "_default_"},
81 {"helpslink", "help", "helpslink"},
82 {"input", "core", "input"},
83 {"inputmark", "core", "inputmark"},
84 {"inputunchanged", "core", "inputunchanged"},
85 {"marked", "core", "marked"},
86 {"markselect", "core", "markselect"},
87 {"menuhot", "menu", "menuhot"},
88 {"menuhotsel", "menu", "menuhotsel"},
89 {"menuinactive", "menu", "menuinactive"},
90 {"menunormal", "menu", "_default_"},
91 {"menusel", "menu", "menusel"},
92 {"normal", "core", "_default_"},
93 {"pmenunormal", "popupmenu", "_default_"},
94 {"pmenusel", "popupmenu", "menusel"},
95 {"pmenutitle", "popupmenu", "menutitle"},
96 {"reverse", "core", "reverse"},
97 {"selected", "core", "selected"},
98 {"statusbar", "statusbar", "_default_"},
99 {"viewbold", "viewer", "viewbold"},
100 {"viewselected", "viewer", "viewselected"},
101 {"viewunderline", "viewer", "viewunderline"}
104 static const size_t num_old_colors
= G_N_ELEMENTS (old_colors
);
106 /*** file scope functions ************************************************************************/
109 old_color_comparator (const void *p1
, const void *p2
)
111 const mc_skin_colors_old_t
*m1
= (const mc_skin_colors_old_t
*) p1
;
112 const mc_skin_colors_old_t
*m2
= (const mc_skin_colors_old_t
*) p2
;
114 return strcmp (m1
->old_color
, m2
->old_color
);
117 /* --------------------------------------------------------------------------------------------- */
120 mc_skin_colors_old_transform (const char *old_color
, const char **group
, const char **key
)
122 const mc_skin_colors_old_t oc
= { old_color
, NULL
, NULL
};
123 mc_skin_colors_old_t
*res
;
125 if (old_color
== NULL
)
128 res
= (mc_skin_colors_old_t
*) bsearch (&oc
, old_colors
, num_old_colors
,
129 sizeof (old_colors
[0]), old_color_comparator
);
141 /* --------------------------------------------------------------------------------------------- */
144 mc_skin_colors_old_configure_one (mc_skin_t
* mc_skin
, const char *the_color_string
)
146 gchar
**colors
, **orig_colors
;
148 if (the_color_string
== NULL
)
151 orig_colors
= colors
= g_strsplit (the_color_string
, ":", -1);
155 for (; *colors
!= NULL
; colors
++)
158 const gchar
*skin_group
, *skin_key
;
160 key_val
= g_strsplit_set (*colors
, "=,", 4);
165 if (key_val
[1] != NULL
&& mc_skin_colors_old_transform (key_val
[0], &skin_group
, &skin_key
))
169 if (key_val
[2] == NULL
)
170 skin_val
= g_strdup_printf ("%s;", key_val
[1]);
171 else if (key_val
[3] == NULL
)
172 skin_val
= g_strdup_printf ("%s;%s", key_val
[1], key_val
[2]);
174 skin_val
= g_strdup_printf ("%s;%s;%s", key_val
[1], key_val
[2], key_val
[3]);
176 mc_config_set_string (mc_skin
->config
, skin_group
, skin_key
, skin_val
);
180 g_strfreev (key_val
);
182 g_strfreev (orig_colors
);
185 /* --------------------------------------------------------------------------------------------- */
186 /*** public functions ****************************************************************************/
187 /* --------------------------------------------------------------------------------------------- */
190 mc_skin_colors_old_configure (mc_skin_t
* mc_skin
)
192 mc_skin_colors_old_configure_one (mc_skin
, mc_global
.tty
.setup_color_string
);
193 mc_skin_colors_old_configure_one (mc_skin
, mc_global
.tty
.term_color_string
);
194 mc_skin_colors_old_configure_one (mc_skin
, getenv ("MC_COLOR_TABLE"));
195 mc_skin_colors_old_configure_one (mc_skin
, mc_global
.tty
.command_line_colors
);
198 /* --------------------------------------------------------------------------------------------- */