(get_fs_usage): avoid compile warning about mixed declarations and code.
[midnight-commander.git] / lib / mcconfig / set.c
blobb60212e7cac17a28829bf319f7a95ae5ea461d2a
1 /*
2 Configure module for the Midnight Commander
4 Copyright (C) 1994, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
5 2007, 2009, 2011
6 The Free Software Foundation, Inc.
8 This file is part of the Midnight Commander.
10 The Midnight Commander is free software: you can redistribute it
11 and/or modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation, either version 3 of the License,
13 or (at your option) any later version.
15 The Midnight Commander is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <config.h>
26 #include "lib/global.h"
27 #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 **********************************************/
39 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
41 static gchar *
42 mc_config_normalize_before_save (const gchar * value)
44 GIConv conv;
45 GString *buffer;
46 gboolean ok;
48 if (mc_global.utf8_display)
49 return g_strdup (value);
51 conv = str_crt_conv_to ("UTF-8");
52 if (conv == INVALID_CONV)
53 return g_strdup (value);
55 buffer = g_string_new ("");
57 ok = (str_convert (conv, value, buffer) != ESTR_FAILURE);
58 str_close_conv (conv);
60 if (!ok)
62 g_string_free (buffer, TRUE);
63 return g_strdup (value);
66 return g_string_free (buffer, FALSE);
69 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
70 /*** public functions **************************************************/
71 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
73 void
74 mc_config_set_string_raw (mc_config_t * mc_config, const gchar * group,
75 const gchar * param, const gchar * value)
77 if (!mc_config || !group || !param || !value)
78 return;
80 g_key_file_set_string (mc_config->handle, group, param, value);
83 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
85 void
86 mc_config_set_string_raw_value (mc_config_t * mc_config, const gchar * group,
87 const gchar * param, const gchar * value)
89 if (!mc_config || !group || !param || !value)
90 return;
92 g_key_file_set_value (mc_config->handle, group, param, value);
95 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
97 void
98 mc_config_set_string (const mc_config_t * mc_config, const gchar * group,
99 const gchar * param, const gchar * value)
101 gchar *buffer;
103 if (!mc_config || !group || !param || !value)
104 return;
106 buffer = mc_config_normalize_before_save (value);
108 g_key_file_set_string (mc_config->handle, group, param, buffer);
110 g_free (buffer);
113 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
115 void
116 mc_config_set_bool (mc_config_t * mc_config, const gchar * group,
117 const gchar * param, gboolean value)
119 if (!mc_config || !group || !param)
120 return;
122 g_key_file_set_boolean (mc_config->handle, group, param, value);
125 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
127 void
128 mc_config_set_int (mc_config_t * mc_config, const gchar * group, const gchar * param, int value)
130 if (!mc_config || !group || !param)
131 return;
133 g_key_file_set_integer (mc_config->handle, group, param, value);
136 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
137 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
139 void
140 mc_config_set_string_list (mc_config_t * mc_config, const gchar * group,
141 const gchar * param, const gchar * const value[], gsize length)
143 if (!mc_config || !group || !param || !value || length == 0)
144 return;
146 g_key_file_set_string_list (mc_config->handle, group, param, value, length);
149 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
152 void
153 mc_config_set_bool_list (mc_config_t * mc_config, const gchar * group,
154 const gchar * param, gboolean value[], gsize length)
156 if (!mc_config || !group || !param || !value || length == 0)
157 return;
159 g_key_file_set_boolean_list (mc_config->handle, group, param, value, length);
162 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
164 void
165 mc_config_set_int_list (mc_config_t * mc_config, const gchar * group,
166 const gchar * param, int value[], gsize length)
168 if (!mc_config || !group || !param || !value || length == 0)
169 return;
171 g_key_file_set_integer_list (mc_config->handle, group, param, value, length);
174 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */