1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
/*
Configure module for the Midnight Commander
Copyright (C) 1994-2022
Free Software Foundation, Inc.
This file is part of the Midnight Commander.
The Midnight Commander is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the License,
or (at your option) any later version.
The Midnight Commander is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include "lib/global.h"
#include "lib/strutil.h"
#include "lib/mcconfig.h"
/*** global variables ****************************************************************************/
/*** file scope macro definitions ****************************************************************/
/*** file scope type declarations ****************************************************************/
/*** file scope variables ************************************************************************/
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
gchar **
mc_config_get_groups (const mc_config_t * mc_config, gsize * len)
{
gchar **ret = NULL;
if (mc_config != NULL)
ret = g_key_file_get_groups (mc_config->handle, len);
if (ret == NULL)
{
ret = g_try_malloc0 (sizeof (gchar **));
if (len != NULL)
*len = 0;
}
return ret;
}
/* --------------------------------------------------------------------------------------------- */
gchar **
mc_config_get_keys (const mc_config_t * mc_config, const gchar * group, gsize * len)
{
gchar **ret = NULL;
if (mc_config != NULL && group != NULL)
ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
if (ret == NULL)
{
ret = g_try_malloc0 (sizeof (gchar **));
if (len != NULL)
*len = 0;
}
return ret;
}
/* --------------------------------------------------------------------------------------------- */
gchar *
mc_config_get_string (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * def)
{
GIConv conv;
GString *buffer;
gchar *ret;
estr_t conv_res;
ret = mc_config_get_string_raw (mc_config, group, param, def);
if (mc_global.utf8_display)
return ret;
conv = str_crt_conv_from ("UTF-8");
if (conv == INVALID_CONV)
return ret;
buffer = g_string_new ("");
conv_res = str_convert (conv, ret, buffer);
str_close_conv (conv);
if (conv_res == ESTR_FAILURE)
{
g_string_free (buffer, TRUE);
return ret;
}
g_free (ret);
return g_string_free (buffer, FALSE);
}
/* --------------------------------------------------------------------------------------------- */
gchar *
mc_config_get_string_raw (mc_config_t * mc_config, const gchar * group,
const gchar * param, const gchar * def)
{
gchar *ret;
if (mc_config == NULL || group == NULL || param == NULL)
return g_strdup (def);
if (!mc_config_has_param (mc_config, group, param))
{
if (def != NULL)
mc_config_set_string (mc_config, group, param, def);
return g_strdup (def);
}
ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
return ret != NULL ? ret : g_strdup (def);
}
/* --------------------------------------------------------------------------------------------- */
gboolean
mc_config_get_bool (mc_config_t * mc_config, const gchar * group, const gchar * param, gboolean def)
{
if (mc_config == NULL || group == NULL || param == NULL)
return def;
if (!mc_config_has_param (mc_config, group, param))
{
mc_config_set_bool (mc_config, group, param, def);
return def;
}
return g_key_file_get_boolean (mc_config->handle, group, param, NULL);
}
/* --------------------------------------------------------------------------------------------- */
int
mc_config_get_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int def)
{
if (mc_config == NULL || group == NULL || param == NULL)
return def;
if (!mc_config_has_param (mc_config, group, param))
{
mc_config_set_int (mc_config, group, param, def);
return def;
}
return g_key_file_get_integer (mc_config->handle, group, param, NULL);
}
/* --------------------------------------------------------------------------------------------- */
gchar **
mc_config_get_string_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gsize * length)
{
if (mc_config == NULL || group == NULL || param == NULL)
return NULL;
return g_key_file_get_string_list (mc_config->handle, group, param, length, NULL);
}
/* --------------------------------------------------------------------------------------------- */
gboolean *
mc_config_get_bool_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gsize * length)
{
if (mc_config == NULL || group == NULL || param == NULL)
return NULL;
return g_key_file_get_boolean_list (mc_config->handle, group, param, length, NULL);
}
/* --------------------------------------------------------------------------------------------- */
int *
mc_config_get_int_list (mc_config_t * mc_config, const gchar * group,
const gchar * param, gsize * length)
{
if (mc_config == NULL || group == NULL || param == NULL)
return NULL;
return g_key_file_get_integer_list (mc_config->handle, group, param, length, NULL);
}
/* --------------------------------------------------------------------------------------------- */
|