Mercurial > mplayer.hg
comparison subreader.c @ 509:1b2cd175236f
add sub autodetect
author | pontscho |
---|---|
date | Wed, 18 Apr 2001 20:25:04 +0000 |
parents | 7d544020e398 |
children | abd7391a31e3 |
comparison
equal
deleted
inserted
replaced
508:05da4b0e3bb8 | 509:1b2cd175236f |
---|---|
197 else printf (".\n"); | 197 else printf (".\n"); |
198 | 198 |
199 return first; | 199 return first; |
200 } | 200 } |
201 | 201 |
202 char * strreplace( char * in,char * what,char * whereof ) | |
203 { | |
204 int i; | |
205 char * tmp; | |
206 | |
207 if ( ( in == NULL )||( what == NULL )||( whereof == NULL )||( ( tmp=strstr( in,what ) ) == NULL ) ) return NULL; | |
208 for( i=0;i<strlen( whereof );i++ ) tmp[i]=whereof[i]; | |
209 if ( strlen( what ) > strlen( whereof ) ) tmp[i]=0; | |
210 return in; | |
211 } | |
212 | |
213 char * sub_filename( char * fname ) | |
214 { | |
215 char * sub_name = NULL; | |
216 char * sub_tmp = NULL; | |
217 int i; | |
218 #define SUB_EXTS 4 | |
219 char * sub_exts[SUB_EXTS] = | |
220 { ".sub", | |
221 ".SUB", | |
222 ".srt", | |
223 ".SRT" }; | |
224 | |
225 if ( fname == NULL ) return NULL; | |
226 for( i=strlen( fname );i>0;i-- ) | |
227 if( fname[i] == '.' ) | |
228 { | |
229 sub_tmp=(char *)&fname[i]; | |
230 break; | |
231 } | |
232 if ( i == 0 ) return NULL; | |
233 sub_name=strdup( fname ); | |
234 for ( i=0;i<SUB_EXTS;i++ ) | |
235 { | |
236 FILE * f; | |
237 | |
238 strcpy( sub_name,fname ); | |
239 f=fopen( strreplace( sub_name,sub_tmp,sub_exts[i] ),"rt" ); | |
240 if ( f != NULL ) | |
241 { | |
242 fclose( f ); | |
243 printf( "SUB: Detected sub file: %s\n",sub_name ); | |
244 return sub_name; | |
245 } | |
246 } | |
247 return NULL; | |
248 } | |
249 | |
202 #if 0 | 250 #if 0 |
203 int main(int argc, char **argv) { // for testing | 251 int main(int argc, char **argv) { // for testing |
204 | 252 |
205 int i,j; | 253 int i,j; |
206 subtitle *subs; | 254 subtitle *subs; |