# HG changeset patch # User laaz # Date 1002894718 0 # Node ID f723e4e8f4fdeaf64b72f336133f4c88a10c7a17 # Parent 1ae16a34f0550eeadbd95fc93d28c9c2b8e9f02d mpsub read support diff -r 1ae16a34f055 -r f723e4e8f4fd subreader.c --- a/subreader.c Fri Oct 12 13:24:07 2001 +0000 +++ b/subreader.c Fri Oct 12 13:51:58 2001 +0000 @@ -22,6 +22,9 @@ char *sub_cp=NULL; #endif + +static long int mpsub_position=0; + int sub_uses_time=0; int sub_errs=0; int sub_num=0; // number of subtitle structs @@ -33,6 +36,7 @@ // 5 for RT format // 6 for ssa (Sub Station Alpha) // 7 for ... erm ... dunnowhat. tell me if you know + // 8 for the glorious MPsub int eol(char p) { return (p=='\r' || p=='\n' || p=='\0'); @@ -367,10 +371,45 @@ return current; } +subtitle *sub_read_line_mpsub(FILE *fd, subtitle *current) { + char line[1000]; + int a,b,num=0; + char *p, *q; + + do + { + if (!fgets(line, 1000, fd)) return NULL; + } while (sscanf (line, "%d %d", &a, &b) !=2); + + mpsub_position += (a*100); + current->start=mpsub_position+1; + mpsub_position += (b*100); + current->end=mpsub_position; + + while (num < SUB_MAX_TEXT) { + if (!fgets (line, 1000, fd)) return NULL; + p=line; + while (isspace(*p)) p++; + if (eol(*p) && num > 0) return current; + if (eol(*p)) return NULL; + + for (q=p; !eol(*q); q++); + *q='\0'; + if (strlen(p)) { + current->text[num]=strdup(p); + current->lines = ++num; + } else { + if (num) return current; + else return NULL; + } + } +} + + int sub_autodetect (FILE *fd) { char line[1001]; int i,j=0; -// char *p; + char p; while (j < 100) { j++; @@ -400,6 +439,10 @@ {sub_uses_time=1; return 6;} if (sscanf (line, "%d,%d,\"%c", &i, &i, (char *) &i) == 3) {sub_uses_time=0;return 7;} + if (sscanf (line, "FORMAT=%d", &i) == 1) + {sub_uses_time=0; return 8;} + if (sscanf (line, "FORMAT=TIM%c", &p)==1 && p=='E') + {sub_uses_time=1; return 8;} } return -1; // too many bad lines @@ -485,7 +528,8 @@ sub_read_line_vplayer, sub_read_line_rt, sub_read_line_ssa, - sub_read_line_dunnowhat + sub_read_line_dunnowhat, + sub_read_line_mpsub }; fd=fopen (filename, "r"); if (!fd) return NULL;