ini-file.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. Skins engine.
  3. Reading and parse ini-files
  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 <string.h>
  23. #include "internal.h"
  24. #include "lib/fileloc.h"
  25. #include "lib/util.h" /* exist_file() */
  26. #include "src/main.h"
  27. /*** global variables ****************************************************************************/
  28. /*** file scope macro definitions ****************************************************************/
  29. /*** file scope type declarations ****************************************************************/
  30. /*** file scope variables ************************************************************************/
  31. /*** file scope functions ************************************************************************/
  32. /* --------------------------------------------------------------------------------------------- */
  33. /* --------------------------------------------------------------------------------------------- */
  34. /*** public functions ****************************************************************************/
  35. /* --------------------------------------------------------------------------------------------- */
  36. gboolean
  37. mc_skin_ini_file_load (mc_skin_t * mc_skin)
  38. {
  39. char *file_name;
  40. file_name = g_path_get_basename (mc_skin->name);
  41. if (file_name == NULL)
  42. return FALSE;
  43. if (strcmp (file_name, mc_skin->name) != 0)
  44. {
  45. g_free (file_name);
  46. if (!g_path_is_absolute (mc_skin->name))
  47. return FALSE;
  48. mc_skin->config = mc_config_init (mc_skin->name);
  49. return (mc_skin->config != NULL);
  50. }
  51. g_free (file_name);
  52. file_name = mc_config_search_conffile(mc_config_get_data_path (), MC_SKINS_SUBDIR, mc_skin->name);
  53. if (file_name == NULL)
  54. {
  55. char *fname_ext = g_strdup_printf ("%s.ini", mc_skin->name);
  56. file_name = mc_config_search_conffile(mc_config_get_data_path (), MC_SKINS_SUBDIR, fname_ext);
  57. g_free(fname_ext);
  58. }
  59. if (file_name == NULL)
  60. return FALSE;
  61. mc_skin->config = mc_config_init (file_name);
  62. g_free (file_name);
  63. return (mc_skin->config != NULL);
  64. }
  65. /* --------------------------------------------------------------------------------------------- */
  66. gboolean
  67. mc_skin_ini_file_parse (mc_skin_t * mc_skin)
  68. {
  69. mc_skin->description =
  70. mc_config_get_string (mc_skin->config, "skin", "description", "- no description -");
  71. if (!mc_skin_color_parse_ini_file (mc_skin))
  72. return FALSE;
  73. mc_skin_lines_parse_ini_file (mc_skin);
  74. mc_skin->have_256_colors = mc_config_get_bool (mc_skin->config, "skin", "256colors", FALSE);
  75. return TRUE;
  76. }
  77. /* --------------------------------------------------------------------------------------------- */
  78. void
  79. mc_skin_set_hardcoded_skin (mc_skin_t * mc_skin)
  80. {
  81. mc_skin->config = mc_config_init (NULL);
  82. mc_config_set_string (mc_skin->config, "skin", "description", "hardcoded skin");
  83. mc_skin_hardcoded_ugly_lines (mc_skin);
  84. mc_skin_hardcoded_blackwhite_colors (mc_skin);
  85. }
  86. /* --------------------------------------------------------------------------------------------- */