Merge branch '2452_handle_baudrate_error'
[midnight-commander.git] / lib / filehighlight / common.c
blobbff518fd8e0059f600b759749c678e0966c2eb7d
1 /*
2 File highlight plugin.
3 Interface functions
5 Copyright (C) 2009-2024
6 Free Software Foundation, Inc.
8 Written by:
9 Slava Zanko <slavazanko@gmail.com>, 2009.
11 This file is part of the Midnight Commander.
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.
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.
23 You should have received a copy of the GNU General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 #include <config.h>
29 #include "lib/global.h"
30 #include "lib/util.h" /* MC_PTR_FREE */
32 #include "lib/filehighlight.h"
34 #include "internal.h"
36 /*** global variables ****************************************************************************/
38 /*** file scope macro definitions ****************************************************************/
40 /*** file scope type declarations ****************************************************************/
42 /*** file scope variables ************************************************************************/
44 /* --------------------------------------------------------------------------------------------- */
45 /*** file scope functions ************************************************************************/
46 /* --------------------------------------------------------------------------------------------- */
48 /* --------------------------------------------------------------------------------------------- */
49 /*** public functions ****************************************************************************/
50 /* --------------------------------------------------------------------------------------------- */
52 void
53 mc_fhl_filter_free (gpointer data)
55 mc_fhl_filter_t *filter = (mc_fhl_filter_t *) data;
57 g_free (filter->fgcolor);
58 g_free (filter->bgcolor);
59 mc_search_free (filter->search_condition);
60 g_free (filter);
63 /* --------------------------------------------------------------------------------------------- */
65 void
66 mc_fhl_array_free (mc_fhl_t *fhl)
68 if (fhl->filters != NULL)
70 g_ptr_array_free (fhl->filters, TRUE);
71 fhl->filters = NULL;
75 /* --------------------------------------------------------------------------------------------- */
77 mc_fhl_t *
78 mc_fhl_new (gboolean need_auto_fill)
80 mc_fhl_t *fhl;
82 fhl = g_try_new0 (mc_fhl_t, 1);
83 if (fhl == NULL)
84 return NULL;
86 if (!need_auto_fill)
87 return fhl;
89 if (!mc_fhl_init_from_standard_files (fhl))
91 g_free (fhl);
92 return NULL;
95 if (!mc_fhl_parse_ini_file (fhl))
97 mc_fhl_free (&fhl);
98 return NULL;
101 return fhl;
104 /* --------------------------------------------------------------------------------------------- */
106 void
107 mc_fhl_free (mc_fhl_t **fhl)
109 if (fhl == NULL || *fhl == NULL)
110 return;
112 mc_fhl_clear (*fhl);
114 MC_PTR_FREE (*fhl);
117 /* --------------------------------------------------------------------------------------------- */
119 void
120 mc_fhl_clear (mc_fhl_t *fhl)
122 if (fhl != NULL)
124 mc_config_deinit (fhl->config);
125 mc_fhl_array_free (fhl);
129 /* --------------------------------------------------------------------------------------------- */