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 );
54 if ( p -> main_category ) {
55 free ( p -> main_category );
57 if ( p -> unique_id ) {
58 free ( p -> unique_id );
60 if ( p -> clockspeed ) {
61 free ( p -> clockspeed );
67 char *pnd_pxml_get_app_name ( pnd_pxml_handle h ) {
68 pnd_pxml_t *p = (pnd_pxml_t*) h;
69 return ( p -> title_en );
72 char *pnd_pxml_get_icon_path ( pnd_pxml_handle h ) {
73 pnd_pxml_t *p = (pnd_pxml_t*) h;
77 char *pnd_pxml_get_clockspeed ( pnd_pxml_handle h ) {
78 pnd_pxml_t *p = (pnd_pxml_t*) h;
79 return ( p -> clockspeed );
82 void pnd_pxml_set_app_name ( pnd_pxml_handle h, char *v ) {
83 pnd_pxml_t *p = (pnd_pxml_t*) h;
84 if ( p -> title_en ) {
85 free ( p -> title_en );
90 p -> title_en = strdup ( v );
96 char *pnd_pxml_get_unique_id ( pnd_pxml_handle h ) {
97 pnd_pxml_t *p = (pnd_pxml_t*) h;
98 return ( p -> unique_id );
101 char *pnd_pxml_get_primary_category ( pnd_pxml_handle h ) {
102 pnd_pxml_t *p = (pnd_pxml_t*) h;
103 return ( p -> main_category );
106 char *pnd_pxml_get_exec_path ( pnd_pxml_handle h ) {
107 pnd_pxml_t *p = (pnd_pxml_t*) h;
108 return ( p -> exec );
111 unsigned char pnd_is_pxml_valid_app ( pnd_pxml_handle h ) {
112 pnd_pxml_t *p = (pnd_pxml_t*) h;
114 // for now, lets just verify the exec-path is valid
115 //printf ( "exec is '%s'\n", p -> exec );
118 if ( stat ( p -> exec, &buf ) == 0 ) {
119 return ( 1 ); // path is present
125 signed char pnd_pxml_merge_override ( pnd_pxml_handle h, char *searchpath ) {
126 // the pxml includes a unique-id; use this value to attempt to find an
127 // override in the given searchpath
128 signed char retval = 0;
129 pnd_pxml_handle mergeh;
135 strncat ( buffer, "/", FILENAME_MAX );
136 strncat ( buffer, pnd_pxml_get_unique_id ( h ), FILENAME_MAX );
137 strncat ( buffer, ".xml", FILENAME_MAX );
138 //printf ( " Path to seek merges: '%s'\n", buffer );
140 mergeh = pnd_pxml_fetch ( buffer );
144 if ( pnd_pxml_get_app_name ( mergeh ) ) {
145 pnd_pxml_set_app_name ( h, pnd_pxml_get_app_name ( mergeh ) );
148 pnd_pxml_delete ( mergeh );