common.c 3.4 KB

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