From e107700e170715a782549ae48424ca61abae2048 Mon Sep 17 00:00:00 2001 From: pl Date: Thu, 15 Nov 2001 11:53:11 +0000 Subject: minor cleanups: a few #define's in subreader.h are now used instead of -1..9 same thing for line length instead of 1000..1001 renamed *_third() to *_subviewer() since it is what it is git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@2913 b3059339-0415-0410-9bf9-f77b7e298cf2 --- subreader.c | 115 +++++++++++++++++++++++++++++------------------------------- subreader.h | 23 ++++++++---- 2 files changed, 72 insertions(+), 66 deletions(-) diff --git a/subreader.c b/subreader.c index 94e916890b..950a4aaff0 100644 --- a/subreader.c +++ b/subreader.c @@ -26,22 +26,17 @@ char *sub_cp=NULL; #endif +/* Maximal length of line of a subtitle */ +#define LINE_LEN 1000 static float mpsub_position=0; int sub_uses_time=0; int sub_errs=0; int sub_num=0; // number of subtitle structs -int sub_format=-1; // 0 for microdvd - // 1 for SubRip - // 2 for SubViewer - // 3 for SAMI (smi) - // 4 for vplayer format - // 5 for RT format - // 6 for ssa (Sub Station Alpha) - // 7 for ... erm ... dunnowhat. tell me if you know - // 8 for the glorious MPsub - // 9 for AQTitle + +/* Use the SUB_* constant defined in the header file */ +int sub_format=SUB_INVALID; int eol(char p) { return (p=='\r' || p=='\n' || p=='\0'); @@ -56,9 +51,9 @@ static inline void trail_space(char *s) { subtitle *sub_read_line_sami(FILE *fd, subtitle *current) { - static char line[1001]; + static char line[LINE_LEN+1]; static char *s = NULL; - char text[1000], *p, *q; + char text[LINE_LEN+1], *p, *q; int state; current->lines = current->start = current->end = 0; @@ -66,7 +61,7 @@ subtitle *sub_read_line_sami(FILE *fd, subtitle *current) { /* read the first line */ if (!s) - if (!(s = fgets(line, 1000, fd))) return 0; + if (!(s = fgets(line, LINE_LEN, fd))) return 0; do { switch (state) { @@ -122,7 +117,7 @@ subtitle *sub_read_line_sami(FILE *fd, subtitle *current) { } /* read next line */ - if (state != 99 && !(s = fgets (line, 1000, fd))) return 0; + if (state != 99 && !(s = fgets (line, LINE_LEN, fd))) return 0; } while (state != 99); @@ -151,15 +146,15 @@ char *sub_readtext(char *source, char **dest) { } subtitle *sub_read_line_microdvd(FILE *fd,subtitle *current) { - char line[1001]; - char line2[1001]; + char line[LINE_LEN+1]; + char line2[LINE_LEN+1]; char *p, *next; int i; bzero (current, sizeof(subtitle)); do { - if (!fgets (line, 1000, fd)) return NULL; + if (!fgets (line, LINE_LEN, fd)) return NULL; } while (sscanf (line, "{%ld}{%ld}%[^\r\n]", &(current->start), &(current->end),line2) <3); p=line2; @@ -176,7 +171,7 @@ subtitle *sub_read_line_microdvd(FILE *fd,subtitle *current) { } subtitle *sub_read_line_subrip(FILE *fd, subtitle *current) { - char line[1001]; + char line[LINE_LEN+1]; int a1,a2,a3,a4,b1,b2,b3,b4; char *p=NULL, *q=NULL; int len; @@ -184,12 +179,12 @@ subtitle *sub_read_line_subrip(FILE *fd, subtitle *current) { bzero (current, sizeof(subtitle)); while (1) { - if (!fgets (line, 1000, fd)) return NULL; + if (!fgets (line, LINE_LEN, fd)) return NULL; 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; - if (!fgets (line, 1000, fd)) return NULL; + if (!fgets (line, LINE_LEN, fd)) return NULL; p=q=line; for (current->lines=1; current->lines < SUB_MAX_TEXT; current->lines++) { @@ -206,8 +201,8 @@ subtitle *sub_read_line_subrip(FILE *fd, subtitle *current) { return current; } -subtitle *sub_read_line_third(FILE *fd,subtitle *current) { - char line[1001]; +subtitle *sub_read_line_subviewer(FILE *fd,subtitle *current) { + char line[LINE_LEN+1]; int a1,a2,a3,a4,b1,b2,b3,b4; char *p=NULL; int i,len; @@ -215,13 +210,13 @@ subtitle *sub_read_line_third(FILE *fd,subtitle *current) { bzero (current, sizeof(subtitle)); while (!current->text[0]) { - if (!fgets (line, 1000, fd)) return NULL; + if (!fgets (line, LINE_LEN, fd)) return NULL; if ((len=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/10; current->end = b1*360000+b2*6000+b3*100+b4/10; for (i=0; itext[0]) { - if (!fgets (line, 1000, fd)) return NULL; + if (!fgets (line, LINE_LEN, fd)) return NULL; if ((len=sscanf (line, "%d:%d:%d:%n",&a1,&a2,&a3,&plen)) < 3) continue; - if (!fgets (line2, 1000, fd)) return NULL; + if (!fgets (line2, LINE_LEN, fd)) return NULL; if ((len2=sscanf (line2, "%d:%d:%d:",&b1,&b2,&b3)) < 3) continue; // przewiń o linijkę do tyłu: @@ -286,7 +281,7 @@ subtitle *sub_read_line_rt(FILE *fd,subtitle *current) { //TODO: This format uses quite rich (sub/super)set of xhtml // I couldn't check it since DTD is not included. // WARNING: full XML parses can be required for proper parsing - char line[1001]; + char line[LINE_LEN+1]; int a1,a2,a3,a4,b1,b2,b3,b4; char *p=NULL,*next=NULL; int i,len,plen; @@ -294,7 +289,7 @@ subtitle *sub_read_line_rt(FILE *fd,subtitle *current) { bzero (current, sizeof(subtitle)); while (!current->text[0]) { - if (!fgets (line, 1000, fd)) return NULL; + if (!fgets (line, LINE_LEN, fd)) return NULL; //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, "