This source file includes following definitions.
- mc_config_get_groups
- mc_config_get_keys
- mc_config_get_string
- mc_config_get_string_strict
- mc_config_get_string_raw
- mc_config_get_bool
- mc_config_get_int
- mc_config_get_string_list
- mc_config_get_bool_list
- mc_config_get_int_list
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include <config.h>
24
25 #include "lib/global.h"
26 #include "lib/strutil.h"
27
28 #include "lib/mcconfig.h"
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 gchar **
49 mc_config_get_groups (const mc_config_t *mc_config, gsize *len)
50 {
51 gchar **ret = NULL;
52
53 if (mc_config != NULL)
54 ret = g_key_file_get_groups (mc_config->handle, len);
55
56 if (ret == NULL)
57 {
58 ret = g_try_malloc0 (sizeof (gchar **));
59 if (len != NULL)
60 *len = 0;
61 }
62
63 return ret;
64 }
65
66
67
68 gchar **
69 mc_config_get_keys (const mc_config_t *mc_config, const gchar *group, gsize *len)
70 {
71 gchar **ret = NULL;
72
73 if (mc_config != NULL && group != NULL)
74 ret = g_key_file_get_keys (mc_config->handle, group, len, NULL);
75
76 if (ret == NULL)
77 {
78 ret = g_try_malloc0 (sizeof (gchar **));
79 if (len != NULL)
80 *len = 0;
81 }
82
83 return ret;
84 }
85
86
87
88 gchar *
89 mc_config_get_string (mc_config_t *mc_config, const gchar *group, const gchar *param,
90 const gchar *def)
91 {
92 GIConv conv;
93 GString *buffer;
94 gchar *ret;
95 estr_t conv_res;
96
97 ret = mc_config_get_string_raw (mc_config, group, param, def);
98
99 if (mc_global.utf8_display)
100 return ret;
101
102 conv = str_crt_conv_from ("UTF-8");
103 if (conv == INVALID_CONV)
104 return ret;
105
106 buffer = g_string_new ("");
107 conv_res = str_convert (conv, ret, buffer);
108 str_close_conv (conv);
109
110 if (conv_res == ESTR_FAILURE)
111 {
112 g_string_free (buffer, TRUE);
113 return ret;
114 }
115
116 g_free (ret);
117
118 return g_string_free (buffer, FALSE);
119 }
120
121
122
123
124
125 gchar *
126 mc_config_get_string_strict (mc_config_t *mc_config, const gchar *group, const gchar *param,
127 const gchar *def)
128 {
129 GIConv conv;
130 GString *buffer;
131 gchar *ret;
132 estr_t conv_res;
133
134 ret = mc_config_get_string_raw (mc_config, group, param, def);
135
136 if (!g_utf8_validate (ret, -1, NULL))
137 {
138 g_free (ret);
139 return g_strdup (def);
140 }
141
142 if (mc_global.utf8_display)
143 return ret;
144
145 conv = str_crt_conv_from ("UTF-8");
146 if (conv == INVALID_CONV)
147 return ret;
148
149 buffer = g_string_new ("");
150 conv_res = str_convert (conv, ret, buffer);
151 g_free (ret);
152 str_close_conv (conv);
153
154 if (conv_res != ESTR_SUCCESS)
155 {
156 g_string_free (buffer, TRUE);
157 return g_strdup (def);
158 }
159
160 return g_string_free (buffer, FALSE);
161 }
162
163
164
165 gchar *
166 mc_config_get_string_raw (mc_config_t *mc_config, const gchar *group, const gchar *param,
167 const gchar *def)
168 {
169 gchar *ret;
170
171 if (mc_config == NULL || group == NULL || param == NULL)
172 return g_strdup (def);
173
174 if (!mc_config_has_param (mc_config, group, param))
175 {
176 if (def != NULL)
177 mc_config_set_string (mc_config, group, param, def);
178 return g_strdup (def);
179 }
180
181 ret = g_key_file_get_string (mc_config->handle, group, param, NULL);
182
183 return ret != NULL ? ret : g_strdup (def);
184 }
185
186
187
188 gboolean
189 mc_config_get_bool (mc_config_t *mc_config, const gchar *group, const gchar *param, gboolean def)
190 {
191 if (mc_config == NULL || group == NULL || param == NULL)
192 return def;
193
194 if (!mc_config_has_param (mc_config, group, param))
195 {
196 mc_config_set_bool (mc_config, group, param, def);
197 return def;
198 }
199
200 return g_key_file_get_boolean (mc_config->handle, group, param, NULL);
201 }
202
203
204
205 int
206 mc_config_get_int (mc_config_t *mc_config, const gchar *group, const gchar *param, int def)
207 {
208 if (mc_config == NULL || group == NULL || param == NULL)
209 return def;
210
211 if (!mc_config_has_param (mc_config, group, param))
212 {
213 mc_config_set_int (mc_config, group, param, def);
214 return def;
215 }
216
217 return g_key_file_get_integer (mc_config->handle, group, param, NULL);
218 }
219
220
221
222 gchar **
223 mc_config_get_string_list (mc_config_t *mc_config, const gchar *group, const gchar *param,
224 gsize *length)
225 {
226 if (mc_config == NULL || group == NULL || param == NULL)
227 return NULL;
228
229 return g_key_file_get_string_list (mc_config->handle, group, param, length, NULL);
230 }
231
232
233
234 gboolean *
235 mc_config_get_bool_list (mc_config_t *mc_config, const gchar *group, const gchar *param,
236 gsize *length)
237 {
238 if (mc_config == NULL || group == NULL || param == NULL)
239 return NULL;
240
241 return g_key_file_get_boolean_list (mc_config->handle, group, param, length, NULL);
242 }
243
244
245
246 int *
247 mc_config_get_int_list (mc_config_t *mc_config, const gchar *group, const gchar *param,
248 gsize *length)
249 {
250 if (mc_config == NULL || group == NULL || param == NULL)
251 return NULL;
252
253 return g_key_file_get_integer_list (mc_config->handle, group, param, length, NULL);
254 }
255
256