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 6 Feb 2004 23:29:47 -0000 @@ -462,8 +462,9 @@ * 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 = 9;/* use only 9 commas, could be easily increase + if needed*/ + static int event = 0, nbcomma = 0; int hour1, min1, sec1, hunsec1, hour2, min2, sec2, hunsec2, nothing; @@ -474,9 +475,31 @@ *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," + while (fgets (line, LINE_LEN, fd)) { + + if (!strncmp (line, "[Events]",8)) + { + event=1; + continue;/*read the next line*/ + } + + /*this line indicate the parameters, and so the number of comma*/ + if (event && !strncmp (line, "Format:",7)) { + tmp=strchr(line, ','); + if (!tmp) continue; /*Format broken*/ + for (comma = 1; comma < max_comma; comma ++) + { + tmp=strchr(++tmp, ','); + if(!tmp) break; + } + max_comma=comma; + nbcomma=1; + event=0; + continue;/*read the next line*/ + } + event=0; + + if (sscanf (line, "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d," "%[^\n\r]", ¬hing, &hour1, &min1, &sec1, &hunsec1, &hour2, &min2, &sec2, &hunsec2, @@ -486,41 +509,48 @@ "%[^\n\r]", ¬hing, &hour1, &min1, &sec1, &hunsec1, &hour2, &min2, &sec2, &hunsec2, - line3) < 9 ); - - line2=strchr(line3, ','); + line3) < 9 ) + continue; /*read the next line*/ - 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; + line2=strchr(line3, ','); + if (!line2) continue; /*Line broken*/ + tmp=line2+1; + + for (comma = 4; comma < max_comma; comma ++) + { + tmp=strchr(tmp, ','); + if(!tmp) break; + line2 = ++tmp; + if(!nbcomma && *(tmp) == ' ') break; + /*don't increment tmp because they could have two comma*/ + /* a space after a comma means we're already in a sentence */ + } + + /*if we don't read the event format ajust max_comma*/ + if(!nbcomma && comma < max_comma)max_comma = comma + 1; + /* eliminate the trailing spaces */ + while (*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; - 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) {