2 Configure module for the Midnight Commander
4 Copyright (C) 1994-2024
5 Free Software Foundation, Inc.
7 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.
14 The Midnight Commander is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "lib/global.h"
26 #include "lib/strutil.h"
28 #include "lib/mcconfig.h"
30 /*** global variables ****************************************************************************/
32 /*** file scope macro definitions ****************************************************************/
34 /*** file scope type declarations ****************************************************************/
36 /*** file scope variables ************************************************************************/
38 /*** file scope functions ************************************************************************/
40 /* --------------------------------------------------------------------------------------------- */
41 /*** file scope functions ************************************************************************/
42 /* --------------------------------------------------------------------------------------------- */
44 /* --------------------------------------------------------------------------------------------- */
45 /*** public functions ****************************************************************************/
46 /* --------------------------------------------------------------------------------------------- */
49 mc_config_get_groups (const mc_config_t
*mc_config
, gsize
*len
)
53 if (mc_config
!= NULL
)
54 ret
= g_key_file_get_groups (mc_config
->handle
, len
);
58 ret
= g_try_malloc0 (sizeof (gchar
**));
66 /* --------------------------------------------------------------------------------------------- */
69 mc_config_get_keys (const mc_config_t
*mc_config
, const gchar
*group
, gsize
*len
)
73 if (mc_config
!= NULL
&& group
!= NULL
)
74 ret
= g_key_file_get_keys (mc_config
->handle
, group
, len
, NULL
);
78 ret
= g_try_malloc0 (sizeof (gchar
**));
86 /* --------------------------------------------------------------------------------------------- */
89 mc_config_get_string (mc_config_t
*mc_config
, const gchar
*group
,
90 const gchar
*param
, const gchar
*def
)
97 ret
= mc_config_get_string_raw (mc_config
, group
, param
, def
);
99 if (mc_global
.utf8_display
)
102 conv
= str_crt_conv_from ("UTF-8");
103 if (conv
== INVALID_CONV
)
106 buffer
= g_string_new ("");
107 conv_res
= str_convert (conv
, ret
, buffer
);
108 str_close_conv (conv
);
110 if (conv_res
== ESTR_FAILURE
)
112 g_string_free (buffer
, TRUE
);
118 return g_string_free (buffer
, FALSE
);
121 /* --------------------------------------------------------------------------------------------- */
124 mc_config_get_string_raw (mc_config_t
*mc_config
, const gchar
*group
,
125 const gchar
*param
, const gchar
*def
)
129 if (mc_config
== NULL
|| group
== NULL
|| param
== NULL
)
130 return g_strdup (def
);
132 if (!mc_config_has_param (mc_config
, group
, param
))
135 mc_config_set_string (mc_config
, group
, param
, def
);
136 return g_strdup (def
);
139 ret
= g_key_file_get_string (mc_config
->handle
, group
, param
, NULL
);
141 return ret
!= NULL
? ret
: g_strdup (def
);
144 /* --------------------------------------------------------------------------------------------- */
147 mc_config_get_bool (mc_config_t
*mc_config
, const gchar
*group
, const gchar
*param
, gboolean def
)
149 if (mc_config
== NULL
|| group
== NULL
|| param
== NULL
)
152 if (!mc_config_has_param (mc_config
, group
, param
))
154 mc_config_set_bool (mc_config
, group
, param
, def
);
158 return g_key_file_get_boolean (mc_config
->handle
, group
, param
, NULL
);
161 /* --------------------------------------------------------------------------------------------- */
164 mc_config_get_int (mc_config_t
*mc_config
, const gchar
*group
, const gchar
*param
, int def
)
166 if (mc_config
== NULL
|| group
== NULL
|| param
== NULL
)
169 if (!mc_config_has_param (mc_config
, group
, param
))
171 mc_config_set_int (mc_config
, group
, param
, def
);
175 return g_key_file_get_integer (mc_config
->handle
, group
, param
, NULL
);
178 /* --------------------------------------------------------------------------------------------- */
181 mc_config_get_string_list (mc_config_t
*mc_config
, const gchar
*group
,
182 const gchar
*param
, gsize
*length
)
184 if (mc_config
== NULL
|| group
== NULL
|| param
== NULL
)
187 return g_key_file_get_string_list (mc_config
->handle
, group
, param
, length
, NULL
);
190 /* --------------------------------------------------------------------------------------------- */
193 mc_config_get_bool_list (mc_config_t
*mc_config
, const gchar
*group
,
194 const gchar
*param
, gsize
*length
)
196 if (mc_config
== NULL
|| group
== NULL
|| param
== NULL
)
199 return g_key_file_get_boolean_list (mc_config
->handle
, group
, param
, length
, NULL
);
202 /* --------------------------------------------------------------------------------------------- */
205 mc_config_get_int_list (mc_config_t
*mc_config
, const gchar
*group
,
206 const gchar
*param
, gsize
*length
)
208 if (mc_config
== NULL
|| group
== NULL
|| param
== NULL
)
211 return g_key_file_get_integer_list (mc_config
->handle
, group
, param
, length
, NULL
);
214 /* --------------------------------------------------------------------------------------------- */