This source file includes following definitions.
- mc_fhl_is_file
- mc_fhl_is_file_exec
- mc_fhl_is_dir
- mc_fhl_is_link
- mc_fhl_is_hlink
- mc_fhl_is_link_to_dir
- mc_fhl_is_stale_link
- mc_fhl_is_device_char
- mc_fhl_is_device_block
- mc_fhl_is_special_socket
- mc_fhl_is_special_fifo
- mc_fhl_is_special_door
- mc_fhl_is_special
- mc_fhl_get_color_filetype
- mc_fhl_get_color_regexp
- mc_fhl_get_color
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/skin.h"
32 #include "lib/util.h"
33 #include "lib/filehighlight.h"
34 #include "internal.h"
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 inline static gboolean
50 mc_fhl_is_file (const file_entry_t * fe)
51 {
52 #if HAVE_S_ISREG == 0
53 (void) fe;
54 #endif
55 return S_ISREG (fe->st.st_mode);
56 }
57
58 inline static gboolean
59 mc_fhl_is_file_exec (const file_entry_t * fe)
60 {
61 return is_exe (fe->st.st_mode);
62 }
63
64 inline static gboolean
65 mc_fhl_is_dir (const file_entry_t * fe)
66 {
67 #if HAVE_S_ISDIR == 0
68 (void) fe;
69 #endif
70 return S_ISDIR (fe->st.st_mode);
71 }
72
73 inline static gboolean
74 mc_fhl_is_link (const file_entry_t * fe)
75 {
76 #if HAVE_S_ISLNK == 0
77 (void) fe;
78 #endif
79 return S_ISLNK (fe->st.st_mode);
80 }
81
82 inline static gboolean
83 mc_fhl_is_hlink (const file_entry_t * fe)
84 {
85 return (fe->st.st_nlink > 1);
86 }
87
88 inline static gboolean
89 mc_fhl_is_link_to_dir (const file_entry_t * fe)
90 {
91 return mc_fhl_is_link (fe) && fe->f.link_to_dir;
92 }
93
94 inline static gboolean
95 mc_fhl_is_stale_link (const file_entry_t * fe)
96 {
97 return mc_fhl_is_link (fe) ? fe->f.stale_link : !mc_fhl_is_file (fe);
98 }
99
100 inline static gboolean
101 mc_fhl_is_device_char (const file_entry_t * fe)
102 {
103 #if HAVE_S_ISCHR == 0
104 (void) fe;
105 #endif
106 return S_ISCHR (fe->st.st_mode);
107 }
108
109 inline static gboolean
110 mc_fhl_is_device_block (const file_entry_t * fe)
111 {
112 #if HAVE_S_ISBLK == 0
113 (void) fe;
114 #endif
115 return S_ISBLK (fe->st.st_mode);
116 }
117
118 inline static gboolean
119 mc_fhl_is_special_socket (const file_entry_t * fe)
120 {
121 #if HAVE_S_ISSOCK == 0
122 (void) fe;
123 #endif
124 return S_ISSOCK (fe->st.st_mode);
125 }
126
127 inline static gboolean
128 mc_fhl_is_special_fifo (const file_entry_t * fe)
129 {
130 #if HAVE_S_ISFIFO == 0
131 (void) fe;
132 #endif
133 return S_ISFIFO (fe->st.st_mode);
134 }
135
136 inline static gboolean
137 mc_fhl_is_special_door (const file_entry_t * fe)
138 {
139 #if HAVE_S_ISDOOR == 0
140 (void) fe;
141 #endif
142 return S_ISDOOR (fe->st.st_mode);
143 }
144
145 inline static gboolean
146 mc_fhl_is_special (const file_entry_t * fe)
147 {
148 return
149 (mc_fhl_is_special_socket (fe) || mc_fhl_is_special_fifo (fe)
150 || mc_fhl_is_special_door (fe));
151 }
152
153
154
155 static int
156 mc_fhl_get_color_filetype (const mc_fhl_filter_t * mc_filter, const mc_fhl_t * fhl,
157 const file_entry_t * fe)
158 {
159 gboolean my_color = FALSE;
160
161 (void) fhl;
162
163 switch (mc_filter->file_type)
164 {
165 case MC_FLHGH_FTYPE_T_FILE:
166 if (mc_fhl_is_file (fe))
167 my_color = TRUE;
168 break;
169 case MC_FLHGH_FTYPE_T_FILE_EXE:
170 if (mc_fhl_is_file (fe) && mc_fhl_is_file_exec (fe))
171 my_color = TRUE;
172 break;
173 case MC_FLHGH_FTYPE_T_DIR:
174 if (mc_fhl_is_dir (fe) || mc_fhl_is_link_to_dir (fe))
175 my_color = TRUE;
176 break;
177 case MC_FLHGH_FTYPE_T_LINK_DIR:
178 if (mc_fhl_is_link_to_dir (fe))
179 my_color = TRUE;
180 break;
181 case MC_FLHGH_FTYPE_T_LINK:
182 if (mc_fhl_is_link (fe) || mc_fhl_is_hlink (fe))
183 my_color = TRUE;
184 break;
185 case MC_FLHGH_FTYPE_T_HARDLINK:
186 if (mc_fhl_is_hlink (fe))
187 my_color = TRUE;
188 break;
189 case MC_FLHGH_FTYPE_T_SYMLINK:
190 if (mc_fhl_is_link (fe))
191 my_color = TRUE;
192 break;
193 case MC_FLHGH_FTYPE_T_STALE_LINK:
194 if (mc_fhl_is_stale_link (fe))
195 my_color = TRUE;
196 break;
197 case MC_FLHGH_FTYPE_T_DEVICE:
198 if (mc_fhl_is_device_char (fe) || mc_fhl_is_device_block (fe))
199 my_color = TRUE;
200 break;
201 case MC_FLHGH_FTYPE_T_DEVICE_BLOCK:
202 if (mc_fhl_is_device_block (fe))
203 my_color = TRUE;
204 break;
205 case MC_FLHGH_FTYPE_T_DEVICE_CHAR:
206 if (mc_fhl_is_device_char (fe))
207 my_color = TRUE;
208 break;
209 case MC_FLHGH_FTYPE_T_SPECIAL:
210 if (mc_fhl_is_special (fe))
211 my_color = TRUE;
212 break;
213 case MC_FLHGH_FTYPE_T_SPECIAL_SOCKET:
214 if (mc_fhl_is_special_socket (fe))
215 my_color = TRUE;
216 break;
217 case MC_FLHGH_FTYPE_T_SPECIAL_FIFO:
218 if (mc_fhl_is_special_fifo (fe))
219 my_color = TRUE;
220 break;
221 case MC_FLHGH_FTYPE_T_SPECIAL_DOOR:
222 if (mc_fhl_is_special_door (fe))
223 my_color = TRUE;
224 break;
225 default:
226 break;
227 }
228
229 return my_color ? mc_filter->color_pair_index : -1;
230 }
231
232
233
234 static int
235 mc_fhl_get_color_regexp (const mc_fhl_filter_t * mc_filter, const mc_fhl_t * fhl,
236 const file_entry_t * fe)
237 {
238 (void) fhl;
239
240 if (mc_filter->search_condition == NULL)
241 return -1;
242
243 if (mc_search_run (mc_filter->search_condition, fe->fname->str, 0, fe->fname->len, NULL))
244 return mc_filter->color_pair_index;
245
246 return -1;
247 }
248
249
250
251
252
253
254
255 int
256 mc_fhl_get_color (const mc_fhl_t * fhl, const file_entry_t * fe)
257 {
258 guint i;
259 int ret;
260
261 if (fhl == NULL)
262 return NORMAL_COLOR;
263
264 for (i = 0; i < fhl->filters->len; i++)
265 {
266 mc_fhl_filter_t *mc_filter;
267
268 mc_filter = (mc_fhl_filter_t *) g_ptr_array_index (fhl->filters, i);
269 switch (mc_filter->type)
270 {
271 case MC_FLHGH_T_FTYPE:
272 ret = mc_fhl_get_color_filetype (mc_filter, fhl, fe);
273 if (ret > 0)
274 return -ret;
275 break;
276 case MC_FLHGH_T_EXT:
277 case MC_FLHGH_T_FREGEXP:
278 ret = mc_fhl_get_color_regexp (mc_filter, fhl, fe);
279 if (ret > 0)
280 return -ret;
281 break;
282 default:
283 break;
284 }
285 }
286 return NORMAL_COLOR;
287 }
288
289