- /* variables to be used for derivatives of psz_fname */
- char *f_dir, *f_fname, *f_fname_noext, *f_fname_trim, *tmp;
- /* variables to be used for derivatives FILE *f */
- char *tmp_fname_noext, *tmp_fname_trim, *tmp_fname_ext, *tmpresult;
-
- int len, i, j, i_sub_count, i_sub_match_fuzziness;
- subfn *result; /* unsorted results */
- char **result2; /* sorted results */
-
- FILE *f;
- DIR *d;
- struct dirent *de;
+ const char *tmp = strrchr( psz_dir_content, '.');
+
+ if( !tmp )
+ return 0;
+ tmp++;
+
+ for( int i = 0; sub_exts[i][0]; i++ )
+ if( strcasecmp( sub_exts[i], tmp ) == 0 )
+ return 1;
+ return 0;
+}
+
+
+/**
+ * Convert a list of paths separated by ',' to a char**
+ */
+static char **paths_to_list( const char *psz_dir, char *psz_path )
+{
+ unsigned int i, k, i_nb_subdirs;
+ char **subdirs; /* list of subdirectories to look in */
+ char *psz_parser = psz_path;
+
+ if( !psz_dir || !psz_path )
+ return NULL;
+
+ for( k = 0, i_nb_subdirs = 1; psz_path[k] != '\0'; k++ )
+ {
+ if( psz_path[k] == ',' )
+ i_nb_subdirs++;
+ }
+
+ subdirs = calloc( i_nb_subdirs + 1, sizeof(char*) );
+ if( !subdirs )
+ return NULL;
+
+ for( i = 0; psz_parser && *psz_parser != '\0' ; )
+ {
+ char *psz_subdir = psz_parser;
+ psz_parser = strchr( psz_subdir, ',' );
+ if( psz_parser )
+ {
+ *psz_parser++ = '\0';
+ while( *psz_parser == ' ' )
+ psz_parser++;
+ }
+ if( *psz_subdir == '\0' )
+ continue;
+
+ if( asprintf( &subdirs[i++], "%s%s%c",
+ psz_subdir[0] == '.' ? psz_dir : "",
+ psz_subdir,
+ psz_subdir[strlen(psz_subdir) - 1] == DIR_SEP_CHAR ?
+ '\0' : DIR_SEP_CHAR ) == -1 )
+ break;
+ }
+ subdirs[i] = NULL;
+
+ return subdirs;
+}