Mercurial > mplayer.hg
comparison sub/subreader.c @ 37116:8e89cf177d51
subreader: Split a monster if() into multiple parts.
Should make code more maintainable.
Also make sure all input variables are properly
reset before each test.
author | reimar |
---|---|
date | Tue, 27 May 2014 19:22:11 +0000 |
parents | 780f1cf49497 |
children | f996bcd28c23 |
comparison
equal
deleted
inserted
replaced
37115:a0a13230b8d1 | 37116:8e89cf177d51 |
---|---|
592 // I couldn't check it since DTD is not included. | 592 // I couldn't check it since DTD is not included. |
593 // WARNING: full XML parses can be required for proper parsing | 593 // WARNING: full XML parses can be required for proper parsing |
594 char line[LINE_LEN+1]; | 594 char line[LINE_LEN+1]; |
595 int a1,a2,a3,a4,b1,b2,b3,b4; | 595 int a1,a2,a3,a4,b1,b2,b3,b4; |
596 char *p=NULL,*next=NULL; | 596 char *p=NULL,*next=NULL; |
597 int len,plen; | 597 int plen; |
598 | 598 |
599 while (!current->text[0]) { | 599 while (!current->text[0]) { |
600 int match = 0; | |
600 if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; | 601 if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; |
601 //TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0 | 602 //TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0 |
602 //to describe the same moment in time. Maybe there are even more formats in use. | 603 //to describe the same moment in time. Maybe there are even more formats in use. |
604 //This probably should be changed to do something nicer than | |
605 //"brute-forcing" a long list of format strings. | |
603 //if ((len=sscanf (line, "<Time Begin=\"%d:%d:%d.%d\" End=\"%d:%d:%d.%d\"",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8) | 606 //if ((len=sscanf (line, "<Time Begin=\"%d:%d:%d.%d\" End=\"%d:%d:%d.%d\"",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8) |
604 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; | 607 if (!match) { |
605 if ( | 608 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; |
606 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&b3,&b4,&plen)) < 4) && | 609 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&b3,&b4,&plen) >= 4; |
607 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&b2,&b3,&b4,&plen)) < 5) && | 610 } |
608 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&plen)) < 4) && | 611 if (!match) { |
609 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&b4,&plen)) < 5) && | 612 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; |
610 // ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&plen)) < 5) && | 613 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&b2,&b3,&b4,&plen) >= 5; |
611 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&b4,&plen)) < 6) && | 614 } |
612 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&plen)) < 8) && | 615 if (!match) { |
616 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; | |
617 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&plen) >= 4; | |
618 } | |
619 if (!match) { | |
620 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; | |
621 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&b4,&plen) >= 5; | |
622 } | |
623 // sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&plen) >= 5 | |
624 if (!match) { | |
625 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; | |
626 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&b4,&plen) >= 6; | |
627 } | |
628 if (!match) { | |
629 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; | |
630 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&plen) >= 8; | |
631 } | |
613 //now try it without end time | 632 //now try it without end time |
614 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&plen)) < 2) && | 633 if (!match) { |
615 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&plen)) < 2) && | 634 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; |
616 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&plen)) < 3) && | 635 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d.%d\"%*[^<]<clear/>%n",&a3,&a4,&plen) >= 2; |
617 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&plen)) < 4) | 636 } |
618 ) | 637 if (!match) { |
638 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; | |
639 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&plen) >= 2; | |
640 } | |
641 if (!match) { | |
642 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; | |
643 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&plen) >= 3; | |
644 } | |
645 if (!match) { | |
646 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; | |
647 match = sscanf(line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&plen) >= 4; | |
648 } | |
649 if (!match) | |
619 continue; | 650 continue; |
620 current->start = a1*360000+a2*6000+a3*100+a4/10; | 651 current->start = a1*360000+a2*6000+a3*100+a4/10; |
621 current->end = b1*360000+b2*6000+b3*100+b4/10; | 652 current->end = b1*360000+b2*6000+b3*100+b4/10; |
622 if (b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0) | 653 if (b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0) |
623 current->end = current->start+200; | 654 current->end = current->start+200; |