annotate libaudacious/rcfile.c @ 2259:3668594b4fc8 trunk

[svn] - moved action_playlist_* implementation from ui_main.c to ui_playlist.c (more appropriate)
author giacomo
date Thu, 04 Jan 2007 04:16:48 -0800
parents f18a5b617c34
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
1 /* Audacious
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
2 * Copyright (c) 2005-2007 Audacious team
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
3 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
4 * BMP
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
5 * Copyright (c) 2003-2005 BMP team
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
6 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
7 * This program is free software; you can redistribute it and/or modify
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 * it under the terms of the GNU General Public License as published by
2105
f18a5b617c34 [svn] - move to GPLv2-only. Based on my interpretation of the license, we are
nenolod
parents: 2057
diff changeset
9 * the Free Software Foundation; under version 2 of the License.
0
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
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0
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 #include "rcfile.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #include <locale.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #include <unistd.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 #include <sys/stat.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 static RcSection *bmp_rcfile_create_section(RcFile * file,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 const gchar * name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 static RcLine *bmp_rcfile_create_string(RcSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 const gchar * key,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 const gchar * value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 static RcSection *bmp_rcfile_find_section(RcFile * file, const gchar * name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 static RcLine *bmp_rcfile_find_string(RcSection * section, const gchar * key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
40 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
41 * bmp_rcfile_new:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
42 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
43 * #RcFile object factory.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
44 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
45 * Return value: A #RcFile object.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
46 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 RcFile *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 bmp_rcfile_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 return g_new0(RcFile, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
53 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
54 * bmp_rcfile_free:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
55 * @file: A #RcFile object to destroy.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
56 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
57 * #RcFile object destructor.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
58 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 bmp_rcfile_free(RcFile * file)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 RcSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 RcLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 GList *section_list, *line_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 if (file == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 section_list = file->sections;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 while (section_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 section = (RcSection *) section_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 g_free(section->name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 line_list = section->lines;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 while (line_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 line = (RcLine *) line_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 g_free(line->key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 g_free(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 g_free(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 line_list = g_list_next(line_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 g_list_free(section->lines);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 g_free(section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 section_list = g_list_next(section_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 g_list_free(file->sections);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 g_free(file);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
91 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
92 * bmp_rcfile_open:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
93 * @filename: Path to rcfile to open.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
94 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
95 * Opens an rcfile and returns an #RcFile object representing it.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
96 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
97 * Return value: An #RcFile object representing the rcfile given.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
98 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 RcFile *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 bmp_rcfile_open(const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 RcFile *file;
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 RcSection *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 g_return_val_if_fail(strlen(filename) > 0, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 if (!g_file_get_contents(filename, &buffer, NULL, NULL))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
114 file = bmp_rcfile_new();
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 lines = g_strsplit(buffer, "\n", 0);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 g_free(buffer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 i = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 while (lines[i]) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 if (lines[i][0] == '[') {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 if ((tmp = strchr(lines[i], ']'))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 *tmp = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 section = bmp_rcfile_create_section(file, &lines[i][1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 else if (lines[i][0] != '#' && section) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 if ((tmp = strchr(lines[i], '='))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 gchar **frags;
1769
8a926dec916f [svn] - parse equals correctly.
nenolod
parents: 1459
diff changeset
128 frags = g_strsplit(lines[i], "=", 2);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 if (strlen(frags[1]) > 0) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 bmp_rcfile_create_string(section, frags[0], frags[1]);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 };
1327
5bd743a3417b [svn] fix for memory leak in bmp_rcfile_open()
yaz
parents: 0
diff changeset
132 g_strfreev(frags);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 i++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 g_strfreev(lines);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 return file;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
141 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
142 * bmp_rcfile_write:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
143 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
144 * @filename: A path to write the #RcFile object's data to.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
145 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
146 * Writes the contents of a #RcFile object to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
147 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
148 * Return value: TRUE on success, FALSE otherwise.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
149 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 bmp_rcfile_write(RcFile * file, const gchar * filename)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 FILE *fp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 GList *section_list, *line_list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 RcSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 RcLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 g_return_val_if_fail(file != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 g_return_val_if_fail(filename != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 if (!(fp = fopen(filename, "w")))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 section_list = file->sections;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 while (section_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 section = (RcSection *) section_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 if (section->lines) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 fprintf(fp, "[%s]\n", section->name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 line_list = section->lines;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170 while (line_list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 line = (RcLine *) line_list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 fprintf(fp, "%s=%s\n", line->key, line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173 line_list = g_list_next(line_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 fprintf(fp, "\n");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 section_list = g_list_next(section_list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 fclose(fp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
183 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
184 * bmp_rcfile_read_string:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
185 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
186 * @section: The section of the RcFile to look in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
187 * @key: The name of the identifier to look up.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
188 * @value: A pointer to a memory location to place the data.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
189 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
190 * Looks up a value in an RcFile and places it in %value.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
191 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
192 * Return value: TRUE on success, FALSE otherwise.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
193 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 bmp_rcfile_read_string(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 const gchar * key, gchar ** value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 RcSection *sect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 RcLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 g_return_val_if_fail(file != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 if (!(sect = bmp_rcfile_find_section(file, section)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 if (!(line = bmp_rcfile_find_string(sect, key)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 *value = g_strdup(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
214 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
215 * bmp_rcfile_read_int:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
216 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
217 * @section: The section of the RcFile to look in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
218 * @key: The name of the identifier to look up.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
219 * @value: A pointer to a memory location to place the data.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
220 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
221 * Looks up a value in an RcFile and places it in %value.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
222 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
223 * Return value: TRUE on success, FALSE otherwise.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
224 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 bmp_rcfile_read_int(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 const gchar * key, gint * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 gchar *str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 g_return_val_if_fail(file != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 if (!bmp_rcfile_read_string(file, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 *value = atoi(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
244 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
245 * bmp_rcfile_read_bool:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
246 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
247 * @section: The section of the RcFile to look in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
248 * @key: The name of the identifier to look up.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
249 * @value: A pointer to a memory location to place the data.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
250 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
251 * Looks up a value in an RcFile and places it in %value.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
252 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
253 * Return value: TRUE on success, FALSE otherwise.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
254 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 bmp_rcfile_read_bool(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 const gchar * key, gboolean * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 gchar *str;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 g_return_val_if_fail(file != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 if (!bmp_rcfile_read_string(file, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 if (!strcasecmp(str, "TRUE"))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 *value = TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 *value = FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
276 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
277 * bmp_rcfile_read_float:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
278 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
279 * @section: The section of the RcFile to look in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
280 * @key: The name of the identifier to look up.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
281 * @value: A pointer to a memory location to place the data.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
282 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
283 * Looks up a value in an RcFile and places it in %value.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
284 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
285 * Return value: TRUE on success, FALSE otherwise.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
286 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 bmp_rcfile_read_float(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 const gchar * key, gfloat * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 gchar *str, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 g_return_val_if_fail(file != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 if (!bmp_rcfile_read_string(file, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 *value = strtod(str, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
311 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
312 * bmp_rcfile_read_double:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
313 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
314 * @section: The section of the RcFile to look in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
315 * @key: The name of the identifier to look up.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
316 * @value: A pointer to a memory location to place the data.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
317 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
318 * Looks up a value in an RcFile and places it in %value.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
319 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
320 * Return value: TRUE on success, FALSE otherwise.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
321 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 bmp_rcfile_read_double(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 const gchar * key, gdouble * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 gchar *str, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 g_return_val_if_fail(file != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 g_return_val_if_fail(section != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 g_return_val_if_fail(key != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331 g_return_val_if_fail(value != NULL, FALSE);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 if (!bmp_rcfile_read_string(file, section, key, &str))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 *value = strtod(str, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 g_free(str);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
346 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
347 * bmp_rcfile_write_string:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
348 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
349 * @section: The section of the RcFile to set the key in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
350 * @key: The name of the identifier to set.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
351 * @value: The value to set for that identifier.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
352 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
353 * Sets a value in an RcFile for %key.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
354 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 bmp_rcfile_write_string(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 const gchar * key, const gchar * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 RcSection *sect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 RcLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 g_return_if_fail(file != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 g_return_if_fail(value != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 sect = bmp_rcfile_find_section(file, section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 if (!sect)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 sect = bmp_rcfile_create_section(file, section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370 if ((line = bmp_rcfile_find_string(sect, key))) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 g_free(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372 line->value = g_strstrip(g_strdup(value));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 bmp_rcfile_create_string(sect, key, value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
378 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
379 * bmp_rcfile_write_int:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
380 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
381 * @section: The section of the RcFile to set the key in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
382 * @key: The name of the identifier to set.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
383 * @value: The value to set for that identifier.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
384 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
385 * Sets a value in an RcFile for %key.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
386 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 bmp_rcfile_write_int(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 const gchar * key, gint value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 gchar *strvalue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 g_return_if_fail(file != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397 strvalue = g_strdup_printf("%d", value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 bmp_rcfile_write_string(file, section, key, strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 g_free(strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
402 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
403 * bmp_rcfile_write_boolean:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
404 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
405 * @section: The section of the RcFile to set the key in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
406 * @key: The name of the identifier to set.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
407 * @value: The value to set for that identifier.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
408 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
409 * Sets a value in an RcFile for %key.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
410 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 bmp_rcfile_write_boolean(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 const gchar * key, gboolean value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
415 g_return_if_fail(file != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
416 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 if (value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420 bmp_rcfile_write_string(file, section, key, "TRUE");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421 else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
422 bmp_rcfile_write_string(file, section, key, "FALSE");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
423 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
424
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
425 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
426 * bmp_rcfile_write_float:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
427 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
428 * @section: The section of the RcFile to set the key in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
429 * @key: The name of the identifier to set.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
430 * @value: The value to set for that identifier.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
431 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
432 * Sets a value in an RcFile for %key.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
433 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 bmp_rcfile_write_float(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 const gchar * key, gfloat value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438 gchar *strvalue, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
440 g_return_if_fail(file != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
441 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
442 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
443
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
444 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
445 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
446 strvalue = g_strdup_printf("%g", value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
447 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
448 bmp_rcfile_write_string(file, section, key, strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
449 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
450 g_free(strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
451 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
452
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
453 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
454 * bmp_rcfile_write_double:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
455 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
456 * @section: The section of the RcFile to set the key in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
457 * @key: The name of the identifier to set.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
458 * @value: The value to set for that identifier.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
459 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
460 * Sets a value in an RcFile for %key.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
461 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
462 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
463 bmp_rcfile_write_double(RcFile * file, const gchar * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
464 const gchar * key, gdouble value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
465 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
466 gchar *strvalue, *locale;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
467
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
468 g_return_if_fail(file != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
469 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
470 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
471
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
472 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
473 setlocale(LC_NUMERIC, "C");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
474 strvalue = g_strdup_printf("%g", value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
475 setlocale(LC_NUMERIC, locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
476 bmp_rcfile_write_string(file, section, key, strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
477 g_free(locale);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
478 g_free(strvalue);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
479 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
480
2057
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
481 /**
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
482 * bmp_rcfile_remove_key:
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
483 * @file: A #RcFile object to write to disk.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
484 * @section: The section of the RcFile to set the key in.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
485 * @key: The name of the identifier to remove.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
486 *
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
487 * Removes %key from an #RcFile object.
a55ad33d882e [svn] - document rcfile
nenolod
parents: 1769
diff changeset
488 **/
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
489 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
490 bmp_rcfile_remove_key(RcFile * file, const gchar * section, const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
491 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
492 RcSection *sect;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
493 RcLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
494
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
495 g_return_if_fail(file != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
496 g_return_if_fail(section != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
497 g_return_if_fail(key != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
498
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
499 if ((sect = bmp_rcfile_find_section(file, section)) != NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
500 if ((line = bmp_rcfile_find_string(sect, key)) != NULL) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
501 g_free(line->key);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
502 g_free(line->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
503 g_free(line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
504 sect->lines = g_list_remove(sect->lines, line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
505 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
506 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
507 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
508
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
509 static RcSection *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
510 bmp_rcfile_create_section(RcFile * file, const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
511 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
512 RcSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
513
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
514 section = g_new0(RcSection, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
515 section->name = g_strdup(name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
516 file->sections = g_list_append(file->sections, section);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
517
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
518 return section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
519 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
520
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
521 static RcLine *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
522 bmp_rcfile_create_string(RcSection * section,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
523 const gchar * key, const gchar * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
524 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
525 RcLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
526
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
527 line = g_new0(RcLine, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
528 line->key = g_strstrip(g_strdup(key));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
529 line->value = g_strstrip(g_strdup(value));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
530 section->lines = g_list_append(section->lines, line);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
531
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
532 return line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
533 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
534
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
535 static RcSection *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
536 bmp_rcfile_find_section(RcFile * file, const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
537 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
538 RcSection *section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
539 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
540
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
541 list = file->sections;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
542 while (list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
543 section = (RcSection *) list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
544 if (!strcasecmp(section->name, name))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
545 return section;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
546 list = g_list_next(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
547 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
548 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
549 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
550
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
551 static RcLine *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
552 bmp_rcfile_find_string(RcSection * section, const gchar * key)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
553 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
554 RcLine *line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
555 GList *list;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
556
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
557 list = section->lines;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
558 while (list) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
559 line = (RcLine *) list->data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
560 if (!strcasecmp(line->key, key))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
561 return line;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
562 list = g_list_next(list);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
563 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
564 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
565 }