From 9c5977f1fb284f47eb12c8b8da87f291fd0f5a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20=27Flameeyes=27=20Petten=C3=B2?= Date: Fri, 4 Jul 2008 16:26:37 +0200 Subject: Simplify code and update code style. --HG-- extra : transplant_source : i%86L%8F_h%1D%DDv%DF%E4%2B%906%8B%FBM%87h%2A --- src/libsputext/demux_sputext.c | 818 +++++++++++++++++----------------- src/libsputext/xine_sputext_decoder.c | 83 ++-- 2 files changed, 452 insertions(+), 449 deletions(-) (limited to 'src') diff --git a/src/libsputext/demux_sputext.c b/src/libsputext/demux_sputext.c index 741d0612b..3e9efb079 100644 --- a/src/libsputext/demux_sputext.c +++ b/src/libsputext/demux_sputext.c @@ -146,8 +146,6 @@ static inline void trail_space(char *s) { */ static char *read_line_from_input(demux_sputext_t *this, char *line, off_t len) { off_t nread = 0; - char *s; - int linelen; if ((len - this->buflen) > 512) { if((nread = this->input->read(this->input, @@ -160,11 +158,11 @@ static char *read_line_from_input(demux_sputext_t *this, char *line, off_t len) this->buflen += nread; this->buf[this->buflen] = '\0'; - s = strchr(this->buf, '\n'); + char *s = strchr(this->buf, '\n'); if (line && (s || this->buflen)) { - linelen = s ? (s - this->buf) + 1 : this->buflen; + size_t linelen = s ? (s - this->buf) + 1 : this->buflen; memcpy(line, this->buf, linelen); line[linelen] = '\0'; @@ -183,13 +181,12 @@ static subtitle_t *sub_read_line_sami(demux_sputext_t *this, subtitle_t *current static char line[LINE_LEN + 1]; static char *s = NULL; - char text[LINE_LEN + 1], *p, *q; - int state; + char text[LINE_LEN + 1]; - p = NULL; + char *p = NULL; current->lines = current->start = 0; current->end = -1; - state = 0; + int state = 0; /* read the first line */ if (!s) @@ -229,14 +226,16 @@ static subtitle_t *sub_read_line_sami(demux_sputext_t *this, subtitle_t *current continue; case 4: /* get current->end or skip */ - q = strstr (s, "Start="); - if (q) { - current->end = strtol (q + 6, &q, 0) / 10 - 1; - *p = '\0'; trail_space (text); - if (text[0] != '\0') - current->text[current->lines++] = strdup (text); - if (current->lines > 0) { state = 99; break; } - state = 0; continue; + { + char *q = strstr (s, "Start="); + if (q) { + current->end = strtol (q + 6, &q, 0) / 10 - 1; + *p = '\0'; trail_space (text); + if (text[0] != '\0') + current->text[current->lines++] = strdup (text); + if (current->lines > 0) { state = 99; break; } + state = 0; continue; + } } s = strchr (s, '>'); if (s) { s++; state = 3; continue; } @@ -254,7 +253,7 @@ static subtitle_t *sub_read_line_sami(demux_sputext_t *this, subtitle_t *current static char *sub_readtext(char *source, char **dest) { - int len=0; + size_t len=0; char *p=source; while ( !eol(*p) && *p!= '|' ) { @@ -274,8 +273,6 @@ static subtitle_t *sub_read_line_microdvd(demux_sputext_t *this, subtitle_t *cur char line[LINE_LEN + 1]; char line2[LINE_LEN + 1]; - char *p, *next; - int i; memset (current, 0, sizeof(subtitle_t)); @@ -286,9 +283,10 @@ static subtitle_t *sub_read_line_microdvd(demux_sputext_t *this, subtitle_t *cur (sscanf (line, "{%ld}{%ld}%" LINE_LEN_QUOT "[^\r\n]", &(current->start), &(current->end),line2) !=3) ); - p=line2; + char *p=line2; - next=p, i=0; + char *next=p; + size_t i=0; while ((next =sub_readtext (next, &(current->text[i])))) { if (current->text[i]==ERR) return ERR; i++; @@ -304,28 +302,30 @@ static subtitle_t *sub_read_line_microdvd(demux_sputext_t *this, subtitle_t *cur } static subtitle_t *sub_read_line_subviewer(demux_sputext_t *this, subtitle_t *current) { - char line[LINE_LEN + 1]; - int a1,a2,a3,a4,b1,b2,b3,b4; - char *p=NULL, *q=NULL; - int len; memset (current, 0, sizeof(subtitle_t)); while (1) { if (!read_line_from_input(this, line, LINE_LEN)) return NULL; - if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) { - if (sscanf (line, "%d:%d:%d,%d,%d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) - continue; + + { + int a1,a2,a3,a4,b1,b2,b3,b4; + if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) { + if (sscanf (line, "%d:%d:%d,%d,%d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) + continue; + } + + current->start = a1*360000+a2*6000+a3*100+a4; + current->end = b1*360000+b2*6000+b3*100+b4; } - current->start = a1*360000+a2*6000+a3*100+a4; - current->end = b1*360000+b2*6000+b3*100+b4; - + if (!read_line_from_input(this, line, LINE_LEN)) return NULL; - p=q=line; + char *p = line, *q = line; for (current->lines=1; current->lines <= SUB_MAX_TEXT; current->lines++) { + size_t len; for (q=p,len=0; *p && *p!='\r' && *p!='\n' && *p!='|' && strncasecmp(p,"[br]",4); p++,len++); current->text[current->lines-1] = strndup(q, len); if (!current->text[current->lines-1]) return ERR; @@ -340,25 +340,27 @@ static subtitle_t *sub_read_line_subviewer(demux_sputext_t *this, subtitle_t *cu } static subtitle_t *sub_read_line_subrip(demux_sputext_t *this,subtitle_t *current) { - char line[LINE_LEN + 1]; - int a1,a2,a3,a4,b1,b2,b3,b4; - int i,end_sub; - memset(current,0,sizeof(subtitle_t)); - do { - if(!read_line_from_input(this,line,LINE_LEN)) - return NULL; - i = sscanf(line,"%d:%d:%d%*[,.]%d --> %d:%d:%d%*[,.]%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4); - } while(i < 8); - current->start = a1*360000+a2*6000+a3*100+a4/10; - current->end = b1*360000+b2*6000+b3*100+b4/10; - i=0; - end_sub=0; + + { + int a1,a2,a3,a4,b1,b2,b3,b4,i; + do { + char line[LINE_LEN + 1]; + if(!read_line_from_input(this,line,LINE_LEN)) + return NULL; + i = sscanf(line,"%d:%d:%d%*[,.]%d --> %d:%d:%d%*[,.]%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4); + } while(i < 8); + current->start = a1*360000+a2*6000+a3*100+a4/10; + current->end = b1*360000+b2*6000+b3*100+b4/10; + } + + int i=0; + int end_sub=0; do { char *p; /* pointer to the curently read char */ - char temp_line[SUB_BUFSIZE]; /* subtitle line that will be transfered to current->text[i] */ - int temp_index; /* ... and its index wich 'points' to the first EMPTY place -> last read char is at temp_index-1 if temp_index>0 */ - temp_line[SUB_BUFSIZE-1]='\0'; /* just in case... */ + char line[LINE_LEN + 1]; + char temp_line[SUB_BUFSIZE] = { 0, }; /* subtitle line that will be transfered to current->text[i] */ + size_t temp_index; /* ... and its index wich 'points' to the first EMPTY place -> last read char is at temp_index-1 if temp_index>0 */ if(!read_line_from_input(this,line,LINE_LEN)) { if(i) break; /* if something was read, transmit it */ @@ -408,9 +410,6 @@ static subtitle_t *sub_read_line_subrip(demux_sputext_t *this,subtitle_t *curren static subtitle_t *sub_read_line_vplayer(demux_sputext_t *this,subtitle_t *current) { char line[LINE_LEN + 1]; - int a1,a2,a3,b1,b2,b3; - char *p=NULL, *next, *p2; - int i; memset (current, 0, sizeof(subtitle_t)); @@ -428,24 +427,32 @@ static subtitle_t *sub_read_line_vplayer(demux_sputext_t *this,subtitle_t *curre this->next_line[0] = '\0'; return NULL; } - if( (sscanf( line, "%d:%d:%d:", &a1, &a2, &a3) < 3) || - (sscanf( this->next_line, "%d:%d:%d:", &b1, &b2, &b3) < 3) ) - continue; - current->start = a1*360000+a2*6000+a3*100; - current->end = b1*360000+b2*6000+b3*100; + + { + int a1,a2,a3,b1,b2,b3; + if( (sscanf( line, "%d:%d:%d:", &a1, &a2, &a3) < 3) || + (sscanf( this->next_line, "%d:%d:%d:", &b1, &b2, &b3) < 3) ) + continue; + current->start = a1*360000+a2*6000+a3*100; + current->end = b1*360000+b2*6000+b3*100; + } + if ((current->end - current->start) > LINE_LEN) current->end = current->start + LINE_LEN; /* not too long though. */ /* teraz czas na wkopiowanie stringu */ - p=line; + char *p=line; /* finds the body of the subtitle_t */ - for (i=0; i<3; i++){ - p2=strchr( p, ':'); - if( p2 == NULL ) break; - p=p2+1; - } + { + int i; + for (i=0; i<3; i++){ + char *p2=strchr( p, ':'); + if( p2 == NULL ) break; + p=p2+1; + } + } - next=p; - i=0; + char *next=p; + int i=0; while( (next = sub_readtext( next, &(current->text[i]))) ) { if (current->text[i]==ERR) return ERR; @@ -467,35 +474,40 @@ static subtitle_t *sub_read_line_rt(demux_sputext_t *this,subtitle_t *current) { * I couldn't check it since DTD is not included. * WARNING: full XML parses can be required for proper parsing */ - char line[LINE_LEN + 1]; - int a1,a2,a3,a4,b1,b2,b3,b4; - char *p=NULL,*next=NULL; - int i,len,plen; - memset (current, 0, sizeof(subtitle_t)); while (!current->text[0]) { + char line[LINE_LEN + 1]; if (!read_line_from_input(this, line, LINE_LEN)) return NULL; + + char *p = line; /* * TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0 * to describe the same moment in time. Maybe there are even more formats in use. */ - if ((len=sscanf (line, "