summaryrefslogtreecommitdiffstats
path: root/subreader.c
diff options
context:
space:
mode:
authorlaaz <laaz@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-10-12 13:51:58 +0000
committerlaaz <laaz@b3059339-0415-0410-9bf9-f77b7e298cf2>2001-10-12 13:51:58 +0000
commita30a8a7365ad377317f638b950b3b7589e77e9a8 (patch)
treeb44375bef151a8cb9a7dd9361af960dc9c25e870 /subreader.c
parentaeb64d730951b68d60f844a2009f2d4f3dfb61cb (diff)
downloadmpv-a30a8a7365ad377317f638b950b3b7589e77e9a8.tar.bz2
mpv-a30a8a7365ad377317f638b950b3b7589e77e9a8.tar.xz
mpsub read support
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2178 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'subreader.c')
-rw-r--r--subreader.c48
1 files changed, 46 insertions, 2 deletions
diff --git a/subreader.c b/subreader.c
index eefbecab90..3fb912ae86 100644
--- a/subreader.c
+++ b/subreader.c
@@ -22,6 +22,9 @@
char *sub_cp=NULL;
#endif
+
+static long int mpsub_position=0;
+
int sub_uses_time=0;
int sub_errs=0;
int sub_num=0; // number of subtitle structs
@@ -33,6 +36,7 @@ int sub_format=-1; // 0 for microdvd
// 5 for RT format
// 6 for ssa (Sub Station Alpha)
// 7 for ... erm ... dunnowhat. tell me if you know
+ // 8 for the glorious MPsub
int eol(char p) {
return (p=='\r' || p=='\n' || p=='\0');
@@ -367,10 +371,45 @@ subtitle *sub_read_line_dunnowhat(FILE *fd,subtitle *current) {
return current;
}
+subtitle *sub_read_line_mpsub(FILE *fd, subtitle *current) {
+ char line[1000];
+ int a,b,num=0;
+ char *p, *q;
+
+ do
+ {
+ if (!fgets(line, 1000, fd)) return NULL;
+ } while (sscanf (line, "%d %d", &a, &b) !=2);
+
+ mpsub_position += (a*100);
+ current->start=mpsub_position+1;
+ mpsub_position += (b*100);
+ current->end=mpsub_position;
+
+ while (num < SUB_MAX_TEXT) {
+ if (!fgets (line, 1000, fd)) return NULL;
+ p=line;
+ while (isspace(*p)) p++;
+ if (eol(*p) && num > 0) return current;
+ if (eol(*p)) return NULL;
+
+ for (q=p; !eol(*q); q++);
+ *q='\0';
+ if (strlen(p)) {
+ current->text[num]=strdup(p);
+ current->lines = ++num;
+ } else {
+ if (num) return current;
+ else return NULL;
+ }
+ }
+}
+
+
int sub_autodetect (FILE *fd) {
char line[1001];
int i,j=0;
-// char *p;
+ char p;
while (j < 100) {
j++;
@@ -400,6 +439,10 @@ int sub_autodetect (FILE *fd) {
{sub_uses_time=1; return 6;}
if (sscanf (line, "%d,%d,\"%c", &i, &i, (char *) &i) == 3)
{sub_uses_time=0;return 7;}
+ if (sscanf (line, "FORMAT=%d", &i) == 1)
+ {sub_uses_time=0; return 8;}
+ if (sscanf (line, "FORMAT=TIM%c", &p)==1 && p=='E')
+ {sub_uses_time=1; return 8;}
}
return -1; // too many bad lines
@@ -485,7 +528,8 @@ subtitle* sub_read_file (char *filename) {
sub_read_line_vplayer,
sub_read_line_rt,
sub_read_line_ssa,
- sub_read_line_dunnowhat
+ sub_read_line_dunnowhat,
+ sub_read_line_mpsub
};
fd=fopen (filename, "r"); if (!fd) return NULL;