annotate src/audacious/rcfile.c @ 3023:49ce30748980

added lastfm GUI stub
author Cristi Magherusan <majeru@atheme-project.org>
date Tue, 10 Jul 2007 17:13:24 +0300
parents d226b83fa329
children 4c758281fe8f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2865
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
1 /*
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
2 * audacious: Cross-platform multimedia player.
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
3 * rcfile.c: Reading and manipulation of .ini-like files.
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
4 *
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
5 * Copyright (c) 2005-2007 Audacious development team.
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
6 * Copyright (c) 2003-2005 BMP development team.
2537
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
7 *
2865
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
8 * Redistribution and use in source and binary forms, with or without
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
9 * modification, are permitted provided that the following conditions are
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
10 * met:
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
11 *
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
12 * 1. Redistributions of source code must retain the above copyright notice,
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
13 * this list of conditions and the following disclaimer.
2537
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
14 *
2865
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
15 * 2. Redistributions in binary form must reproduce the above copyright
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
16 * notice, this list of conditions and the following disclaimer in the
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
17 * documentation and/or other materials provided with the distribution.
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
18 *
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
19 * 3. The name of the author may not be used to endorse or promote products
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
20 * derived from this software without specific prior written permission.
2537
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
21 *
2865
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
31 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
d226b83fa329 BSD relicensing (pass 6).
William Pitcock <nenolod@atheme.org>
parents: 2537
diff changeset
32 * POSSIBILITY OF SUCH DAMAGE.
2537
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
33 */
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
34
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
35 #include "rcfile.h"
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
36
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
37 #include <stdio.h>
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
38 #include <string.h>
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
39 #include <stdlib.h>
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
40 #include <locale.h>
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
41
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
42 #include <unistd.h>
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
43 #include <sys/stat.h>
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
44
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
45
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
46 static RcSection *bmp_rcfile_create_section(RcFile * file,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
47 const gchar * name);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
48 static RcLine *bmp_rcfile_create_string(RcSection * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
49 const gchar * key,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
50 const gchar * value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
51 static RcSection *bmp_rcfile_find_section(RcFile * file, const gchar * name);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
52 static RcLine *bmp_rcfile_find_string(RcSection * section, const gchar * key);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
53
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
54 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
55 * bmp_rcfile_new:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
56 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
57 * #RcFile object factory.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
58 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
59 * Return value: A #RcFile object.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
60 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
61 RcFile *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
62 bmp_rcfile_new(void)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
63 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
64 return g_new0(RcFile, 1);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
65 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
66
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
67 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
68 * bmp_rcfile_free:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
69 * @file: A #RcFile object to destroy.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
70 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
71 * #RcFile object destructor.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
72 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
73 void
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
74 bmp_rcfile_free(RcFile * file)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
75 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
76 RcSection *section;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
77 RcLine *line;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
78 GList *section_list, *line_list;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
79
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
80 if (file == NULL)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
81 return;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
82
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
83 section_list = file->sections;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
84 while (section_list) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
85 section = (RcSection *) section_list->data;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
86 g_free(section->name);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
87
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
88 line_list = section->lines;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
89 while (line_list) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
90 line = (RcLine *) line_list->data;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
91 g_free(line->key);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
92 g_free(line->value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
93 g_free(line);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
94 line_list = g_list_next(line_list);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
95 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
96 g_list_free(section->lines);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
97 g_free(section);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
98
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
99 section_list = g_list_next(section_list);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
100 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
101 g_list_free(file->sections);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
102 g_free(file);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
103 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
104
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
105 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
106 * bmp_rcfile_open:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
107 * @filename: Path to rcfile to open.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
108 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
109 * Opens an rcfile and returns an #RcFile object representing it.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
110 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
111 * Return value: An #RcFile object representing the rcfile given.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
112 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
113 RcFile *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
114 bmp_rcfile_open(const gchar * filename)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
115 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
116 RcFile *file;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
117
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
118 gchar *buffer, **lines, *tmp;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
119 gint i;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
120 RcSection *section = NULL;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
121
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
122 g_return_val_if_fail(filename != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
123 g_return_val_if_fail(strlen(filename) > 0, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
124
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
125 if (!g_file_get_contents(filename, &buffer, NULL, NULL))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
126 return NULL;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
127
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
128 file = bmp_rcfile_new();
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
129 lines = g_strsplit(buffer, "\n", 0);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
130 g_free(buffer);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
131 i = 0;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
132 while (lines[i]) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
133 if (lines[i][0] == '[') {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
134 if ((tmp = strchr(lines[i], ']'))) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
135 *tmp = '\0';
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
136 section = bmp_rcfile_create_section(file, &lines[i][1]);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
137 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
138 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
139 else if (lines[i][0] != '#' && section) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
140 if ((tmp = strchr(lines[i], '='))) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
141 gchar **frags;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
142 frags = g_strsplit(lines[i], "=", 2);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
143 if (strlen(frags[1]) > 0) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
144 bmp_rcfile_create_string(section, frags[0], frags[1]);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
145 };
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
146 g_strfreev(frags);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
147 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
148 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
149 i++;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
150 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
151 g_strfreev(lines);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
152 return file;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
153 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
154
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
155 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
156 * bmp_rcfile_write:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
157 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
158 * @filename: A path to write the #RcFile object's data to.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
159 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
160 * Writes the contents of a #RcFile object to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
161 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
162 * Return value: TRUE on success, FALSE otherwise.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
163 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
164 gboolean
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
165 bmp_rcfile_write(RcFile * file, const gchar * filename)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
166 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
167 FILE *fp;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
168 GList *section_list, *line_list;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
169 RcSection *section;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
170 RcLine *line;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
171
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
172 g_return_val_if_fail(file != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
173 g_return_val_if_fail(filename != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
174
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
175 if (!(fp = fopen(filename, "w")))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
176 return FALSE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
177
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
178 section_list = file->sections;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
179 while (section_list) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
180 section = (RcSection *) section_list->data;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
181 if (section->lines) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
182 fprintf(fp, "[%s]\n", section->name);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
183 line_list = section->lines;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
184 while (line_list) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
185 line = (RcLine *) line_list->data;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
186 fprintf(fp, "%s=%s\n", line->key, line->value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
187 line_list = g_list_next(line_list);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
188 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
189 fprintf(fp, "\n");
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
190 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
191 section_list = g_list_next(section_list);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
192 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
193 fclose(fp);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
194 return TRUE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
195 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
196
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
197 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
198 * bmp_rcfile_read_string:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
199 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
200 * @section: The section of the RcFile to look in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
201 * @key: The name of the identifier to look up.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
202 * @value: A pointer to a memory location to place the data.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
203 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
204 * Looks up a value in an RcFile and places it in %value.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
205 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
206 * Return value: TRUE on success, FALSE otherwise.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
207 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
208 gboolean
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
209 bmp_rcfile_read_string(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
210 const gchar * key, gchar ** value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
211 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
212 RcSection *sect;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
213 RcLine *line;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
214
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
215 g_return_val_if_fail(file != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
216 g_return_val_if_fail(section != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
217 g_return_val_if_fail(key != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
218 g_return_val_if_fail(value != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
219
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
220 if (!(sect = bmp_rcfile_find_section(file, section)))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
221 return FALSE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
222 if (!(line = bmp_rcfile_find_string(sect, key)))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
223 return FALSE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
224 *value = g_strdup(line->value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
225 return TRUE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
226 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
227
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
228 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
229 * bmp_rcfile_read_int:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
230 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
231 * @section: The section of the RcFile to look in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
232 * @key: The name of the identifier to look up.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
233 * @value: A pointer to a memory location to place the data.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
234 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
235 * Looks up a value in an RcFile and places it in %value.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
236 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
237 * Return value: TRUE on success, FALSE otherwise.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
238 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
239 gboolean
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
240 bmp_rcfile_read_int(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
241 const gchar * key, gint * value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
242 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
243 gchar *str;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
244
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
245 g_return_val_if_fail(file != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
246 g_return_val_if_fail(section != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
247 g_return_val_if_fail(key != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
248 g_return_val_if_fail(value != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
249
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
250 if (!bmp_rcfile_read_string(file, section, key, &str))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
251 return FALSE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
252 *value = atoi(str);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
253 g_free(str);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
254
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
255 return TRUE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
256 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
257
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
258 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
259 * bmp_rcfile_read_bool:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
260 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
261 * @section: The section of the RcFile to look in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
262 * @key: The name of the identifier to look up.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
263 * @value: A pointer to a memory location to place the data.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
264 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
265 * Looks up a value in an RcFile and places it in %value.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
266 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
267 * Return value: TRUE on success, FALSE otherwise.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
268 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
269 gboolean
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
270 bmp_rcfile_read_bool(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
271 const gchar * key, gboolean * value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
272 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
273 gchar *str;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
274
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
275 g_return_val_if_fail(file != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
276 g_return_val_if_fail(section != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
277 g_return_val_if_fail(key != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
278 g_return_val_if_fail(value != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
279
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
280 if (!bmp_rcfile_read_string(file, section, key, &str))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
281 return FALSE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
282 if (!strcasecmp(str, "TRUE"))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
283 *value = TRUE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
284 else
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
285 *value = FALSE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
286 g_free(str);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
287 return TRUE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
288 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
289
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
290 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
291 * bmp_rcfile_read_float:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
292 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
293 * @section: The section of the RcFile to look in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
294 * @key: The name of the identifier to look up.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
295 * @value: A pointer to a memory location to place the data.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
296 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
297 * Looks up a value in an RcFile and places it in %value.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
298 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
299 * Return value: TRUE on success, FALSE otherwise.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
300 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
301 gboolean
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
302 bmp_rcfile_read_float(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
303 const gchar * key, gfloat * value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
304 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
305 gchar *str, *locale;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
306
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
307 g_return_val_if_fail(file != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
308 g_return_val_if_fail(section != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
309 g_return_val_if_fail(key != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
310 g_return_val_if_fail(value != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
311
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
312 if (!bmp_rcfile_read_string(file, section, key, &str))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
313 return FALSE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
314
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
315 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
316 setlocale(LC_NUMERIC, "C");
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
317 *value = strtod(str, NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
318 setlocale(LC_NUMERIC, locale);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
319 g_free(locale);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
320 g_free(str);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
321
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
322 return TRUE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
323 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
324
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
325 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
326 * bmp_rcfile_read_double:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
327 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
328 * @section: The section of the RcFile to look in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
329 * @key: The name of the identifier to look up.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
330 * @value: A pointer to a memory location to place the data.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
331 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
332 * Looks up a value in an RcFile and places it in %value.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
333 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
334 * Return value: TRUE on success, FALSE otherwise.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
335 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
336 gboolean
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
337 bmp_rcfile_read_double(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
338 const gchar * key, gdouble * value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
339 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
340 gchar *str, *locale;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
341
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
342 g_return_val_if_fail(file != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
343 g_return_val_if_fail(section != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
344 g_return_val_if_fail(key != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
345 g_return_val_if_fail(value != NULL, FALSE);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
346
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
347 if (!bmp_rcfile_read_string(file, section, key, &str))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
348 return FALSE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
349
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
350 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
351 setlocale(LC_NUMERIC, "C");
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
352 *value = strtod(str, NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
353 setlocale(LC_NUMERIC, locale);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
354 g_free(locale);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
355 g_free(str);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
356
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
357 return TRUE;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
358 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
359
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
360 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
361 * bmp_rcfile_write_string:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
362 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
363 * @section: The section of the RcFile to set the key in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
364 * @key: The name of the identifier to set.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
365 * @value: The value to set for that identifier.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
366 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
367 * Sets a value in an RcFile for %key.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
368 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
369 void
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
370 bmp_rcfile_write_string(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
371 const gchar * key, const gchar * value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
372 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
373 RcSection *sect;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
374 RcLine *line;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
375
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
376 g_return_if_fail(file != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
377 g_return_if_fail(section != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
378 g_return_if_fail(key != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
379 g_return_if_fail(value != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
380
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
381 sect = bmp_rcfile_find_section(file, section);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
382 if (!sect)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
383 sect = bmp_rcfile_create_section(file, section);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
384 if ((line = bmp_rcfile_find_string(sect, key))) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
385 g_free(line->value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
386 line->value = g_strstrip(g_strdup(value));
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
387 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
388 else
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
389 bmp_rcfile_create_string(sect, key, value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
390 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
391
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
392 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
393 * bmp_rcfile_write_int:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
394 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
395 * @section: The section of the RcFile to set the key in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
396 * @key: The name of the identifier to set.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
397 * @value: The value to set for that identifier.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
398 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
399 * Sets a value in an RcFile for %key.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
400 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
401 void
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
402 bmp_rcfile_write_int(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
403 const gchar * key, gint value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
404 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
405 gchar *strvalue;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
406
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
407 g_return_if_fail(file != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
408 g_return_if_fail(section != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
409 g_return_if_fail(key != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
410
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
411 strvalue = g_strdup_printf("%d", value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
412 bmp_rcfile_write_string(file, section, key, strvalue);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
413 g_free(strvalue);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
414 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
415
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
416 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
417 * bmp_rcfile_write_boolean:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
418 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
419 * @section: The section of the RcFile to set the key in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
420 * @key: The name of the identifier to set.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
421 * @value: The value to set for that identifier.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
422 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
423 * Sets a value in an RcFile for %key.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
424 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
425 void
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
426 bmp_rcfile_write_boolean(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
427 const gchar * key, gboolean value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
428 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
429 g_return_if_fail(file != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
430 g_return_if_fail(section != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
431 g_return_if_fail(key != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
432
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
433 if (value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
434 bmp_rcfile_write_string(file, section, key, "TRUE");
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
435 else
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
436 bmp_rcfile_write_string(file, section, key, "FALSE");
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
437 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
438
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
439 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
440 * bmp_rcfile_write_float:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
441 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
442 * @section: The section of the RcFile to set the key in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
443 * @key: The name of the identifier to set.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
444 * @value: The value to set for that identifier.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
445 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
446 * Sets a value in an RcFile for %key.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
447 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
448 void
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
449 bmp_rcfile_write_float(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
450 const gchar * key, gfloat value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
451 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
452 gchar *strvalue, *locale;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
453
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
454 g_return_if_fail(file != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
455 g_return_if_fail(section != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
456 g_return_if_fail(key != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
457
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
458 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
459 setlocale(LC_NUMERIC, "C");
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
460 strvalue = g_strdup_printf("%g", value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
461 setlocale(LC_NUMERIC, locale);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
462 bmp_rcfile_write_string(file, section, key, strvalue);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
463 g_free(locale);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
464 g_free(strvalue);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
465 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
466
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
467 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
468 * bmp_rcfile_write_double:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
469 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
470 * @section: The section of the RcFile to set the key in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
471 * @key: The name of the identifier to set.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
472 * @value: The value to set for that identifier.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
473 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
474 * Sets a value in an RcFile for %key.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
475 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
476 void
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
477 bmp_rcfile_write_double(RcFile * file, const gchar * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
478 const gchar * key, gdouble value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
479 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
480 gchar *strvalue, *locale;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
481
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
482 g_return_if_fail(file != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
483 g_return_if_fail(section != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
484 g_return_if_fail(key != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
485
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
486 locale = g_strdup(setlocale(LC_NUMERIC, NULL));
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
487 setlocale(LC_NUMERIC, "C");
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
488 strvalue = g_strdup_printf("%g", value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
489 setlocale(LC_NUMERIC, locale);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
490 bmp_rcfile_write_string(file, section, key, strvalue);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
491 g_free(locale);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
492 g_free(strvalue);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
493 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
494
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
495 /**
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
496 * bmp_rcfile_remove_key:
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
497 * @file: A #RcFile object to write to disk.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
498 * @section: The section of the RcFile to set the key in.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
499 * @key: The name of the identifier to remove.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
500 *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
501 * Removes %key from an #RcFile object.
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
502 **/
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
503 void
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
504 bmp_rcfile_remove_key(RcFile * file, const gchar * section, const gchar * key)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
505 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
506 RcSection *sect;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
507 RcLine *line;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
508
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
509 g_return_if_fail(file != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
510 g_return_if_fail(section != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
511 g_return_if_fail(key != NULL);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
512
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
513 if ((sect = bmp_rcfile_find_section(file, section)) != NULL) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
514 if ((line = bmp_rcfile_find_string(sect, key)) != NULL) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
515 g_free(line->key);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
516 g_free(line->value);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
517 g_free(line);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
518 sect->lines = g_list_remove(sect->lines, line);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
519 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
520 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
521 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
522
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
523 static RcSection *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
524 bmp_rcfile_create_section(RcFile * file, const gchar * name)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
525 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
526 RcSection *section;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
527
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
528 section = g_new0(RcSection, 1);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
529 section->name = g_strdup(name);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
530 file->sections = g_list_append(file->sections, section);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
531
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
532 return section;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
533 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
534
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
535 static RcLine *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
536 bmp_rcfile_create_string(RcSection * section,
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
537 const gchar * key, const gchar * value)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
538 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
539 RcLine *line;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
540
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
541 line = g_new0(RcLine, 1);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
542 line->key = g_strstrip(g_strdup(key));
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
543 line->value = g_strstrip(g_strdup(value));
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
544 section->lines = g_list_append(section->lines, line);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
545
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
546 return line;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
547 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
548
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
549 static RcSection *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
550 bmp_rcfile_find_section(RcFile * file, const gchar * name)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
551 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
552 RcSection *section;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
553 GList *list;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
554
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
555 list = file->sections;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
556 while (list) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
557 section = (RcSection *) list->data;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
558 if (!strcasecmp(section->name, name))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
559 return section;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
560 list = g_list_next(list);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
561 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
562 return NULL;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
563 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
564
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
565 static RcLine *
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
566 bmp_rcfile_find_string(RcSection * section, const gchar * key)
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
567 {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
568 RcLine *line;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
569 GList *list;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
570
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
571 list = section->lines;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
572 while (list) {
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
573 line = (RcLine *) list->data;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
574 if (!strcasecmp(line->key, key))
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
575 return line;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
576 list = g_list_next(list);
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
577 }
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
578 return NULL;
7aac1b5ef85d [svn] - reinstate rcfile class for now
nenolod
parents:
diff changeset
579 }