comparison libaudacious/rcfile.c @ 2057:a55ad33d882e trunk

[svn] - document rcfile
author nenolod
date Mon, 04 Dec 2006 18:08:15 -0800
parents 8a926dec916f
children f18a5b617c34
comparison
equal deleted inserted replaced
2056:6f1346ce2764 2057:a55ad33d882e
1 /* This program is free software; you can redistribute it and/or modify 1 /* Audacious
2 * Copyright (c) 2005-2007 Audacious team
3 *
4 * BMP
5 * Copyright (c) 2003-2005 BMP team
6 *
7 * This program is free software; you can redistribute it and/or modify
2 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
3 * the Free Software Foundation; either version 2 of the License, or 9 * the Free Software Foundation; either version 2 of the License, or
4 * (at your option) any later version. 10 * (at your option) any later version.
5 * 11 *
6 * This program is distributed in the hope that it will be useful, 12 * This program is distributed in the hope that it will be useful,
30 const gchar * key, 36 const gchar * key,
31 const gchar * value); 37 const gchar * value);
32 static RcSection *bmp_rcfile_find_section(RcFile * file, const gchar * name); 38 static RcSection *bmp_rcfile_find_section(RcFile * file, const gchar * name);
33 static RcLine *bmp_rcfile_find_string(RcSection * section, const gchar * key); 39 static RcLine *bmp_rcfile_find_string(RcSection * section, const gchar * key);
34 40
35 41 /**
42 * bmp_rcfile_new:
43 *
44 * #RcFile object factory.
45 *
46 * Return value: A #RcFile object.
47 **/
36 RcFile * 48 RcFile *
37 bmp_rcfile_new(void) 49 bmp_rcfile_new(void)
38 { 50 {
39 return g_new0(RcFile, 1); 51 return g_new0(RcFile, 1);
40 } 52 }
41 53
54 /**
55 * bmp_rcfile_free:
56 * @file: A #RcFile object to destroy.
57 *
58 * #RcFile object destructor.
59 **/
42 void 60 void
43 bmp_rcfile_free(RcFile * file) 61 bmp_rcfile_free(RcFile * file)
44 { 62 {
45 RcSection *section; 63 RcSection *section;
46 RcLine *line; 64 RcLine *line;
69 } 87 }
70 g_list_free(file->sections); 88 g_list_free(file->sections);
71 g_free(file); 89 g_free(file);
72 } 90 }
73 91
92 /**
93 * bmp_rcfile_open:
94 * @filename: Path to rcfile to open.
95 *
96 * Opens an rcfile and returns an #RcFile object representing it.
97 *
98 * Return value: An #RcFile object representing the rcfile given.
99 **/
74 RcFile * 100 RcFile *
75 bmp_rcfile_open(const gchar * filename) 101 bmp_rcfile_open(const gchar * filename)
76 { 102 {
77 RcFile *file; 103 RcFile *file;
78 104
84 g_return_val_if_fail(strlen(filename) > 0, FALSE); 110 g_return_val_if_fail(strlen(filename) > 0, FALSE);
85 111
86 if (!g_file_get_contents(filename, &buffer, NULL, NULL)) 112 if (!g_file_get_contents(filename, &buffer, NULL, NULL))
87 return NULL; 113 return NULL;
88 114
89 file = g_malloc0(sizeof(RcFile)); 115 file = bmp_rcfile_new();
90 lines = g_strsplit(buffer, "\n", 0); 116 lines = g_strsplit(buffer, "\n", 0);
91 g_free(buffer); 117 g_free(buffer);
92 i = 0; 118 i = 0;
93 while (lines[i]) { 119 while (lines[i]) {
94 if (lines[i][0] == '[') { 120 if (lines[i][0] == '[') {
111 } 137 }
112 g_strfreev(lines); 138 g_strfreev(lines);
113 return file; 139 return file;
114 } 140 }
115 141
142 /**
143 * bmp_rcfile_write:
144 * @file: A #RcFile object to write to disk.
145 * @filename: A path to write the #RcFile object's data to.
146 *
147 * Writes the contents of a #RcFile object to disk.
148 *
149 * Return value: TRUE on success, FALSE otherwise.
150 **/
116 gboolean 151 gboolean
117 bmp_rcfile_write(RcFile * file, const gchar * filename) 152 bmp_rcfile_write(RcFile * file, const gchar * filename)
118 { 153 {
119 FILE *fp; 154 FILE *fp;
120 GList *section_list, *line_list; 155 GList *section_list, *line_list;
144 } 179 }
145 fclose(fp); 180 fclose(fp);
146 return TRUE; 181 return TRUE;
147 } 182 }
148 183
184 /**
185 * bmp_rcfile_read_string:
186 * @file: A #RcFile object to write to disk.
187 * @section: The section of the RcFile to look in.
188 * @key: The name of the identifier to look up.
189 * @value: A pointer to a memory location to place the data.
190 *
191 * Looks up a value in an RcFile and places it in %value.
192 *
193 * Return value: TRUE on success, FALSE otherwise.
194 **/
149 gboolean 195 gboolean
150 bmp_rcfile_read_string(RcFile * file, const gchar * section, 196 bmp_rcfile_read_string(RcFile * file, const gchar * section,
151 const gchar * key, gchar ** value) 197 const gchar * key, gchar ** value)
152 { 198 {
153 RcSection *sect; 199 RcSection *sect;
164 return FALSE; 210 return FALSE;
165 *value = g_strdup(line->value); 211 *value = g_strdup(line->value);
166 return TRUE; 212 return TRUE;
167 } 213 }
168 214
215 /**
216 * bmp_rcfile_read_int:
217 * @file: A #RcFile object to write to disk.
218 * @section: The section of the RcFile to look in.
219 * @key: The name of the identifier to look up.
220 * @value: A pointer to a memory location to place the data.
221 *
222 * Looks up a value in an RcFile and places it in %value.
223 *
224 * Return value: TRUE on success, FALSE otherwise.
225 **/
169 gboolean 226 gboolean
170 bmp_rcfile_read_int(RcFile * file, const gchar * section, 227 bmp_rcfile_read_int(RcFile * file, const gchar * section,
171 const gchar * key, gint * value) 228 const gchar * key, gint * value)
172 { 229 {
173 gchar *str; 230 gchar *str;
183 g_free(str); 240 g_free(str);
184 241
185 return TRUE; 242 return TRUE;
186 } 243 }
187 244
245 /**
246 * bmp_rcfile_read_bool:
247 * @file: A #RcFile object to write to disk.
248 * @section: The section of the RcFile to look in.
249 * @key: The name of the identifier to look up.
250 * @value: A pointer to a memory location to place the data.
251 *
252 * Looks up a value in an RcFile and places it in %value.
253 *
254 * Return value: TRUE on success, FALSE otherwise.
255 **/
188 gboolean 256 gboolean
189 bmp_rcfile_read_bool(RcFile * file, const gchar * section, 257 bmp_rcfile_read_bool(RcFile * file, const gchar * section,
190 const gchar * key, gboolean * value) 258 const gchar * key, gboolean * value)
191 { 259 {
192 gchar *str; 260 gchar *str;
204 *value = FALSE; 272 *value = FALSE;
205 g_free(str); 273 g_free(str);
206 return TRUE; 274 return TRUE;
207 } 275 }
208 276
277 /**
278 * bmp_rcfile_read_float:
279 * @file: A #RcFile object to write to disk.
280 * @section: The section of the RcFile to look in.
281 * @key: The name of the identifier to look up.
282 * @value: A pointer to a memory location to place the data.
283 *
284 * Looks up a value in an RcFile and places it in %value.
285 *
286 * Return value: TRUE on success, FALSE otherwise.
287 **/
209 gboolean 288 gboolean
210 bmp_rcfile_read_float(RcFile * file, const gchar * section, 289 bmp_rcfile_read_float(RcFile * file, const gchar * section,
211 const gchar * key, gfloat * value) 290 const gchar * key, gfloat * value)
212 { 291 {
213 gchar *str, *locale; 292 gchar *str, *locale;
228 g_free(str); 307 g_free(str);
229 308
230 return TRUE; 309 return TRUE;
231 } 310 }
232 311
312 /**
313 * bmp_rcfile_read_double:
314 * @file: A #RcFile object to write to disk.
315 * @section: The section of the RcFile to look in.
316 * @key: The name of the identifier to look up.
317 * @value: A pointer to a memory location to place the data.
318 *
319 * Looks up a value in an RcFile and places it in %value.
320 *
321 * Return value: TRUE on success, FALSE otherwise.
322 **/
233 gboolean 323 gboolean
234 bmp_rcfile_read_double(RcFile * file, const gchar * section, 324 bmp_rcfile_read_double(RcFile * file, const gchar * section,
235 const gchar * key, gdouble * value) 325 const gchar * key, gdouble * value)
236 { 326 {
237 gchar *str, *locale; 327 gchar *str, *locale;
252 g_free(str); 342 g_free(str);
253 343
254 return TRUE; 344 return TRUE;
255 } 345 }
256 346
347 /**
348 * bmp_rcfile_write_string:
349 * @file: A #RcFile object to write to disk.
350 * @section: The section of the RcFile to set the key in.
351 * @key: The name of the identifier to set.
352 * @value: The value to set for that identifier.
353 *
354 * Sets a value in an RcFile for %key.
355 **/
257 void 356 void
258 bmp_rcfile_write_string(RcFile * file, const gchar * section, 357 bmp_rcfile_write_string(RcFile * file, const gchar * section,
259 const gchar * key, const gchar * value) 358 const gchar * key, const gchar * value)
260 { 359 {
261 RcSection *sect; 360 RcSection *sect;
275 } 374 }
276 else 375 else
277 bmp_rcfile_create_string(sect, key, value); 376 bmp_rcfile_create_string(sect, key, value);
278 } 377 }
279 378
379 /**
380 * bmp_rcfile_write_int:
381 * @file: A #RcFile object to write to disk.
382 * @section: The section of the RcFile to set the key in.
383 * @key: The name of the identifier to set.
384 * @value: The value to set for that identifier.
385 *
386 * Sets a value in an RcFile for %key.
387 **/
280 void 388 void
281 bmp_rcfile_write_int(RcFile * file, const gchar * section, 389 bmp_rcfile_write_int(RcFile * file, const gchar * section,
282 const gchar * key, gint value) 390 const gchar * key, gint value)
283 { 391 {
284 gchar *strvalue; 392 gchar *strvalue;
290 strvalue = g_strdup_printf("%d", value); 398 strvalue = g_strdup_printf("%d", value);
291 bmp_rcfile_write_string(file, section, key, strvalue); 399 bmp_rcfile_write_string(file, section, key, strvalue);
292 g_free(strvalue); 400 g_free(strvalue);
293 } 401 }
294 402
403 /**
404 * bmp_rcfile_write_boolean:
405 * @file: A #RcFile object to write to disk.
406 * @section: The section of the RcFile to set the key in.
407 * @key: The name of the identifier to set.
408 * @value: The value to set for that identifier.
409 *
410 * Sets a value in an RcFile for %key.
411 **/
295 void 412 void
296 bmp_rcfile_write_boolean(RcFile * file, const gchar * section, 413 bmp_rcfile_write_boolean(RcFile * file, const gchar * section,
297 const gchar * key, gboolean value) 414 const gchar * key, gboolean value)
298 { 415 {
299 g_return_if_fail(file != NULL); 416 g_return_if_fail(file != NULL);
304 bmp_rcfile_write_string(file, section, key, "TRUE"); 421 bmp_rcfile_write_string(file, section, key, "TRUE");
305 else 422 else
306 bmp_rcfile_write_string(file, section, key, "FALSE"); 423 bmp_rcfile_write_string(file, section, key, "FALSE");
307 } 424 }
308 425
426 /**
427 * bmp_rcfile_write_float:
428 * @file: A #RcFile object to write to disk.
429 * @section: The section of the RcFile to set the key in.
430 * @key: The name of the identifier to set.
431 * @value: The value to set for that identifier.
432 *
433 * Sets a value in an RcFile for %key.
434 **/
309 void 435 void
310 bmp_rcfile_write_float(RcFile * file, const gchar * section, 436 bmp_rcfile_write_float(RcFile * file, const gchar * section,
311 const gchar * key, gfloat value) 437 const gchar * key, gfloat value)
312 { 438 {
313 gchar *strvalue, *locale; 439 gchar *strvalue, *locale;
323 bmp_rcfile_write_string(file, section, key, strvalue); 449 bmp_rcfile_write_string(file, section, key, strvalue);
324 g_free(locale); 450 g_free(locale);
325 g_free(strvalue); 451 g_free(strvalue);
326 } 452 }
327 453
454 /**
455 * bmp_rcfile_write_double:
456 * @file: A #RcFile object to write to disk.
457 * @section: The section of the RcFile to set the key in.
458 * @key: The name of the identifier to set.
459 * @value: The value to set for that identifier.
460 *
461 * Sets a value in an RcFile for %key.
462 **/
328 void 463 void
329 bmp_rcfile_write_double(RcFile * file, const gchar * section, 464 bmp_rcfile_write_double(RcFile * file, const gchar * section,
330 const gchar * key, gdouble value) 465 const gchar * key, gdouble value)
331 { 466 {
332 gchar *strvalue, *locale; 467 gchar *strvalue, *locale;
342 bmp_rcfile_write_string(file, section, key, strvalue); 477 bmp_rcfile_write_string(file, section, key, strvalue);
343 g_free(locale); 478 g_free(locale);
344 g_free(strvalue); 479 g_free(strvalue);
345 } 480 }
346 481
482 /**
483 * bmp_rcfile_remove_key:
484 * @file: A #RcFile object to write to disk.
485 * @section: The section of the RcFile to set the key in.
486 * @key: The name of the identifier to remove.
487 *
488 * Removes %key from an #RcFile object.
489 **/
347 void 490 void
348 bmp_rcfile_remove_key(RcFile * file, const gchar * section, const gchar * key) 491 bmp_rcfile_remove_key(RcFile * file, const gchar * section, const gchar * key)
349 { 492 {
350 RcSection *sect; 493 RcSection *sect;
351 RcLine *line; 494 RcLine *line;