[MPlayer-cvslog] r33992 - trunk/sub/subreader.c
reimar
subversion at mplayerhq.hu
Mon Aug 15 22:05:09 CEST 2011
Author: reimar
Date: Mon Aug 15 22:05:09 2011
New Revision: 33992
Log:
Get rid of some code duplication.
Modified:
trunk/sub/subreader.c
Modified: trunk/sub/subreader.c
==============================================================================
--- trunk/sub/subreader.c Mon Aug 15 20:38:24 2011 (r33991)
+++ trunk/sub/subreader.c Mon Aug 15 22:05:09 2011 (r33992)
@@ -263,9 +263,9 @@ static subtitle *sub_read_line_sami(stre
}
-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,11 +285,26 @@ static char *sub_readtext(char *source,
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, int 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;
@@ -308,22 +323,12 @@ static subtitle *sub_read_line_microdvd(
#endif
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, int 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;
@@ -332,17 +337,8 @@ static subtitle *sub_read_line_mpl2(stre
&(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, int utf16) {
@@ -525,8 +521,8 @@ static subtitle *sub_read_line_subviewer
static subtitle *sub_read_line_vplayer(stream_t *st,subtitle *current, int 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;
@@ -553,16 +549,9 @@ static subtitle *sub_read_line_vplayer(s
// 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;
@@ -575,7 +564,7 @@ static subtitle *sub_read_line_rt(stream
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;
@@ -602,18 +591,13 @@ static subtitle *sub_read_line_rt(stream
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;
}
@@ -805,8 +789,6 @@ subtitle *previous_aqt_sub = NULL;
static subtitle *sub_read_line_aqt(stream_t *st,subtitle *current, int utf16) {
char line[LINE_LEN+1];
- char *next;
- int i;
while (1) {
// try to locate next subtitle
@@ -835,13 +817,8 @@ static subtitle *sub_read_line_aqt(strea
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
@@ -863,8 +840,7 @@ subtitle *previous_subrip09_sub = NULL;
static subtitle *sub_read_line_subrip09(stream_t *st,subtitle *current, int 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
@@ -888,18 +864,12 @@ static subtitle *sub_read_line_subrip09(
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
More information about the MPlayer-cvslog
mailing list