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"
36 /*** global variables ****************************************************************************/
38 /*** file scope macro definitions ****************************************************************/
40 /*** file scope type declarations ****************************************************************/
42 /*** file scope variables ************************************************************************/
44 /*** file scope functions ************************************************************************/
46 /* --------------------------------------------------------------------------------------------- */
49 mc_skin_ini_file_load_search_in_dir (mc_skin_t
* mc_skin
, const gchar
* base_dir
)
51 char *file_name
, *file_name2
;
53 file_name
= g_build_filename (base_dir
, MC_SKINS_SUBDIR
, mc_skin
->name
, NULL
);
54 if (exist_file (file_name
))
56 mc_skin
->config
= mc_config_init (file_name
);
58 return (mc_skin
->config
!= NULL
);
62 file_name2
= g_strdup_printf ("%s.ini", mc_skin
->name
);
63 file_name
= g_build_filename (base_dir
, MC_SKINS_SUBDIR
, file_name2
, NULL
);
66 if (exist_file (file_name
))
68 mc_skin
->config
= mc_config_init (file_name
);
70 return (mc_skin
->config
!= NULL
);
76 /* --------------------------------------------------------------------------------------------- */
77 /*** public functions ****************************************************************************/
78 /* --------------------------------------------------------------------------------------------- */
81 mc_skin_ini_file_load (mc_skin_t
* mc_skin
)
83 char *file_name
, *user_home_dir
;
85 file_name
= g_path_get_basename (mc_skin
->name
);
86 if (file_name
== NULL
)
89 if (strcmp (file_name
, mc_skin
->name
) != 0)
92 if (!g_path_is_absolute (mc_skin
->name
))
94 mc_skin
->config
= mc_config_init (mc_skin
->name
);
95 return (mc_skin
->config
!= NULL
);
100 user_home_dir
= concat_dir_and_file (home_dir
, MC_USERCONF_DIR
);
101 if (mc_skin_ini_file_load_search_in_dir (mc_skin
, user_home_dir
))
103 g_free (user_home_dir
);
106 g_free (user_home_dir
);
109 if (mc_skin_ini_file_load_search_in_dir (mc_skin
, mc_home
))
112 /* /usr/share/mc/skins/ */
113 return mc_skin_ini_file_load_search_in_dir (mc_skin
, mc_home_alt
);
116 /* --------------------------------------------------------------------------------------------- */
119 mc_skin_ini_file_parse (mc_skin_t
* mc_skin
)
121 mc_skin
->description
=
122 mc_config_get_string (mc_skin
->config
, "skin", "description", "- no description -");
123 if (!mc_skin_color_parse_ini_file (mc_skin
))
126 mc_skin_lines_parse_ini_file (mc_skin
);
131 /* --------------------------------------------------------------------------------------------- */
134 mc_skin_set_hardcoded_skin (mc_skin_t
* mc_skin
)
136 mc_skin
->config
= mc_config_init (NULL
);
138 mc_config_set_string (mc_skin
->config
, "skin", "description", "hardcoded skin");
140 mc_skin_hardcoded_ugly_lines (mc_skin
);
141 mc_skin_hardcoded_blackwhite_colors (mc_skin
);
144 /* --------------------------------------------------------------------------------------------- */