+
+//int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_pxml_handle h ) {
+int pnd_map_dotdesktop_categories ( pnd_conf_handle c, char *target_buffer, unsigned short int len, pnd_disco_t *d ) {
+ unsigned short int n = 0; // no. matches
+ char *t;
+ char *match;
+
+ // clear target so we can easily append
+ memset ( target_buffer, '\0', len );
+
+ /* attempt primary category chain
+ */
+ match = NULL;
+
+ if ( ( t = d -> main_category ) ) {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( ( ! match ) &&
+ ( t = d -> main_category1 ) )
+ {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( ( ! match ) &&
+ ( t = d -> main_category2 ) )
+ {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( match ) {
+ strncat ( target_buffer, match, len );
+ len -= strlen ( target_buffer );
+ n += 1;
+ }
+
+ /* attempt secondary category chain
+ */
+ match = NULL;
+
+ if ( ( t = d -> alt_category ) ) {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( ( ! match ) &&
+ ( t = d -> alt_category1 ) )
+ {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( ( ! match ) &&
+ ( t = d -> alt_category2 ) )
+ {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( match ) {
+ if ( target_buffer [ 0 ] != '\0' && len > 0 ) {
+ strcat ( target_buffer, ";" );
+ len -= 1;
+ }
+ strncat ( target_buffer, match, len );
+ len -= strlen ( target_buffer );
+ n += 1;
+ }
+
+#if 0 // doh, originally I was using pxml-t till I realized I pre-boned myself on that one
+ match = NULL;
+
+ if ( ( t = pnd_pxml_get_main_category ( h ) ) ) {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( ( ! match ) &&
+ ( t = pnd_pxml_get_subcategory1 ( h ) ) )
+ {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( ( ! match ) &&
+ ( t = pnd_pxml_get_subcategory2 ( h ) ) )
+ {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( match ) {
+ strncat ( target_buffer, match, len );
+ len -= strlen ( target_buffer );
+ n += 1;
+ }
+
+ /* attempt secondary category chain
+ */
+ match = NULL;
+
+ if ( ( t = pnd_pxml_get_altcategory ( h ) ) ) {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( ( ! match ) &&
+ ( t = pnd_pxml_get_altsubcategory1 ( h ) ) )
+ {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( ( ! match ) &&
+ ( t = pnd_pxml_get_altsubcategory2 ( h ) ) )
+ {
+ match = pnd_map_dotdesktop_category ( c, t );
+ }
+
+ if ( match ) {
+ if ( target_buffer [ 0 ] != '\0' && len > 0 ) {
+ strcat ( target_buffer, ";" );
+ len -= 1;
+ }
+ strncat ( target_buffer, match, len );
+ len -= strlen ( target_buffer );
+ n += 1;
+ }
+#endif
+
+ if ( n && len ) {
+ strcat ( target_buffer, ";" );
+ }
+
+ return ( n );
+}
+
+// given category 'foo', look it up in the provided config map. return the char* reference, or NULL
+char *pnd_map_dotdesktop_category ( pnd_conf_handle c, char *single_category ) {
+ char *key;
+
+ key = malloc ( strlen ( single_category ) + 4 + 1 );
+
+ sprintf ( key, "map.%s", single_category );
+
+ return ( pnd_conf_get_as_char ( c, key ) );
+}