This source file includes following definitions.
- mc_fhl_parse_fill_color_info
- mc_fhl_parse_get_file_type_id
- mc_fhl_parse_get_regexp
- mc_fhl_parse_get_extensions
- mc_fhl_read_ini_file
- mc_fhl_init_from_standard_files
- mc_fhl_parse_ini_file
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 #include <config.h>
28 #include <string.h>
29
30 #include "lib/global.h"
31 #include "lib/fileloc.h"
32 #include "lib/strutil.h"
33 #include "lib/skin.h"
34 #include "lib/util.h"
35
36 #include "lib/filehighlight.h"
37
38 #include "internal.h"
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 static void
55 mc_fhl_parse_fill_color_info (mc_fhl_filter_t *mc_filter, mc_fhl_t *fhl, const gchar *group_name)
56 {
57 (void) fhl;
58
59 mc_filter->color_pair_index = mc_skin_color_get ("filehighlight", group_name);
60 }
61
62
63
64 static gboolean
65 mc_fhl_parse_get_file_type_id (mc_fhl_t *fhl, const gchar *group_name)
66 {
67 mc_fhl_filter_t *mc_filter;
68
69 const gchar *types[] = {
70 "FILE", "FILE_EXE",
71 "DIR", "LINK_DIR",
72 "LINK", "HARDLINK", "SYMLINK", "STALE_LINK",
73 "DEVICE", "DEVICE_BLOCK", "DEVICE_CHAR",
74 "SPECIAL", "SPECIAL_SOCKET", "SPECIAL_FIFO", "SPECIAL_DOOR",
75 NULL,
76 };
77 int i;
78 gchar *param_type;
79
80 param_type = mc_config_get_string (fhl->config, group_name, "type", "");
81 if (*param_type == '\0')
82 {
83 g_free (param_type);
84 return FALSE;
85 }
86
87 for (i = 0; types[i] != NULL; i++)
88 if (strcmp (types[i], param_type) == 0)
89 break;
90
91 g_free (param_type);
92
93 if (types[i] == NULL)
94 return FALSE;
95
96 mc_filter = g_new0 (mc_fhl_filter_t, 1);
97 mc_filter->type = MC_FLHGH_T_FTYPE;
98 mc_filter->file_type = (mc_flhgh_ftype_type) i;
99 mc_fhl_parse_fill_color_info (mc_filter, fhl, group_name);
100
101 g_ptr_array_add (fhl->filters, (gpointer) mc_filter);
102
103 return TRUE;
104 }
105
106
107
108 static gboolean
109 mc_fhl_parse_get_regexp (mc_fhl_t *fhl, const gchar *group_name)
110 {
111 mc_fhl_filter_t *mc_filter;
112 gchar *regexp;
113
114 regexp = mc_config_get_string (fhl->config, group_name, "regexp", "");
115 if (*regexp == '\0')
116 {
117 g_free (regexp);
118 return FALSE;
119 }
120
121 mc_filter = g_new0 (mc_fhl_filter_t, 1);
122 mc_filter->type = MC_FLHGH_T_FREGEXP;
123 mc_filter->search_condition = mc_search_new (regexp, DEFAULT_CHARSET);
124 mc_filter->search_condition->is_case_sensitive = TRUE;
125 mc_filter->search_condition->search_type = MC_SEARCH_T_REGEX;
126
127 mc_fhl_parse_fill_color_info (mc_filter, fhl, group_name);
128 g_ptr_array_add (fhl->filters, (gpointer) mc_filter);
129 g_free (regexp);
130
131 return TRUE;
132 }
133
134
135
136 static gboolean
137 mc_fhl_parse_get_extensions (mc_fhl_t *fhl, const gchar *group_name)
138 {
139 mc_fhl_filter_t *mc_filter;
140 gchar **exts, **exts_orig;
141 GString *buf;
142
143 exts_orig = mc_config_get_string_list (fhl->config, group_name, "extensions", NULL);
144 if (exts_orig == NULL || exts_orig[0] == NULL)
145 {
146 g_strfreev (exts_orig);
147 return FALSE;
148 }
149
150 buf = g_string_sized_new (64);
151
152 for (exts = exts_orig; *exts != NULL; exts++)
153 {
154 char *esc_ext;
155
156 esc_ext = str_regex_escape (*exts);
157 if (buf->len != 0)
158 g_string_append_c (buf, '|');
159 g_string_append (buf, esc_ext);
160 g_free (esc_ext);
161 }
162
163 g_strfreev (exts_orig);
164
165 g_string_prepend (buf, ".*\\.(");
166 g_string_append (buf, ")$");
167
168 mc_filter = g_new0 (mc_fhl_filter_t, 1);
169 mc_filter->type = MC_FLHGH_T_FREGEXP;
170 mc_filter->search_condition = mc_search_new_len (buf->str, buf->len, DEFAULT_CHARSET);
171 mc_filter->search_condition->is_case_sensitive =
172 mc_config_get_bool (fhl->config, group_name, "extensions_case", FALSE);
173 mc_filter->search_condition->search_type = MC_SEARCH_T_REGEX;
174
175 mc_fhl_parse_fill_color_info (mc_filter, fhl, group_name);
176 g_ptr_array_add (fhl->filters, (gpointer) mc_filter);
177 g_string_free (buf, TRUE);
178
179 return TRUE;
180 }
181
182
183
184
185
186 gboolean
187 mc_fhl_read_ini_file (mc_fhl_t *fhl, const gchar *filename)
188 {
189 if (fhl == NULL || filename == NULL || !exist_file (filename))
190 return FALSE;
191
192 if (fhl->config != NULL)
193 return mc_config_read_file (fhl->config, filename, TRUE, FALSE);
194
195 fhl->config = mc_config_init (filename, TRUE);
196
197 return (fhl->config != NULL);
198 }
199
200
201
202 gboolean
203 mc_fhl_init_from_standard_files (mc_fhl_t *fhl)
204 {
205 gchar *name;
206 gboolean ok;
207
208
209 name = mc_config_get_full_path (MC_FHL_INI_FILE);
210 ok = mc_fhl_read_ini_file (fhl, name);
211 g_free (name);
212 if (ok)
213 return TRUE;
214
215
216 name = g_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, (char *) NULL);
217 ok = mc_fhl_read_ini_file (fhl, name);
218 g_free (name);
219 if (ok)
220 return TRUE;
221
222
223 name = g_build_filename (mc_global.share_data_dir, MC_FHL_INI_FILE, (char *) NULL);
224 ok = mc_fhl_read_ini_file (fhl, name);
225 g_free (name);
226 return ok;
227 }
228
229
230
231 gboolean
232 mc_fhl_parse_ini_file (mc_fhl_t *fhl)
233 {
234 gchar **group_names, **orig_group_names;
235 gboolean ok;
236
237 mc_fhl_array_free (fhl);
238 fhl->filters = g_ptr_array_new_with_free_func (mc_fhl_filter_free);
239
240 orig_group_names = mc_config_get_groups (fhl->config, NULL);
241 ok = (*orig_group_names != NULL);
242
243 for (group_names = orig_group_names; *group_names != NULL; group_names++)
244 {
245 if (mc_config_has_param (fhl->config, *group_names, "type"))
246 {
247
248 mc_fhl_parse_get_file_type_id (fhl, *group_names);
249 }
250 if (mc_config_has_param (fhl->config, *group_names, "regexp"))
251 {
252
253 mc_fhl_parse_get_regexp (fhl, *group_names);
254 }
255 if (mc_config_has_param (fhl->config, *group_names, "extensions"))
256 {
257
258 mc_fhl_parse_get_extensions (fhl, *group_names);
259 }
260 }
261
262 g_strfreev (orig_group_names);
263
264 return ok;
265 }
266
267