annotate libaudacious/configfile.c @ 525:6e332a32d2f5 trunk

[svn] amidi-plug: do not try to guess the correct alsa port from alsa-lib version if there's not a wavetable hw synth available
author giacomo
date Fri, 27 Jan 2006 12:00:13 -0800
parents cb178e5ad177
children dc9aaf5eba90
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
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include "configfile.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #include <locale.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include <sys/stat.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 typedef gboolean(*XmmsCfgValueReadFunc) (ConfigFile * config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 gpointer * value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 typedef void (*XmmsCfgValueWriteFunc) (ConfigFile * config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 gpointer * value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 struct _XmmsCfgValueTypeInfo {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 XmmsCfgValueReadFunc read;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 XmmsCfgValueWriteFunc write;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 typedef struct _XmmsCfgValueTypeInfo XmmsCfgValueTypeInfo;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 static XmmsCfgValueTypeInfo xmms_cfg_value_type_func[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 {(XmmsCfgValueReadFunc) xmms_cfg_read_int,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 (XmmsCfgValueWriteFunc) xmms_cfg_write_int},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 {(XmmsCfgValueReadFunc) xmms_cfg_read_float,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 (XmmsCfgValueWriteFunc) xmms_cfg_write_float},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 {(XmmsCfgValueReadFunc) xmms_cfg_read_boolean,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 (XmmsCfgValueWriteFunc) xmms_cfg_write_boolean},
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 {(XmmsCfgValueReadFunc) xmms_cfg_read_string,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 (XmmsCfgValueWriteFunc) xmms_cfg_write_string}
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 static ConfigSection *xmms_cfg_create_section(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 const gchar * name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 static ConfigLine *xmms_cfg_create_string(ConfigSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 const gchar * value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 static ConfigSection *xmms_cfg_find_section(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 const gchar * name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 static ConfigLine *xmms_cfg_find_string(ConfigSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 const gchar * key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 ConfigFile *xmms_cfg_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 return g_new0(ConfigFile, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 gboolean xmms_cfg_read_value(ConfigFile * config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 XmmsCfgValueType value_type, gpointer * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 return xmms_cfg_value_type_func[value_type].read(config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 void xmms_cfg_write_value(ConfigFile * config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 XmmsCfgValueType value_type, gpointer * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 xmms_cfg_value_type_func[value_type].read(config_file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 section, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 ConfigFile *xmms_cfg_open_file(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 ConfigFile *cfg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 gchar *buffer, **lines, *tmp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 gint i;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 ConfigSection *section = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 if (!g_file_get_contents(filename, &buffer, NULL, NULL))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 cfg = g_malloc0(sizeof(ConfigFile));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 lines = g_strsplit(buffer, "\n", 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 g_free(buffer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 while (lines[i]) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 if (lines[i][0] == '[') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 if ((tmp = strchr(lines[i], ']'))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 *tmp = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 section = xmms_cfg_create_section(cfg, &lines[i][1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 } else if (lines[i][0] != '#' && section) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 if ((tmp = strchr(lines[i], '='))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 *tmp = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 tmp++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 xmms_cfg_create_string(section, lines[i], tmp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 i++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 g_strfreev(lines);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 return cfg;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 gchar *xmms_cfg_get_default_filename(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 static gchar *filename = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 if (!filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 filename =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 g_strconcat(g_get_home_dir(), "/", BMP_RCPATH, "/config",
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 return filename;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 ConfigFile *xmms_cfg_open_default_file(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 ConfigFile *ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 ret = xmms_cfg_open_file(xmms_cfg_get_default_filename());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 if (!ret)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 ret = xmms_cfg_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 return ret;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 gboolean xmms_cfg_write_file(ConfigFile * cfg, const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 FILE *file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 GList *section_list, *line_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 ConfigSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 if (!(file = fopen(filename, "w")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 section_list = cfg->sections;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 while (section_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 section = (ConfigSection *) section_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 if (section->lines) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 fprintf(file, "[%s]\n", section->name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 line_list = section->lines;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 while (line_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 line = (ConfigLine *) line_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 fprintf(file, "%s=%s\n", line->key, line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 line_list = g_list_next(line_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 fprintf(file, "\n");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 section_list = g_list_next(section_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 fclose(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 gboolean xmms_cfg_write_default_file(ConfigFile * cfg)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188 return xmms_cfg_write_file(cfg, xmms_cfg_get_default_filename());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 gboolean xmms_cfg_read_string(ConfigFile * cfg, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 const gchar * key, gchar ** value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 ConfigSection *sect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 if (!(sect = xmms_cfg_find_section(cfg, section)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 if (!(line = xmms_cfg_find_string(sect, key)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 *value = g_strdup(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 gboolean xmms_cfg_read_int(ConfigFile * cfg, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 const gchar * key, gint * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213 gchar *str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 if (!xmms_cfg_read_string(cfg, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 *value = atoi(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 gboolean xmms_cfg_read_boolean(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 gboolean * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 gchar *str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 if (!xmms_cfg_read_string(cfg, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 if (!strcasecmp(str, "TRUE"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 *value = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 *value = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 gboolean xmms_cfg_read_float(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 gfloat * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 gchar *str, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 if (!xmms_cfg_read_string(cfg, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 *value = strtod(str, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 gboolean xmms_cfg_read_double(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 gdouble * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 gchar *str, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 g_return_val_if_fail(cfg != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 if (!xmms_cfg_read_string(cfg, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 *value = strtod(str, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 void xmms_cfg_write_string(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 gchar * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 ConfigSection *sect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 g_return_if_fail(value != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 sect = xmms_cfg_find_section(cfg, section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 if (!sect)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 sect = xmms_cfg_create_section(cfg, section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 if ((line = xmms_cfg_find_string(sect, key))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 g_free(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 line->value = g_strstrip(g_strdup(value));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 } else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 xmms_cfg_create_string(sect, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319 void xmms_cfg_write_int(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 gint value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 gchar *strvalue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 strvalue = g_strdup_printf("%d", value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 xmms_cfg_write_string(cfg, section, key, strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 g_free(strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 void xmms_cfg_write_boolean(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 gboolean value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 if (value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 xmms_cfg_write_string(cfg, section, key, "TRUE");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 xmms_cfg_write_string(cfg, section, key, "FALSE");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 void xmms_cfg_write_float(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 gfloat value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 gchar *strvalue, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 strvalue = g_strdup_printf("%g", value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 xmms_cfg_write_string(cfg, section, key, strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 g_free(strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 void xmms_cfg_write_double(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 const gchar * section, const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 gdouble value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 gchar *strvalue, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 strvalue = g_strdup_printf("%g", value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 xmms_cfg_write_string(cfg, section, key, strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383 g_free(strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 void xmms_cfg_remove_key(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 const gchar * section, const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 ConfigSection *sect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 g_return_if_fail(cfg != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 if ((sect = xmms_cfg_find_section(cfg, section)) != NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397 if ((line = xmms_cfg_find_string(sect, key)) != NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 g_free(line->key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 g_free(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 g_free(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401 sect->lines = g_list_remove(sect->lines, line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403 }
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 void xmms_cfg_free(ConfigFile * cfg)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408 ConfigSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
410 GList *section_list, *line_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 if (cfg == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
415 section_list = cfg->sections;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
416 while (section_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417 section = (ConfigSection *) section_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 g_free(section->name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420 line_list = section->lines;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421 while (line_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
422 line = (ConfigLine *) line_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
423 g_free(line->key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
424 g_free(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
425 g_free(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
426 line_list = g_list_next(line_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
427 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
428 g_list_free(section->lines);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
429 g_free(section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
430
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
431 section_list = g_list_next(section_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
432 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 g_list_free(cfg->sections);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 g_free(cfg);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437 static ConfigSection *xmms_cfg_create_section(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438 const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 ConfigSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442 section = g_new0(ConfigSection, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443 section->name = g_strdup(name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444 cfg->sections = g_list_append(cfg->sections, section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446 return section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 static ConfigLine *xmms_cfg_create_string(ConfigSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 const gchar * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
452 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
453 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
454
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
455 line = g_new0(ConfigLine, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
456 line->key = g_strstrip(g_strdup(key));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
457 line->value = g_strstrip(g_strdup(value));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
458 section->lines = g_list_append(section->lines, line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
459
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
460 return line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
461 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463 static ConfigSection *xmms_cfg_find_section(ConfigFile * cfg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464 const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466 ConfigSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 list = cfg->sections;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470 while (list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471 section = (ConfigSection *) list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 if (!strcasecmp(section->name, name))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 return section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 list = g_list_next(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 static ConfigLine *xmms_cfg_find_string(ConfigSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480 const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
481 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
482 ConfigLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
483 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
484
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
485 list = section->lines;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
486 while (list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
487 line = (ConfigLine *) list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
488 if (!strcasecmp(line->key, key))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 return line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 list = g_list_next(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493 }