Index: subreader.c =================================================================== RCS file: /cvsroot/mplayer/main/subreader.c,v retrieving revision 1.128 diff -u -r1.128 subreader.c --- subreader.c 29 Jan 2004 10:53:19 -0000 1.128 +++ subreader.c 9 Feb 2004 21:56:47 -0000 @@ -461,66 +461,68 @@ * http://www.scriptclub.org is a good place to find more examples * http://www.eswat.demon.co.uk is where the SSA specs can be found */ - int comma; - static int max_comma = 32; /* let's use 32 for the case that the */ - /* amount of commas increase with newer SSA versions */ + static int max_comma = 8; int hour1, min1, sec1, hunsec1, - hour2, min2, sec2, hunsec2, nothing; - int num; + hour2, min2, sec2, hunsec2; + int num, comma; char line[LINE_LEN+1], - line3[LINE_LEN+1], *line2; char *tmp; - do { - if (!fgets (line, LINE_LEN, fd)) return NULL; - } while (sscanf (line, "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d," - "%[^\n\r]", ¬hing, - &hour1, &min1, &sec1, &hunsec1, + while (fgets (line, LINE_LEN, fd)) { + + if (!strncmp (line, "ScriptType: v",13)) { + max_comma = 9; + continue;/*read the next line*/ + } + else if (strncmp (line, "Dialogue:",9)) + continue;/*read the next line*/ + + tmp = strchr(line, ','); + if (!tmp) continue;/*read the next line*/ + + if (sscanf (tmp,"," + "%1d:%2d:%2d.%2d,%1d:%2d:%2d.%2d," + "%[^\n\r]", + &hour1, &min1, &sec1, &hunsec1, &hour2, &min2, &sec2, &hunsec2, - line3) < 9 - && - sscanf (line, "Dialogue: %d,%d:%d:%d.%d,%d:%d:%d.%d," - "%[^\n\r]", ¬hing, - &hour1, &min1, &sec1, &hunsec1, - &hour2, &min2, &sec2, &hunsec2, - line3) < 9 ); - - line2=strchr(line3, ','); - - for (comma = 4; comma < max_comma; comma ++) - { - tmp = line2; - if(!(tmp=strchr(++tmp, ','))) break; - if(*(++tmp) == ' ') break; - /* a space after a comma means we're already in a sentence */ - line2 = tmp; - } - - if(comma < max_comma)max_comma = comma; - /* eliminate the trailing comma */ - if(*line2 == ',') line2++; - - current->lines=0;num=0; - current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1; - current->end = 360000*hour2 + 6000*min2 + 100*sec2 + hunsec2; + line) < 9) + continue;/*read the next line*/ + + line2=strchr(line, ','); + if (!line2) continue; /*Line broken*/ + tmp=line2+1; + for (comma = 4; comma < max_comma; comma ++) { + tmp=strchr(tmp, ','); + if(!tmp) { + max_comma = 8; + break; + } + line2 = ++tmp; + } + + current->lines=0;num=0; + current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1; + current->end = 360000*hour2 + 6000*min2 + 100*sec2 + hunsec2; - while (((tmp=strstr(line2, "\\n")) != NULL) || ((tmp=strstr(line2, "\\N")) != NULL) ){ - current->text[num]=(char *)malloc(tmp-line2+1); - strncpy (current->text[num], line2, tmp-line2); - current->text[num][tmp-line2]='\0'; - line2=tmp+2; - num++; - current->lines++; - if (current->lines >= SUB_MAX_TEXT) return current; - } + while (((tmp=strstr(line2, "\\n")) != NULL) || ((tmp=strstr(line2, "\\N")) != NULL) ){ + current->text[num]=(char *)malloc(tmp-line2+1); + strncpy (current->text[num], line2, tmp-line2); + current->text[num][tmp-line2]='\0'; + line2=tmp+2; + num++; + current->lines++; + if (current->lines >= SUB_MAX_TEXT) return current; + } - current->text[num]=strdup(line2); - current->lines++; + current->text[num]=strdup(line2); + current->lines++; - return current; + return current; + } + return NULL; } void sub_pp_ssa(subtitle *sub) {