Implementation of getting last editing/viewing position of file.
[midnight-commander.git] / lib / filehighlight / common.c
blobd5e049d56d7a797a72e39702df70d2bfc645939f
1 /*
2 File highlight plugin.
3 Interface functions
5 Copyright (C) 2009, 2011
6 The 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/filehighlight.h"
31 #include "internal.h"
33 /*** global variables ****************************************************************************/
35 /*** file scope macro definitions ****************************************************************/
37 /*** file scope type declarations ****************************************************************/
39 /*** file scope variables ************************************************************************/
41 /*** file scope functions ************************************************************************/
43 static void
44 mc_fhl_filter_free (void *data)
46 mc_fhl_filter_t *filter = (mc_fhl_filter_t *) data;
48 g_free (filter->fgcolor);
49 g_free (filter->bgcolor);
50 mc_search_free (filter->search_condition);
51 g_free (filter);
54 /* --------------------------------------------------------------------------------------------- */
56 void
57 mc_fhl_array_free (mc_fhl_t * fhl)
59 if (fhl->filters != NULL)
61 g_ptr_array_foreach (fhl->filters, (GFunc) mc_fhl_filter_free, NULL);
62 fhl->filters = (GPtrArray *) g_ptr_array_free (fhl->filters, TRUE);
66 /* --------------------------------------------------------------------------------------------- */
67 /*** public functions ****************************************************************************/
68 /* --------------------------------------------------------------------------------------------- */
70 mc_fhl_t *
71 mc_fhl_new (gboolean need_auto_fill)
73 mc_fhl_t *fhl;
75 fhl = g_try_new0 (mc_fhl_t, 1);
76 if (fhl == NULL)
77 return NULL;
79 if (!need_auto_fill)
80 return fhl;
82 if (!mc_fhl_init_from_standard_files (fhl))
84 g_free (fhl);
85 return NULL;
88 if (!mc_fhl_parse_ini_file (fhl))
90 mc_fhl_free (&fhl);
91 return NULL;
94 return fhl;
97 /* --------------------------------------------------------------------------------------------- */
99 void
100 mc_fhl_free (mc_fhl_t ** fhl)
102 if (fhl == NULL || *fhl == NULL)
103 return;
105 mc_fhl_clear (*fhl);
107 g_free (*fhl);
108 *fhl = NULL;
111 /* --------------------------------------------------------------------------------------------- */
113 void
114 mc_fhl_clear (mc_fhl_t * fhl)
116 if (fhl != NULL)
118 mc_config_deinit (fhl->config);
119 mc_fhl_array_free (fhl);
123 /* --------------------------------------------------------------------------------------------- */