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 #include "src/setup.h"
40 /*** global variables ****************************************************************************/
42 /*** file scope macro definitions ****************************************************************/
44 /*** file scope type declarations ****************************************************************/
46 typedef struct mc_skin_colors_old_struct
48 const char *old_color
;
51 } mc_skin_colors_old_t
;
53 /*** file scope variables ************************************************************************/
55 /* keep this table alphabetically sorted */
56 static const mc_skin_colors_old_t old_colors
[] = {
57 {"bbarbutton", "buttonbar", "button"},
58 {"bbarhotkey", "buttonbar", "hotkey"},
59 {"commandlinemark", "core", "commandlinemark"},
60 {"dfocus", "dialog", "dfocus"},
61 {"dhotfocus", "dialog", "dhotfocus"},
62 {"dhotnormal", "dialog", "dhotnormal"},
63 {"disabled", "core", "disabled"},
64 {"dnormal", "dialog", "_default_"},
65 {"editbold", "editor", "editbold"},
66 {"editlinestate", "editor", "editlinestate"},
67 {"editmarked", "editor", "editmarked"},
68 {"editnormal", "editor", "_default_"},
69 {"editwhitespace", "editor", "editwhitespace"},
70 {"errdhotfocus", "error", "errdhotfocus"},
71 {"errdhotnormal", "error", "errdhotnormal"},
72 {"errors", "error", "_default_"},
73 {"gauge", "core", "gauge"},
74 {"header", "core", "header"},
75 {"helpbold", "help", "helpbold"},
76 {"helpitalic", "help", "helpitalic"},
77 {"helplink", "help", "helplink"},
78 {"helpnormal", "help", "_default_"},
79 {"helpslink", "help", "helpslink"},
80 {"input", "core", "input"},
81 {"inputmark", "core", "inputmark"},
82 {"inputunchanged", "core", "inputunchanged"},
83 {"marked", "core", "marked"},
84 {"markselect", "core", "markselect"},
85 {"menuhot", "menu", "menuhot"},
86 {"menuhotsel", "menu", "menuhotsel"},
87 {"menuinactive", "menu", "menuinactive"},
88 {"menunormal", "menu", "_default_"},
89 {"menusel", "menu", "menusel"},
90 {"normal", "core", "_default_"},
91 {"pmenunormal", "popupmenu", "_default_"},
92 {"pmenusel", "popupmenu", "menusel"},
93 {"pmenutitle", "popupmenu", "menutitle"},
94 {"reverse", "core", "reverse"},
95 {"selected", "core", "selected"},
96 {"statusbar", "statusbar", "_default_"},
97 {"viewbold", "viewer", "viewbold"}
98 {"viewselected", "viewer", "viewselected"}
99 {"viewunderline", "viewer", "viewunderline"}
102 static const size_t num_old_colors
= G_N_ELEMENTS (old_colors
);
104 /*** file scope functions ************************************************************************/
107 old_color_comparator (const void *p1
, const void *p2
)
109 const mc_skin_colors_old_t
*m1
= (const mc_skin_colors_old_t
*) p1
;
110 const mc_skin_colors_old_t
*m2
= (const mc_skin_colors_old_t
*) p2
;
112 return strcmp (m1
->old_color
, m2
->old_color
);
115 /* --------------------------------------------------------------------------------------------- */
118 mc_skin_colors_old_transform (const char *old_color
, const char **group
, const char **key
)
120 const mc_skin_colors_old_t oc
= { old_color
, NULL
, NULL
};
121 mc_skin_colors_old_t
*res
;
123 if (old_color
== NULL
)
126 res
= (mc_skin_colors_old_t
*) bsearch (&oc
, old_colors
, num_old_colors
,
127 sizeof (old_colors
[0]), old_color_comparator
);
139 /* --------------------------------------------------------------------------------------------- */
142 mc_skin_colors_old_configure_one (mc_skin_t
* mc_skin
, const char *the_color_string
)
144 gchar
**colors
, **orig_colors
;
146 if (the_color_string
== NULL
)
149 orig_colors
= colors
= g_strsplit (the_color_string
, ":", -1);
153 for (; *colors
!= NULL
; colors
++)
156 const gchar
*skin_group
, *skin_key
;
158 key_val
= g_strsplit_set (*colors
, "=,", 4);
163 if (key_val
[1] != NULL
164 && mc_skin_colors_old_transform (key_val
[0], &skin_group
, &skin_key
))
168 if (key_val
[2] == NULL
)
169 skin_val
= g_strdup_printf ("%s;", key_val
[1]);
170 else if (key_val
[3] == NULL
)
171 skin_val
= g_strdup_printf ("%s;%s", key_val
[1], key_val
[2]);
173 skin_val
= g_strdup_printf ("%s;%s;%s", key_val
[1], key_val
[2], key_val
[3]);
175 mc_config_set_string (mc_skin
->config
, skin_group
, skin_key
, skin_val
);
179 g_strfreev (key_val
);
181 g_strfreev (orig_colors
);
184 /* --------------------------------------------------------------------------------------------- */
185 /*** public functions ****************************************************************************/
186 /* --------------------------------------------------------------------------------------------- */
189 mc_skin_colors_old_configure (mc_skin_t
* mc_skin
)
191 mc_skin_colors_old_configure_one (mc_skin
, setup_color_string
);
192 mc_skin_colors_old_configure_one (mc_skin
, term_color_string
);
193 mc_skin_colors_old_configure_one (mc_skin
, getenv ("MC_COLOR_TABLE"));
194 mc_skin_colors_old_configure_one (mc_skin
, command_line_colors
);
197 /* --------------------------------------------------------------------------------------------- */