2 #include <stdio.h> /* for FILE */
3 #include <stdlib.h> /* for malloc */
4 #include <string.h> /* for string ops */
6 #include <sys/types.h> /* for stat */
7 #include <sys/stat.h> /* for stat */
8 #include <unistd.h> /* for stat */
11 #include "pnd_pathiter.h"
12 #include "pnd_tinyxml.h"
14 pnd_pxml_handle pnd_pxml_fetch ( char *fullpath ) {
16 pnd_pxml_t *p = malloc ( sizeof(pnd_pxml_t) );
18 memset ( p, '\0', sizeof(pnd_pxml_t) );
20 if ( ! pnd_pxml_load ( fullpath, p ) ) {
27 pnd_pxml_handle pnd_pxml_fetch_buffer ( char *filename, char *buffer ) {
29 pnd_pxml_t *p = malloc ( sizeof(pnd_pxml_t) );
31 memset ( p, '\0', sizeof(pnd_pxml_t) );
33 if ( ! pnd_pxml_parse ( filename, buffer, strlen ( buffer ), p ) ) {
40 void pnd_pxml_delete ( pnd_pxml_handle h ) {
41 pnd_pxml_t *p = (pnd_pxml_t*) h;
43 if ( p -> title_en ) {
44 free ( p -> title_en );
46 if ( p -> title_de ) {
47 free ( p -> title_de );
49 if ( p -> title_it ) {
50 free ( p -> title_it );
52 if ( p -> title_fr ) {
53 free ( p -> title_fr );
55 if ( p -> unique_id ) {
56 free ( p -> unique_id );
58 if ( p -> standalone ) {
59 free ( p -> standalone );
64 if ( p -> description_en ) {
65 free ( p -> description_en );
67 if ( p -> description_de ) {
68 free ( p -> description_de );
70 if ( p -> description_it ) {
71 free ( p -> description_it );
73 if ( p -> description_fr ) {
74 free ( p -> description_fr );
76 if ( p -> previewpic1 ) {
77 free ( p -> previewpic1 );
79 if ( p -> previewpic2 ) {
80 free ( p -> previewpic2 );
82 if ( p -> author_name ) {
83 free ( p -> author_name );
85 if ( p -> author_website ) {
86 free ( p -> author_website );
88 if ( p -> version_major ) {
89 free ( p -> version_major );
91 if ( p -> version_minor ) {
92 free ( p -> version_minor );
94 if ( p -> version_release ) {
95 free ( p -> version_release );
97 if ( p -> version_build ) {
98 free ( p -> version_build );
103 if ( p -> main_category ) {
104 free ( p -> main_category );
106 if ( p -> subcategory1 ) {
107 free ( p -> subcategory1 );
109 if ( p -> subcategory2 ) {
110 free ( p -> subcategory2 );
112 if ( p -> altcategory ) {
113 free ( p -> altcategory );
115 if ( p -> altsubcategory1 ) {
116 free ( p -> altsubcategory1 );
118 if ( p -> altsubcategory2 ) {
119 free ( p -> altsubcategory2 );
121 if ( p -> osversion_major ) {
122 free ( p -> osversion_major );
124 if ( p -> osversion_minor ) {
125 free ( p -> osversion_minor );
127 if ( p -> osversion_release ) {
128 free ( p -> osversion_release );
130 if ( p -> osversion_build ) {
131 free ( p -> osversion_build );
133 if ( p -> associationitem1_name ) {
134 free ( p -> associationitem1_name );
136 if ( p -> associationitem1_filetype ) {
137 free ( p -> associationitem1_filetype );
139 if ( p -> associationitem1_parameter ) {
140 free ( p -> associationitem1_parameter );
142 if ( p -> associationitem2_name ) {
143 free ( p -> associationitem2_name );
145 if ( p -> associationitem2_filetype ) {
146 free ( p -> associationitem2_filetype );
148 if ( p -> associationitem2_parameter ) {
149 free ( p -> associationitem2_parameter );
151 if ( p -> associationitem3_name ) {
152 free ( p -> associationitem3_name );
154 if ( p -> associationitem1_filetype ) {
155 free ( p -> associationitem3_filetype );
157 if ( p -> associationitem1_parameter ) {
158 free ( p -> associationitem3_parameter );
160 if ( p -> clockspeed ) {
161 free ( p -> clockspeed );
163 if ( p -> background ) {
164 free ( p -> background );
166 if ( p -> startdir ) {
167 free ( p -> startdir );
173 void pnd_pxml_set_app_name ( pnd_pxml_handle h, char *v ) {
174 pnd_pxml_t *p = (pnd_pxml_t*) h;
175 if ( p -> title_en ) {
176 free ( p -> title_en );
177 p -> title_en = NULL;
181 p -> title_en = strdup ( v );
187 unsigned char pnd_is_pxml_valid_app ( pnd_pxml_handle h ) {
188 pnd_pxml_t *p = (pnd_pxml_t*) h;
190 // for now, lets just verify the exec-path is valid
192 //printf ( "exec is '%s'\n", p -> exec );
196 // even this is complicated by pnd_run.sh semantics .. can't check if it exists
197 // during discovery, since it is not mounted yet..
200 if ( stat ( p -> exec, &buf ) == 0 ) {
201 return ( 1 ); // path is present
208 signed char pnd_pxml_merge_override ( pnd_pxml_handle h, char *searchpath ) {
209 // the pxml includes a unique-id; use this value to attempt to find an
210 // override in the given searchpath
211 signed char retval = 0;
212 pnd_pxml_handle mergeh;
214 if ( ! pnd_pxml_get_unique_id ( h ) ) {
215 return ( -1 ); // no unique-id present, so can't use it to name potential override files
222 strncat ( buffer, "/", FILENAME_MAX );
223 strncat ( buffer, pnd_pxml_get_unique_id ( h ), FILENAME_MAX );
224 strncat ( buffer, ".xml", FILENAME_MAX );
225 //printf ( " Path to seek merges: '%s'\n", buffer );
227 mergeh = pnd_pxml_fetch ( buffer );
231 if ( pnd_pxml_get_app_name_en ( mergeh ) ) {
232 pnd_pxml_set_app_name ( h, pnd_pxml_get_app_name_en ( mergeh ) );
235 pnd_pxml_delete ( mergeh );
244 char *pnd_pxml_get_app_name_en ( pnd_pxml_handle h ) {
245 pnd_pxml_t *p = (pnd_pxml_t*) h;
246 return ( p -> title_en );
249 char *pnd_pxml_get_app_name_de ( pnd_pxml_handle h ) {
250 pnd_pxml_t *p = (pnd_pxml_t*) h;
251 return ( p -> title_de );
254 char *pnd_pxml_get_app_name_it ( pnd_pxml_handle h ) {
255 pnd_pxml_t *p = (pnd_pxml_t*) h;
256 return ( p -> title_it );
259 char *pnd_pxml_get_app_name_fr ( pnd_pxml_handle h ) {
260 pnd_pxml_t *p = (pnd_pxml_t*) h;
261 return ( p -> title_fr );
264 char *pnd_pxml_get_unique_id ( pnd_pxml_handle h ) {
265 pnd_pxml_t *p = (pnd_pxml_t*) h;
266 return ( p -> unique_id );
269 char *pnd_pxml_get_standalone ( pnd_pxml_handle h ) {
270 pnd_pxml_t *p = (pnd_pxml_t*) h;
271 return ( p -> standalone );
274 char *pnd_pxml_get_icon ( pnd_pxml_handle h ) {
275 pnd_pxml_t *p = (pnd_pxml_t*) h;
276 return ( p -> icon );
279 char *pnd_pxml_get_description_en ( pnd_pxml_handle h ) {
280 pnd_pxml_t *p = (pnd_pxml_t*) h;
281 return ( p -> description_en );
284 char *pnd_pxml_get_description_de ( pnd_pxml_handle h ) {
285 pnd_pxml_t *p = (pnd_pxml_t*) h;
286 return ( p -> description_de );
289 char *pnd_pxml_get_description_it ( pnd_pxml_handle h ) {
290 pnd_pxml_t *p = (pnd_pxml_t*) h;
291 return ( p -> description_it );
294 char *pnd_pxml_get_description_fr ( pnd_pxml_handle h ) {
295 pnd_pxml_t *p = (pnd_pxml_t*) h;
296 return ( p -> description_fr );
299 char *pnd_pxml_get_previewpic1 ( pnd_pxml_handle h ) {
300 pnd_pxml_t *p = (pnd_pxml_t*) h;
301 return ( p -> previewpic1 );
304 char *pnd_pxml_get_previewpic2 ( pnd_pxml_handle h ) {
305 pnd_pxml_t *p = (pnd_pxml_t*) h;
306 return ( p -> previewpic2 );
309 char *pnd_pxml_get_author_name ( pnd_pxml_handle h ) {
310 pnd_pxml_t *p = (pnd_pxml_t*) h;
311 return ( p -> author_name );
314 char *pnd_pxml_get_author_website ( pnd_pxml_handle h ) {
315 pnd_pxml_t *p = (pnd_pxml_t*) h;
316 return ( p -> author_website );
319 char *pnd_pxml_get_version_major ( pnd_pxml_handle h ) {
320 pnd_pxml_t *p = (pnd_pxml_t*) h;
321 return ( p -> version_major );
324 char *pnd_pxml_get_version_minor ( pnd_pxml_handle h ) {
325 pnd_pxml_t *p = (pnd_pxml_t*) h;
326 return ( p -> version_minor );
329 char *pnd_pxml_get_version_release ( pnd_pxml_handle h ) {
330 pnd_pxml_t *p = (pnd_pxml_t*) h;
331 return ( p -> version_release );
334 char *pnd_pxml_get_version_build ( pnd_pxml_handle h ) {
335 pnd_pxml_t *p = (pnd_pxml_t*) h;
336 return ( p -> version_build );
339 char *pnd_pxml_get_exec ( pnd_pxml_handle h ) {
340 pnd_pxml_t *p = (pnd_pxml_t*) h;
341 return ( p -> exec );
344 char *pnd_pxml_get_main_category ( pnd_pxml_handle h ) {
345 pnd_pxml_t *p = (pnd_pxml_t*) h;
346 return ( p -> main_category );
349 char *pnd_pxml_get_subcategory1 ( pnd_pxml_handle h ) {
350 pnd_pxml_t *p = (pnd_pxml_t*) h;
351 return ( p -> subcategory1 );
354 char *pnd_pxml_get_subcategory2 ( pnd_pxml_handle h ) {
355 pnd_pxml_t *p = (pnd_pxml_t*) h;
356 return ( p -> subcategory2 );
359 char *pnd_pxml_get_altcategory ( pnd_pxml_handle h ) {
360 pnd_pxml_t *p = (pnd_pxml_t*) h;
361 return ( p -> altcategory );
364 char *pnd_pxml_get_altsubcategory1 ( pnd_pxml_handle h ) {
365 pnd_pxml_t *p = (pnd_pxml_t*) h;
366 return ( p -> altsubcategory1 );
369 char *pnd_pxml_get_altsubcategory2 ( pnd_pxml_handle h ) {
370 pnd_pxml_t *p = (pnd_pxml_t*) h;
371 return ( p -> altsubcategory2 );
374 char *pnd_pxml_get_osversion_major ( pnd_pxml_handle h ) {
375 pnd_pxml_t *p = (pnd_pxml_t*) h;
376 return ( p -> osversion_major );
379 char *pnd_pxml_get_osversion_minor ( pnd_pxml_handle h ) {
380 pnd_pxml_t *p = (pnd_pxml_t*) h;
381 return ( p -> osversion_minor );
384 char *pnd_pxml_get_osversion_release ( pnd_pxml_handle h ) {
385 pnd_pxml_t *p = (pnd_pxml_t*) h;
386 return ( p -> osversion_release );
389 char *pnd_pxml_get_osversion_build ( pnd_pxml_handle h ) {
390 pnd_pxml_t *p = (pnd_pxml_t*) h;
391 return ( p -> osversion_build );
394 char *pnd_pxml_get_associationitem1_name ( pnd_pxml_handle h ) {
395 pnd_pxml_t *p = (pnd_pxml_t*) h;
396 return ( p -> associationitem1_name );
399 char *pnd_pxml_get_associationitem1_filetype ( pnd_pxml_handle h ) {
400 pnd_pxml_t *p = (pnd_pxml_t*) h;
401 return ( p -> associationitem1_filetype );
404 char *pnd_pxml_get_associationitem1_parameter ( pnd_pxml_handle h ) {
405 pnd_pxml_t *p = (pnd_pxml_t*) h;
406 return ( p -> associationitem1_parameter );
409 char *pnd_pxml_get_associationitem2_name ( pnd_pxml_handle h ) {
410 pnd_pxml_t *p = (pnd_pxml_t*) h;
411 return ( p -> associationitem2_name );
414 char *pnd_pxml_get_associationitem2_filetype ( pnd_pxml_handle h ) {
415 pnd_pxml_t *p = (pnd_pxml_t*) h;
416 return ( p -> associationitem2_filetype );
419 char *pnd_pxml_get_associationitem2_parameter ( pnd_pxml_handle h ) {
420 pnd_pxml_t *p = (pnd_pxml_t*) h;
421 return ( p -> associationitem2_parameter );
424 char *pnd_pxml_get_associationitem3_name ( pnd_pxml_handle h ) {
425 pnd_pxml_t *p = (pnd_pxml_t*) h;
426 return ( p -> associationitem3_name );
429 char *pnd_pxml_get_associationitem3_filetype ( pnd_pxml_handle h ) {
430 pnd_pxml_t *p = (pnd_pxml_t*) h;
431 return ( p -> associationitem3_filetype );
434 char *pnd_pxml_get_associationitem3_parameter ( pnd_pxml_handle h ) {
435 pnd_pxml_t *p = (pnd_pxml_t*) h;
436 return ( p -> associationitem3_parameter );
439 char *pnd_pxml_get_clockspeed ( pnd_pxml_handle h ) {
440 pnd_pxml_t *p = (pnd_pxml_t*) h;
441 return ( p -> clockspeed );
444 char *pnd_pxml_get_background ( pnd_pxml_handle h ) {
445 pnd_pxml_t *p = (pnd_pxml_t*) h;
446 return ( p -> background );
449 char *pnd_pxml_get_startdir ( pnd_pxml_handle h ) {
450 pnd_pxml_t *p = (pnd_pxml_t*) h;
451 return ( p -> startdir );