Mercurial > mplayer.hg
comparison subreader.c @ 9009:f2d4324561b2
1) Removed the code to remove {} from sub_read_line_ssa
2) Put this code in a separated function: sub_pp_ssa
3) After recoding added a call to sub_pp_ssa. To be more acqurate: I
added a pointer to function to hold a postprocessing function to be
invoked after using iconv. There are one pointer for each format, if
this pointer isn.t NULL the post processing function is called.
patch by Salvador Eduardo Tropea <salvador@inti.gov.ar>
help by <hephooey@fastmail.fm>
author | arpi |
---|---|
date | Sun, 19 Jan 2003 00:54:55 +0000 |
parents | dc963ad8dafe |
children | 3086611e8213 |
comparison
equal
deleted
inserted
replaced
9008:654bc667a450 | 9009:f2d4324561b2 |
---|---|
423 hour2, min2, sec2, hunsec2, nothing; | 423 hour2, min2, sec2, hunsec2, nothing; |
424 int num; | 424 int num; |
425 | 425 |
426 char line[LINE_LEN+1], | 426 char line[LINE_LEN+1], |
427 line3[LINE_LEN+1], | 427 line3[LINE_LEN+1], |
428 *line2,*so,*de; | 428 *line2; |
429 char *tmp; | 429 char *tmp; |
430 | 430 |
431 do { | 431 do { |
432 if (!fgets (line, LINE_LEN, fd)) return NULL; | 432 if (!fgets (line, LINE_LEN, fd)) return NULL; |
433 } while (sscanf (line, "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d," | 433 } while (sscanf (line, "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d," |
448 } | 448 } |
449 | 449 |
450 if(comma < max_comma)max_comma = comma; | 450 if(comma < max_comma)max_comma = comma; |
451 /* eliminate the trailing comma */ | 451 /* eliminate the trailing comma */ |
452 if(*line2 == ',') line2++; | 452 if(*line2 == ',') line2++; |
453 /* eliminate any text enclosed with {}, they are font and color settings */ | |
454 so=de=line2; | |
455 while (*so) { | |
456 if(*so == '{') { | |
457 for (; *so && *so!='}'; so++); | |
458 if(*so) so++; | |
459 } | |
460 if(*so) { | |
461 *de=*so; | |
462 so++; de++; | |
463 } | |
464 } | |
465 *de=*so; | |
466 | 453 |
467 current->lines=0;num=0; | 454 current->lines=0;num=0; |
468 current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1; | 455 current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1; |
469 current->end = 360000*hour2 + 6000*min2 + 100*sec2 + hunsec2; | 456 current->end = 360000*hour2 + 6000*min2 + 100*sec2 + hunsec2; |
470 | 457 |
480 | 467 |
481 current->text[num]=strdup(line2); | 468 current->text[num]=strdup(line2); |
482 current->lines++; | 469 current->lines++; |
483 | 470 |
484 return current; | 471 return current; |
472 } | |
473 | |
474 void sub_pp_ssa(subtitle *sub) { | |
475 int l=sub->lines; | |
476 char *so,*de,*start; | |
477 | |
478 while (l){ | |
479 /* eliminate any text enclosed with {}, they are font and color settings */ | |
480 so=de=sub->text[--l]; | |
481 while (*so) { | |
482 if(*so == '{' && so[1]=='\\') { | |
483 for (start=so; *so && *so!='}'; so++); | |
484 if(*so) so++; else so=start; | |
485 } | |
486 if(*so) { | |
487 *de=*so; | |
488 so++; de++; | |
489 } | |
490 } | |
491 *de=*so; | |
492 } | |
485 } | 493 } |
486 | 494 |
487 subtitle *sub_read_line_dunnowhat(FILE *fd,subtitle *current) { | 495 subtitle *sub_read_line_dunnowhat(FILE *fd,subtitle *current) { |
488 char line[LINE_LEN+1]; | 496 char line[LINE_LEN+1]; |
489 char text[LINE_LEN+1]; | 497 char text[LINE_LEN+1]; |
1043 m = 0; | 1051 m = 0; |
1044 } | 1052 } |
1045 if (n) mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Adjusted %d subtitle(s).\n", n); | 1053 if (n) mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Adjusted %d subtitle(s).\n", n); |
1046 } | 1054 } |
1047 | 1055 |
1056 struct subreader { | |
1057 subtitle * (*read)(FILE *fd,subtitle *dest); | |
1058 void (*post)(subtitle *dest); | |
1059 const char *name; | |
1060 }; | |
1061 | |
1048 subtitle* sub_read_file (char *filename, float fps) { | 1062 subtitle* sub_read_file (char *filename, float fps) { |
1049 FILE *fd; | 1063 FILE *fd; |
1050 int n_max, n_first, i, j, sub_first, sub_orig; | 1064 int n_max, n_first, i, j, sub_first, sub_orig; |
1051 subtitle *first, *second, *sub; | 1065 subtitle *first, *second, *sub; |
1052 char *fmtname[] = { "microdvd", "subrip", "subviewer", "sami", "vplayer", | 1066 struct subreader sr[]= |
1053 "rt", "ssa", "dunnowhat", "mpsub", "aqt", "subviewer 2.0", "subrip 0.9", "jacosub" }; | |
1054 subtitle * (*func[])(FILE *fd,subtitle *dest)= | |
1055 { | 1067 { |
1056 sub_read_line_microdvd, | 1068 { sub_read_line_microdvd, NULL, "microdvd" }, |
1057 sub_read_line_subrip, | 1069 { sub_read_line_subrip, NULL, "subrip" }, |
1058 sub_read_line_subviewer, | 1070 { sub_read_line_subviewer, NULL, "subviewer" }, |
1059 sub_read_line_sami, | 1071 { sub_read_line_sami, NULL, "sami" }, |
1060 sub_read_line_vplayer, | 1072 { sub_read_line_vplayer, NULL, "vplayer" }, |
1061 sub_read_line_rt, | 1073 { sub_read_line_rt, NULL, "rt" }, |
1062 sub_read_line_ssa, | 1074 { sub_read_line_ssa, sub_pp_ssa, "ssa" }, |
1063 sub_read_line_dunnowhat, | 1075 { sub_read_line_dunnowhat, NULL, "dunnowhat" }, |
1064 sub_read_line_mpsub, | 1076 { sub_read_line_mpsub, NULL, "mpsub" }, |
1065 sub_read_line_aqt, | 1077 { sub_read_line_aqt, NULL, "aqt" }, |
1066 sub_read_line_subviewer2, | 1078 { sub_read_line_subviewer2, NULL, "subviewer 2.0" }, |
1067 sub_read_line_subrip09, | 1079 { sub_read_line_subrip09, NULL, "subrip 0.9" }, |
1068 sub_read_line_jacosub | 1080 { sub_read_line_jacosub, NULL, "jacosub" } |
1069 | |
1070 }; | 1081 }; |
1082 struct subreader *srp; | |
1083 | |
1071 if(filename==NULL) return NULL; //qnx segfault | 1084 if(filename==NULL) return NULL; //qnx segfault |
1072 fd=fopen (filename, "r"); if (!fd) return NULL; | 1085 fd=fopen (filename, "r"); if (!fd) return NULL; |
1073 | 1086 |
1074 sub_format=sub_autodetect (fd); | 1087 sub_format=sub_autodetect (fd); |
1075 if (sub_format==SUB_INVALID) {mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: Could not determine file format\n");return NULL;} | 1088 if (sub_format==SUB_INVALID) {mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: Could not determine file format\n");return NULL;} |
1076 mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Detected subtitle file format: %s\n", fmtname[sub_format]); | 1089 srp=sr+sub_format; |
1090 mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Detected subtitle file format: %s\n", srp->name); | |
1077 | 1091 |
1078 rewind (fd); | 1092 rewind (fd); |
1079 | 1093 |
1080 #ifdef USE_ICONV | 1094 #ifdef USE_ICONV |
1081 subcp_open(); | 1095 subcp_open(); |
1098 } | 1112 } |
1099 #ifndef USE_SORTSUB | 1113 #ifndef USE_SORTSUB |
1100 sub = &first[sub_num]; | 1114 sub = &first[sub_num]; |
1101 #endif | 1115 #endif |
1102 memset(sub, '\0', sizeof(subtitle)); | 1116 memset(sub, '\0', sizeof(subtitle)); |
1103 sub=func[sub_format](fd,sub); | 1117 sub=srp->read(fd,sub); |
1104 if(!sub) break; // EOF | 1118 if(!sub) break; // EOF |
1105 #ifdef USE_ICONV | 1119 #ifdef USE_ICONV |
1106 if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub); | 1120 if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub); |
1107 #endif | 1121 #endif |
1122 // Apply any post processing that needs recoding first | |
1123 if ((sub!=ERR) && srp->post) srp->post(sub); | |
1108 #ifdef USE_SORTSUB | 1124 #ifdef USE_SORTSUB |
1109 if(!sub_num || (first[sub_num - 1].start <= sub->start)){ | 1125 if(!sub_num || (first[sub_num - 1].start <= sub->start)){ |
1110 first[sub_num].start = sub->start; | 1126 first[sub_num].start = sub->start; |
1111 first[sub_num].end = sub->end; | 1127 first[sub_num].end = sub->end; |
1112 first[sub_num].lines = sub->lines; | 1128 first[sub_num].lines = sub->lines; |