[Mplayer-cvslog] CVS: main subreader.c,1.5,1.6 subreader.h,1.3,1.4

Megyer Laszlo laaz at users.sourceforge.net
Tue Apr 24 23:39:20 CEST 2001


Update of /cvsroot/mplayer/main
In directory usw-pr-cvs1:/tmp/cvs-serv4514

Modified Files:
	subreader.c subreader.h 
Log Message:
added support for SAMI subtitle support (.smi)


Index: subreader.c
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** subreader.c	2001/04/23 23:46:24	1.5
--- subreader.c	2001/04/24 21:39:18	1.6
***************
*** 18,24 ****
  int sub_uses_time=0;
  int sub_errs=0;
! int sub_num=0;         // number of subtitle structs
! int sub_format=-1;     // 0 for microdvd, 1 for SubRip, 2 for the third format
  
  
  char *sub_readtext(char *source, char **dest) {
--- 18,76 ----
  int sub_uses_time=0;
  int sub_errs=0;
! int sub_num=0;          // number of subtitle structs
! int sub_format=-1;     // 0 for microdvd
! 		      // 1 for SubRip
! 		     // 2 for the third format (what's this?)
! 		    // 3 for SAMI (smi)
  
+ int eol(char p) {
+     return (p=='\r' || p=='\n' || p=='\0');
+ }
+ 
+ 
+ subtitle *sub_read_line_sami(FILE *fd, subtitle *current) {
+     char line[1001];
+     int i;
+     char *s, *p;
+ 
+     current->start=0;
+     do {
+ 	if (! (fgets (line, 1000, fd)))  return 0;
+ 	s= strstr(line, "Start=");
+ 	if (s) {
+ 	    sscanf (s, "Start=%d", &current->start);
+ 	    if (strstr (s, "<P><br>"))  current->start=0;
+ 	}
+     } while ( !current->start );
+     
+     if (! (fgets (line, 1000, fd)))  return 0;
+     s=strstr (line, "<P>")+3;
+ 
+     i=0;
+     do {
+ 	for (p=s; !eol(*p) && strncmp(p,"<br>",4); p++);
+ 	if (p==s) {
+ 	    s+=4;
+ 	    continue;
+ 	}
+ 	current->text[i]=(char *)malloc(p-s+1);
+ 	strncpy (current->text[i], s, p-s);
+ 	current->text[i++][p-s]='\0';
+ 	if (!strncmp(p,"<br>",4)) s=p+4;
+ 	else s=p;
+     } while (!eol (*p));
+     
+     current->lines=i;
+ 
+     if (! (fgets (line, 1000, fd)))  return 0;
+     s= strstr(line, "Start=");
+     if (s) {
+         sscanf (s, "Start=%d", &current->end);
+         if (!strstr (s, "<P><br>"))  return ERR;
+     } else return ERR;
+ 
+     return current;
+ }
+ 
  
  char *sub_readtext(char *source, char **dest) {
***************
*** 40,45 ****
  }
  
- 
- 
  subtitle *sub_read_line_microdvd(FILE *fd,subtitle *current) {
      char line[1001];
--- 92,95 ----
***************
*** 139,149 ****
  //    char *p;
      
!     while (1) {
  	j++;
  	if (!fgets (line, 1000, fd))
  	    return -1;
  
! //	if (sscanf (line, "{%i}{%i}", &i, &i, p)==2) // ha valaki tudja miert 2, mondja mar el nekem ;)
! 	if (sscanf (line, "{%d}{%d}", &i, &i)==2) // ha valaki tudja miert 2, mondja mar el nekem ;)
  		{sub_uses_time=0;return 0;}
  	if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",     &i, &i, &i, &i, &i, &i, &i, &i)==8)
--- 189,198 ----
  //    char *p;
      
!     while (j < 100) {
  	j++;
  	if (!fgets (line, 1000, fd))
  	    return -1;
  
! 	if (sscanf (line, "{%d}{%d}", &i, &i)==2)
  		{sub_uses_time=0;return 0;}
  	if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",     &i, &i, &i, &i, &i, &i, &i, &i)==8)
***************
*** 151,156 ****
  	if (sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d", &i, &i, &i, &i, &i, &i, &i, &i)==8)
  		{sub_uses_time=1;return 2;}
! 	if (j>100) return -1;  // too many bad lines or bad coder
      }
  }
  
--- 200,208 ----
  	if (sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d", &i, &i, &i, &i, &i, &i, &i, &i)==8)
  		{sub_uses_time=1;return 2;}
! 	if (strstr (line, "<SAMI>"))
! 		{sub_uses_time=0; return 3;}
      }
+ 
+     return -1;  // too many bad lines
  }
  
***************
*** 160,168 ****
      int n_max;
      subtitle *first;
!     subtitle * (*func[3])(FILE *fd,subtitle *dest)=
      {
  	    sub_read_line_microdvd,
  	    sub_read_line_subrip,
! 	    sub_read_line_third
      };
  
--- 212,221 ----
      int n_max;
      subtitle *first;
!     subtitle * (*func[4])(FILE *fd,subtitle *dest)=
      {
  	    sub_read_line_microdvd,
  	    sub_read_line_subrip,
! 	    sub_read_line_third,
! 	    sub_read_line_sami
      };
  
***************
*** 171,175 ****
      sub_format=sub_autodetect (fd);
      if (sub_format==-1) {printf ("SUB: Could not determine file format\n");return NULL;}
!     printf ("SUB: Detected subtitle file format: %i\n",sub_format);
      
      rewind (fd);
--- 224,228 ----
      sub_format=sub_autodetect (fd);
      if (sub_format==-1) {printf ("SUB: Could not determine file format\n");return NULL;}
!     printf ("SUB: Detected subtitle file format: %d\n",sub_format);
      
      rewind (fd);
***************
*** 194,198 ****
  //    printf ("SUB: Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use");
      printf ("SUB: Read %i subtitles", sub_num);
!     if (sub_errs) printf (", %i error(s).\n", sub_errs);
      else 	  printf (".\n");
  
--- 247,251 ----
  //    printf ("SUB: Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use");
      printf ("SUB: Read %i subtitles", sub_num);
!     if (sub_errs) printf (", %i bad line(s).\n", sub_errs);
      else 	  printf (".\n");
  
***************
*** 248,252 ****
  }
  
- #if 0
  int main(int argc, char **argv) {  // for testing
  
--- 301,304 ----
***************
*** 260,264 ****
      }
      
!     subs=sub_get_subtitles(argv[1]);
      if(!subs){
          printf("Couldn't load file... let's write a bugreport :)\n");
--- 312,316 ----
      }
      
!     subs=sub_read_file(argv[1]);
      if(!subs){
          printf("Couldn't load file... let's write a bugreport :)\n");
***************
*** 283,285 ****
      return 0;
  }
- #endif
--- 335,336 ----

Index: subreader.h
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** subreader.h	2001/04/24 11:42:04	1.3
--- subreader.h	2001/04/24 21:39:18	1.4
***************
*** 6,10 ****
  extern int sub_errs;
  extern int sub_num;         // number of subtitle structs
! extern int sub_format;     // 0 for microdvd, 1 for SubRip, 2 for the third format
  
  #define SUB_MAX_TEXT 5
--- 6,13 ----
  extern int sub_errs;
  extern int sub_num;         // number of subtitle structs
! extern int sub_format;     // 0 for microdvd
! 			  // 1 for SubRip
! 			 // 2 for the third format
! 			// 3 for SAMI (smi)
  
  #define SUB_MAX_TEXT 5


_______________________________________________
Mplayer-cvslog mailing list
Mplayer-cvslog at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-cvslog



More information about the MPlayer-cvslog mailing list