+ if( i_nb_subdirs > 0 )
+ {
+ char *psz_parser = NULL, *psz_temp = NULL;
+
+ subdirs = (char**)malloc( sizeof(char*) * ( i_nb_subdirs + 1 ) );
+ memset( subdirs, 0, sizeof(char*) * ( i_nb_subdirs + 1 ) );
+ i = 0;
+ psz_parser = psz_path;
+ while( psz_parser && *psz_parser )
+ {
+ char *psz_subdir;
+ psz_subdir = psz_parser;
+ psz_parser = strchr( psz_subdir, ',' );
+ if( psz_parser )
+ {
+ *psz_parser = '\0';
+ psz_parser++;
+ while( *psz_parser == ' ' )
+ {
+ psz_parser++;
+ }
+ }
+ if( strlen( psz_subdir ) > 0 )
+ {
+ psz_temp = (char *)malloc( strlen(psz_dir)
+ + strlen(psz_subdir) + 2 );
+ if( psz_temp )
+ {
+ sprintf( psz_temp, "%s%s%c",
+ psz_subdir[0] == '.' ? psz_dir : "",
+ psz_subdir,
+ psz_subdir[strlen(psz_subdir) - 1] ==
+ DIRECTORY_SEPARATOR ? '\0' : DIRECTORY_SEPARATOR );
+ subdirs[i] = psz_temp;
+ i++;
+ }
+ }
+ }
+ subdirs[i] = NULL;
+ }
+ else
+ {
+ subdirs = NULL;
+ }
+ return subdirs;
+}
+
+
+/**
+ * Detect subtitle files.
+ *
+ * When called this function will split up the psz_name string into a
+ * directory, filename and extension. It then opens the directory
+ * in which the file resides and tries to find possible matches of
+ * subtitles files.
+ *
+ * \ingroup Demux
+ * \param p_this the calling \ref input_thread_t
+ * \param psz_path a list of subdirectories (separated by a ',') to look in.
+ * \param psz_name the complete filename to base the search on.
+ * \return a NULL terminated array of filenames with detected possible subtitles.
+ * The array contains max MAX_SUBTITLE_FILES items and you need to free it after use.
+ */
+char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
+ char *psz_name )
+{
+ vlc_value_t fuzzy;
+ int j, i_result2, i_sub_count = 0, i_fname_len = 0;
+ char *f_dir = NULL, *f_fname = NULL, *f_fname_noext = NULL, *f_fname_trim = NULL;
+ char *tmp = NULL;
+
+ char **tmp_subdirs, **subdirs; /* list of subdirectories to look in */
+
+ subfn *result = NULL; /* unsorted results */
+ char **result2; /* sorted results */
+
+ char *psz_fname_original = strdup( psz_name );
+ char *psz_fname = psz_fname_original;
+
+ if( psz_fname == NULL ) return NULL;
+
+ if( !strncmp( psz_fname, "file://", 7 ) )
+ {
+ psz_fname += 7;
+ }