3 Work with colors - backward compability
5 Copyright (C) 2009, 2010 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2009
9 Egmont Koblinger <egmont@gmail.com>, 2010
11 This file is part of the Midnight Commander.
13 The Midnight Commander is free software; you can redistribute it
14 and/or modify it under the terms of the GNU General Public License as
15 published by the Free Software Foundation; either version 2 of the
16 License, or (at your option) any later version.
18 The Midnight Commander is distributed in the hope that it will be
19 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
20 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
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 {"editbold", "editor", "editbold"},
64 {"editlinestate", "editor", "editlinestate"},
65 {"editmarked", "editor", "editmarked"},
66 {"editnormal", "editor", "_default_"},
67 {"editwhitespace", "editor", "editwhitespace"},
68 {"errdhotfocus", "error", "errdhotfocus"},
69 {"errdhotnormal", "error", "errdhotnormal"},
70 {"errors", "error", "_default_"},
71 {"gauge", "core", "gauge"},
72 {"header", "core", "header"},
73 {"helpbold", "help", "helpbold"},
74 {"helpitalic", "help", "helpitalic"},
75 {"helplink", "help", "helplink"},
76 {"helpnormal", "help", "_default_"},
77 {"helpslink", "help", "helpslink"},
78 {"input", "core", "input"},
79 {"inputmark", "core", "inputmark"},
80 {"inputunchanged", "core", "inputunchanged"},
81 {"marked", "core", "marked"},
82 {"markselect", "core", "markselect"},
83 {"menuhot", "menu", "menuhot"},
84 {"menuhotsel", "menu", "menuhotsel"},
85 {"menuinactive", "menu", "menuinactive"},
86 {"menunormal", "menu", "_default_"},
87 {"menusel", "menu", "menusel"},
88 {"normal", "core", "_default_"},
89 {"pmenunormal", "popupmenu", "_default_"},
90 {"pmenusel", "popupmenu", "menusel"},
91 {"pmenutitle", "popupmenu", "menutitle"},
92 {"reverse", "core", "reverse"},
93 {"selected", "core", "selected"},
94 {"statusbar", "statusbar", "_default_"},
95 {"viewbold", "viewer", "viewbold"},
96 {"viewselected", "viewer", "viewselected"},
97 {"viewunderline", "viewer", "viewunderline"}
100 static const size_t num_old_colors
= G_N_ELEMENTS (old_colors
);
102 /*** file scope functions ************************************************************************/
105 old_color_comparator (const void *p1
, const void *p2
)
107 const mc_skin_colors_old_t
*m1
= (const mc_skin_colors_old_t
*) p1
;
108 const mc_skin_colors_old_t
*m2
= (const mc_skin_colors_old_t
*) p2
;
110 return strcmp (m1
->old_color
, m2
->old_color
);
113 /* --------------------------------------------------------------------------------------------- */
116 mc_skin_colors_old_transform (const char *old_color
, const char **group
, const char **key
)
118 const mc_skin_colors_old_t oc
= { old_color
, NULL
, NULL
};
119 mc_skin_colors_old_t
*res
;
121 if (old_color
== NULL
)
124 res
= (mc_skin_colors_old_t
*) bsearch (&oc
, old_colors
, num_old_colors
,
125 sizeof (old_colors
[0]), old_color_comparator
);
137 /* --------------------------------------------------------------------------------------------- */
140 mc_skin_colors_old_configure_one (mc_skin_t
* mc_skin
, const char *the_color_string
)
142 gchar
**colors
, **orig_colors
;
144 if (the_color_string
== NULL
)
147 orig_colors
= colors
= g_strsplit (the_color_string
, ":", -1);
151 for (; *colors
!= NULL
; colors
++)
154 const gchar
*skin_group
, *skin_key
;
156 key_val
= g_strsplit_set (*colors
, "=,", 4);
161 if (key_val
[1] != NULL
&& mc_skin_colors_old_transform (key_val
[0], &skin_group
, &skin_key
))
165 if (key_val
[2] == NULL
)
166 skin_val
= g_strdup_printf ("%s;", key_val
[1]);
167 else if (key_val
[3] == NULL
)
168 skin_val
= g_strdup_printf ("%s;%s", key_val
[1], key_val
[2]);
170 skin_val
= g_strdup_printf ("%s;%s;%s", key_val
[1], key_val
[2], key_val
[3]);
172 mc_config_set_string (mc_skin
->config
, skin_group
, skin_key
, skin_val
);
176 g_strfreev (key_val
);
178 g_strfreev (orig_colors
);
181 /* --------------------------------------------------------------------------------------------- */
182 /*** public functions ****************************************************************************/
183 /* --------------------------------------------------------------------------------------------- */
186 mc_skin_colors_old_configure (mc_skin_t
* mc_skin
)
188 mc_skin_colors_old_configure_one (mc_skin
, mc_global
.tty
.setup_color_string
);
189 mc_skin_colors_old_configure_one (mc_skin
, mc_global
.tty
.term_color_string
);
190 mc_skin_colors_old_configure_one (mc_skin
, getenv ("MC_COLOR_TABLE"));
191 mc_skin_colors_old_configure_one (mc_skin
, mc_global
.tty
.command_line_colors
);
194 /* --------------------------------------------------------------------------------------------- */