1
0
mirror of https://github.com/mpv-player/mpv synced 2024-12-30 19:22:11 +00:00

subreader: get rid of some code duplication

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@33992 b3059339-0415-0410-9bf9-f77b7e298cf2
Author: reimar
This commit is contained in:
mplayer-svn 2011-08-15 20:05:09 +00:00 committed by wm4
parent b0e695cf79
commit c5b0ec92f9

View File

@ -263,9 +263,9 @@ static subtitle *sub_read_line_sami(stream_t* st, subtitle *current,
} }
static char *sub_readtext(char *source, char **dest) { static const char *sub_readtext(const char *source, char **dest) {
int len=0; int len=0;
char *p=source; const char *p=source;
// printf("src=%p dest=%p \n",source,dest); // printf("src=%p dest=%p \n",source,dest);
@ -285,14 +285,29 @@ static char *sub_readtext(char *source, char **dest) {
else return NULL; // last text field else return NULL; // last text field
} }
static subtitle *set_multiline_text(subtitle *current, const char *text, int start)
{
int i = start;
while ((text = sub_readtext(text, current->text + i))) {
if (current->text[i] == ERR) return ERR;
i++;
if (i >= SUB_MAX_TEXT) {
mp_msg(MSGT_SUBREADER, MSGL_WARN, "Too many lines in a subtitle\n");
current->lines = i;
return current;
}
}
current->lines = i + 1;
return current;
}
static subtitle *sub_read_line_microdvd(stream_t *st,subtitle *current, static subtitle *sub_read_line_microdvd(stream_t *st,subtitle *current,
struct readline_args *args) struct readline_args *args)
{ {
int utf16 = args->utf16; int utf16 = args->utf16;
char line[LINE_LEN+1]; char line[LINE_LEN+1];
char line2[LINE_LEN+1]; char line2[LINE_LEN+1];
char *p, *next; char *p;
int i;
do { do {
if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL;
@ -309,15 +324,7 @@ static subtitle *sub_read_line_microdvd(stream_t *st,subtitle *current,
} else } else
p = line2; p = line2;
next=p, i=0; return set_multiline_text(current, p, 0);
while ((next =sub_readtext (next, &(current->text[i])))) {
if (current->text[i]==ERR) {return ERR;}
i++;
if (i>=SUB_MAX_TEXT) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"Too many lines in a subtitle\n");current->lines=i;return current;}
}
current->lines= ++i;
return current;
} }
static subtitle *sub_read_line_mpl2(stream_t *st,subtitle *current, static subtitle *sub_read_line_mpl2(stream_t *st,subtitle *current,
@ -326,8 +333,6 @@ static subtitle *sub_read_line_mpl2(stream_t *st,subtitle *current,
int utf16 = args->utf16; int utf16 = args->utf16;
char line[LINE_LEN+1]; char line[LINE_LEN+1];
char line2[LINE_LEN+1]; char line2[LINE_LEN+1];
char *p, *next;
int i;
do { do {
if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL;
@ -336,17 +341,8 @@ static subtitle *sub_read_line_mpl2(stream_t *st,subtitle *current,
&(current->start), &(current->end), line2) < 3)); &(current->start), &(current->end), line2) < 3));
current->start *= 10; current->start *= 10;
current->end *= 10; current->end *= 10;
p=line2;
next=p, i=0; return set_multiline_text(current, line2, 0);
while ((next =sub_readtext (next, &(current->text[i])))) {
if (current->text[i]==ERR) {return ERR;}
i++;
if (i>=SUB_MAX_TEXT) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"Too many lines in a subtitle\n");current->lines=i;return current;}
}
current->lines= ++i;
return current;
} }
static subtitle *sub_read_line_subrip(stream_t* st, subtitle *current, static subtitle *sub_read_line_subrip(stream_t* st, subtitle *current,
@ -539,8 +535,8 @@ static subtitle *sub_read_line_vplayer(stream_t *st,subtitle *current,
int utf16 = args->utf16; int utf16 = args->utf16;
char line[LINE_LEN+1]; char line[LINE_LEN+1];
int a1,a2,a3; int a1,a2,a3;
char *p=NULL, *next,separator; char *p=NULL, separator;
int i,len,plen; int len,plen;
while (!current->text[0]) { while (!current->text[0]) {
if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL;
@ -567,16 +563,9 @@ static subtitle *sub_read_line_vplayer(stream_t *st,subtitle *current,
// colon! look, what simple it can be: // colon! look, what simple it can be:
p = &line[ plen ]; p = &line[ plen ];
i=0;
if (*p!='|') { if (*p!='|') {
// //
next = p,i=0; return set_multiline_text(current, p, 0);
while ((next =sub_readtext (next, &(current->text[i])))) {
if (current->text[i]==ERR) {return ERR;}
i++;
if (i>=SUB_MAX_TEXT) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"Too many lines in a subtitle\n");current->lines=i;return current;}
}
current->lines=i+1;
} }
} }
return current; return current;
@ -593,7 +582,7 @@ static subtitle *sub_read_line_rt(stream_t *st,subtitle *current,
char line[LINE_LEN+1]; char line[LINE_LEN+1];
int a1,a2,a3,a4,b1,b2,b3,b4; int a1,a2,a3,a4,b1,b2,b3,b4;
char *p=NULL,*next=NULL; char *p=NULL,*next=NULL;
int i,len,plen; int len,plen;
while (!current->text[0]) { while (!current->text[0]) {
if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL; if (!stream_read_line (st, line, LINE_LEN, utf16)) return NULL;
@ -620,18 +609,13 @@ static subtitle *sub_read_line_rt(stream_t *st,subtitle *current,
current->end = b1*360000+b2*6000+b3*100+b4/10; current->end = b1*360000+b2*6000+b3*100+b4/10;
if (b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0) if (b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0)
current->end = current->start+200; current->end = current->start+200;
p=line; p+=plen;i=0; p=line; p+=plen;
// TODO: I don't know what kind of convention is here for marking multiline subs, maybe <br/> like in xml? // TODO: I don't know what kind of convention is here for marking multiline subs, maybe <br/> like in xml?
next = strstr(line,"<clear/>"); next = strstr(line,"<clear/>");
if(next && strlen(next)>8){ if(next && strlen(next)>8){
next+=8;i=0; next+=8;
while ((next =sub_readtext (next, &(current->text[i])))) { return set_multiline_text(current, next, 0);
if (current->text[i]==ERR) {return ERR;}
i++;
if (i>=SUB_MAX_TEXT) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"Too many lines in a subtitle\n");current->lines=i;return current;}
} }
}
current->lines=i+1;
} }
return current; return current;
} }
@ -835,8 +819,6 @@ static subtitle *sub_read_line_aqt(stream_t *st,subtitle *current,
{ {
int utf16 = args->utf16; int utf16 = args->utf16;
char line[LINE_LEN+1]; char line[LINE_LEN+1];
char *next;
int i;
while (1) { while (1) {
// try to locate next subtitle // try to locate next subtitle
@ -865,13 +847,8 @@ static subtitle *sub_read_line_aqt(stream_t *st,subtitle *current,
if (!stream_read_line (st, line, LINE_LEN, utf16)) if (!stream_read_line (st, line, LINE_LEN, utf16))
return current; return current;
next = line,i=1; if (set_multiline_text(current, line, 1) == ERR)
while ((next =sub_readtext (next, &(current->text[i])))) { return ERR;
if (current->text[i]==ERR) {return ERR;}
i++;
if (i>=SUB_MAX_TEXT) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"Too many lines in a subtitle\n");current->lines=i;return current;}
}
current->lines=i+1;
if (!strlen(current->text[0]) && !strlen(current->text[1])) { if (!strlen(current->text[0]) && !strlen(current->text[1])) {
#ifdef CONFIG_SORTSUB #ifdef CONFIG_SORTSUB
@ -896,8 +873,7 @@ static subtitle *sub_read_line_subrip09(stream_t *st,subtitle *current,
int utf16 = args->utf16; int utf16 = args->utf16;
char line[LINE_LEN+1]; char line[LINE_LEN+1];
int a1,a2,a3; int a1,a2,a3;
char * next=NULL; int len;
int i,len;
while (1) { while (1) {
// try to locate next subtitle // try to locate next subtitle
@ -921,18 +897,12 @@ static subtitle *sub_read_line_subrip09(stream_t *st,subtitle *current,
if (!stream_read_line (st, line, LINE_LEN, utf16)) if (!stream_read_line (st, line, LINE_LEN, utf16))
return NULL; return NULL;
next = line,i=0;
current->text[0]=""; // just to be sure that string is clear current->text[0]=""; // just to be sure that string is clear
while ((next =sub_readtext (next, &(current->text[i])))) { if (set_multiline_text(current, line, 0) == ERR)
if (current->text[i]==ERR) {return ERR;} return ERR;
i++;
if (i>=SUB_MAX_TEXT) { mp_msg(MSGT_SUBREADER,MSGL_WARN,"Too many lines in a subtitle\n");current->lines=i;return current;}
}
current->lines=i+1;
if (!strlen(current->text[0]) && (i==0)) { if (!strlen(current->text[0]) && current->lines <= 1) {
#ifdef CONFIG_SORTSUB #ifdef CONFIG_SORTSUB
previous_sub_end = 0; previous_sub_end = 0;
#else #else