Syncing up before merging in cpasjuste changes in pxml
[pandora-libraries.git] / lib / pnd_tinyxml.cpp
1
2 #include "tinyxml/tinyxml.h"
3 #include "../include/pnd_pxml.h"
4 #include "pnd_tinyxml.h"
5
6 extern "C" {
7
8 unsigned char pnd_pxml_load ( const char* pFilename, pnd_pxml_t *app ) {
9   FILE *f;
10   char *b;
11   unsigned int len;
12
13   f = fopen ( pFilename, "r" );
14
15   if ( ! f ) {
16     return ( 0 );
17   }
18
19   fseek ( f, 0, SEEK_END );
20
21   len = ftell ( f );
22
23   fseek ( f, 0, SEEK_SET );
24
25   b = (char*) malloc ( len );
26
27   if ( ! b ) {
28     fclose ( f );
29     return ( 0 );
30   }
31
32   fread ( b, 1, len, f );
33
34   return ( pnd_pxml_parse ( pFilename, b, len, app ) );
35 }
36
37 unsigned char pnd_pxml_parse ( const char *pFilename, char *buffer, unsigned int length, pnd_pxml_t *app ) {
38
39   //TiXmlDocument doc(pFilename);
40   //if (!doc.LoadFile()) return;
41
42   TiXmlDocument doc;
43
44   doc.Parse ( buffer );
45
46         TiXmlHandle hDoc(&doc);
47         TiXmlElement* pElem;
48         TiXmlHandle hRoot(0);
49
50         pElem=hDoc.FirstChildElement().Element();
51         if (!pElem) return ( 0 );
52         hRoot=TiXmlHandle(pElem);
53
54         pElem = hRoot.FirstChild( "title" ).FirstChildElement("en").Element();
55         if ( pElem )
56         {
57                 app->title_en = strdup(pElem->GetText());
58         }
59
60         pElem = hRoot.FirstChild( "title" ).FirstChildElement("de").Element();
61         if ( pElem )
62         {
63                 app->title_de = strdup(pElem->GetText());
64         }
65
66         pElem = hRoot.FirstChild( "title" ).FirstChildElement("it").Element();
67         if ( pElem )
68         {
69                 app->title_it = strdup(pElem->GetText());
70         }
71         
72         pElem = hRoot.FirstChild( "title" ).FirstChildElement("fr").Element();
73         if ( pElem )
74         {
75                 app->title_fr = strdup(pElem->GetText());
76         }
77
78         pElem=hRoot.FirstChild("unique_id").Element();
79         if (pElem)
80         {       
81                 app->unique_id = strdup(pElem->GetText());
82         }
83
84         pElem=hRoot.FirstChild("standalone").Element();
85         if (pElem)
86         {       
87                 app->standalone = strdup(pElem->GetText());
88         }
89
90         pElem=hRoot.FirstChild("icon").Element();
91         if (pElem)
92         {       
93                 char anotherbuffer [ FILENAME_MAX ];
94                 strcpy ( anotherbuffer, pFilename );
95                 char *s = strstr ( anotherbuffer, PXML_FILENAME );
96                 strcpy ( s, strdup(pElem->GetText()));
97                 app->icon = strdup(anotherbuffer);
98         }
99
100         pElem = hRoot.FirstChild( "description" ).FirstChildElement("en").Element();
101         if ( pElem )
102         {
103                 app->description_en = strdup(pElem->GetText());
104         }
105
106         pElem = hRoot.FirstChild( "description" ).FirstChildElement("de").Element();
107         if ( pElem )
108         {
109                 app->description_de = strdup(pElem->GetText());
110         }
111
112         pElem = hRoot.FirstChild( "description" ).FirstChildElement("it").Element();
113         if ( pElem )
114         {
115                 app->description_it = strdup(pElem->GetText());
116         }
117         
118         pElem = hRoot.FirstChild( "description" ).FirstChildElement("fr").Element();
119         if ( pElem )
120         {
121                 app->description_fr = strdup(pElem->GetText());
122         }
123
124         pElem = hRoot.FirstChild( "previewpic" ).FirstChildElement("pic1").Element();
125         if ( pElem )
126         {
127                 app->previewpic1 = strdup(pElem->GetText());
128         }
129
130         pElem = hRoot.FirstChild( "previewpic" ).FirstChildElement("pic2").Element();
131         if ( pElem )
132         {
133                 app->previewpic2 = strdup(pElem->GetText());
134         }
135
136         pElem = hRoot.FirstChild( "author" ).FirstChildElement("name").Element();
137         if ( pElem )
138         {
139                 app->author_name = strdup(pElem->GetText());
140         }
141
142         pElem = hRoot.FirstChild( "author" ).FirstChildElement("website").Element();
143         if ( pElem )
144         {
145                 app->author_website = strdup(pElem->GetText());;
146         }
147
148         pElem = hRoot.FirstChild( "version" ).FirstChildElement("major").Element();
149         if ( pElem )
150         {
151                 app->version_major = strdup(pElem->GetText());
152         }       
153
154         pElem = hRoot.FirstChild( "version" ).FirstChildElement("minor").Element();
155         if ( pElem )
156         {
157                 app->version_minor = strdup(pElem->GetText());
158         }       
159
160         pElem = hRoot.FirstChild( "version" ).FirstChildElement("release").Element();
161         if ( pElem )
162         {
163                 app->version_release = strdup(pElem->GetText());
164         }       
165
166         pElem = hRoot.FirstChild( "version" ).FirstChildElement("build").Element();
167         if ( pElem )
168         {
169                 app->version_build = strdup(pElem->GetText());
170         }
171
172         pElem=hRoot.FirstChild("exec").Element();
173         if (pElem)
174         {       
175                 char anotherbuffer [ FILENAME_MAX ];
176                 strcpy ( anotherbuffer, pFilename );
177                 char *s = strstr ( anotherbuffer, PXML_FILENAME );
178                 strcpy ( s, strdup(pElem->GetText()));
179                 app->exec = strdup(anotherbuffer);
180         }       
181
182         pElem = hRoot.FirstChild( "category" ).FirstChildElement("main").Element();
183         if ( pElem )
184         {
185                 app->main_category = strdup(pElem->GetText());
186         }
187
188         pElem = hRoot.FirstChild( "category" ).FirstChildElement("subcategory1").Element();
189         if ( pElem )
190         {
191                 app->subcategory1 = strdup(pElem->GetText());
192         }
193
194         pElem = hRoot.FirstChild( "category" ).FirstChildElement("subcategory2").Element();
195         if ( pElem )
196         {
197                 app->subcategory2 = strdup(pElem->GetText());
198         }
199
200         pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("main").Element();
201         if ( pElem )
202         {
203                 app->altcategory = strdup(pElem->GetText());
204         }
205
206         pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("subcategory1").Element();
207         if ( pElem )
208         {
209                 app->altsubcategory1 = strdup(pElem->GetText());
210         }
211
212         pElem = hRoot.FirstChild( "altcategory" ).FirstChildElement("subcategory2").Element();
213         if ( pElem )
214         {
215                 app->altsubcategory2 = strdup(pElem->GetText());
216         }
217
218         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("major").Element();
219         if ( pElem )
220         {
221                 app->osversion_major = strdup(pElem->GetText());
222         }       
223
224         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("minor").Element();
225         if ( pElem )
226         {
227                 app->osversion_minor = strdup(pElem->GetText());
228         }       
229
230         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("release").Element();
231         if ( pElem )
232         {
233                 app->osversion_release = strdup(pElem->GetText());
234         }       
235
236         pElem = hRoot.FirstChild( "osversion" ).FirstChildElement("build").Element();
237         if ( pElem )
238         {
239                 app->osversion_build = strdup(pElem->GetText());
240         }
241
242         pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("name").Element();
243         if ( pElem )
244         {
245                 app->associationitem1_name = strdup(pElem->GetText());
246         }
247
248         pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("filetype").Element();
249         if ( pElem )
250         {
251                 app->associationitem1_filetype = strdup(pElem->GetText());
252         }
253
254         pElem = hRoot.FirstChild( "associationitem1" ).FirstChildElement("parameter").Element();
255         if ( pElem )
256         {
257                 app->associationitem1_parameter = strdup(pElem->GetText());
258         }
259
260         pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("name").Element();
261         if ( pElem )
262         {
263                 app->associationitem2_name = strdup(pElem->GetText());
264         }
265
266         pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("filetype").Element();
267         if ( pElem )
268         {
269                 app->associationitem2_filetype = strdup(pElem->GetText());
270         }
271
272         pElem = hRoot.FirstChild( "associationitem2" ).FirstChildElement("parameter").Element();
273         if ( pElem )
274         {
275                 app->associationitem2_parameter = strdup(pElem->GetText());
276         }
277
278         pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("name").Element();
279         if ( pElem )
280         {
281                 app->associationitem3_name = strdup(pElem->GetText());
282         }
283
284         pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("filetype").Element();
285         if ( pElem )
286         {
287                 app->associationitem3_filetype = strdup(pElem->GetText());
288         }
289
290         pElem = hRoot.FirstChild( "associationitem3" ).FirstChildElement("parameter").Element();
291         if ( pElem )
292         {
293                 app->associationitem3_parameter = strdup(pElem->GetText());
294         }
295
296         pElem=hRoot.FirstChild("clockspeed").Element();
297         if (pElem)
298         {       
299                 app->clockspeed = strdup(pElem->GetText());
300         }
301
302         pElem=hRoot.FirstChild("background").Element();
303         if (pElem)
304         {       
305                 app->background = strdup(pElem->GetText());
306         }
307
308         pElem=hRoot.FirstChild("startdir").Element();
309         if (pElem)
310         {       
311                 app->startdir = strdup(pElem->GetText());
312         }
313
314         return ( 1 );
315 }
316
317 } // extern C