common.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. File highlight plugin.
  3. Interface functions
  4. Copyright (C) 2009-2015
  5. Free Software Foundation, Inc.
  6. Written by:
  7. Slava Zanko <slavazanko@gmail.com>, 2009.
  8. This file is part of the Midnight Commander.
  9. The Midnight Commander is free software: you can redistribute it
  10. and/or modify it under the terms of the GNU General Public License as
  11. published by the Free Software Foundation, either version 3 of the License,
  12. or (at your option) any later version.
  13. The Midnight Commander is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. GNU General Public License for more details.
  17. You should have received a copy of the GNU General Public License
  18. along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include "lib/global.h"
  22. #include "lib/filehighlight.h"
  23. #include "internal.h"
  24. /*** global variables ****************************************************************************/
  25. /*** file scope macro definitions ****************************************************************/
  26. /*** file scope type declarations ****************************************************************/
  27. /*** file scope variables ************************************************************************/
  28. /*** file scope functions ************************************************************************/
  29. static void
  30. mc_fhl_filter_free (void *data)
  31. {
  32. mc_fhl_filter_t *filter = (mc_fhl_filter_t *) data;
  33. g_free (filter->fgcolor);
  34. g_free (filter->bgcolor);
  35. mc_search_free (filter->search_condition);
  36. g_free (filter);
  37. }
  38. /* --------------------------------------------------------------------------------------------- */
  39. void
  40. mc_fhl_array_free (mc_fhl_t * fhl)
  41. {
  42. if (fhl->filters != NULL)
  43. {
  44. g_ptr_array_foreach (fhl->filters, (GFunc) mc_fhl_filter_free, NULL);
  45. fhl->filters = (GPtrArray *) g_ptr_array_free (fhl->filters, TRUE);
  46. }
  47. }
  48. /* --------------------------------------------------------------------------------------------- */
  49. /*** public functions ****************************************************************************/
  50. /* --------------------------------------------------------------------------------------------- */
  51. mc_fhl_t *
  52. mc_fhl_new (gboolean need_auto_fill)
  53. {
  54. mc_fhl_t *fhl;
  55. fhl = g_try_new0 (mc_fhl_t, 1);
  56. if (fhl == NULL)
  57. return NULL;
  58. if (!need_auto_fill)
  59. return fhl;
  60. if (!mc_fhl_init_from_standard_files (fhl))
  61. {
  62. g_free (fhl);
  63. return NULL;
  64. }
  65. if (!mc_fhl_parse_ini_file (fhl))
  66. {
  67. mc_fhl_free (&fhl);
  68. return NULL;
  69. }
  70. return fhl;
  71. }
  72. /* --------------------------------------------------------------------------------------------- */
  73. void
  74. mc_fhl_free (mc_fhl_t ** fhl)
  75. {
  76. if (fhl == NULL || *fhl == NULL)
  77. return;
  78. mc_fhl_clear (*fhl);
  79. MC_PTR_FREE (*fhl);
  80. }
  81. /* --------------------------------------------------------------------------------------------- */
  82. void
  83. mc_fhl_clear (mc_fhl_t * fhl)
  84. {
  85. if (fhl != NULL)
  86. {
  87. mc_config_deinit (fhl->config);
  88. mc_fhl_array_free (fhl);
  89. }
  90. }
  91. /* --------------------------------------------------------------------------------------------- */