(mc_build_filenamev): refactoring.
[midnight-commander.git] / lib / skin / colors-old.c
blob3430cd641975b116da593a07776a8cb756367185
1 /*
2 Skins engine.
3 Work with colors - backward compatibility
5 Copyright (C) 2009-2024
6 Free Software Foundation, Inc.
8 Written by:
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/>.
29 #include <config.h>
30 #include <stdlib.h>
31 #include <string.h> /* strcmp() */
32 #include <sys/types.h> /* size_t */
34 #include "internal.h"
36 #include "lib/tty/color.h"
38 /*** global variables ****************************************************************************/
40 /*** file scope macro definitions ****************************************************************/
42 /*** forward declarations (file scope functions) *************************************************/
44 /*** file scope type declarations ****************************************************************/
46 typedef struct mc_skin_colors_old_struct
48 const char *old_color;
49 const char *group;
50 const char *key;
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 {"editbg", "editor", "editbg"},
66 {"editbold", "editor", "editbold"},
67 {"editframe", "editor", "editframe"},
68 {"editframeactive", "editor", "editframeactive"},
69 {"editframedrag", "editor", "editframedrag"},
70 {"editlinestate", "editor", "editlinestate"},
71 {"editmarked", "editor", "editmarked"},
72 {"editnonprintable", "editor", "editnonprintable"},
73 {"editnormal", "editor", "_default_"},
74 {"editwhitespace", "editor", "editwhitespace"},
75 {"errdhotfocus", "error", "errdhotfocus"},
76 {"errdhotnormal", "error", "errdhotnormal"},
77 {"errors", "error", "_default_"},
78 {"gauge", "core", "gauge"},
79 {"header", "core", "header"},
80 {"helpbold", "help", "helpbold"},
81 {"helpitalic", "help", "helpitalic"},
82 {"helplink", "help", "helplink"},
83 {"helpnormal", "help", "_default_"},
84 {"helpslink", "help", "helpslink"},
85 {"input", "core", "input"},
86 {"inputmark", "core", "inputmark"},
87 {"inputunchanged", "core", "inputunchanged"},
88 {"marked", "core", "marked"},
89 {"markselect", "core", "markselect"},
90 {"menuhot", "menu", "menuhot"},
91 {"menuhotsel", "menu", "menuhotsel"},
92 {"menuinactive", "menu", "menuinactive"},
93 {"menunormal", "menu", "_default_"},
94 {"menusel", "menu", "menusel"},
95 {"normal", "core", "_default_"},
96 {"pmenunormal", "popupmenu", "_default_"},
97 {"pmenusel", "popupmenu", "menusel"},
98 {"pmenutitle", "popupmenu", "menutitle"},
99 {"reverse", "core", "reverse"},
100 {"selected", "core", "selected"},
101 {"statusbar", "statusbar", "_default_"},
102 {"viewbold", "viewer", "viewbold"},
103 {"viewnormal", "viewer", "_default_"},
104 {"viewselected", "viewer", "viewselected"},
105 {"viewunderline", "viewer", "viewunderline"}
108 static const size_t num_old_colors = G_N_ELEMENTS (old_colors);
110 /* --------------------------------------------------------------------------------------------- */
111 /*** file scope functions ************************************************************************/
112 /* --------------------------------------------------------------------------------------------- */
114 static int
115 old_color_comparator (const void *p1, const void *p2)
117 const mc_skin_colors_old_t *m1 = (const mc_skin_colors_old_t *) p1;
118 const mc_skin_colors_old_t *m2 = (const mc_skin_colors_old_t *) p2;
120 return strcmp (m1->old_color, m2->old_color);
123 /* --------------------------------------------------------------------------------------------- */
125 static gboolean
126 mc_skin_colors_old_transform (const char *old_color, const char **group, const char **key)
128 const mc_skin_colors_old_t oc = { old_color, NULL, NULL };
129 mc_skin_colors_old_t *res;
131 if (old_color == NULL)
132 return FALSE;
134 res = (mc_skin_colors_old_t *) bsearch (&oc, old_colors, num_old_colors,
135 sizeof (old_colors[0]), old_color_comparator);
137 if (res == NULL)
138 return FALSE;
140 if (group != NULL)
141 *group = res->group;
142 if (key != NULL)
143 *key = res->key;
144 return TRUE;
147 /* --------------------------------------------------------------------------------------------- */
149 static void
150 mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_string)
152 gchar **colors, **orig_colors;
154 if (the_color_string == NULL)
155 return;
157 orig_colors = g_strsplit (the_color_string, ":", -1);
158 if (orig_colors == NULL)
159 return;
161 for (colors = orig_colors; *colors != NULL; colors++)
163 gchar **key_val;
164 const gchar *skin_group, *skin_key;
166 key_val = g_strsplit_set (*colors, "=,", 4);
168 if (key_val == NULL)
169 continue;
171 if (key_val[1] != NULL && mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key))
173 gchar *skin_val;
175 if (key_val[2] == NULL)
176 skin_val = g_strdup_printf ("%s;", key_val[1]);
177 else if (key_val[3] == NULL)
178 skin_val = g_strdup_printf ("%s;%s", key_val[1], key_val[2]);
179 else
180 skin_val = g_strdup_printf ("%s;%s;%s", key_val[1], key_val[2], key_val[3]);
182 mc_config_set_string (mc_skin->config, skin_group, skin_key, skin_val);
183 g_free (skin_val);
186 g_strfreev (key_val);
188 g_strfreev (orig_colors);
191 /* --------------------------------------------------------------------------------------------- */
192 /*** public functions ****************************************************************************/
193 /* --------------------------------------------------------------------------------------------- */
195 void
196 mc_skin_colors_old_configure (mc_skin_t * mc_skin)
198 mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.setup_color_string);
199 mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.term_color_string);
200 mc_skin_colors_old_configure_one (mc_skin, getenv ("MC_COLOR_TABLE"));
201 mc_skin_colors_old_configure_one (mc_skin, mc_global.tty.command_line_colors);
204 /* --------------------------------------------------------------------------------------------- */