[Mplayer-cvslog] CVS: main subreader.c,1.91,1.92

Arpi of Ize arpi at mplayerhq.hu
Sun Jan 19 01:54:58 CET 2003


Update of /cvsroot/mplayer/main
In directory mail:/var/tmp.root/cvs-serv8468

Modified Files:
	subreader.c 
Log Message:
1) Removed the code to remove {} from sub_read_line_ssa
2) Put this code in a separated function: sub_pp_ssa
3) After recoding added a call to sub_pp_ssa. To be more acqurate: I
added a pointer to function to hold a postprocessing function to be
invoked after using iconv. There are one pointer for each format, if
this pointer isn.t NULL the post processing function is called.
patch by Salvador Eduardo Tropea <salvador at inti.gov.ar>
help by <hephooey at fastmail.fm>


Index: subreader.c
===================================================================
RCS file: /cvsroot/mplayer/main/subreader.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -u -r1.91 -r1.92
--- subreader.c	13 Jan 2003 10:07:38 -0000	1.91
+++ subreader.c	19 Jan 2003 00:54:55 -0000	1.92
@@ -425,7 +425,7 @@
 	
 	char line[LINE_LEN+1],
 	     line3[LINE_LEN+1],
-	     *line2,*so,*de;
+	     *line2;
 	char *tmp;
 
 	do {
@@ -450,19 +450,6 @@
         if(comma < max_comma)max_comma = comma;
 	/* eliminate the trailing comma */
 	if(*line2 == ',') line2++;
-	/* eliminate any text enclosed with {}, they are font and color settings */
-	so=de=line2;
-	while (*so) {
-		if(*so == '{') {
-			for (; *so && *so!='}'; so++);
-			if(*so) so++;
-		}
-		if(*so) {
-			*de=*so;
-			so++; de++;
-		}
-	}
-	*de=*so;
 
 	current->lines=0;num=0;
 	current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1;
@@ -484,6 +471,27 @@
 	return current;
 }
 
+void sub_pp_ssa(subtitle *sub) {
+	int l=sub->lines;
+	char *so,*de,*start;
+
+	while (l){
+            	/* eliminate any text enclosed with {}, they are font and color settings */
+            	so=de=sub->text[--l];
+            	while (*so) {
+            		if(*so == '{' && so[1]=='\\') {
+            			for (start=so; *so && *so!='}'; so++);
+            			if(*so) so++; else so=start;
+            		}
+            		if(*so) {
+            			*de=*so;
+            			so++; de++;
+            		}
+            	}
+            	*de=*so;
+        }
+}
+
 subtitle *sub_read_line_dunnowhat(FILE *fd,subtitle *current) {
     char line[LINE_LEN+1];
     char text[LINE_LEN+1];
@@ -1045,35 +1053,41 @@
 	if (n) mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Adjusted %d subtitle(s).\n", n);
 }
 
+struct subreader {
+    subtitle * (*read)(FILE *fd,subtitle *dest);
+    void       (*post)(subtitle *dest);
+    const char *name;
+};
+
 subtitle* sub_read_file (char *filename, float fps) {
     FILE *fd;
     int n_max, n_first, i, j, sub_first, sub_orig;
     subtitle *first, *second, *sub;
-    char *fmtname[] = { "microdvd", "subrip", "subviewer", "sami", "vplayer",
-			"rt", "ssa", "dunnowhat", "mpsub", "aqt", "subviewer 2.0", "subrip 0.9", "jacosub" };
-    subtitle * (*func[])(FILE *fd,subtitle *dest)= 
+    struct subreader sr[]=
     {
-	    sub_read_line_microdvd,
-	    sub_read_line_subrip,
-	    sub_read_line_subviewer,
-	    sub_read_line_sami,
-	    sub_read_line_vplayer,
-	    sub_read_line_rt,
-	    sub_read_line_ssa,
-	    sub_read_line_dunnowhat,
-	    sub_read_line_mpsub,
-	    sub_read_line_aqt,
-	    sub_read_line_subviewer2,
-	    sub_read_line_subrip09,
-	    sub_read_line_jacosub
-	    
+	    { sub_read_line_microdvd, NULL, "microdvd" },
+	    { sub_read_line_subrip, NULL, "subrip" },
+	    { sub_read_line_subviewer, NULL, "subviewer" },
+	    { sub_read_line_sami, NULL, "sami" },
+	    { sub_read_line_vplayer, NULL, "vplayer" },
+	    { sub_read_line_rt, NULL, "rt" },
+	    { sub_read_line_ssa, sub_pp_ssa, "ssa" },
+	    { sub_read_line_dunnowhat, NULL, "dunnowhat" },
+	    { sub_read_line_mpsub, NULL, "mpsub" },
+	    { sub_read_line_aqt, NULL, "aqt" },
+	    { sub_read_line_subviewer2, NULL, "subviewer 2.0" },
+	    { sub_read_line_subrip09, NULL, "subrip 0.9" },
+	    { sub_read_line_jacosub, NULL, "jacosub" }
     };
+    struct subreader *srp;
+    
     if(filename==NULL) return NULL; //qnx segfault
     fd=fopen (filename, "r"); if (!fd) return NULL;
 
     sub_format=sub_autodetect (fd);
     if (sub_format==SUB_INVALID) {mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: Could not determine file format\n");return NULL;}
-    mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Detected subtitle file format: %s\n", fmtname[sub_format]);
+    srp=sr+sub_format;
+    mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Detected subtitle file format: %s\n", srp->name);
     
     rewind (fd);
 
@@ -1100,11 +1114,13 @@
 	sub = &first[sub_num];
 #endif	
 	memset(sub, '\0', sizeof(subtitle));
-        sub=func[sub_format](fd,sub);
+        sub=srp->read(fd,sub);
         if(!sub) break;   // EOF
 #ifdef USE_ICONV
 	if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub);
 #endif
+        // Apply any post processing that needs recoding first
+        if ((sub!=ERR) && srp->post) srp->post(sub);
 #ifdef USE_SORTSUB
 	if(!sub_num || (first[sub_num - 1].start <= sub->start)){
 	    first[sub_num].start = sub->start;



More information about the MPlayer-cvslog mailing list