1 /* Configure module for the Midnight Commander
2 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
3 2007, 2009 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include "lib/global.h"
23 #include "lib/strutil.h"
24 #include "lib/mcconfig.h"
26 /*** global variables **************************************************/
28 extern int utf8_display
;
30 /*** file scope macro definitions **************************************/
32 /*** file scope type declarations **************************************/
34 /*** file scope variables **********************************************/
36 /*** file scope functions **********************************************/
38 /*** public functions **************************************************/
41 mc_config_get_groups (mc_config_t
* mc_config
, gsize
* len
)
47 ret
= g_try_malloc0 (sizeof (gchar
**));
52 ret
= g_key_file_get_groups (mc_config
->handle
, len
);
55 ret
= g_try_malloc0 (sizeof (gchar
**));
60 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
63 mc_config_get_keys (mc_config_t
* mc_config
, const gchar
* group
, gsize
* len
)
67 if (!mc_config
|| !group
)
69 ret
= g_try_malloc0 (sizeof (gchar
**));
74 ret
= g_key_file_get_keys (mc_config
->handle
, group
, len
, NULL
);
77 ret
= g_try_malloc0 (sizeof (gchar
**));
82 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
85 mc_config_get_string (mc_config_t
* mc_config
, const gchar
* group
,
86 const gchar
* param
, const gchar
* def
)
93 if (!mc_config
|| !group
|| !param
)
94 return g_strdup (def
);
96 if (!mc_config_has_param (mc_config
, group
, param
))
98 mc_config_set_string (mc_config
, group
, param
, def
? def
: "");
99 return g_strdup (def
);
102 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
104 ret
= g_strdup (def
);
109 conv
= str_crt_conv_from ("UTF-8");
110 if (conv
== INVALID_CONV
)
113 buffer
= g_string_new ("");
114 conv_res
= str_convert (conv
, ret
, buffer
);
115 str_close_conv (conv
);
117 if (conv_res
== ESTR_FAILURE
)
119 g_string_free (buffer
, TRUE
);
125 return g_string_free (buffer
, FALSE
);
128 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
131 mc_config_get_string_raw (mc_config_t
* mc_config
, const gchar
* group
,
132 const gchar
* param
, const gchar
* def
)
136 if (!mc_config
|| !group
|| !param
)
137 return g_strdup (def
);
139 if (!mc_config_has_param (mc_config
, group
, param
))
141 mc_config_set_string (mc_config
, group
, param
, def
? def
: "");
142 return g_strdup (def
);
145 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
147 return ret
!= NULL
? ret
: g_strdup (def
);
150 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
153 mc_config_get_bool (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, gboolean def
)
155 if (!mc_config
|| !group
|| !param
)
158 if (!mc_config_has_param (mc_config
, group
, param
))
160 mc_config_set_bool (mc_config
, group
, param
, def
);
164 return g_key_file_get_boolean (mc_config
->handle
, group
, param
, NULL
);
167 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
170 mc_config_get_int (mc_config_t
* mc_config
, const gchar
* group
, const gchar
* param
, int def
)
172 if (!mc_config
|| !group
|| !param
)
175 if (!mc_config_has_param (mc_config
, group
, param
))
177 mc_config_set_int (mc_config
, group
, param
, def
);
181 return g_key_file_get_integer (mc_config
->handle
, group
, param
, NULL
);
184 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
185 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
188 mc_config_get_string_list (mc_config_t
* mc_config
, const gchar
* group
,
189 const gchar
* param
, gsize
* length
)
191 if (!mc_config
|| !group
|| !param
)
194 return g_key_file_get_string_list (mc_config
->handle
, group
, param
, length
, NULL
);
197 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
200 mc_config_get_bool_list (mc_config_t
* mc_config
, const gchar
* group
,
201 const gchar
* param
, gsize
* length
)
203 if (!mc_config
|| !group
|| !param
)
206 return g_key_file_get_boolean_list (mc_config
->handle
, group
, param
, length
, NULL
);
209 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
212 mc_config_get_int_list (mc_config_t
* mc_config
, const gchar
* group
,
213 const gchar
* param
, gsize
* length
)
215 if (!mc_config
|| !group
|| !param
)
218 return g_key_file_get_integer_list (mc_config
->handle
, group
, param
, length
, NULL
);
221 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */