diff subreader.c @ 11873:9c66ef56b1b1

Fix the PJS (aka dunnowhat) subtitles patch by Salvador Eduardo Tropea <salvador@inti.gov.ar>
author attila
date Thu, 29 Jan 2004 10:53:19 +0000
parents b4f1df0c1e3a
children 8f2e47faee88
line wrap: on
line diff
--- a/subreader.c	Thu Jan 29 10:36:33 2004 +0000
+++ b/subreader.c	Thu Jan 29 10:53:19 2004 +0000
@@ -3,7 +3,7 @@
  *
  * Written by laaz
  * Some code cleanup & realloc() by A'rpi/ESP-team
- * dunnowhat sub format by szabi
+ *
  */
 
 
@@ -544,15 +544,46 @@
         }
 }
 
-subtitle *sub_read_line_dunnowhat(FILE *fd,subtitle *current) {
+/*
+ * PJS subtitles reader.
+ * That's the "Phoenix Japanimation Society" format.
+ * I found some of them in http://www.scriptsclub.org/ (used for anime).
+ * The time is in tenths of second.
+ *
+ * by set, based on code by szabi (dunnowhat sub format ;-)
+ */
+subtitle *sub_read_line_pjs(FILE *fd,subtitle *current) {
     char line[LINE_LEN+1];
-    char text[LINE_LEN+1];
+    char text[LINE_LEN+1], *s, *d;
 
     if (!fgets (line, LINE_LEN, fd))
 	return NULL;
-    if (sscanf (line, "%ld,%ld,\"%[^\"]", &(current->start),
-		&(current->end), text) <3)
+    /* skip spaces */
+    for (s=line; *s && isspace(*s); s++);
+    /* allow empty lines at the end of the file */
+    if (*s==0)
+	return NULL;
+    /* get the time */
+    if (sscanf (s, "%ld,%ld,", &(current->start),
+		&(current->end)) <2) {
 	return ERR;
+    }
+    /* the files I have are in tenths of second */
+    current->start *= 10;
+    current->end *= 10;
+    /* walk to the beggining of the string */
+    for (; *s; s++) if (*s==',') break;
+    if (*s) {
+	for (s++; *s; s++) if (*s==',') break;
+	if (*s) s++;
+    }
+    if (*s!='"') {
+	return ERR;
+    }
+    /* copy the string to the text buffer */
+    for (s++, d=text; *s && *s!='"'; s++, d++)
+	*d=*s;
+    *d=0;
     current->text[0] = strdup(text);
     current->lines = 1;
 
@@ -946,7 +977,7 @@
 	if (!memcmp(line, "Dialogue: ", 10))
 		{*uses_time=1; return SUB_SSA;}
 	if (sscanf (line, "%d,%d,\"%c", &i, &i, (char *) &i) == 3)
-		{*uses_time=0;return SUB_DUNNOWHAT;}
+		{*uses_time=1;return SUB_PJS;}
 	if (sscanf (line, "FORMAT=%d", &i) == 1)
 		{*uses_time=0; return SUB_MPSUB;}
 	if (sscanf (line, "FORMAT=TIM%c", &p)==1 && p=='E')
@@ -1198,7 +1229,7 @@
 	    { 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_pjs, NULL, "pjs" },
 	    { sub_read_line_mpsub, NULL, "mpsub" },
 	    { sub_read_line_aqt, NULL, "aqt" },
 	    { sub_read_line_subviewer2, NULL, "subviewer 2.0" },