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