common.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. /* --------------------------------------------------------------------------------------------- */
  31. void
  32. mc_fhl_array_free (mc_fhl_t * fhl)
  33. {
  34. guint i;
  35. mc_fhl_filter_t *mc_filter;
  36. if (fhl->filters == NULL)
  37. return;
  38. for (i = 0; i < fhl->filters->len; i++) {
  39. mc_filter = (mc_fhl_filter_t *) g_ptr_array_index (fhl->filters, i);
  40. g_free (mc_filter->fgcolor);
  41. g_free (mc_filter->bgcolor);
  42. if (mc_filter->search_condition != NULL)
  43. mc_search_free (mc_filter->search_condition);
  44. g_free (mc_filter);
  45. }
  46. g_ptr_array_free (fhl->filters, TRUE);
  47. fhl->filters = NULL;
  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_standart_files (fhl)) {
  62. g_free (fhl);
  63. return NULL;
  64. }
  65. if (!mc_fhl_parse_ini_file (fhl)) {
  66. mc_fhl_free (&fhl);
  67. return NULL;
  68. }
  69. return fhl;
  70. }
  71. /* --------------------------------------------------------------------------------------------- */
  72. void
  73. mc_fhl_free (mc_fhl_t ** fhl)
  74. {
  75. if (fhl == NULL || *fhl == NULL)
  76. return;
  77. mc_fhl_clear (*fhl);
  78. g_free (*fhl);
  79. *fhl = NULL;
  80. }
  81. /* --------------------------------------------------------------------------------------------- */
  82. void
  83. mc_fhl_clear (mc_fhl_t * fhl)
  84. {
  85. if (fhl == NULL)
  86. return;
  87. if (fhl->config)
  88. mc_config_deinit (fhl->config);
  89. mc_fhl_array_free (fhl);
  90. }
  91. /* --------------------------------------------------------------------------------------------- */