Mercurial > audlegacy
annotate src/audacious/rcfile.c @ 4669:ec88df86deef
Split out headless specific interface code (mostly).
author | William Pitcock <nenolod@atheme.org> |
---|---|
date | Sun, 29 Jun 2008 01:19:23 -0500 |
parents | 15c491f342eb |
children |
rev | line source |
---|---|
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
1 /* Audacious |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
2 * Copyright (c) 2005-2007 Audacious team |
2537 | 3 * |
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
4 * BMP |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
5 * Copyright (c) 2003-2005 BMP team |
2537 | 6 * |
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
7 * This program is free software; you can redistribute it and/or modify |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
8 * it under the terms of the GNU General Public License as published by |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3112
diff
changeset
|
9 * the Free Software Foundation; under version 3 of the License. |
2537 | 10 * |
3112
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
14 * GNU General Public License for more details. |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
15 * |
4c758281fe8f
Backed out changeset d226b83fa3298fc92f25f9519befcd754f44b0ef
William Pitcock <nenolod@atheme-project.org>
parents:
2865
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
3121
3b6d316f8b09
GPL3 relicensing.
William Pitcock <nenolod@atheme-project.org>
parents:
3112
diff
changeset
|
17 * along with this program. If not, see <http://www.gnu.org/licenses>. |
3123
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
18 * |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
19 * The Audacious team does not consider modular code linking to |
f1c756f39e6c
Invoke "Plugins are not derived work" clause provided by GPL3.
William Pitcock <nenolod@atheme-project.org>
parents:
3121
diff
changeset
|
20 * Audacious or using our public API to be a derived work. |
2537 | 21 */ |
22 | |
23 #include "rcfile.h" | |
24 | |
25 #include <stdio.h> | |
26 #include <string.h> | |
27 #include <stdlib.h> | |
28 #include <locale.h> | |
29 | |
30 #include <unistd.h> | |
31 #include <sys/stat.h> | |
32 | |
33 | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
34 static RcSection *aud_rcfile_create_section(RcFile * file, |
2537 | 35 const gchar * name); |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
36 static RcLine *aud_rcfile_create_string(RcSection * section, |
2537 | 37 const gchar * key, |
38 const gchar * value); | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
39 static RcSection *aud_rcfile_find_section(RcFile * file, const gchar * name); |
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
40 static RcLine *aud_rcfile_find_string(RcSection * section, const gchar * key); |
2537 | 41 |
42 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
43 * aud_rcfile_new: |
2537 | 44 * |
45 * #RcFile object factory. | |
46 * | |
47 * Return value: A #RcFile object. | |
48 **/ | |
49 RcFile * | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
50 aud_rcfile_new(void) |
2537 | 51 { |
52 return g_new0(RcFile, 1); | |
53 } | |
54 | |
55 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
56 * aud_rcfile_free: |
2537 | 57 * @file: A #RcFile object to destroy. |
58 * | |
59 * #RcFile object destructor. | |
60 **/ | |
61 void | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
62 aud_rcfile_free(RcFile * file) |
2537 | 63 { |
64 RcSection *section; | |
65 RcLine *line; | |
66 GList *section_list, *line_list; | |
67 | |
68 if (file == NULL) | |
69 return; | |
70 | |
71 section_list = file->sections; | |
72 while (section_list) { | |
73 section = (RcSection *) section_list->data; | |
74 g_free(section->name); | |
75 | |
76 line_list = section->lines; | |
77 while (line_list) { | |
78 line = (RcLine *) line_list->data; | |
79 g_free(line->key); | |
80 g_free(line->value); | |
81 g_free(line); | |
82 line_list = g_list_next(line_list); | |
83 } | |
84 g_list_free(section->lines); | |
85 g_free(section); | |
86 | |
87 section_list = g_list_next(section_list); | |
88 } | |
89 g_list_free(file->sections); | |
90 g_free(file); | |
91 } | |
92 | |
93 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
94 * aud_rcfile_open: |
2537 | 95 * @filename: Path to rcfile to open. |
96 * | |
97 * Opens an rcfile and returns an #RcFile object representing it. | |
98 * | |
99 * Return value: An #RcFile object representing the rcfile given. | |
100 **/ | |
101 RcFile * | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
102 aud_rcfile_open(const gchar * filename) |
2537 | 103 { |
104 RcFile *file; | |
105 | |
106 gchar *buffer, **lines, *tmp; | |
107 gint i; | |
108 RcSection *section = NULL; | |
109 | |
110 g_return_val_if_fail(filename != NULL, FALSE); | |
111 g_return_val_if_fail(strlen(filename) > 0, FALSE); | |
112 | |
113 if (!g_file_get_contents(filename, &buffer, NULL, NULL)) | |
114 return NULL; | |
115 | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
116 file = aud_rcfile_new(); |
2537 | 117 lines = g_strsplit(buffer, "\n", 0); |
118 g_free(buffer); | |
119 i = 0; | |
120 while (lines[i]) { | |
121 if (lines[i][0] == '[') { | |
122 if ((tmp = strchr(lines[i], ']'))) { | |
123 *tmp = '\0'; | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
124 section = aud_rcfile_create_section(file, &lines[i][1]); |
2537 | 125 } |
126 } | |
127 else if (lines[i][0] != '#' && section) { | |
128 if ((tmp = strchr(lines[i], '='))) { | |
129 gchar **frags; | |
130 frags = g_strsplit(lines[i], "=", 2); | |
131 if (strlen(frags[1]) > 0) { | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
132 aud_rcfile_create_string(section, frags[0], frags[1]); |
2537 | 133 }; |
134 g_strfreev(frags); | |
135 } | |
136 } | |
137 i++; | |
138 } | |
139 g_strfreev(lines); | |
140 return file; | |
141 } | |
142 | |
143 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
144 * aud_rcfile_write: |
2537 | 145 * @file: A #RcFile object to write to disk. |
146 * @filename: A path to write the #RcFile object's data to. | |
147 * | |
148 * Writes the contents of a #RcFile object to disk. | |
149 * | |
150 * Return value: TRUE on success, FALSE otherwise. | |
151 **/ | |
152 gboolean | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
153 aud_rcfile_write(RcFile * file, const gchar * filename) |
2537 | 154 { |
155 FILE *fp; | |
156 GList *section_list, *line_list; | |
157 RcSection *section; | |
158 RcLine *line; | |
159 | |
160 g_return_val_if_fail(file != NULL, FALSE); | |
161 g_return_val_if_fail(filename != NULL, FALSE); | |
162 | |
163 if (!(fp = fopen(filename, "w"))) | |
164 return FALSE; | |
165 | |
166 section_list = file->sections; | |
167 while (section_list) { | |
168 section = (RcSection *) section_list->data; | |
169 if (section->lines) { | |
170 fprintf(fp, "[%s]\n", section->name); | |
171 line_list = section->lines; | |
172 while (line_list) { | |
173 line = (RcLine *) line_list->data; | |
174 fprintf(fp, "%s=%s\n", line->key, line->value); | |
175 line_list = g_list_next(line_list); | |
176 } | |
177 fprintf(fp, "\n"); | |
178 } | |
179 section_list = g_list_next(section_list); | |
180 } | |
181 fclose(fp); | |
182 return TRUE; | |
183 } | |
184 | |
185 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
186 * aud_rcfile_read_string: |
2537 | 187 * @file: A #RcFile object to write to disk. |
188 * @section: The section of the RcFile to look in. | |
189 * @key: The name of the identifier to look up. | |
190 * @value: A pointer to a memory location to place the data. | |
191 * | |
192 * Looks up a value in an RcFile and places it in %value. | |
193 * | |
194 * Return value: TRUE on success, FALSE otherwise. | |
195 **/ | |
196 gboolean | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
197 aud_rcfile_read_string(RcFile * file, const gchar * section, |
2537 | 198 const gchar * key, gchar ** value) |
199 { | |
200 RcSection *sect; | |
201 RcLine *line; | |
202 | |
203 g_return_val_if_fail(file != NULL, FALSE); | |
204 g_return_val_if_fail(section != NULL, FALSE); | |
205 g_return_val_if_fail(key != NULL, FALSE); | |
206 g_return_val_if_fail(value != NULL, FALSE); | |
207 | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
208 if (!(sect = aud_rcfile_find_section(file, section))) |
2537 | 209 return FALSE; |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
210 if (!(line = aud_rcfile_find_string(sect, key))) |
2537 | 211 return FALSE; |
212 *value = g_strdup(line->value); | |
213 return TRUE; | |
214 } | |
215 | |
216 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
217 * aud_rcfile_read_int: |
2537 | 218 * @file: A #RcFile object to write to disk. |
219 * @section: The section of the RcFile to look in. | |
220 * @key: The name of the identifier to look up. | |
221 * @value: A pointer to a memory location to place the data. | |
222 * | |
223 * Looks up a value in an RcFile and places it in %value. | |
224 * | |
225 * Return value: TRUE on success, FALSE otherwise. | |
226 **/ | |
227 gboolean | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
228 aud_rcfile_read_int(RcFile * file, const gchar * section, |
2537 | 229 const gchar * key, gint * value) |
230 { | |
231 gchar *str; | |
232 | |
233 g_return_val_if_fail(file != NULL, FALSE); | |
234 g_return_val_if_fail(section != NULL, FALSE); | |
235 g_return_val_if_fail(key != NULL, FALSE); | |
236 g_return_val_if_fail(value != NULL, FALSE); | |
237 | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
238 if (!aud_rcfile_read_string(file, section, key, &str)) |
2537 | 239 return FALSE; |
240 *value = atoi(str); | |
241 g_free(str); | |
242 | |
243 return TRUE; | |
244 } | |
245 | |
246 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
247 * aud_rcfile_read_bool: |
2537 | 248 * @file: A #RcFile object to write to disk. |
249 * @section: The section of the RcFile to look in. | |
250 * @key: The name of the identifier to look up. | |
251 * @value: A pointer to a memory location to place the data. | |
252 * | |
253 * Looks up a value in an RcFile and places it in %value. | |
254 * | |
255 * Return value: TRUE on success, FALSE otherwise. | |
256 **/ | |
257 gboolean | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
258 aud_rcfile_read_bool(RcFile * file, const gchar * section, |
2537 | 259 const gchar * key, gboolean * value) |
260 { | |
261 gchar *str; | |
262 | |
263 g_return_val_if_fail(file != NULL, FALSE); | |
264 g_return_val_if_fail(section != NULL, FALSE); | |
265 g_return_val_if_fail(key != NULL, FALSE); | |
266 g_return_val_if_fail(value != NULL, FALSE); | |
267 | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
268 if (!aud_rcfile_read_string(file, section, key, &str)) |
2537 | 269 return FALSE; |
270 if (!strcasecmp(str, "TRUE")) | |
271 *value = TRUE; | |
272 else | |
273 *value = FALSE; | |
274 g_free(str); | |
275 return TRUE; | |
276 } | |
277 | |
278 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
279 * aud_rcfile_read_float: |
2537 | 280 * @file: A #RcFile object to write to disk. |
281 * @section: The section of the RcFile to look in. | |
282 * @key: The name of the identifier to look up. | |
283 * @value: A pointer to a memory location to place the data. | |
284 * | |
285 * Looks up a value in an RcFile and places it in %value. | |
286 * | |
287 * Return value: TRUE on success, FALSE otherwise. | |
288 **/ | |
289 gboolean | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
290 aud_rcfile_read_float(RcFile * file, const gchar * section, |
2537 | 291 const gchar * key, gfloat * value) |
292 { | |
293 gchar *str, *locale; | |
294 | |
295 g_return_val_if_fail(file != NULL, FALSE); | |
296 g_return_val_if_fail(section != NULL, FALSE); | |
297 g_return_val_if_fail(key != NULL, FALSE); | |
298 g_return_val_if_fail(value != NULL, FALSE); | |
299 | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
300 if (!aud_rcfile_read_string(file, section, key, &str)) |
2537 | 301 return FALSE; |
302 | |
303 locale = g_strdup(setlocale(LC_NUMERIC, NULL)); | |
304 setlocale(LC_NUMERIC, "C"); | |
305 *value = strtod(str, NULL); | |
306 setlocale(LC_NUMERIC, locale); | |
307 g_free(locale); | |
308 g_free(str); | |
309 | |
310 return TRUE; | |
311 } | |
312 | |
313 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
314 * aud_rcfile_read_double: |
2537 | 315 * @file: A #RcFile object to write to disk. |
316 * @section: The section of the RcFile to look in. | |
317 * @key: The name of the identifier to look up. | |
318 * @value: A pointer to a memory location to place the data. | |
319 * | |
320 * Looks up a value in an RcFile and places it in %value. | |
321 * | |
322 * Return value: TRUE on success, FALSE otherwise. | |
323 **/ | |
324 gboolean | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
325 aud_rcfile_read_double(RcFile * file, const gchar * section, |
2537 | 326 const gchar * key, gdouble * value) |
327 { | |
328 gchar *str, *locale; | |
329 | |
330 g_return_val_if_fail(file != NULL, FALSE); | |
331 g_return_val_if_fail(section != NULL, FALSE); | |
332 g_return_val_if_fail(key != NULL, FALSE); | |
333 g_return_val_if_fail(value != NULL, FALSE); | |
334 | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
335 if (!aud_rcfile_read_string(file, section, key, &str)) |
2537 | 336 return FALSE; |
337 | |
338 locale = g_strdup(setlocale(LC_NUMERIC, NULL)); | |
339 setlocale(LC_NUMERIC, "C"); | |
340 *value = strtod(str, NULL); | |
341 setlocale(LC_NUMERIC, locale); | |
342 g_free(locale); | |
343 g_free(str); | |
344 | |
345 return TRUE; | |
346 } | |
347 | |
348 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
349 * aud_rcfile_write_string: |
2537 | 350 * @file: A #RcFile object to write to disk. |
351 * @section: The section of the RcFile to set the key in. | |
352 * @key: The name of the identifier to set. | |
353 * @value: The value to set for that identifier. | |
354 * | |
355 * Sets a value in an RcFile for %key. | |
356 **/ | |
357 void | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
358 aud_rcfile_write_string(RcFile * file, const gchar * section, |
2537 | 359 const gchar * key, const gchar * value) |
360 { | |
361 RcSection *sect; | |
362 RcLine *line; | |
363 | |
364 g_return_if_fail(file != NULL); | |
365 g_return_if_fail(section != NULL); | |
366 g_return_if_fail(key != NULL); | |
367 g_return_if_fail(value != NULL); | |
368 | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
369 sect = aud_rcfile_find_section(file, section); |
2537 | 370 if (!sect) |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
371 sect = aud_rcfile_create_section(file, section); |
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
372 if ((line = aud_rcfile_find_string(sect, key))) { |
2537 | 373 g_free(line->value); |
374 line->value = g_strstrip(g_strdup(value)); | |
375 } | |
376 else | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
377 aud_rcfile_create_string(sect, key, value); |
2537 | 378 } |
379 | |
380 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
381 * aud_rcfile_write_int: |
2537 | 382 * @file: A #RcFile object to write to disk. |
383 * @section: The section of the RcFile to set the key in. | |
384 * @key: The name of the identifier to set. | |
385 * @value: The value to set for that identifier. | |
386 * | |
387 * Sets a value in an RcFile for %key. | |
388 **/ | |
389 void | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
390 aud_rcfile_write_int(RcFile * file, const gchar * section, |
2537 | 391 const gchar * key, gint value) |
392 { | |
393 gchar *strvalue; | |
394 | |
395 g_return_if_fail(file != NULL); | |
396 g_return_if_fail(section != NULL); | |
397 g_return_if_fail(key != NULL); | |
398 | |
399 strvalue = g_strdup_printf("%d", value); | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
400 aud_rcfile_write_string(file, section, key, strvalue); |
2537 | 401 g_free(strvalue); |
402 } | |
403 | |
404 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
405 * aud_rcfile_write_boolean: |
2537 | 406 * @file: A #RcFile object to write to disk. |
407 * @section: The section of the RcFile to set the key in. | |
408 * @key: The name of the identifier to set. | |
409 * @value: The value to set for that identifier. | |
410 * | |
411 * Sets a value in an RcFile for %key. | |
412 **/ | |
413 void | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
414 aud_rcfile_write_boolean(RcFile * file, const gchar * section, |
2537 | 415 const gchar * key, gboolean value) |
416 { | |
417 g_return_if_fail(file != NULL); | |
418 g_return_if_fail(section != NULL); | |
419 g_return_if_fail(key != NULL); | |
420 | |
421 if (value) | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
422 aud_rcfile_write_string(file, section, key, "TRUE"); |
2537 | 423 else |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
424 aud_rcfile_write_string(file, section, key, "FALSE"); |
2537 | 425 } |
426 | |
427 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
428 * aud_rcfile_write_float: |
2537 | 429 * @file: A #RcFile object to write to disk. |
430 * @section: The section of the RcFile to set the key in. | |
431 * @key: The name of the identifier to set. | |
432 * @value: The value to set for that identifier. | |
433 * | |
434 * Sets a value in an RcFile for %key. | |
435 **/ | |
436 void | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
437 aud_rcfile_write_float(RcFile * file, const gchar * section, |
2537 | 438 const gchar * key, gfloat value) |
439 { | |
440 gchar *strvalue, *locale; | |
441 | |
442 g_return_if_fail(file != NULL); | |
443 g_return_if_fail(section != NULL); | |
444 g_return_if_fail(key != NULL); | |
445 | |
446 locale = g_strdup(setlocale(LC_NUMERIC, NULL)); | |
447 setlocale(LC_NUMERIC, "C"); | |
448 strvalue = g_strdup_printf("%g", value); | |
449 setlocale(LC_NUMERIC, locale); | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
450 aud_rcfile_write_string(file, section, key, strvalue); |
2537 | 451 g_free(locale); |
452 g_free(strvalue); | |
453 } | |
454 | |
455 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
456 * aud_rcfile_write_double: |
2537 | 457 * @file: A #RcFile object to write to disk. |
458 * @section: The section of the RcFile to set the key in. | |
459 * @key: The name of the identifier to set. | |
460 * @value: The value to set for that identifier. | |
461 * | |
462 * Sets a value in an RcFile for %key. | |
463 **/ | |
464 void | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
465 aud_rcfile_write_double(RcFile * file, const gchar * section, |
2537 | 466 const gchar * key, gdouble value) |
467 { | |
468 gchar *strvalue, *locale; | |
469 | |
470 g_return_if_fail(file != NULL); | |
471 g_return_if_fail(section != NULL); | |
472 g_return_if_fail(key != NULL); | |
473 | |
474 locale = g_strdup(setlocale(LC_NUMERIC, NULL)); | |
475 setlocale(LC_NUMERIC, "C"); | |
476 strvalue = g_strdup_printf("%g", value); | |
477 setlocale(LC_NUMERIC, locale); | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
478 aud_rcfile_write_string(file, section, key, strvalue); |
2537 | 479 g_free(locale); |
480 g_free(strvalue); | |
481 } | |
482 | |
483 /** | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
484 * aud_rcfile_remove_key: |
2537 | 485 * @file: A #RcFile object to write to disk. |
486 * @section: The section of the RcFile to set the key in. | |
487 * @key: The name of the identifier to remove. | |
488 * | |
489 * Removes %key from an #RcFile object. | |
490 **/ | |
491 void | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
492 aud_rcfile_remove_key(RcFile * file, const gchar * section, const gchar * key) |
2537 | 493 { |
494 RcSection *sect; | |
495 RcLine *line; | |
496 | |
497 g_return_if_fail(file != NULL); | |
498 g_return_if_fail(section != NULL); | |
499 g_return_if_fail(key != NULL); | |
500 | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
501 if ((sect = aud_rcfile_find_section(file, section)) != NULL) { |
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
502 if ((line = aud_rcfile_find_string(sect, key)) != NULL) { |
2537 | 503 g_free(line->key); |
504 g_free(line->value); | |
505 g_free(line); | |
506 sect->lines = g_list_remove(sect->lines, line); | |
507 } | |
508 } | |
509 } | |
510 | |
511 static RcSection * | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
512 aud_rcfile_create_section(RcFile * file, const gchar * name) |
2537 | 513 { |
514 RcSection *section; | |
515 | |
516 section = g_new0(RcSection, 1); | |
517 section->name = g_strdup(name); | |
518 file->sections = g_list_append(file->sections, section); | |
519 | |
520 return section; | |
521 } | |
522 | |
523 static RcLine * | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
524 aud_rcfile_create_string(RcSection * section, |
2537 | 525 const gchar * key, const gchar * value) |
526 { | |
527 RcLine *line; | |
528 | |
529 line = g_new0(RcLine, 1); | |
530 line->key = g_strstrip(g_strdup(key)); | |
531 line->value = g_strstrip(g_strdup(value)); | |
532 section->lines = g_list_append(section->lines, line); | |
533 | |
534 return line; | |
535 } | |
536 | |
537 static RcSection * | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
538 aud_rcfile_find_section(RcFile * file, const gchar * name) |
2537 | 539 { |
540 RcSection *section; | |
541 GList *list; | |
542 | |
543 list = file->sections; | |
544 while (list) { | |
545 section = (RcSection *) list->data; | |
546 if (!strcasecmp(section->name, name)) | |
547 return section; | |
548 list = g_list_next(list); | |
549 } | |
550 return NULL; | |
551 } | |
552 | |
553 static RcLine * | |
4405
15c491f342eb
Rename bmp_rcfile* -> aud_rcfile*
Matti Hamalainen <ccr@tnsp.org>
parents:
3123
diff
changeset
|
554 aud_rcfile_find_string(RcSection * section, const gchar * key) |
2537 | 555 { |
556 RcLine *line; | |
557 GList *list; | |
558 | |
559 list = section->lines; | |
560 while (list) { | |
561 line = (RcLine *) list->data; | |
562 if (!strcasecmp(line->key, key)) | |
563 return line; | |
564 list = g_list_next(list); | |
565 } | |
566 return NULL; | |
567 } |