(mc_search__hex_translate_to_regex): rename variables.
[midnight-commander.git] / lib / mcconfig / get.c
blob5e2f78d3ac098ea20e86e158cd1f07837d270185
1 /*
2 Configure module for the Midnight Commander
4 Copyright (C) 1994-2016
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/>.
23 #include <config.h>
25 #include "lib/global.h"
26 #include "lib/strutil.h"
27 #include "lib/mcconfig.h"
29 /*** global variables **************************************************/
31 /*** file scope macro definitions **************************************/
33 /*** file scope type declarations **************************************/
35 /*** file scope variables **********************************************/
37 /*** file scope functions **********************************************/
39 /*** public functions **************************************************/
41 gchar **
42 mc_config_get_groups (const mc_config_t * mc_config, gsize * len)
44 gchar **ret = NULL;
46 if (mc_config != NULL)
47 ret = g_key_file_get_groups (mc_config->handle, len);
49 if (ret == NULL)
51 ret = g_try_malloc0 (sizeof (gchar **));
52 if (len != NULL)
53 *len = 0;
56 return ret;
59 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
61 gchar **
62 mc_config_get_keys (const mc_config_t * mc_config, const gchar * group, gsize * len)
64 gchar **ret = NULL;
66 if (mc_config != NULL && group != NULL)
67 ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
69 if (ret == NULL)
71 ret = g_try_malloc0 (sizeof (gchar **));
72 if (len != NULL)
73 *len = 0;
76 return ret;
79 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
81 gchar *
82 mc_config_get_string (mc_config_t * mc_config, const gchar * group,
83 const gchar * param, const gchar * def)
85 GIConv conv;
86 GString *buffer;
87 gchar *ret;
88 estr_t conv_res;
90 if (!mc_config || !group || !param)
91 return g_strdup (def);
93 if (!mc_config_has_param (mc_config, group, param))
95 if (def != NULL)
96 mc_config_set_string (mc_config, group, param, def);
97 return g_strdup (def);
100 ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
101 if (ret == NULL)
102 ret = g_strdup (def);
104 if (mc_global.utf8_display)
105 return ret;
107 conv = str_crt_conv_from ("UTF-8");
108 if (conv == INVALID_CONV)
109 return ret;
111 buffer = g_string_new ("");
112 conv_res = str_convert (conv, ret, buffer);
113 str_close_conv (conv);
115 if (conv_res == ESTR_FAILURE)
117 g_string_free (buffer, TRUE);
118 return ret;
121 g_free (ret);
123 return g_string_free (buffer, FALSE);
126 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
128 gchar *
129 mc_config_get_string_raw (const mc_config_t * mc_config, const gchar * group,
130 const gchar * param, const gchar * def)
132 gchar *ret;
134 if (!mc_config || !group || !param)
135 return g_strdup (def);
137 if (!mc_config_has_param (mc_config, group, param))
139 if (def != NULL)
140 mc_config_set_string (mc_config, group, param, def);
141 return g_strdup (def);
144 ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
146 return ret != NULL ? ret : g_strdup (def);
149 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
151 gboolean
152 mc_config_get_bool (mc_config_t * mc_config, const gchar * group, const gchar * param, gboolean def)
154 if (!mc_config || !group || !param)
155 return def;
157 if (!mc_config_has_param (mc_config, group, param))
159 mc_config_set_bool (mc_config, group, param, def);
160 return def;
163 return g_key_file_get_boolean (mc_config->handle, group, param, NULL);
166 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
169 mc_config_get_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int def)
171 if (!mc_config || !group || !param)
172 return def;
174 if (!mc_config_has_param (mc_config, group, param))
176 mc_config_set_int (mc_config, group, param, def);
177 return def;
180 return g_key_file_get_integer (mc_config->handle, group, param, NULL);
183 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
184 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
186 gchar **
187 mc_config_get_string_list (mc_config_t * mc_config, const gchar * group,
188 const gchar * param, gsize * length)
190 if (!mc_config || !group || !param)
191 return NULL;
193 return g_key_file_get_string_list (mc_config->handle, group, param, length, NULL);
196 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
198 gboolean *
199 mc_config_get_bool_list (mc_config_t * mc_config, const gchar * group,
200 const gchar * param, gsize * length)
202 if (!mc_config || !group || !param)
203 return NULL;
205 return g_key_file_get_boolean_list (mc_config->handle, group, param, length, NULL);
208 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
210 int *
211 mc_config_get_int_list (mc_config_t * mc_config, const gchar * group,
212 const gchar * param, gsize * length)
214 if (!mc_config || !group || !param)
215 return NULL;
217 return g_key_file_get_integer_list (mc_config->handle, group, param, length, NULL);
220 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */