This source file includes following definitions.
- old_color_comparator
- mc_skin_colors_old_transform
- mc_skin_colors_old_configure_one
- mc_skin_colors_old_configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include <config.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <sys/types.h>
33
34 #include "internal.h"
35
36 #include "lib/tty/color.h"
37
38
39
40
41
42
43
44
45
46 typedef struct mc_skin_colors_old_struct
47 {
48 const char *old_color;
49 const char *group;
50 const char *key;
51 } mc_skin_colors_old_t;
52
53
54
55
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"}
106 };
107
108 static const size_t num_old_colors = G_N_ELEMENTS (old_colors);
109
110
111
112
113
114 static int
115 old_color_comparator (const void *p1, const void *p2)
116 {
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;
119
120 return strcmp (m1->old_color, m2->old_color);
121 }
122
123
124
125 static gboolean
126 mc_skin_colors_old_transform (const char *old_color, const char **group, const char **key)
127 {
128 const mc_skin_colors_old_t oc = { old_color, NULL, NULL };
129 mc_skin_colors_old_t *res;
130
131 if (old_color == NULL)
132 return FALSE;
133
134 res = (mc_skin_colors_old_t *) bsearch (&oc, old_colors, num_old_colors,
135 sizeof (old_colors[0]), old_color_comparator);
136
137 if (res == NULL)
138 return FALSE;
139
140 if (group != NULL)
141 *group = res->group;
142 if (key != NULL)
143 *key = res->key;
144 return TRUE;
145 }
146
147
148
149 static void
150 mc_skin_colors_old_configure_one (mc_skin_t *mc_skin, const char *the_color_string)
151 {
152 gchar **colors, **orig_colors;
153
154 if (the_color_string == NULL)
155 return;
156
157 orig_colors = g_strsplit (the_color_string, ":", -1);
158 if (orig_colors == NULL)
159 return;
160
161 for (colors = orig_colors; *colors != NULL; colors++)
162 {
163 gchar **key_val;
164 const gchar *skin_group, *skin_key;
165
166 key_val = g_strsplit_set (*colors, "=,", 4);
167
168 if (key_val == NULL)
169 continue;
170
171 if (key_val[1] != NULL && mc_skin_colors_old_transform (key_val[0], &skin_group, &skin_key))
172 {
173 gchar *skin_val;
174
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]);
181
182 mc_config_set_string (mc_skin->config, skin_group, skin_key, skin_val);
183 g_free (skin_val);
184 }
185
186 g_strfreev (key_val);
187 }
188 g_strfreev (orig_colors);
189 }
190
191
192
193
194
195 void
196 mc_skin_colors_old_configure (mc_skin_t *mc_skin)
197 {
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);
202 }
203
204