* This file contains functions to dectect subtitle files.
*/
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
#include <vlc_input.h>
#include <vlc_charset.h>
# include <dirent.h>
#endif
-#ifdef HAVE_LIMITS_H
-# include <limits.h>
-#endif
+#include <limits.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
* The possible extensions for subtitle files we support
*/
static const char const sub_exts[][6] = {
+ "idx", "sub", "srt",
+ "ssa", "ass", "smi",
"utf", "utf8", "utf-8",
- "sub", "srt", "smi",
- "txt", "ssa", "idx",
-
- "cdg",
-
+ "txt", "rt", "aqt",
+ "usf", "jss", "cdg",
+ "psb", "mpsub","mpl2",
+ "pjs", "dks",
""
};
-/* extensions from unsupported types */
-/* rt, aqt, jss, js, ass */
-
static void strcpy_trim( char *d, const char *s )
{
/* skip leading whitespace */
if( *psz_subdir == '\0' )
continue;
- asprintf( &subdirs[i++], "%s%s%c",
+ 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 );
+ psz_subdir[strlen(psz_subdir) - 1] == DIR_SEP_CHAR ?
+ '\0' : DIR_SEP_CHAR ) == -1 )
+ break;
}
subdirs[i] = NULL;
char **subtitles_Detect( input_thread_t *p_this, char *psz_path,
const char *psz_name_org )
{
- vlc_value_t fuzzy;
+ int i_fuzzy;
int j, i_result2, i_sub_count, i_fname_len;
char *f_dir = NULL, *f_fname = NULL, *f_fname_noext = NULL, *f_fname_trim = NULL;
char *tmp = NULL;
}
else
{
-#ifdef HAVE_UNISTD_H
+#if defined (HAVE_UNISTD_H) && !defined (UNDER_CE)
/* Get the current working directory */
char *psz_cwd = getcwd( NULL, 0 );
#else
return NULL;
f_fname = strdup( psz_fname );
- asprintf( &f_dir, "%s%c", psz_cwd, DIR_SEP_CHAR );
+ if( asprintf( &f_dir, "%s%c", psz_cwd, DIR_SEP_CHAR ) == -1 )
+ f_dir = NULL; /* Assure that function will return in next test */
free( psz_cwd );
}
if( !f_fname || !f_dir )
strcpy_strip_ext( f_fname_noext, f_fname );
strcpy_trim( f_fname_trim, f_fname_noext );
- var_Get( p_this, "sub-autodetect-fuzzy", &fuzzy );
+ 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 );
int i_prio;
- if( psz_name == NULL )
+ if( psz_name == NULL || psz_name[0] == '.' )
continue;
/* retrieve various parts of the filename */
/* doesn't contain the movie name, prefer files in f_dir over subdirs */
i_prio = SUB_PRIORITY_MATCH_NONE;
}
- if( i_prio >= fuzzy.i_int )
+ if( i_prio >= i_fuzzy )
{
char psz_path[strlen( psz_dir ) + strlen( psz_name ) + 1];
struct stat st;
for( j = 0, i_result2 = 0; j < i_sub_count && result2 != NULL; j++ )
{
- vlc_bool_t b_reject = VLC_FALSE;
+ bool b_reject = false;
if( !result[j].psz_fname || !result[j].psz_ext ) /* memory out */
break;
break;
}
if( i < i_sub_count )
- b_reject = VLC_TRUE;
+ b_reject = true;
}
else if( !strcasecmp( result[j].psz_ext, "cdg" ) )
{
if( result[j].priority < SUB_PRIORITY_MATCH_ALL )
- b_reject = VLC_TRUE;
+ b_reject = true;
}
/* */