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
1 changed files with 34 additions and 64 deletions

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;
char *p=source;
const char *p=source;
// 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
}
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,
struct readline_args *args)
{
int utf16 = args->utf16;
char line[LINE_LEN+1];
char line2[LINE_LEN+1];
char *p, *next;
int i;
char *p;
do {
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
p = line2;
next=p, i=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;
return set_multiline_text(current, p, 0);
}
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;
char line[LINE_LEN+1];
char line2[LINE_LEN+1];
char *p, *next;
int i;
do {
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 *= 10;
current->end *= 10;
p=line2;
next=p, i=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;
return set_multiline_text(current, line2, 0);
}
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;
char line[LINE_LEN+1];
int a1,a2,a3;
char *p=NULL, *next,separator;
int i,len,plen;
char *p=NULL, separator;
int len,plen;
while (!current->text[0]) {
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:
p = &line[ plen ];
i=0;
if (*p!='|') {
//
next = p,i=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 set_multiline_text(current, p, 0);
}
}
return current;
@ -593,7 +582,7 @@ static subtitle *sub_read_line_rt(stream_t *st,subtitle *current,
char line[LINE_LEN+1];
int a1,a2,a3,a4,b1,b2,b3,b4;
char *p=NULL,*next=NULL;
int i,len,plen;
int len,plen;
while (!current->text[0]) {
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;
if (b1 == 0 && b2 == 0 && b3 == 0 && b4 == 0)
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?
next = strstr(line,"<clear/>");
if(next && strlen(next)>8){
next+=8;i=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;}
}
next+=8;
return set_multiline_text(current, next, 0);
}
current->lines=i+1;
}
return current;
}
@ -835,8 +819,6 @@ static subtitle *sub_read_line_aqt(stream_t *st,subtitle *current,
{
int utf16 = args->utf16;
char line[LINE_LEN+1];
char *next;
int i;
while (1) {
// 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))
return current;
next = line,i=1;
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;
if (set_multiline_text(current, line, 1) == ERR)
return ERR;
if (!strlen(current->text[0]) && !strlen(current->text[1])) {
#ifdef CONFIG_SORTSUB
@ -896,8 +873,7 @@ static subtitle *sub_read_line_subrip09(stream_t *st,subtitle *current,
int utf16 = args->utf16;
char line[LINE_LEN+1];
int a1,a2,a3;
char * next=NULL;
int i,len;
int len;
while (1) {
// 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))
return NULL;
next = line,i=0;
current->text[0]=""; // just to be sure that string is clear
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;
if (set_multiline_text(current, line, 0) == ERR)
return ERR;
if (!strlen(current->text[0]) && (i==0)) {
if (!strlen(current->text[0]) && current->lines <= 1) {
#ifdef CONFIG_SORTSUB
previous_sub_end = 0;
#else