X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpnd_pxml.c;h=4b743d437ec669c27a27e1e3cbdd1532e402a7a2;hb=b2aaaf39eef7bcc2bfa000fbdb9f72e6d0f656c8;hp=02d08410047d97673af040a633cc9dd81c061d1c;hpb=fb01d515a1d360db44093cdb870d37a07b3e2309;p=pandora-libraries.git diff --git a/lib/pnd_pxml.c b/lib/pnd_pxml.c index 02d0841..4b743d4 100644 --- a/lib/pnd_pxml.c +++ b/lib/pnd_pxml.c @@ -10,31 +10,49 @@ #include "pnd_pxml.h" #include "pnd_pathiter.h" #include "pnd_tinyxml.h" +#include "pnd_logger.h" -pnd_pxml_handle pnd_pxml_fetch ( char *fullpath ) { +pnd_pxml_handle *pnd_pxml_fetch ( char *fullpath ) { + FILE *f; + char *b; + unsigned int len; - pnd_pxml_t *p = malloc ( sizeof(pnd_pxml_t) ); + f = fopen ( fullpath, "r" ); - memset ( p, '\0', sizeof(pnd_pxml_t) ); + if ( ! f ) { + return ( 0 ); + } + + fseek ( f, 0, SEEK_END ); + + len = ftell ( f ); - if ( ! pnd_pxml_load ( fullpath, p ) ) { + fseek ( f, 0, SEEK_SET ); + + b = (char*) malloc ( len ); + + if ( ! b ) { + fclose ( f ); return ( 0 ); } - return ( p ); -} + fread ( b, 1, len, f ); -pnd_pxml_handle pnd_pxml_fetch_buffer ( char *filename, char *buffer ) { + fclose ( f ); - pnd_pxml_t *p = malloc ( sizeof(pnd_pxml_t) ); + return ( pnd_pxml_fetch_buffer ( fullpath, b ) ); +} + +pnd_pxml_handle *pnd_pxml_fetch_buffer ( char *filename, char *buffer ) { - memset ( p, '\0', sizeof(pnd_pxml_t) ); + pnd_pxml_t **p = malloc ( sizeof(pnd_pxml_t*) * PXML_MAXAPPS ); + memset ( p, '\0', sizeof(pnd_pxml_t*) * PXML_MAXAPPS ); if ( ! pnd_pxml_parse ( filename, buffer, strlen ( buffer ), p ) ) { return ( 0 ); } - return ( p ); + return ( (pnd_pxml_handle*) p ); } void pnd_pxml_delete ( pnd_pxml_handle h ) { @@ -158,6 +176,9 @@ void pnd_pxml_delete ( pnd_pxml_handle h ) { if ( p -> startdir ) { free ( p -> startdir ); } + if ( p -> appdata_dirname ) { + free ( p -> appdata_dirname ); + } free(p); /*very important!*/ @@ -226,6 +247,8 @@ signed char pnd_pxml_merge_override ( pnd_pxml_handle h, char *searchpath ) { // the pxml includes a unique-id; use this value to attempt to find an // override in the given searchpath signed char retval = 0; + +#if 0 // TODO: Unfinished entirely now pnd_pxml_handle mergeh; if ( ! pnd_pxml_get_unique_id ( h ) ) { @@ -241,10 +264,12 @@ signed char pnd_pxml_merge_override ( pnd_pxml_handle h, char *searchpath ) { strncat ( buffer, ".xml", FILENAME_MAX ); //printf ( " Path to seek merges: '%s'\n", buffer ); + // TODO: handle multiple subapps! mergeh = pnd_pxml_fetch ( buffer ); if ( mergeh ) { + // TODO: handle all the various data bits if ( pnd_pxml_get_app_name_en ( mergeh ) ) { pnd_pxml_set_app_name ( h, pnd_pxml_get_app_name_en ( mergeh ) ); } @@ -254,6 +279,7 @@ signed char pnd_pxml_merge_override ( pnd_pxml_handle h, char *searchpath ) { } SEARCHPATH_POST +#endif return ( retval ); } @@ -261,12 +287,17 @@ signed char pnd_pxml_merge_override ( pnd_pxml_handle h, char *searchpath ) { char *pnd_pxml_get_best_localized_string(pnd_localized_string_t strings[], int strings_c, char *iso_lang) { int i; - int similarity_weight = 0xff; /*Set to something Really Bad in the beginning*/ + int similarity_weight = 0xffff; /*Set to something Really Bad in the beginning*/ char *best_match = NULL; for(i = 0; i < strings_c; i++) { - int new_weight = abs(strcmp(strings[i].language, iso_lang)); + // factor in the length -- if we're given 'en' and have a string 'en_US', thats better than 'de_something'; if we don't + // use length, then en_US and de_FO are same to 'en'. + int maxcount = strlen ( strings[i].language ) < strlen ( iso_lang ) ? strlen ( strings[i].language ) : strlen ( iso_lang ); + int new_weight = abs(strncmp(strings[i].language, iso_lang, maxcount)); + //pnd_log ( PND_LOG_DEFAULT, "looking for lang %s, looking at lang %s (weight %d, old %d): %s\n", + // iso_lang, strings [ i ].language, new_weight, similarity_weight, strings [ i ].string ); if (new_weight < similarity_weight) { similarity_weight = new_weight; @@ -275,12 +306,20 @@ char *pnd_pxml_get_best_localized_string(pnd_localized_string_t strings[], int s } if ( best_match ) { + //pnd_log ( PND_LOG_DEFAULT, "best match: %s\n", best_match ); return strdup(best_match); } + //pnd_log ( PND_LOG_DEFAULT, "best match: FAIL\n" ); + return ( NULL ); } +char *pnd_pxml_get_package_id ( pnd_pxml_handle h ) { + pnd_pxml_t *p = (pnd_pxml_t*) h; + return ( p -> package_id ); +} + char *pnd_pxml_get_app_name ( pnd_pxml_handle h, char *iso_lang ) { pnd_pxml_t *p = (pnd_pxml_t *) h; return pnd_pxml_get_best_localized_string(p->titles, p->titles_c, iso_lang); @@ -301,12 +340,16 @@ char *pnd_pxml_get_app_name_it ( pnd_pxml_handle h ) { char *pnd_pxml_get_app_name_fr ( pnd_pxml_handle h ) { return pnd_pxml_get_app_name(h, "fr"); } - char *pnd_pxml_get_unique_id ( pnd_pxml_handle h ) { pnd_pxml_t *p = (pnd_pxml_t*) h; return ( p -> unique_id ); } +char *pnd_pxml_get_appdata_dirname ( pnd_pxml_handle h ) { + pnd_pxml_t *p = (pnd_pxml_t*) h; + return ( p -> appdata_dirname ); +} + char *pnd_pxml_get_standalone ( pnd_pxml_handle h ) { pnd_pxml_t *p = (pnd_pxml_t*) h; return ( p -> standalone ); @@ -317,6 +360,10 @@ char *pnd_pxml_get_icon ( pnd_pxml_handle h ) { return ( p -> icon ); } +// this guy's func name is 'out of sync' with the family of functions below; but since it +// exists, rather than just remove it and break someones code, will add in the appropriate +// function wrapper; the header only specifies the other guy (always did), so the header +// was already on the right path. char *pnd_pxml_get_app_description ( pnd_pxml_handle h, char *iso_lang ) { pnd_pxml_t *p = (pnd_pxml_t *) h; return pnd_pxml_get_best_localized_string(p->descriptions, p->descriptions_c, iso_lang); @@ -338,6 +385,11 @@ char *pnd_pxml_get_description_fr ( pnd_pxml_handle h ) { return pnd_pxml_get_app_description(h, "fr"); } +// wrapper added so family of function names is consistent; see comment for pnd_pxml_get_app_description() above +char *pnd_pxml_get_description ( pnd_pxml_handle h, char *iso_lang) { + return ( pnd_pxml_get_app_description ( h, iso_lang ) ); +} + char *pnd_pxml_get_previewpic1 ( pnd_pxml_handle h ) { pnd_pxml_t *p = (pnd_pxml_t*) h; return ( p -> previewpic1 ); @@ -383,6 +435,11 @@ char *pnd_pxml_get_exec ( pnd_pxml_handle h ) { return ( p -> exec ); } +char *pnd_pxml_get_execargs ( pnd_pxml_handle h ) { + pnd_pxml_t *p = (pnd_pxml_t*) h; + return ( p -> execargs ); +} + char *pnd_pxml_get_exec_option_no_x11 ( pnd_pxml_handle h ) { pnd_pxml_t *p = (pnd_pxml_t*) h; return ( p -> exec_no_x11 ); @@ -502,3 +559,49 @@ char *pnd_pxml_get_mkdir ( pnd_pxml_handle h ) { pnd_pxml_t *p = (pnd_pxml_t*) h; return ( p -> mkdir_sp ); } + +unsigned char pnd_pxml_is_affirmative ( char *v ) { + + if ( ! v ) { + return ( 0 ); + } + + if ( ( v [ 0 ] == 'Y' ) || + ( v [ 0 ] == 'y' ) || + ( v [ 0 ] == '1' ) ) + { + return ( 0 ); + } + + return ( 0 ); +} + +pnd_pxml_x11_req_e pnd_pxml_get_x11 ( char *pxmlvalue ) { + + if ( ! pxmlvalue ) { + return ( pnd_pxml_x11_ignored ); + } else if ( strcasecmp ( pxmlvalue, "req" ) == 0 ) { + return ( pnd_pxml_x11_required ); + } else if ( strcasecmp ( pxmlvalue, "stop" ) == 0 ) { + return ( pnd_pxml_x11_stop ); + } else if ( strcasecmp ( pxmlvalue, "ignore" ) == 0 ) { + return ( pnd_pxml_x11_ignored ); + } + + return ( pnd_pxml_x11_ignored ); // default +} + +char *pnd_pxml_get_info_name ( pnd_pxml_handle h ) { + pnd_pxml_t *p = (pnd_pxml_t*) h; + return ( p -> info_name ); +} + +char *pnd_pxml_get_info_type ( pnd_pxml_handle h ) { + pnd_pxml_t *p = (pnd_pxml_t*) h; + return ( p -> info_type ); +} + +char *pnd_pxml_get_info_src ( pnd_pxml_handle h ) { + pnd_pxml_t *p = (pnd_pxml_t*) h; + return ( p -> info_filename ); +}