]> git.sesse.net Git - vlc/blobdiff - src/input/subtitles.c
aout: remove legacy HAVE_FPU checks
[vlc] / src / input / subtitles.c
index 94231eaed0db0c5d990dd88842111bacb02c5ebb..61378d52d92aa46c92fd3e167163ef933cf980e0 100644 (file)
@@ -1,25 +1,25 @@
 /*****************************************************************************
  * subtitles.c : subtitles detection
  *****************************************************************************
- * Copyright (C) 2003-2009 the VideoLAN team
+ * Copyright (C) 2003-2009 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Derk-Jan Hartman <hartman at videolan.org>
  * This is adapted code from the GPL'ed MPlayer (http://mplayerhq.hu)
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
 /**
 # include "config.h"
 #endif
 
-#include <vlc_common.h>
-#include <vlc_fs.h>
-#include <vlc_url.h>
-
+#include <ctype.h> /* isalnum() */
 #ifdef HAVE_UNISTD_H
 #   include <unistd.h>
 #endif
-
 #include <sys/stat.h>
 
-#include <ctype.h> /* isalnum */
+#include <vlc_common.h>
+#include <vlc_fs.h>
+#include <vlc_url.h>
 
 #include "input_internal.h"
 
@@ -60,28 +58,30 @@ static const char const sub_exts[][6] = {
     "rt",   "aqt", "txt",
     "usf", "jss",  "cdg",
     "psb", "mpsub","mpl2",
-    "pjs", "dks",
+    "pjs", "dks", "stl",
     ""
 };
 
 static void strcpy_trim( char *d, const char *s )
 {
+    unsigned char c;
+
     /* skip leading whitespace */
-    while( *s && !isalnum(*s) )
+    while( ((c = *s) != '\0') && !isalnum(c) )
     {
         s++;
     }
     for(;;)
     {
         /* copy word */
-        while( *s && isalnum(*s) )
+        while( ((c = *s) != '\0') && isalnum(c) )
         {
-            *d = tolower(*s);
+            *d = tolower(c);
             s++; d++;
         }
         if( *s == 0 ) break;
         /* trim excess whitespace */
-        while( *s && !isalnum(*s) )
+        while( ((c = *s) != '\0') && !isalnum(c) )
         {
             s++;
         }
@@ -93,6 +93,8 @@ static void strcpy_trim( char *d, const char *s )
 
 static void strcpy_strip_ext( char *d, const char *s )
 {
+    unsigned char c;
+
     const char *tmp = strrchr(s, '.');
     if( !tmp )
     {
@@ -101,9 +103,9 @@ static void strcpy_strip_ext( char *d, const char *s )
     }
     else
         strlcpy(d, s, tmp - s + 1 );
-    while( *d )
+    while( (c = *d) != '\0' )
     {
-        *d = tolower(*d);
+        *d = tolower(c);
         d++;
     }
 }
@@ -119,9 +121,11 @@ static void strcpy_get_ext( char *d, const char *s )
 
 static int whiteonly( const char *s )
 {
-    while( *s )
+    unsigned char c;
+
+    while( (c = *s) != '\0' )
     {
-        if( isalnum( *s ) )
+        if( isalnum( c ) )
             return 0;
         s++;
     }
@@ -243,7 +247,9 @@ static char **paths_to_list( const char *psz_dir, char *psz_path )
 char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                          const char *psz_name_org )
 {
-    int i_fuzzy;
+    int i_fuzzy = var_GetInteger( p_this, "sub-autodetect-fuzzy" );
+    if ( i_fuzzy == 0 )
+        return NULL;
     int j, i_result2, i_sub_count, i_fname_len;
     char *f_fname_noext = NULL, *f_fname_trim = NULL;
 
@@ -267,14 +273,15 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
         return NULL;
     }
 
-    char *f_fname = strrchr( f_dir, DIR_SEP_CHAR );
+    const char *f_fname = strrchr( psz_fname, DIR_SEP_CHAR );
     if( !f_fname )
     {
         free( f_dir );
         free( psz_fname );
         return NULL;
     }
-    *(f_fname++) = 0; /* skip dir separator */
+    f_fname++; /* Skip the '/' */
+    f_dir[f_fname - psz_fname] = 0; /* keep dir separator in f_dir */
 
     i_fname_len = strlen( f_fname );
 
@@ -292,8 +299,6 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
     strcpy_strip_ext( f_fname_noext, f_fname );
     strcpy_trim( f_fname_trim, f_fname_noext );
 
-    i_fuzzy = var_GetInteger( p_this, "sub-autodetect-fuzzy" );
-
     result = calloc( MAX_SUBTITLE_FILES+1, sizeof(vlc_subfn_t) ); /* We check it later (simplify code) */
     subdirs = paths_to_list( f_dir, psz_path );
     for( j = -1, i_sub_count = 0; (j == -1) || ( j >= 0 && subdirs != NULL && subdirs[j] != NULL ); j++ )
@@ -321,23 +326,20 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
             char tmp_fname_noext[strlen( psz_name ) + 1];
             char tmp_fname_trim[strlen( psz_name ) + 1];
             char tmp_fname_ext[strlen( psz_name ) + 1];
-            char *tmp;
-
-            int i_prio;
+            const char *tmp;
+            int i_prio = SUB_PRIORITY_NONE;
 
             /* retrieve various parts of the filename */
             strcpy_strip_ext( tmp_fname_noext, psz_name );
             strcpy_get_ext( tmp_fname_ext, psz_name );
             strcpy_trim( tmp_fname_trim, tmp_fname_noext );
 
-            i_prio = SUB_PRIORITY_NONE;
-            if( i_prio == SUB_PRIORITY_NONE && !strcmp( tmp_fname_trim, f_fname_trim ) )
+            if( !strcmp( tmp_fname_trim, f_fname_trim ) )
             {
                 /* matches the movie name exactly */
                 i_prio = SUB_PRIORITY_MATCH_ALL;
             }
-            if( i_prio == SUB_PRIORITY_NONE &&
-                ( tmp = strstr( tmp_fname_trim, f_fname_trim ) ) )
+            else if( (tmp = strstr( tmp_fname_trim, f_fname_trim )) )
             {
                 /* contains the movie name */
                 tmp += strlen( f_fname_trim );
@@ -353,8 +355,7 @@ char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
                     i_prio = SUB_PRIORITY_MATCH_LEFT;
                 }
             }
-            if( i_prio == SUB_PRIORITY_NONE &&
-                j == 0 )
+            else if( j == -1 )
             {
                 /* doesn't contain the movie name, prefer files in f_dir over subdirs */
                 i_prio = SUB_PRIORITY_MATCH_NONE;