]> git.sesse.net Git - vlc/commitdiff
* If input file in current dir specified, then retrieve CWD when we try to look for...
authorDerk-Jan Hartman <hartman@videolan.org>
Wed, 1 Feb 2006 20:51:18 +0000 (20:51 +0000)
committerDerk-Jan Hartman <hartman@videolan.org>
Wed, 1 Feb 2006 20:51:18 +0000 (20:51 +0000)
* When probing the autodetected files, probe them in the Locale, not in UTF-8. refs #528

src/input/subtitles.c

index 46e7326916ea0c85837bd5bb77a923cc47e9d29a..875fa7429e99440007f20c3d92397e40e20be382 100644 (file)
 #   include <limits.h>  
 #endif
 
+#ifdef HAVE_UNISTD_H
+#   include <unistd.h>
+#endif
+
 #include <ctype.h>
 
 /**
@@ -314,10 +318,16 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     }
     else
     {
-        /* FIXME: we should check the CWD here */
-        /* f_fname = strdup( psz_fname ); */
-        if( psz_fname_original ) free( psz_fname_original );
-        return NULL;
+        /* Get the current working directory */
+#ifdef HAVE_UNISTD_H
+        f_dir = getcwd( NULL, 0 );
+#endif
+        if( f_dir == NULL )
+        {
+            if( psz_fname_original ) free( psz_fname_original );
+            return NULL;
+        }
+        f_fname = strdup( psz_fname );
     }
 
     i_fname_len = strlen( f_fname );
@@ -396,27 +406,35 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                 if( i_prio >= fuzzy.i_int )
                 {
                     FILE *f;
-                    char *tmpresult;
+                    char *psz_UTF8_path;
+                    char *psz_locale_path;
 
-                    asprintf( &tmpresult, "%s%s", j < 0 ? f_dir : *subdirs, p_fixed_name );
+                    asprintf( &psz_UTF8_path, "%s%s", j < 0 ? f_dir : *subdirs, p_fixed_name );
+                    psz_locale_path = ToLocale( psz_UTF8_path );
                     msg_Dbg( p_this, "autodetected subtitle: %s with priority %d", p_fixed_name, i_prio );
-                    if( ( f = fopen( tmpresult, "rt" ) ) )
+                    if( ( f = fopen( psz_locale_path, "rt" ) ) )
                     {
                         fclose( f );
+                        LocaleFree( psz_locale_path );
                         result[i_sub_count].priority = i_prio;
-                        result[i_sub_count].psz_fname = tmpresult;
+                        result[i_sub_count].psz_fname = psz_UTF8_path;
                         result[i_sub_count].psz_ext = strdup(tmp_fname_ext);
                         i_sub_count++;
-                    } else free( tmpresult );
+                    }
+                    else
+                    {
+                        if( psz_UTF8_path ) free( psz_UTF8_path );
+                        LocaleFree( psz_locale_path );
+                    }
                 }
                 if( i_sub_count >= MAX_SUBTITLE_FILES ) break;
-                free( p_fixed_name );
+                if( p_fixed_name ) free( p_fixed_name );
             }
             for( a = 0; a < i_dir_content; a++ )
                 if( pp_dir_content[a] ) free( pp_dir_content[a] );
             if( pp_dir_content ) free( pp_dir_content );
         }
-        if( j >= 0 ) free( *subdirs++ );
+        if( j >= 0 ) if( *subdirs ) free( *subdirs++ );
     }
 
     if( tmp_subdirs )   free( tmp_subdirs );