changeset 892:bad858a47870

implemented ~/.mplayer/sub/filename.sub stuff
author arpi_esp
date Sun, 27 May 2001 20:59:58 +0000
parents ceb1ae196e3a
children 2d6bfc0cdb84
files mplayer.c subreader.c subreader.h
diffstat 3 files changed, 33 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/mplayer.c	Sun May 27 20:18:52 2001 +0000
+++ b/mplayer.c	Sun May 27 20:59:58 2001 +0000
@@ -623,9 +623,9 @@
     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:
   }
 
 
--- a/subreader.c	Sun May 27 20:18:52 2001 +0000
+++ b/subreader.c	Sun May 27 20:59:58 2001 +0000
@@ -373,6 +373,7 @@
     return first;
 }
 
+#if 0
 char * strreplace( char * in,char * what,char * whereof )
 {
  int i;
@@ -383,14 +384,16 @@
  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 @@
     ".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;
 }
 
--- a/subreader.h	Sun May 27 20:18:52 2001 +0000
+++ b/subreader.h	Sun May 27 20:59:58 2001 +0000
@@ -24,6 +24,6 @@
 } subtitle;
 
 subtitle* sub_read_file (char *filename);
-char * sub_filename( char * fname );
+char * sub_filename(char *path, char * fname );
 
 #endif