1 /*
2 File highlight plugin.
3 Interface functions
4
5 Copyright (C) 2009-2025
6 Free Software Foundation, Inc.
7
8 Written by:
9 Slava Zanko <slavazanko@gmail.com>, 2009.
10
11 This file is part of the Midnight Commander.
12
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 3 of the License,
16 or (at your option) any later version.
17
18 The Midnight Commander is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
27 #include <config.h>
28
29 #include "lib/global.h"
30 #include "lib/util.h" // MC_PTR_FREE
31
32 #include "lib/filehighlight.h"
33
34 #include "internal.h"
35
36 /*** global variables ****************************************************************************/
37
38 /*** file scope macro definitions ****************************************************************/
39
40 /*** file scope type declarations ****************************************************************/
41
42 /*** file scope variables ************************************************************************/
43
44 /* --------------------------------------------------------------------------------------------- */
45 /*** file scope functions ************************************************************************/
46 /* --------------------------------------------------------------------------------------------- */
47
48 /* --------------------------------------------------------------------------------------------- */
49 /*** public functions ****************************************************************************/
50 /* --------------------------------------------------------------------------------------------- */
51
52 void
53 mc_fhl_filter_free (gpointer data)
/* ![[previous]](../icons/n_left.png)
![[next]](../icons/right.png)
![[first]](../icons/n_first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
54 {
55 mc_fhl_filter_t *filter = (mc_fhl_filter_t *) data;
56
57 g_free (filter->fgcolor);
58 g_free (filter->bgcolor);
59 mc_search_free (filter->search_condition);
60 g_free (filter);
61 }
62
63 /* --------------------------------------------------------------------------------------------- */
64
65 void
66 mc_fhl_array_free (mc_fhl_t *fhl)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
67 {
68 if (fhl->filters != NULL)
69 {
70 g_ptr_array_free (fhl->filters, TRUE);
71 fhl->filters = NULL;
72 }
73 }
74
75 /* --------------------------------------------------------------------------------------------- */
76
77 mc_fhl_t *
78 mc_fhl_new (gboolean need_auto_fill)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
79 {
80 mc_fhl_t *fhl;
81
82 fhl = g_try_new0 (mc_fhl_t, 1);
83 if (fhl == NULL)
84 return NULL;
85
86 if (!need_auto_fill)
87 return fhl;
88
89 if (!mc_fhl_init_from_standard_files (fhl))
90 {
91 g_free (fhl);
92 return NULL;
93 }
94
95 if (!mc_fhl_parse_ini_file (fhl))
96 {
97 mc_fhl_free (&fhl);
98 return NULL;
99 }
100
101 return fhl;
102 }
103
104 /* --------------------------------------------------------------------------------------------- */
105
106 void
107 mc_fhl_free (mc_fhl_t **fhl)
/* ![[previous]](../icons/left.png)
![[next]](../icons/right.png)
![[first]](../icons/first.png)
![[last]](../icons/last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
108 {
109 if (fhl == NULL || *fhl == NULL)
110 return;
111
112 mc_fhl_clear (*fhl);
113
114 MC_PTR_FREE (*fhl);
115 }
116
117 /* --------------------------------------------------------------------------------------------- */
118
119 void
120 mc_fhl_clear (mc_fhl_t *fhl)
/* ![[previous]](../icons/left.png)
![[next]](../icons/n_right.png)
![[first]](../icons/first.png)
![[last]](../icons/n_last.png)
![[top]](../icons/top.png)
![[bottom]](../icons/bottom.png)
![[index]](../icons/index.png)
*/
121 {
122 if (fhl != NULL)
123 {
124 mc_config_deinit (fhl->config);
125 mc_fhl_array_free (fhl);
126 }
127 }
128
129 /* --------------------------------------------------------------------------------------------- */