annotate libaudacious/xml_document.c @ 1579:d60e3dbe1a48 trunk

[svn] - better handling for file name which can't be represented correctly in current locale encoding.
author yaz
date Sat, 12 Aug 2006 20:00:08 -0700
parents 705d4c089fce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* BMP - Cross-platform multimedia player
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 * Copyright (C) 2003-2004 BMP development team.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4 * This program is free software; you can redistribute it and/or modify
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 * (at your option) any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 * GNU General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 * along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19 #include "xml_document.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 #include <glib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 /* document builder callbacks */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 static void bmp_xml_doc_build_start_element(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27 const gchar * element_name,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 const gchar ** attrib_names,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 const gchar ** attrib_values,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 gpointer user_data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31 GError ** error);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 static void bmp_xml_doc_build_end_element(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34 const gchar * element_name,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 gpointer user_data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36 GError ** error);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 static void bmp_xml_doc_build_text(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 const gchar * text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 gsize text_len,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41 gpointer user_data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 GError ** error);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 static void bmp_xml_doc_build_ignore(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 const gchar * text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 gsize text_len,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47 gpointer user_data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 GError ** error);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 static void bmp_xml_doc_build_error(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 GError * error,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 gpointer user_data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 static void bmp_xml_doc_build_destroy(BmpXmlDocument * data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 static GMarkupParser bmp_xml_doc_builder = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57 bmp_xml_doc_build_start_element,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 bmp_xml_doc_build_end_element,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 bmp_xml_doc_build_text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 bmp_xml_doc_build_ignore,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 bmp_xml_doc_build_error
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 static GDestroyNotify bmp_xml_node_data_free_func[] = {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65 (GDestroyNotify) bmp_xml_doc_node_data_free,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 (GDestroyNotify) bmp_xml_element_node_data_free,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 (GDestroyNotify) bmp_xml_attrib_node_data_free,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 (GDestroyNotify) bmp_xml_text_node_data_free
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 };
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 GNode *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 bmp_xml_doc_node_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 BmpXmlDocNodeData *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 data = g_new0(BmpXmlDocNodeData, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 data->type = BMP_XML_NODE_DOC;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 return g_node_new(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 bmp_xml_doc_node_data_free(BmpXmlDocNodeData * data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 g_return_if_fail(data != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 g_free(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 GNode *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 bmp_xml_element_node_new(const gchar * name)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 BmpXmlElementNodeData *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 data = g_new0(BmpXmlElementNodeData, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 data->type = BMP_XML_NODE_ELEMENT;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 data->name = g_strdup(name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94 return g_node_new(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 bmp_xml_element_node_data_free(BmpXmlElementNodeData * data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 g_return_if_fail(data != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 g_free(data->name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 g_free(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 GNode *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 bmp_xml_attrib_node_new(const gchar * name,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 const gchar * value)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 BmpXmlAttribNodeData *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 data = g_new0(BmpXmlAttribNodeData, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111 data->type = BMP_XML_NODE_ATTRIB;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 data->name = g_strdup(name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 data->value = g_strdup(value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 return g_node_new(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 bmp_xml_attrib_node_data_free(BmpXmlAttribNodeData * data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 g_assert(data != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 g_free(data->name);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 g_free(data->value);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 g_free(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 GNode *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 bmp_xml_text_node_new(const gchar * text, gsize length)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 BmpXmlTextNodeData *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 data = g_new0(BmpXmlTextNodeData, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 data->type = BMP_XML_NODE_TEXT;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132 data->text = g_new0(gchar, length);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 memcpy(data->text, text, length);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 data->length = length;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 return g_node_new(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 bmp_xml_text_node_data_free(BmpXmlTextNodeData * data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 g_return_if_fail(data != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142 g_free(data->text);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 g_free(data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 bmp_xml_node_data_free(GNode * node)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 BmpXmlNodeData *data;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 g_return_if_fail(node != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 g_return_if_fail(node->data != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154 data = BMP_XML_NODE_DATA(node->data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 (*bmp_xml_node_data_free_func[data->type]) (data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 BmpXmlDocument *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 bmp_xml_document_new(void)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 BmpXmlDocument *document;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 document = g_new0(BmpXmlDocument, 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 document->parse_context =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 g_markup_parse_context_new(&bmp_xml_doc_builder, 0,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 document, (GDestroyNotify)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 bmp_xml_doc_build_destroy);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 document->current_depth = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 document->tree = bmp_xml_doc_node_new();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 document->current_node = document->tree;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 return document;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 bmp_xml_document_free(BmpXmlDocument * document)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 g_return_if_fail(document != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182 g_node_traverse(document->tree, G_IN_ORDER, G_TRAVERSE_ALL, -1,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 (GNodeTraverseFunc) bmp_xml_node_data_free, NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 g_node_destroy(document->tree);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 g_free(document);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 GNode *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 bmp_xml_document_get_tree(BmpXmlDocument * document)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 return document->tree;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195 gboolean
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 bmp_xml_document_load(BmpXmlDocument ** document_ref,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 const gchar * filename, GError ** error_out)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 BmpXmlDocument *document;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 gchar *buffer;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 gsize buffer_size;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 GError *error = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 g_assert(document_ref != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205 g_assert(filename != NULL);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 *document_ref = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 if (!g_file_get_contents(filename, &buffer, &buffer_size, &error)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 g_propagate_error(error_out, error);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 if (!(document = bmp_xml_document_new())) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 g_free(buffer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219 if (!g_markup_parse_context_parse(document->parse_context, buffer,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 buffer_size, &error)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 bmp_xml_document_free(document);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 g_free(buffer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 g_propagate_error(error_out, error);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 g_free(buffer);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 if (!g_markup_parse_context_end_parse(document->parse_context, &error)) {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 bmp_xml_document_free(document);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 g_propagate_error(error_out, error);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 *document_ref = document;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 bmp_xml_doc_build_start_element(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 const gchar * element_name,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 const gchar ** attrib_names,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 const gchar ** attrib_values,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 gpointer user_data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247 GError ** error)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 BmpXmlDocument *document;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251 document = BMP_XML_DOCUMENT(user_data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 document->current_node =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 g_node_append(document->current_node,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255 bmp_xml_element_node_new(element_name));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 while (*attrib_names) {
462
b65fe3b68300 [svn] Move xml_document stuff into libaudacious.
nenolod
parents: 0
diff changeset
258 g_print("%s = %s\n", *attrib_names, *attrib_values);
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 g_node_append(document->current_node,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 bmp_xml_attrib_node_new(*attrib_names++,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 *attrib_values++));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 document->current_depth++;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268 bmp_xml_doc_build_end_element(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 const gchar * element_name,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270 gpointer user_data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 GError ** error)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273 BmpXmlDocument *document;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275 document = BMP_XML_DOCUMENT(user_data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 document->current_node = document->current_node->parent;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277 document->current_depth--;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 bmp_xml_doc_build_text(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282 const gchar * text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 gsize text_len,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 gpointer user_data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 GError ** error)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287 BmpXmlDocument *document;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 document = BMP_XML_DOCUMENT(user_data);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 g_node_append(document->current_node,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 bmp_xml_text_node_new(text, text_len));
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 bmp_xml_doc_build_ignore(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295 const gchar * text,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 gsize text_len,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 gpointer user_data,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298 GError ** error)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303 bmp_xml_doc_build_error(GMarkupParseContext * context,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 GError * error,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 gpointer user_data)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 bmp_xml_doc_build_destroy(BmpXmlDocument * document)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 g_markup_parse_context_free(document->parse_context);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 }