common.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. File highlight plugin.
  3. Interface functions
  4. Copyright (C) 2009-2024
  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/util.h" /* MC_PTR_FREE */
  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. /* --------------------------------------------------------------------------------------------- */
  30. /*** file scope functions ************************************************************************/
  31. /* --------------------------------------------------------------------------------------------- */
  32. /* --------------------------------------------------------------------------------------------- */
  33. /*** public functions ****************************************************************************/
  34. /* --------------------------------------------------------------------------------------------- */
  35. void
  36. mc_fhl_filter_free (gpointer data)
  37. {
  38. mc_fhl_filter_t *filter = (mc_fhl_filter_t *) data;
  39. g_free (filter->fgcolor);
  40. g_free (filter->bgcolor);
  41. mc_search_free (filter->search_condition);
  42. g_free (filter);
  43. }
  44. /* --------------------------------------------------------------------------------------------- */
  45. void
  46. mc_fhl_array_free (mc_fhl_t *fhl)
  47. {
  48. if (fhl->filters != NULL)
  49. {
  50. g_ptr_array_free (fhl->filters, TRUE);
  51. fhl->filters = NULL;
  52. }
  53. }
  54. /* --------------------------------------------------------------------------------------------- */
  55. mc_fhl_t *
  56. mc_fhl_new (gboolean need_auto_fill)
  57. {
  58. mc_fhl_t *fhl;
  59. fhl = g_try_new0 (mc_fhl_t, 1);
  60. if (fhl == NULL)
  61. return NULL;
  62. if (!need_auto_fill)
  63. return fhl;
  64. if (!mc_fhl_init_from_standard_files (fhl))
  65. {
  66. g_free (fhl);
  67. return NULL;
  68. }
  69. if (!mc_fhl_parse_ini_file (fhl))
  70. {
  71. mc_fhl_free (&fhl);
  72. return NULL;
  73. }
  74. return fhl;
  75. }
  76. /* --------------------------------------------------------------------------------------------- */
  77. void
  78. mc_fhl_free (mc_fhl_t **fhl)
  79. {
  80. if (fhl == NULL || *fhl == NULL)
  81. return;
  82. mc_fhl_clear (*fhl);
  83. MC_PTR_FREE (*fhl);
  84. }
  85. /* --------------------------------------------------------------------------------------------- */
  86. void
  87. mc_fhl_clear (mc_fhl_t *fhl)
  88. {
  89. if (fhl != NULL)
  90. {
  91. mc_config_deinit (fhl->config);
  92. mc_fhl_array_free (fhl);
  93. }
  94. }
  95. /* --------------------------------------------------------------------------------------------- */