diff options
author | arpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-05-27 20:59:58 +0000 |
---|---|---|
committer | arpi_esp <arpi_esp@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-05-27 20:59:58 +0000 |
commit | 7895a99e80db01f665bd8581833153872f9dcc99 (patch) | |
tree | 658a040c85de94e14c25b2a658c0928d095258ce | |
parent | b874045618e6ab4f0c8ad5fcbdd7eb1502141517 (diff) |
implemented ~/.mplayer/sub/filename.sub stuff
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@893 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | mplayer.c | 6 | ||||
-rw-r--r-- | subreader.c | 53 | ||||
-rw-r--r-- | subreader.h | 2 |
3 files changed, 33 insertions, 28 deletions
@@ -623,9 +623,9 @@ if(!parse_codec_cfg(get_path("codecs.conf"))){ if ( sub_auto ) { // auto load sub file ... - subtitles=sub_read_file( sub_filename( filename ) ); - if ( subtitles == NULL ) subtitles=sub_read_file(get_path("default.sub")); // try default: - } else subtitles=sub_read_file(get_path("default.sub")); // try default: + subtitles=sub_read_file( sub_filename( get_path("sub/"), filename ) ); + } + if ( subtitles == NULL ) subtitles=sub_read_file(get_path("default.sub")); // try default: } diff --git a/subreader.c b/subreader.c index 667eb2eeb3..e06e880a75 100644 --- a/subreader.c +++ b/subreader.c @@ -373,6 +373,7 @@ subtitle* sub_read_file (char *filename) { return first; } +#if 0 char * strreplace( char * in,char * what,char * whereof ) { int i; @@ -383,14 +384,16 @@ char * strreplace( char * in,char * what,char * whereof ) if ( strlen( what ) > strlen( whereof ) ) tmp[i]=0; return in; } +#endif -char * sub_filename( char * fname ) +char * sub_filename(char* path, char * fname ) { - char * sub_name = NULL; - char * sub_tmp = NULL; - int i; -#define SUB_EXTS 10 - char * sub_exts[SUB_EXTS] = + char * sub_name1; + char * sub_name2; + int i,j; + FILE * f; + int pos=0; + char * sub_exts[] = { ".sub", ".SUB", ".srt", @@ -401,29 +404,31 @@ char * sub_filename( char * fname ) ".RT", ".txt", ".TXT"}; - + if ( fname == NULL ) return NULL; - for( i=strlen( fname );i>0;i-- ) - if( fname[i] == '.' ) - { - sub_tmp=(char *)&fname[i]; - break; - } - if ( i == 0 ) return NULL; - sub_name=strdup( fname ); - for ( i=0;i<SUB_EXTS;i++ ) - { - FILE * f; - - strcpy( sub_name,fname ); - f=fopen( strreplace( sub_name,sub_tmp,sub_exts[i] ),"rt" ); - if ( f != NULL ) - { + + sub_name1=strrchr(fname,'.'); + if (!sub_name1) return NULL; + pos=sub_name1-fname; + + sub_name1=malloc(strlen(path)+strlen(fname)+8); + strcpy(sub_name1,path); + sub_name2=sub_name1+strlen(path); + strncpy(sub_name2,fname,pos); + + for(j=0;j<=1;j++){ + char* sub_name=j?sub_name1:sub_name2; + for ( i=0;i<(sizeof(sub_exts)/sizeof(char*));i++ ) { + strcpy(sub_name2+pos,sub_exts[i]); +// printf("trying: '%s'\n",sub_name); + if((f=fopen( sub_name,"rt" ))) { fclose( f ); printf( "SUB: Detected sub file: %s\n",sub_name ); return sub_name; - } + } } + } + return NULL; } diff --git a/subreader.h b/subreader.h index ca021ff338..565d9b2242 100644 --- a/subreader.h +++ b/subreader.h @@ -24,6 +24,6 @@ typedef struct { } subtitle; subtitle* sub_read_file (char *filename); -char * sub_filename( char * fname ); +char * sub_filename(char *path, char * fname ); #endif |