[Mplayer-cvslog] CVS: main subreader.c,1.8,1.9

GEREOFFY arpi_esp at users.sourceforge.net
Sun May 6 04:26:02 CEST 2001


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

Modified Files:
	subreader.c 
Log Message:
better .smi support and display two-byte characters- patch by Sunjin Yang

Index: subreader.c
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** subreader.c	2001/05/01 21:28:18	1.8
--- subreader.c	2001/05/06 02:26:00	1.9
***************
*** 10,13 ****
--- 10,14 ----
  #include <stdlib.h>
  #include <string.h>
+ #include <ctype.h>
  
  #include "subreader.h"
***************
*** 28,72 ****
  }
  
  
  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;
--- 29,104 ----
  }
  
+ static inline void trail_space(char *s) {
+ 	int i;
+ 	while (isspace(*s)) strcpy(s, s + 1);
+ 	i = strlen(s) - 1;
+ 	while (i > 0 && isspace(s[i])) s[i--] = '\0';
+ }
  
  subtitle *sub_read_line_sami(FILE *fd, subtitle *current) {
!     static char line[1001];
!     static char *s = NULL;
!     char text[1000], *p, *q;
!     int state;
! 
!     current->lines = current->start = current->end = 0;
!     state = 0;
! 
!     /* read the first line */
!     if (!s)
! 	    if (!(s = fgets(line, 1000, fd))) return 0;
  
      do {
! 	switch (state) {
  
! 	case 0: /* find "START=" */
! 	    s = strstr (s, "Start=");
! 	    if (s) {
! 		current->start = strtol (s + 6, &s, 0) / 10;
! 		state = 1; continue;
! 	    }
! 	    break;
!  
! 	case 1: /* find "<P" */
! 	    if ((s = strstr (s, "<P"))) { s += 2; state = 2; continue; }
! 	    break;
!  
! 	case 2: /* find ">" */
! 	    if ((s = strchr (s, '>'))) { s++; state = 3; p = text; continue; }
! 	    break;
!  
! 	case 3: /* get all text until '<' appears */
! 	    if (*s == '\0') { break; }
! 	    else if (*s == '<') { state = 4; }
! 	    else if (!strncasecmp (s, "&nbsp;", 6)) { *p++ = ' '; s += 6; }
! 	    else if (*s == '\r') { s++; }
! 	    else if (!strncasecmp (s, "<br>", 4) || *s == '\n') {
! 		*p = '\0'; p = text; trail_space (text);
! 		if (text[0] != '\0')
! 		    current->text[current->lines++] = strdup (text);
! 		if (*s == '\n') s++; else s += 4;
! 	    }
! 	    else *p++ = *s++;
  	    continue;
+ 
+ 	case 4: /* get current->end or skip <TAG> */
+ 	    q = strstr (s, "Start=");
+ 	    if (q) {
+ 		current->end = strtol (q + 6, &q, 0) / 10 - 1;
+ 		*p = '\0'; trail_space (text);
+ 		if (text[0] != '\0')
+ 		    current->text[current->lines++] = strdup (text);
+ 		if (current->lines > 0) { state = 99; break; }
+ 		state = 0; continue;
+ 	    }
+ 	    s = strchr (s, '>');
+ 	    if (s) { s++; state = 3; continue; }
+ 	    break;
  	}
! 
! 	/* read next line */
! 	if (state != 99 && !(s = fgets (line, 1000, fd))) return 0;
! 
!     } while (state != 99);
  
      return current;
***************
*** 201,205 ****
  		{sub_uses_time=1;return 2;}
  	if (strstr (line, "<SAMI>"))
! 		{sub_uses_time=0; return 3;}
      }
  
--- 233,237 ----
  		{sub_uses_time=1;return 2;}
  	if (strstr (line, "<SAMI>"))
! 		{sub_uses_time=1; return 3;}
      }
  
***************
*** 269,278 ****
   char * sub_tmp  = NULL;
   int    i;
! #define SUB_EXTS 4
   char * sub_exts[SUB_EXTS] = 
    { ".sub",
      ".SUB",
      ".srt",
!     ".SRT" };
   
   if ( fname == NULL ) return NULL;
--- 301,312 ----
   char * sub_tmp  = NULL;
   int    i;
! #define SUB_EXTS 6
   char * sub_exts[SUB_EXTS] = 
    { ".sub",
      ".SUB",
      ".srt",
!     ".SRT",
!     ".smi",
!     ".SMI"};
   
   if ( fname == NULL ) return NULL;
***************
*** 336,338 ****
      return 0;
  }
! #endif
\ No newline at end of file
--- 370,372 ----
      return 0;
  }
! #endif


_______________________________________________
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