Mercurial > mplayer.hg
annotate subreader.c @ 2161:d157f31719f6
test -e -> -d
author | arpi |
---|---|
date | Thu, 11 Oct 2001 11:58:24 +0000 |
parents | a9d91476085a |
children | f723e4e8f4fd |
rev | line source |
---|---|
258 | 1 /* |
2 * Subtitle reader with format autodetection | |
3 * | |
4 * Written by laaz | |
5 * Some code cleanup & realloc() by A'rpi/ESP-team | |
1081 | 6 * dunnowhat sub format by szabi |
258 | 7 */ |
8 | |
9 | |
10 #include <stdio.h> | |
11 #include <stdlib.h> | |
12 #include <string.h> | |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
13 #include <ctype.h> |
258 | 14 |
2151
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
15 #include "config.h" |
258 | 16 #include "subreader.h" |
17 | |
18 #define ERR (void *)-1 | |
19 | |
2151
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
20 #ifdef USE_ICONV |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
21 #include <iconv.h> |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
22 char *sub_cp=NULL; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
23 #endif |
258 | 24 |
25 int sub_uses_time=0; | |
26 int sub_errs=0; | |
624 | 27 int sub_num=0; // number of subtitle structs |
28 int sub_format=-1; // 0 for microdvd | |
29 // 1 for SubRip | |
921 | 30 // 2 for SubViewer |
624 | 31 // 3 for SAMI (smi) |
818 | 32 // 4 for vplayer format |
850 | 33 // 5 for RT format |
921 | 34 // 6 for ssa (Sub Station Alpha) |
1081 | 35 // 7 for ... erm ... dunnowhat. tell me if you know |
624 | 36 |
37 int eol(char p) { | |
38 return (p=='\r' || p=='\n' || p=='\0'); | |
39 } | |
40 | |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
41 static inline void trail_space(char *s) { |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
42 int i; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
43 while (isspace(*s)) strcpy(s, s + 1); |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
44 i = strlen(s) - 1; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
45 while (i > 0 && isspace(s[i])) s[i--] = '\0'; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
46 } |
624 | 47 |
48 subtitle *sub_read_line_sami(FILE *fd, subtitle *current) { | |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
49 static char line[1001]; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
50 static char *s = NULL; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
51 char text[1000], *p, *q; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
52 int state; |
624 | 53 |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
54 current->lines = current->start = current->end = 0; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
55 state = 0; |
624 | 56 |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
57 /* read the first line */ |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
58 if (!s) |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
59 if (!(s = fgets(line, 1000, fd))) return 0; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
60 |
624 | 61 do { |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
62 switch (state) { |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
63 |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
64 case 0: /* find "START=" */ |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
65 s = strstr (s, "Start="); |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
66 if (s) { |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
67 current->start = strtol (s + 6, &s, 0) / 10; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
68 state = 1; continue; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
69 } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
70 break; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
71 |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
72 case 1: /* find "<P" */ |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
73 if ((s = strstr (s, "<P"))) { s += 2; state = 2; continue; } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
74 break; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
75 |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
76 case 2: /* find ">" */ |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
77 if ((s = strchr (s, '>'))) { s++; state = 3; p = text; continue; } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
78 break; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
79 |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
80 case 3: /* get all text until '<' appears */ |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
81 if (*s == '\0') { break; } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
82 else if (*s == '<') { state = 4; } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
83 else if (!strncasecmp (s, " ", 6)) { *p++ = ' '; s += 6; } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
84 else if (*s == '\r') { s++; } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
85 else if (!strncasecmp (s, "<br>", 4) || *s == '\n') { |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
86 *p = '\0'; p = text; trail_space (text); |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
87 if (text[0] != '\0') |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
88 current->text[current->lines++] = strdup (text); |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
89 if (*s == '\n') s++; else s += 4; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
90 } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
91 else *p++ = *s++; |
624 | 92 continue; |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
93 |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
94 case 4: /* get current->end or skip <TAG> */ |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
95 q = strstr (s, "Start="); |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
96 if (q) { |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
97 current->end = strtol (q + 6, &q, 0) / 10 - 1; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
98 *p = '\0'; trail_space (text); |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
99 if (text[0] != '\0') |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
100 current->text[current->lines++] = strdup (text); |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
101 if (current->lines > 0) { state = 99; break; } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
102 state = 0; continue; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
103 } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
104 s = strchr (s, '>'); |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
105 if (s) { s++; state = 3; continue; } |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
106 break; |
624 | 107 } |
108 | |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
109 /* read next line */ |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
110 if (state != 99 && !(s = fgets (line, 1000, fd))) return 0; |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
111 |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
112 } while (state != 99); |
624 | 113 |
114 return current; | |
115 } | |
258 | 116 |
117 | |
118 char *sub_readtext(char *source, char **dest) { | |
119 int len=0; | |
932 | 120 char *p=source; |
258 | 121 |
932 | 122 while ( !eol(*p) && *p!= '|' ) { |
123 p++,len++; | |
124 } | |
258 | 125 |
126 *dest= (char *)malloc (len+1); | |
127 if (!dest) {return ERR;} | |
128 | |
129 strncpy(*dest, source, len); | |
130 (*dest)[len]=0; | |
131 | |
132 while (*p=='\r' || *p=='\n' || *p=='|') p++; | |
133 | |
134 if (*p) return p; // not-last text field | |
135 else return NULL; // last text field | |
136 } | |
137 | |
138 subtitle *sub_read_line_microdvd(FILE *fd,subtitle *current) { | |
139 char line[1001]; | |
140 char line2[1001]; | |
141 char *p, *next; | |
142 int i; | |
143 | |
1764 | 144 bzero (current, sizeof(subtitle)); |
258 | 145 |
146 do { | |
147 if (!fgets (line, 1000, fd)) return NULL; | |
932 | 148 } while (sscanf (line, "{%ld}{%ld}%[^\r\n]", &(current->start), &(current->end),line2) <3); |
258 | 149 |
932 | 150 p=line2; |
258 | 151 |
152 next=p, i=0; | |
1081 | 153 while ((next =sub_readtext (next, &(current->text[i])))) { |
270 | 154 if (current->text[i]==ERR) {return ERR;} |
258 | 155 i++; |
1081 | 156 if (i>=SUB_MAX_TEXT) { printf ("Too many lines in a subtitle\n");current->lines=i;return current;} |
258 | 157 } |
932 | 158 current->lines= ++i; |
258 | 159 |
160 return current; | |
161 } | |
162 | |
163 subtitle *sub_read_line_subrip(FILE *fd, subtitle *current) { | |
164 char line[1001]; | |
165 int a1,a2,a3,a4,b1,b2,b3,b4; | |
166 char *p=NULL, *q=NULL; | |
167 int len; | |
168 | |
1764 | 169 bzero (current, sizeof(subtitle)); |
258 | 170 |
1764 | 171 while (1) { |
258 | 172 if (!fgets (line, 1000, fd)) return NULL; |
269 | 173 if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) continue; |
258 | 174 current->start = a1*360000+a2*6000+a3*100+a4; |
175 current->end = b1*360000+b2*6000+b3*100+b4; | |
176 | |
177 if (!fgets (line, 1000, fd)) return NULL; | |
178 | |
179 p=q=line; | |
180 for (current->lines=1; current->lines < SUB_MAX_TEXT; current->lines++) { | |
181 for (q=p,len=0; *p && *p!='\r' && *p!='\n' && strncmp(p,"[br]",4); p++,len++); | |
182 current->text[current->lines-1]=(char *)malloc (len+1); | |
183 if (!current->text[current->lines-1]) return ERR; | |
184 strncpy (current->text[current->lines-1], q, len); | |
270 | 185 current->text[current->lines-1][len]='\0'; |
258 | 186 if (!*p || *p=='\r' || *p=='\n') break; |
187 while (*p++!=']'); | |
188 } | |
1764 | 189 break; |
258 | 190 } |
191 return current; | |
192 } | |
193 | |
194 subtitle *sub_read_line_third(FILE *fd,subtitle *current) { | |
195 char line[1001]; | |
196 int a1,a2,a3,a4,b1,b2,b3,b4; | |
197 char *p=NULL; | |
198 int i,len; | |
199 | |
1764 | 200 bzero (current, sizeof(subtitle)); |
258 | 201 |
202 while (!current->text[0]) { | |
203 if (!fgets (line, 1000, fd)) return NULL; | |
269 | 204 if ((len=sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8) |
258 | 205 continue; |
206 current->start = a1*360000+a2*6000+a3*100+a4/10; | |
207 current->end = b1*360000+b2*6000+b3*100+b4/10; | |
208 for (i=0; i<SUB_MAX_TEXT;) { | |
269 | 209 if (!fgets (line, 1000, fd)) break; |
258 | 210 len=0; |
211 for (p=line; *p!='\n' && *p!='\r' && *p; p++,len++); | |
212 if (len) { | |
213 current->text[i]=(char *)malloc (len+1); | |
214 if (!current->text[i]) return ERR; | |
270 | 215 strncpy (current->text[i], line, len); current->text[i][len]='\0'; |
258 | 216 i++; |
217 } else { | |
218 break; | |
219 } | |
220 } | |
221 current->lines=i; | |
222 } | |
223 return current; | |
224 } | |
225 | |
818 | 226 subtitle *sub_read_line_vplayer(FILE *fd,subtitle *current) { |
227 char line[1001]; | |
228 char line2[1001]; | |
229 int a1,a2,a3,b1,b2,b3; | |
1081 | 230 char *p=NULL, *next; |
858 | 231 int i,len,len2,plen; |
818 | 232 |
1764 | 233 bzero (current, sizeof(subtitle)); |
818 | 234 |
235 while (!current->text[0]) { | |
236 if (!fgets (line, 1000, fd)) return NULL; | |
858 | 237 if ((len=sscanf (line, "%d:%d:%d:%n",&a1,&a2,&a3,&plen)) < 3) |
818 | 238 continue; |
239 if (!fgets (line2, 1000, fd)) return NULL; | |
240 if ((len2=sscanf (line2, "%d:%d:%d:",&b1,&b2,&b3)) < 3) | |
241 continue; | |
242 // przewiñ o linijkê do ty³u: | |
243 fseek(fd,-strlen(line2),SEEK_CUR); | |
244 | |
245 current->start = a1*360000+a2*6000+a3*100; | |
246 current->end = b1*360000+b2*6000+b3*100; | |
896
d46de26aef48
there is another format that get detected as vplayers.
eyck
parents:
892
diff
changeset
|
247 if ((current->end - current->start) > 1000) {current->end = current->start + 1000;} // not too long though. |
818 | 248 // teraz czas na wkopiowanie stringu |
1640
cbedcfab877b
Fixup to vplayer subtitle submitted to sourceforge by Igor Wojnicki
eyck
parents:
1501
diff
changeset
|
249 p=line; |
cbedcfab877b
Fixup to vplayer subtitle submitted to sourceforge by Igor Wojnicki
eyck
parents:
1501
diff
changeset
|
250 // finds the body of the subtitle |
cbedcfab877b
Fixup to vplayer subtitle submitted to sourceforge by Igor Wojnicki
eyck
parents:
1501
diff
changeset
|
251 for (i=0; i<3; i++){ |
cbedcfab877b
Fixup to vplayer subtitle submitted to sourceforge by Igor Wojnicki
eyck
parents:
1501
diff
changeset
|
252 p=strchr(p,':')+1; |
cbedcfab877b
Fixup to vplayer subtitle submitted to sourceforge by Igor Wojnicki
eyck
parents:
1501
diff
changeset
|
253 } |
cbedcfab877b
Fixup to vplayer subtitle submitted to sourceforge by Igor Wojnicki
eyck
parents:
1501
diff
changeset
|
254 i=0; |
cbedcfab877b
Fixup to vplayer subtitle submitted to sourceforge by Igor Wojnicki
eyck
parents:
1501
diff
changeset
|
255 |
818 | 256 if (*p!='|') { |
257 // | |
258 next = p,i=0; | |
259 while ((next =sub_readtext (next, &(current->text[i])))) { | |
260 if (current->text[i]==ERR) {return ERR;} | |
261 i++; | |
1081 | 262 if (i>=SUB_MAX_TEXT) { printf ("Too many lines in a subtitle\n");current->lines=i;return current;} |
818 | 263 } |
264 current->lines=i+1; | |
265 } | |
266 } | |
267 return current; | |
268 } | |
269 | |
850 | 270 subtitle *sub_read_line_rt(FILE *fd,subtitle *current) { |
271 //TODO: This format uses quite rich (sub/super)set of xhtml | |
272 // I couldn't check it since DTD is not included. | |
273 // WARNING: full XML parses can be required for proper parsing | |
274 char line[1001]; | |
275 int a1,a2,a3,a4,b1,b2,b3,b4; | |
276 char *p=NULL,*next=NULL; | |
277 int i,len,plen; | |
278 | |
1764 | 279 bzero (current, sizeof(subtitle)); |
850 | 280 |
281 while (!current->text[0]) { | |
282 if (!fgets (line, 1000, fd)) return NULL; | |
283 //TODO: it seems that format of time is not easily determined, it may be 1:12, 1:12.0 or 0:1:12.0 | |
284 //to describe the same moment in time. Maybe there are even more formats in use. | |
285 //if ((len=sscanf (line, "<Time Begin=\"%d:%d:%d.%d\" End=\"%d:%d:%d.%d\"",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8) | |
286 plen=a1=a2=a3=a4=b1=b2=b3=b4=0; | |
287 if ( | |
288 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&plen)) < 4) && | |
289 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&b2,&b3,&b4,&plen)) < 5) && | |
290 // ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&plen)) < 5) && | |
291 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d.%d\" %*[Ee]nd=\"%d:%d.%d\"%*[^<]<clear/>%n",&a2,&a3,&a4,&b2,&b3,&b4,&plen)) < 6) && | |
292 ((len=sscanf (line, "<%*[tT]ime %*[bB]egin=\"%d:%d:%d.%d\" %*[Ee]nd=\"%d:%d:%d.%d\"%*[^<]<clear/>%n",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4,&plen)) < 8) | |
293 ) | |
294 continue; | |
295 current->start = a1*360000+a2*6000+a3*100+a4/10; | |
296 current->end = b1*360000+b2*6000+b3*100+b4/10; | |
297 p=line; p+=plen;i=0; | |
298 // TODO: I don't know what kind of convention is here for marking multiline subs, maybe <br/> like in xml? | |
299 next = strstr(line,"<clear/>")+8;i=0; | |
300 while ((next =sub_readtext (next, &(current->text[i])))) { | |
301 if (current->text[i]==ERR) {return ERR;} | |
302 i++; | |
1081 | 303 if (i>=SUB_MAX_TEXT) { printf ("Too many lines in a subtitle\n");current->lines=i;return current;} |
850 | 304 } |
305 current->lines=i+1; | |
306 } | |
307 return current; | |
308 } | |
309 | |
921 | 310 subtitle *sub_read_line_ssa(FILE *fd,subtitle *current) { |
311 int hour1, min1, sec1, hunsec1, | |
312 hour2, min2, sec2, hunsec2, nothing; | |
2141 | 313 int num; |
921 | 314 |
315 char line[1000], | |
2140 | 316 line3[1000], |
317 *line2; | |
2141 | 318 char *tmp; |
319 | |
921 | 320 do { |
321 if (!fgets (line, 1000, fd)) return NULL; | |
322 } while (sscanf (line, "Dialogue: Marked=%d,%d:%d:%d.%d,%d:%d:%d.%d," | |
2140 | 323 "%[^\n\r]", ¬hing, |
324 &hour1, &min1, &sec1, &hunsec1, | |
325 &hour2, &min2, &sec2, &hunsec2, | |
326 line3) < 9); | |
327 line2=strstr(line3,",,"); | |
328 if (!line2) return NULL; | |
329 line2 ++; | |
330 line2 ++; | |
331 | |
2141 | 332 current->lines=1;num=0; |
921 | 333 current->start = 360000*hour1 + 6000*min1 + 100*sec1 + hunsec1; |
334 current->end = 360000*hour2 + 6000*min2 + 100*sec2 + hunsec2; | |
2141 | 335 |
336 while (tmp=strstr(line2, "\\n")) { | |
337 current->text[num]=(char *)malloc(tmp-line2+1); | |
338 strncpy (current->text[num], line2, tmp-line2); | |
339 current->text[num][tmp-line2]='\0'; | |
340 line2=tmp+2; | |
341 num++; | |
342 current->lines++; | |
343 if (current->lines >= SUB_MAX_TEXT) return current; | |
344 } | |
345 | |
346 | |
347 current->text[num]=(char *) malloc(strlen(line2)+1); | |
348 strcpy(current->text[num],line2); | |
818 | 349 |
921 | 350 return current; |
351 } | |
258 | 352 |
1081 | 353 subtitle *sub_read_line_dunnowhat(FILE *fd,subtitle *current) { |
354 char line[1001]; | |
355 char text[1001]; | |
356 | |
1764 | 357 bzero (current, sizeof(subtitle)); |
1081 | 358 |
359 if (!fgets (line, 1000, fd)) | |
360 return NULL; | |
361 if (sscanf (line, "%ld,%ld,\"%[^\"]", &(current->start), | |
362 &(current->end), text) <3) | |
363 return ERR; | |
364 current->text[0] = strdup(text); | |
365 current->lines = 1; | |
366 | |
367 return current; | |
368 } | |
369 | |
258 | 370 int sub_autodetect (FILE *fd) { |
371 char line[1001]; | |
372 int i,j=0; | |
373 // char *p; | |
374 | |
624 | 375 while (j < 100) { |
258 | 376 j++; |
377 if (!fgets (line, 1000, fd)) | |
378 return -1; | |
379 | |
624 | 380 if (sscanf (line, "{%d}{%d}", &i, &i)==2) |
258 | 381 {sub_uses_time=0;return 0;} |
269 | 382 if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d", &i, &i, &i, &i, &i, &i, &i, &i)==8) |
258 | 383 {sub_uses_time=1;return 1;} |
269 | 384 if (sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d", &i, &i, &i, &i, &i, &i, &i, &i)==8) |
258 | 385 {sub_uses_time=1;return 2;} |
624 | 386 if (strstr (line, "<SAMI>")) |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
387 {sub_uses_time=1; return 3;} |
818 | 388 if (sscanf (line, "%d:%d:%d:", &i, &i, &i )==3) |
389 {sub_uses_time=1;return 4;} | |
850 | 390 //TODO: just checking if first line of sub starts with "<" is WAY |
913
18c43d261c35
corrected strcmp() bug, now it works again with every subs (it was broken)
laaz
parents:
896
diff
changeset
|
391 // too weak test for RT |
18c43d261c35
corrected strcmp() bug, now it works again with every subs (it was broken)
laaz
parents:
896
diff
changeset
|
392 // Please someone who knows the format of RT... FIX IT!!! |
921 | 393 // It may conflict with other sub formats in the future (actually it doesn't) |
913
18c43d261c35
corrected strcmp() bug, now it works again with every subs (it was broken)
laaz
parents:
896
diff
changeset
|
394 if ( *line == '<' ) |
850 | 395 {sub_uses_time=1;return 5;} |
921 | 396 |
397 // I have only seen only 1 piece of .ssa file. | |
398 // It may be not correct (tell me if it's not) | |
399 if (!memcmp(line, "Dialogue: Marked", 16)) | |
400 {sub_uses_time=1; return 6;} | |
1081 | 401 if (sscanf (line, "%d,%d,\"%c", &i, &i, (char *) &i) == 3) |
402 {sub_uses_time=0;return 7;} | |
258 | 403 } |
624 | 404 |
405 return -1; // too many bad lines | |
258 | 406 } |
2151
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
407 |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
408 extern int sub_utf8; |
258 | 409 |
2151
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
410 #ifdef USE_ICONV |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
411 static iconv_t icdsc; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
412 |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
413 void subcp_open (void) |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
414 { |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
415 char *tocp = "UTF-8"; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
416 icdsc = (iconv_t)(-1); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
417 if (sub_cp){ |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
418 if ((icdsc = iconv_open (tocp, sub_cp)) != (iconv_t)(-1)){ |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
419 printf ("SUB: opened iconv descriptor.\n"); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
420 sub_utf8 = 2; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
421 } else |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
422 printf ("SUB: error opening iconv descriptor.\n"); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
423 } |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
424 } |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
425 |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
426 void subcp_close (void) |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
427 { |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
428 if (icdsc != (iconv_t)(-1)){ |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
429 (void) iconv_close (icdsc); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
430 printf ("SUB: closed iconv descriptor.\n"); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
431 } |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
432 } |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
433 |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
434 #define ICBUFFSIZE 512 |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
435 static char icbuffer[ICBUFFSIZE]; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
436 |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
437 subtitle* subcp_recode (subtitle *sub) |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
438 { |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
439 int l=sub->lines; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
440 size_t ileft, oleft, otlen; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
441 char *op, *ip, *ot; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
442 |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
443 while (l){ |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
444 op = icbuffer; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
445 ip = sub->text[--l]; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
446 ileft = strlen(ip); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
447 oleft = ICBUFFSIZE - 1; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
448 |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
449 if (iconv(icdsc, (const char **) &ip, &ileft, |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
450 &op, &oleft) == (size_t)(-1)) { |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
451 printf ("SUB: error recoding line.\n"); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
452 l++; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
453 break; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
454 } |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
455 if (!(ot = (char *)malloc(op - icbuffer + 1))){ |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
456 printf ("SUB: error allocating mem.\n"); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
457 l++; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
458 break; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
459 } |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
460 *op='\0' ; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
461 strcpy (ot, icbuffer); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
462 free (sub->text[l]); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
463 sub->text[l] = ot; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
464 } |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
465 if (l){ |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
466 for (l = sub->lines; l;) |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
467 free (sub->text[--l]); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
468 return ERR; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
469 } |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
470 return sub; |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
471 } |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
472 |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
473 #endif |
258 | 474 |
475 subtitle* sub_read_file (char *filename) { | |
476 FILE *fd; | |
477 int n_max; | |
478 subtitle *first; | |
1081 | 479 subtitle * (*func[])(FILE *fd,subtitle *dest)= |
258 | 480 { |
481 sub_read_line_microdvd, | |
482 sub_read_line_subrip, | |
624 | 483 sub_read_line_third, |
818 | 484 sub_read_line_sami, |
850 | 485 sub_read_line_vplayer, |
921 | 486 sub_read_line_rt, |
1081 | 487 sub_read_line_ssa, |
488 sub_read_line_dunnowhat | |
258 | 489 }; |
490 | |
491 fd=fopen (filename, "r"); if (!fd) return NULL; | |
492 | |
493 sub_format=sub_autodetect (fd); | |
494 if (sub_format==-1) {printf ("SUB: Could not determine file format\n");return NULL;} | |
624 | 495 printf ("SUB: Detected subtitle file format: %d\n",sub_format); |
258 | 496 |
497 rewind (fd); | |
498 | |
2151
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
499 #ifdef USE_ICONV |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
500 subcp_open(); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
501 #endif |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
502 |
258 | 503 sub_num=0;n_max=32; |
504 first=(subtitle *)malloc(n_max*sizeof(subtitle)); | |
505 if(!first) return NULL; | |
506 | |
507 while(1){ | |
508 subtitle *sub; | |
509 if(sub_num>=n_max){ | |
510 n_max+=16; | |
511 first=realloc(first,n_max*sizeof(subtitle)); | |
512 } | |
513 sub=func[sub_format](fd,&first[sub_num]); | |
514 if(!sub) break; // EOF | |
2151
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
515 #ifdef USE_ICONV |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
516 if ((sub!=ERR) && (sub_utf8 & 2)) sub=subcp_recode(sub); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
517 #endif |
258 | 518 if(sub==ERR) ++sub_errs; else ++sub_num; // Error vs. Valid |
519 } | |
520 | |
521 fclose(fd); | |
522 | |
2151
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
523 #ifdef USE_ICONV |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
524 subcp_close(); |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
525 #endif |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
526 |
258 | 527 // printf ("SUB: Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use"); |
269 | 528 printf ("SUB: Read %i subtitles", sub_num); |
624 | 529 if (sub_errs) printf (", %i bad line(s).\n", sub_errs); |
269 | 530 else printf (".\n"); |
258 | 531 |
532 return first; | |
533 } | |
534 | |
892 | 535 #if 0 |
509 | 536 char * strreplace( char * in,char * what,char * whereof ) |
537 { | |
538 int i; | |
539 char * tmp; | |
540 | |
541 if ( ( in == NULL )||( what == NULL )||( whereof == NULL )||( ( tmp=strstr( in,what ) ) == NULL ) ) return NULL; | |
542 for( i=0;i<strlen( whereof );i++ ) tmp[i]=whereof[i]; | |
543 if ( strlen( what ) > strlen( whereof ) ) tmp[i]=0; | |
544 return in; | |
545 } | |
892 | 546 #endif |
509 | 547 |
892 | 548 char * sub_filename(char* path, char * fname ) |
509 | 549 { |
892 | 550 char * sub_name1; |
551 char * sub_name2; | |
934
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
552 char * aviptr1, * aviptr2, * tmp; |
892 | 553 int i,j; |
554 FILE * f; | |
555 int pos=0; | |
556 char * sub_exts[] = | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1081
diff
changeset
|
557 { ".utf", |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1081
diff
changeset
|
558 ".UTF", |
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1081
diff
changeset
|
559 ".sub", |
509 | 560 ".SUB", |
561 ".srt", | |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
562 ".SRT", |
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
563 ".smi", |
850 | 564 ".SMI", |
565 ".rt", | |
566 ".RT", | |
567 ".txt", | |
1081 | 568 ".TXT", |
569 ".ssa", | |
570 ".SSA"}; | |
892 | 571 |
934
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
572 |
509 | 573 if ( fname == NULL ) return NULL; |
892 | 574 |
575 sub_name1=strrchr(fname,'.'); | |
576 if (!sub_name1) return NULL; | |
577 pos=sub_name1-fname; | |
578 | |
934
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
579 sub_name1=malloc(strlen(fname)+8); |
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
580 strcpy(sub_name1,fname); |
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
581 |
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
582 sub_name2=malloc (strlen(path) + strlen(fname) + 8); |
1081 | 583 if ((tmp=strrchr(fname,'/'))) |
934
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
584 sprintf (sub_name2, "%s%s", path, tmp+1); |
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
585 else |
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
586 sprintf (sub_name2, "%s%s", path, fname); |
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
587 |
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
588 aviptr1=strrchr(sub_name1,'.'); |
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
589 aviptr2=strrchr(sub_name2,'.'); |
892 | 590 |
591 for(j=0;j<=1;j++){ | |
592 char* sub_name=j?sub_name1:sub_name2; | |
2151
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
593 #ifdef USE_ICONV |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
594 for ( i=(sub_cp?2:0);i<(sizeof(sub_exts)/sizeof(char*));i++ ) { |
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
595 #else |
892 | 596 for ( i=0;i<(sizeof(sub_exts)/sizeof(char*));i++ ) { |
2151
a9d91476085a
modifications to use iconv(3) function to recode text of subs (autodetect)
atlka
parents:
2141
diff
changeset
|
597 #endif |
934
b2c7c4b49948
Gabucino (CGA user)'s request (finds default.subs well)
laaz
parents:
932
diff
changeset
|
598 strcpy(j?aviptr1:aviptr2,sub_exts[i]); |
935 | 599 // printf("trying: '%s'\n",sub_name); |
892 | 600 if((f=fopen( sub_name,"rt" ))) { |
509 | 601 fclose( f ); |
602 printf( "SUB: Detected sub file: %s\n",sub_name ); | |
1501
d40f2b686846
changes according to -utf8 option, draw_osd() function added
atlka
parents:
1081
diff
changeset
|
603 if (i<2) sub_utf8=1; |
509 | 604 return sub_name; |
892 | 605 } |
509 | 606 } |
892 | 607 } |
608 | |
509 | 609 return NULL; |
610 } | |
611 | |
1761 | 612 void list_sub_file(subtitle* subs){ |
613 int i,j; | |
614 | |
615 for(j=0;j<sub_num;j++){ | |
616 subtitle* egysub=&subs[j]; | |
617 printf ("%i line%c (%li-%li) ", | |
618 egysub->lines, | |
619 (1==egysub->lines)?' ':'s', | |
620 egysub->start, | |
621 egysub->end); | |
622 for (i=0; i<egysub->lines; i++) { | |
623 printf ("%s%s",egysub->text[i], i==egysub->lines-1?"":" <BREAK> "); | |
624 } | |
625 printf ("\n"); | |
626 } | |
627 | |
628 printf ("Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use"); | |
629 printf ("Read %i subtitles, %i errors.\n", sub_num, sub_errs); | |
630 | |
631 } | |
632 | |
625 | 633 #if 0 |
258 | 634 int main(int argc, char **argv) { // for testing |
635 | |
636 int i,j; | |
637 subtitle *subs; | |
638 subtitle *egysub; | |
639 | |
640 if(argc<2){ | |
641 printf("\nUsage: subreader filename.sub\n\n"); | |
642 exit(1); | |
643 } | |
644 | |
624 | 645 subs=sub_read_file(argv[1]); |
258 | 646 if(!subs){ |
647 printf("Couldn't load file... let's write a bugreport :)\n"); | |
648 exit(1); | |
649 } | |
1761 | 650 |
651 list_sub_file(subs); | |
258 | 652 |
653 return 0; | |
654 } | |
706
8a7666a78f83
better .smi support and display two-byte characters- patch by Sunjin Yang
arpi_esp
parents:
678
diff
changeset
|
655 #endif |