root/lib/filehighlight/common.c

/* [previous][next][first][last][top][bottom][index][help]  */

DEFINITIONS

This source file includes following definitions.
  1. mc_fhl_filter_free
  2. mc_fhl_array_free
  3. mc_fhl_new
  4. mc_fhl_free
  5. mc_fhl_clear

   1 /*
   2    File highlight plugin.
   3    Interface functions
   4 
   5    Copyright (C) 2009-2019
   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 <http://www.gnu.org/licenses/>.
  25  */
  26 
  27 #include <config.h>
  28 
  29 #include "lib/global.h"
  30 #include "lib/filehighlight.h"
  31 #include "internal.h"
  32 
  33 /*** global variables ****************************************************************************/
  34 
  35 /*** file scope macro definitions ****************************************************************/
  36 
  37 /*** file scope type declarations ****************************************************************/
  38 
  39 /*** file scope variables ************************************************************************/
  40 
  41 /*** file scope functions ************************************************************************/
  42 
  43 static void
  44 mc_fhl_filter_free (void *data)
     /* [previous][next][first][last][top][bottom][index][help]  */
  45 {
  46     mc_fhl_filter_t *filter = (mc_fhl_filter_t *) data;
  47 
  48     g_free (filter->fgcolor);
  49     g_free (filter->bgcolor);
  50     mc_search_free (filter->search_condition);
  51     g_free (filter);
  52 }
  53 
  54 /* --------------------------------------------------------------------------------------------- */
  55 
  56 void
  57 mc_fhl_array_free (mc_fhl_t * fhl)
     /* [previous][next][first][last][top][bottom][index][help]  */
  58 {
  59     if (fhl->filters != NULL)
  60     {
  61         g_ptr_array_foreach (fhl->filters, (GFunc) mc_fhl_filter_free, NULL);
  62         fhl->filters = (GPtrArray *) g_ptr_array_free (fhl->filters, TRUE);
  63     }
  64 }
  65 
  66 /* --------------------------------------------------------------------------------------------- */
  67 /*** public functions ****************************************************************************/
  68 /* --------------------------------------------------------------------------------------------- */
  69 
  70 mc_fhl_t *
  71 mc_fhl_new (gboolean need_auto_fill)
     /* [previous][next][first][last][top][bottom][index][help]  */
  72 {
  73     mc_fhl_t *fhl;
  74 
  75     fhl = g_try_new0 (mc_fhl_t, 1);
  76     if (fhl == NULL)
  77         return NULL;
  78 
  79     if (!need_auto_fill)
  80         return fhl;
  81 
  82     if (!mc_fhl_init_from_standard_files (fhl))
  83     {
  84         g_free (fhl);
  85         return NULL;
  86     }
  87 
  88     if (!mc_fhl_parse_ini_file (fhl))
  89     {
  90         mc_fhl_free (&fhl);
  91         return NULL;
  92     }
  93 
  94     return fhl;
  95 }
  96 
  97 /* --------------------------------------------------------------------------------------------- */
  98 
  99 void
 100 mc_fhl_free (mc_fhl_t ** fhl)
     /* [previous][next][first][last][top][bottom][index][help]  */
 101 {
 102     if (fhl == NULL || *fhl == NULL)
 103         return;
 104 
 105     mc_fhl_clear (*fhl);
 106 
 107     MC_PTR_FREE (*fhl);
 108 }
 109 
 110 /* --------------------------------------------------------------------------------------------- */
 111 
 112 void
 113 mc_fhl_clear (mc_fhl_t * fhl)
     /* [previous][next][first][last][top][bottom][index][help]  */
 114 {
 115     if (fhl != NULL)
 116     {
 117         mc_config_deinit (fhl->config);
 118         mc_fhl_array_free (fhl);
 119     }
 120 }
 121 
 122 /* --------------------------------------------------------------------------------------------- */

/* [previous][next][first][last][top][bottom][index][help]  */