3 Reading and parse ini-files
5 Copyright (C) 2009 The Free Software Foundation, Inc.
8 Slava Zanko <slavazanko@gmail.com>, 2009.
10 This file is part of the Midnight Commander.
12 The Midnight Commander is free software; you can redistribute it
13 and/or modify it under the terms of the GNU General Public License as
14 published by the Free Software Foundation; either version 2 of the
15 License, or (at your option) any later version.
17 The Midnight Commander is distributed in the hope that it will be
18 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
19 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
32 #include "lib/fileloc.h"
33 #include "lib/util.h" /* exist_file() */
35 /*** global variables ****************************************************************************/
37 /*** file scope macro definitions ****************************************************************/
39 /*** file scope type declarations ****************************************************************/
41 /*** file scope variables ************************************************************************/
43 /*** file scope functions ************************************************************************/
45 /* --------------------------------------------------------------------------------------------- */
48 mc_skin_ini_file_load_search_in_dir (mc_skin_t
* mc_skin
, const gchar
* base_dir
)
50 char *file_name
, *file_name2
;
52 file_name
= g_build_filename (base_dir
, MC_SKINS_SUBDIR
, mc_skin
->name
, NULL
);
53 if (exist_file (file_name
))
55 mc_skin
->config
= mc_config_init (file_name
);
57 return (mc_skin
->config
!= NULL
);
61 file_name2
= g_strdup_printf ("%s.ini", mc_skin
->name
);
62 file_name
= g_build_filename (base_dir
, MC_SKINS_SUBDIR
, file_name2
, NULL
);
65 if (exist_file (file_name
))
67 mc_skin
->config
= mc_config_init (file_name
);
69 return (mc_skin
->config
!= NULL
);
75 /* --------------------------------------------------------------------------------------------- */
76 /*** public functions ****************************************************************************/
77 /* --------------------------------------------------------------------------------------------- */
80 mc_skin_ini_file_load (mc_skin_t
* mc_skin
)
84 file_name
= g_path_get_basename (mc_skin
->name
);
85 if (file_name
== NULL
)
88 if (strcmp (file_name
, mc_skin
->name
) != 0)
91 if (!g_path_is_absolute (mc_skin
->name
))
93 mc_skin
->config
= mc_config_init (mc_skin
->name
);
94 return (mc_skin
->config
!= NULL
);
98 /* ${XDG_DATA_HOME}/mc/skins/ */
99 if (mc_skin_ini_file_load_search_in_dir (mc_skin
, mc_config_get_data_path ()))
103 if (mc_skin_ini_file_load_search_in_dir (mc_skin
, mc_global
.sysconfig_dir
))
106 /* /usr/share/mc/skins/ */
107 return mc_skin_ini_file_load_search_in_dir (mc_skin
, mc_global
.share_data_dir
);
110 /* --------------------------------------------------------------------------------------------- */
113 mc_skin_ini_file_parse (mc_skin_t
* mc_skin
)
115 mc_skin
->description
=
116 mc_config_get_string (mc_skin
->config
, "skin", "description", "- no description -");
117 if (!mc_skin_color_parse_ini_file (mc_skin
))
120 mc_skin_lines_parse_ini_file (mc_skin
);
121 mc_skin
->have_256_colors
= mc_config_get_bool (mc_skin
->config
, "skin", "256colors", FALSE
);
126 /* --------------------------------------------------------------------------------------------- */
129 mc_skin_set_hardcoded_skin (mc_skin_t
* mc_skin
)
131 mc_skin
->config
= mc_config_init (NULL
);
133 mc_config_set_string (mc_skin
->config
, "skin", "description", "hardcoded skin");
135 mc_skin_hardcoded_ugly_lines (mc_skin
);
136 mc_skin_hardcoded_blackwhite_colors (mc_skin
);
139 /* --------------------------------------------------------------------------------------------- */