summaryrefslogtreecommitdiffstats
path: root/subreader.c
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-01-19 00:54:55 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-01-19 00:54:55 +0000
commit824048ca440aaab154eefaefd1a8d3abc14e8314 (patch)
tree61cdba7101796d37743f542975b505918f014e55 /subreader.c
parent586233bf3daa7770550eb47e9aedb7c0c519d5df (diff)
downloadmpv-824048ca440aaab154eefaefd1a8d3abc14e8314.tar.bz2
mpv-824048ca440aaab154eefaefd1a8d3abc14e8314.tar.xz
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> git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@9010 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'subreader.c')
-rw-r--r--subreader.c82
1 files changed, 49 insertions, 33 deletions
diff --git a/subreader.c b/subreader.c
index 5ea73609aa..620329ea0d 100644
--- a/subreader.c
+++ b/subreader.c
@@ -425,7 +425,7 @@ subtitle *sub_read_line_ssa(FILE *fd,subtitle *current) {
char line[LINE_LEN+1],
line3[LINE_LEN+1],
- *line2,*so,*de;
+ *line2;
char *tmp;
do {
@@ -450,19 +450,6 @@ subtitle *sub_read_line_ssa(FILE *fd,subtitle *current) {
if(comma < max_comma)max_comma = comma;
/* eliminate the trailing comma */
if(*line2 == ',') line2++;
- /* eliminate any text enclosed with {}, they are font and color settings */
- so=de=line2;
- while (*so) {
- if(*so == '{') {
- for (; *so && *so!='}'; so++);
- if(*so) so++;
- }
- if(*so) {
- *de=*so;
- so++; de++;
- }
- }
- *de=*so;
current->lines=0;num=0;
current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1;
@@ -484,6 +471,27 @@ subtitle *sub_read_line_ssa(FILE *fd,subtitle *current) {
return current;
}
+void sub_pp_ssa(subtitle *sub) {
+ int l=sub->lines;
+ char *so,*de,*start;
+
+ while (l){
+ /* eliminate any text enclosed with {}, they are font and color settings */
+ so=de=sub->text[--l];
+ while (*so) {
+ if(*so == '{' && so[1]=='\\') {
+ for (start=so; *so && *so!='}'; so++);
+ if(*so) so++; else so=start;
+ }
+ if(*so) {
+ *de=*so;
+ so++; de++;
+ }
+ }
+ *de=*so;
+ }
+}
+
subtitle *sub_read_line_dunnowhat(FILE *fd,subtitle *current) {
char line[LINE_LEN+1];
char text[LINE_LEN+1];
@@ -1045,35 +1053,41 @@ static void adjust_subs_time(subtitle* sub, float subtime, float fps, int block)
if (n) mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Adjusted %d subtitle(s).\n", n);
}
+struct subreader {
+ subtitle * (*read)(FILE *fd,subtitle *dest);
+ void (*post)(subtitle *dest);
+ const char *name;
+};
+
subtitle* sub_read_file (char *filename, float fps) {
FILE *fd;
int n_max, n_first, i, j, sub_first, sub_orig;
subtitle *first, *second, *sub;
- char *fmtname[] = { "microdvd", "subrip", "subviewer", "sami", "vplayer",
- "rt", "ssa", "dunnowhat", "mpsub", "aqt", "subviewer 2.0", "subrip 0.9", "jacosub" };
- subtitle * (*func[])(FILE *fd,subtitle *dest)=
+ struct subreader sr[]=
{
- sub_read_line_microdvd,
- sub_read_line_subrip,
- sub_read_line_subviewer,
- sub_read_line_sami,
- sub_read_line_vplayer,
- sub_read_line_rt,
- sub_read_line_ssa,
- sub_read_line_dunnowhat,
- sub_read_line_mpsub,
- sub_read_line_aqt,
- sub_read_line_subviewer2,
- sub_read_line_subrip09,
- sub_read_line_jacosub
-
+ { sub_read_line_microdvd, NULL, "microdvd" },
+ { sub_read_line_subrip, NULL, "subrip" },
+ { sub_read_line_subviewer, NULL, "subviewer" },
+ { sub_read_line_sami, NULL, "sami" },
+ { sub_read_line_vplayer, NULL, "vplayer" },
+ { sub_read_line_rt, NULL, "rt" },
+ { sub_read_line_ssa, sub_pp_ssa, "ssa" },
+ { sub_read_line_dunnowhat, NULL, "dunnowhat" },
+ { sub_read_line_mpsub, NULL, "mpsub" },
+ { sub_read_line_aqt, NULL, "aqt" },
+ { sub_read_line_subviewer2, NULL, "subviewer 2.0" },
+ { sub_read_line_subrip09, NULL, "subrip 0.9" },
+ { sub_read_line_jacosub, NULL, "jacosub" }
};
+ struct subreader *srp;
+
if(filename==NULL) return NULL; //qnx segfault
fd=fopen (filename, "r"); if (!fd) return NULL;
sub_format=sub_autodetect (fd);
if (sub_format==SUB_INVALID) {mp_msg(MSGT_SUBREADER,MSGL_WARN,"SUB: Could not determine file format\n");return NULL;}
- mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Detected subtitle file format: %s\n", fmtname[sub_format]);
+ srp=sr+sub_format;
+ mp_msg(MSGT_SUBREADER,MSGL_INFO,"SUB: Detected subtitle file format: %s\n", srp->name);
rewind (fd);
@@ -1100,11 +1114,13 @@ subtitle* sub_read_file (char *filename, float fps) {
sub = &first[sub_num];
#endif
memset(sub, '\0', sizeof(subtitle));
- sub=func[sub_format](fd,sub);
+ sub=srp->read(fd,sub);
if(!sub) break; // EOF
#ifdef USE_ICONV
if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub);
#endif
+ // Apply any post processing that needs recoding first
+ if ((sub!=ERR) && srp->post) srp->post(sub);
#ifdef USE_SORTSUB
if(!sub_num || (first[sub_num - 1].start <= sub->start)){
first[sub_num].start = sub->start;