annotate libaudacious/configfile.c @ 1082:968a9449f270 trunk

[svn] - handle the redraw more effectively here
author nenolod
date Fri, 19 May 2006 13:07:38 -0700
parents dc9aaf5eba90
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* XMMS - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 1998-2002 Peter Alm, Mikael Alm, Olle Hallnas,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 * Thomas Nilsson and 4Front Technologies
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * Copyright (C) 1999-2002 Haavard Kvaalen
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 #if defined(HAVE_CONFIG_H)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include "../config.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24
1017
dc9aaf5eba90 [svn] - bypass poisoning on configfile.c
nenolod
parents: 0
diff changeset
25 /* bypass the poisoning of the symbols we need */
dc9aaf5eba90 [svn] - bypass poisoning on configfile.c
nenolod
parents: 0
diff changeset
26 #define I_AM_A_THIRD_PARTY_DEVELOPER_WHO_NEEDS_TO_BE_KICKED_IN_THE_HEAD_BY_CHUCK_NORRIS
dc9aaf5eba90 [svn] - bypass poisoning on configfile.c
nenolod
parents: 0
diff changeset
27
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include "configfile.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include <locale.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 #include <sys/stat.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 typedef gboolean(*XmmsCfgValueReadFunc) (ConfigFile * config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 gpointer * value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 typedef void (*XmmsCfgValueWriteFunc) (ConfigFile * config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 gpointer * value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 struct _XmmsCfgValueTypeInfo {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 XmmsCfgValueReadFunc read;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 XmmsCfgValueWriteFunc write;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 typedef struct _XmmsCfgValueTypeInfo XmmsCfgValueTypeInfo;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 static XmmsCfgValueTypeInfo xmms_cfg_value_type_func[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 {(XmmsCfgValueReadFunc) xmms_cfg_read_int,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 (XmmsCfgValueWriteFunc) xmms_cfg_write_int},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 {(XmmsCfgValueReadFunc) xmms_cfg_read_float,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 (XmmsCfgValueWriteFunc) xmms_cfg_write_float},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 {(XmmsCfgValueReadFunc) xmms_cfg_read_boolean,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 (XmmsCfgValueWriteFunc) xmms_cfg_write_boolean},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 {(XmmsCfgValueReadFunc) xmms_cfg_read_string,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 (XmmsCfgValueWriteFunc) xmms_cfg_write_string}
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 static ConfigSection *xmms_cfg_create_section(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 const gchar * name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 static ConfigLine *xmms_cfg_create_string(ConfigSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 const gchar * value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 static ConfigSection *xmms_cfg_find_section(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 const gchar * name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 static ConfigLine *xmms_cfg_find_string(ConfigSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 const gchar * key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 ConfigFile *xmms_cfg_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 return g_new0(ConfigFile, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 gboolean xmms_cfg_read_value(ConfigFile * config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 XmmsCfgValueType value_type, gpointer * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 return xmms_cfg_value_type_func[value_type].read(config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 void xmms_cfg_write_value(ConfigFile * config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 XmmsCfgValueType value_type, gpointer * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 xmms_cfg_value_type_func[value_type].read(config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 ConfigFile *xmms_cfg_open_file(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 ConfigFile *cfg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 gchar *buffer, **lines, *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 gint i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 ConfigSection *section = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 if (!g_file_get_contents(filename, &buffer, NULL, NULL))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 cfg = g_malloc0(sizeof(ConfigFile));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 lines = g_strsplit(buffer, "\n", 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 g_free(buffer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 while (lines[i]) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 if (lines[i][0] == '[') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 if ((tmp = strchr(lines[i], ']'))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 *tmp = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 section = xmms_cfg_create_section(cfg, &lines[i][1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 } else if (lines[i][0] != '#' && section) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 if ((tmp = strchr(lines[i], '='))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 *tmp = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 tmp++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 xmms_cfg_create_string(section, lines[i], tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 i++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 g_strfreev(lines);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 return cfg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 gchar *xmms_cfg_get_default_filename(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 static gchar *filename = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 if (!filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 filename =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 g_strconcat(g_get_home_dir(), "/", BMP_RCPATH, "/config",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 return filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 ConfigFile *xmms_cfg_open_default_file(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 ConfigFile *ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 ret = xmms_cfg_open_file(xmms_cfg_get_default_filename());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 if (!ret)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 ret = xmms_cfg_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 gboolean xmms_cfg_write_file(ConfigFile * cfg, const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 FILE *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 GList *section_list, *line_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 ConfigSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 if (!(file = fopen(filename, "w")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 section_list = cfg->sections;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 while (section_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 section = (ConfigSection *) section_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 if (section->lines) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 fprintf(file, "[%s]\n", section->name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 line_list = section->lines;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 while (line_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 line = (ConfigLine *) line_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 fprintf(file, "%s=%s\n", line->key, line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 line_list = g_list_next(line_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 fprintf(file, "\n");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 section_list = g_list_next(section_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 fclose(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 gboolean xmms_cfg_write_default_file(ConfigFile * cfg)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 return xmms_cfg_write_file(cfg, xmms_cfg_get_default_filename());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 gboolean xmms_cfg_read_string(ConfigFile * cfg, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 const gchar * key, gchar ** value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 ConfigSection *sect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 if (!(sect = xmms_cfg_find_section(cfg, section)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 if (!(line = xmms_cfg_find_string(sect, key)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 *value = g_strdup(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 gboolean xmms_cfg_read_int(ConfigFile * cfg, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 const gchar * key, gint * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 gchar *str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 if (!xmms_cfg_read_string(cfg, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 *value = atoi(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 gboolean xmms_cfg_read_boolean(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 gboolean * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 gchar *str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 if (!xmms_cfg_read_string(cfg, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 if (!strcasecmp(str, "TRUE"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 *value = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 *value = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 gboolean xmms_cfg_read_float(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 gfloat * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 gchar *str, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 if (!xmms_cfg_read_string(cfg, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 *value = strtod(str, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 gboolean xmms_cfg_read_double(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 gdouble * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 gchar *str, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 if (!xmms_cfg_read_string(cfg, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 *value = strtod(str, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 void xmms_cfg_write_string(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 gchar * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 ConfigSection *sect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 g_return_if_fail(value != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 sect = xmms_cfg_find_section(cfg, section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 if (!sect)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 sect = xmms_cfg_create_section(cfg, section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 if ((line = xmms_cfg_find_string(sect, key))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 g_free(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 line->value = g_strstrip(g_strdup(value));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 } else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 xmms_cfg_create_string(sect, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 void xmms_cfg_write_int(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 gint value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 gchar *strvalue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 strvalue = g_strdup_printf("%d", value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 xmms_cfg_write_string(cfg, section, key, strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 g_free(strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 void xmms_cfg_write_boolean(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 gboolean value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 if (value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 xmms_cfg_write_string(cfg, section, key, "TRUE");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 xmms_cfg_write_string(cfg, section, key, "FALSE");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 void xmms_cfg_write_float(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 gfloat value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 gchar *strvalue, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 strvalue = g_strdup_printf("%g", value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 xmms_cfg_write_string(cfg, section, key, strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 g_free(strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 void xmms_cfg_write_double(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 gdouble value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 gchar *strvalue, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 strvalue = g_strdup_printf("%g", value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383 xmms_cfg_write_string(cfg, section, key, strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 g_free(strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 void xmms_cfg_remove_key(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 const gchar * section, const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 ConfigSection *sect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 if ((sect = xmms_cfg_find_section(cfg, section)) != NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 if ((line = xmms_cfg_find_string(sect, key)) != NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 g_free(line->key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401 g_free(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 g_free(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403 sect->lines = g_list_remove(sect->lines, line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408 void xmms_cfg_free(ConfigFile * cfg)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
410 ConfigSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 GList *section_list, *line_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414 if (cfg == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
415 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
416
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417 section_list = cfg->sections;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 while (section_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 section = (ConfigSection *) section_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420 g_free(section->name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
422 line_list = section->lines;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
423 while (line_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
424 line = (ConfigLine *) line_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
425 g_free(line->key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
426 g_free(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
427 g_free(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
428 line_list = g_list_next(line_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
429 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
430 g_list_free(section->lines);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
431 g_free(section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
432
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 section_list = g_list_next(section_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 g_list_free(cfg->sections);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 g_free(cfg);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439 static ConfigSection *xmms_cfg_create_section(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442 ConfigSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444 section = g_new0(ConfigSection, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445 section->name = g_strdup(name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446 cfg->sections = g_list_append(cfg->sections, section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448 return section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 static ConfigLine *xmms_cfg_create_string(ConfigSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
452 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
453 const gchar * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
454 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
455 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
456
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
457 line = g_new0(ConfigLine, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
458 line->key = g_strstrip(g_strdup(key));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
459 line->value = g_strstrip(g_strdup(value));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
460 section->lines = g_list_append(section->lines, line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
461
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462 return line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465 static ConfigSection *xmms_cfg_find_section(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466 const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468 ConfigSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471 list = cfg->sections;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 while (list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 section = (ConfigSection *) list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 if (!strcasecmp(section->name, name))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 return section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 list = g_list_next(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 static ConfigLine *xmms_cfg_find_string(ConfigSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
485 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 list = section->lines;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488 while (list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 line = (ConfigLine *) list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 if (!strcasecmp(line->key, key))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 return line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 list = g_list_next(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495 }