diff options
author | pontscho <pontscho@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-04-18 20:25:04 +0000 |
---|---|---|
committer | pontscho <pontscho@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2001-04-18 20:25:04 +0000 |
commit | 7eef93819f9d3f96c8d016e45aba0a5eccdb0d35 (patch) | |
tree | f28a48d241aefe0ec55dbede841717ed2228f25c | |
parent | 254f29dc0f56b98931e18c603f4e031fccd028c9 (diff) | |
download | mpv-7eef93819f9d3f96c8d016e45aba0a5eccdb0d35.tar.bz2 mpv-7eef93819f9d3f96c8d016e45aba0a5eccdb0d35.tar.xz |
add sub autodetect
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@510 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | subreader.c | 48 | ||||
-rw-r--r-- | subreader.h | 1 |
2 files changed, 49 insertions, 0 deletions
diff --git a/subreader.c b/subreader.c index 48da79e200..b42f60605f 100644 --- a/subreader.c +++ b/subreader.c @@ -199,6 +199,54 @@ subtitle* sub_read_file (char *filename) { return first; } +char * strreplace( char * in,char * what,char * whereof ) +{ + int i; + char * tmp; + + if ( ( in == NULL )||( what == NULL )||( whereof == NULL )||( ( tmp=strstr( in,what ) ) == NULL ) ) return NULL; + for( i=0;i<strlen( whereof );i++ ) tmp[i]=whereof[i]; + if ( strlen( what ) > strlen( whereof ) ) tmp[i]=0; + return in; +} + +char * sub_filename( char * fname ) +{ + char * sub_name = NULL; + char * sub_tmp = NULL; + int i; +#define SUB_EXTS 4 + char * sub_exts[SUB_EXTS] = + { ".sub", + ".SUB", + ".srt", + ".SRT" }; + + 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 ) + { + fclose( f ); + printf( "SUB: Detected sub file: %s\n",sub_name ); + return sub_name; + } + } + return NULL; +} + #if 0 int main(int argc, char **argv) { // for testing diff --git a/subreader.h b/subreader.h index 41fbec278b..f83a053f33 100644 --- a/subreader.h +++ b/subreader.h @@ -17,3 +17,4 @@ typedef struct { } subtitle; subtitle* sub_read_file (char *filename); +char * sub_filename( char * fname ); |