annotate subreader.c @ 359:db6b78fa7331

video mode change supported
author szabii
date Wed, 11 Apr 2001 20:52:56 +0000
parents 7d544020e398
children 1b2cd175236f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
1 /*
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
2 * Subtitle reader with format autodetection
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
3 *
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
4 * Written by laaz
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
5 * Some code cleanup & realloc() by A'rpi/ESP-team
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
6 */
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
7
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
8
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
9 #include <stdio.h>
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
10 #include <stdlib.h>
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
11 #include <string.h>
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
12
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
13 #include "subreader.h"
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
14
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
15 #define ERR (void *)-1
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
16
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
17
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
18 int sub_uses_time=0;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
19 int sub_errs=0;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
20 int sub_num=0; // number of subtitle structs
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
21 int sub_format=-1; // 0 for microdvd, 1 for SubRip, 2 for the third format
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
22
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
23
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
24 char *sub_readtext(char *source, char **dest) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
25 int len=0;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
26 char *p;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
27
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
28 for (p=source;*p!='\r' && *p!='\n' && *p!='|'; p++,len++);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
29
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
30 *dest= (char *)malloc (len+1);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
31 if (!dest) {return ERR;}
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
32
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
33 strncpy(*dest, source, len);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
34 (*dest)[len]=0;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
35
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
36 while (*p=='\r' || *p=='\n' || *p=='|') p++;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
37
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
38 if (*p) return p; // not-last text field
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
39 else return NULL; // last text field
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
40 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
41
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
42
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
43
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
44 subtitle *sub_read_line_microdvd(FILE *fd,subtitle *current) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
45 char line[1001];
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
46 char line2[1001];
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
47 char *p, *next;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
48 int i;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
49
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
50 bzero (current, sizeof(current));
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
51
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
52 do {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
53 if (!fgets (line, 1000, fd)) return NULL;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
54 } while (*line=='\n' || *line == '\r' || !*line);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
55
269
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
56 if (sscanf (line, "{%d}{%d}%s", &(current->start), &(current->end),line2) <2) {return ERR;}
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
57
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
58 p=line;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
59 while (*p++!='}');
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
60 while (*p++!='}');
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
61
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
62 next=p, i=0;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
63 while ((next =sub_readtext (next, &(current->text[i])))) {
270
7d544020e398 no more garbage! (fixed by laaz)
gabucino
parents: 269
diff changeset
64 if (current->text[i]==ERR) {return ERR;}
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
65 i++;
270
7d544020e398 no more garbage! (fixed by laaz)
gabucino
parents: 269
diff changeset
66 if (i>SUB_MAX_TEXT) { printf ("Too many lines in a subtitle\n");current->lines=i;return;}
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
67 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
68 current->lines=i+1;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
69
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
70 return current;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
71 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
72
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
73 subtitle *sub_read_line_subrip(FILE *fd, subtitle *current) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
74 char line[1001];
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
75 int a1,a2,a3,a4,b1,b2,b3,b4;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
76 char *p=NULL, *q=NULL;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
77 int len;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
78
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
79 bzero (current, sizeof(current));
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
80
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
81 while (!current->text[0]) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
82 if (!fgets (line, 1000, fd)) return NULL;
269
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
83 if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) continue;
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
84 current->start = a1*360000+a2*6000+a3*100+a4;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
85 current->end = b1*360000+b2*6000+b3*100+b4;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
86
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
87 if (!fgets (line, 1000, fd)) return NULL;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
88
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
89 p=q=line;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
90 for (current->lines=1; current->lines < SUB_MAX_TEXT; current->lines++) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
91 for (q=p,len=0; *p && *p!='\r' && *p!='\n' && strncmp(p,"[br]",4); p++,len++);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
92 current->text[current->lines-1]=(char *)malloc (len+1);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
93 if (!current->text[current->lines-1]) return ERR;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
94 strncpy (current->text[current->lines-1], q, len);
270
7d544020e398 no more garbage! (fixed by laaz)
gabucino
parents: 269
diff changeset
95 current->text[current->lines-1][len]='\0';
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
96 if (!*p || *p=='\r' || *p=='\n') break;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
97 while (*p++!=']');
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
98 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
99 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
100 return current;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
101 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
102
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
103 subtitle *sub_read_line_third(FILE *fd,subtitle *current) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
104 char line[1001];
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
105 int a1,a2,a3,a4,b1,b2,b3,b4;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
106 char *p=NULL;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
107 int i,len;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
108
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
109 bzero (current, sizeof(current));
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
110
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
111 while (!current->text[0]) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
112 if (!fgets (line, 1000, fd)) return NULL;
269
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
113 if ((len=sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8)
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
114 continue;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
115 current->start = a1*360000+a2*6000+a3*100+a4/10;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
116 current->end = b1*360000+b2*6000+b3*100+b4/10;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
117 for (i=0; i<SUB_MAX_TEXT;) {
269
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
118 if (!fgets (line, 1000, fd)) break;
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
119 len=0;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
120 for (p=line; *p!='\n' && *p!='\r' && *p; p++,len++);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
121 if (len) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
122 current->text[i]=(char *)malloc (len+1);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
123 if (!current->text[i]) return ERR;
270
7d544020e398 no more garbage! (fixed by laaz)
gabucino
parents: 269
diff changeset
124 strncpy (current->text[i], line, len); current->text[i][len]='\0';
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
125 i++;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
126 } else {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
127 break;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
128 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
129 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
130 current->lines=i;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
131 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
132 return current;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
133 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
134
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
135
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
136 int sub_autodetect (FILE *fd) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
137 char line[1001];
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
138 int i,j=0;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
139 // char *p;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
140
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
141 while (1) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
142 j++;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
143 if (!fgets (line, 1000, fd))
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
144 return -1;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
145
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
146 // if (sscanf (line, "{%i}{%i}", &i, &i, p)==2) // ha valaki tudja miert 2, mondja mar el nekem ;)
269
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
147 if (sscanf (line, "{%d}{%d}", &i, &i)==2) // ha valaki tudja miert 2, mondja mar el nekem ;)
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
148 {sub_uses_time=0;return 0;}
269
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
149 if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d", &i, &i, &i, &i, &i, &i, &i, &i)==8)
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
150 {sub_uses_time=1;return 1;}
269
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
151 if (sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d", &i, &i, &i, &i, &i, &i, &i, &i)==8)
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
152 {sub_uses_time=1;return 2;}
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
153 if (j>100) return -1; // too many bad lines or bad coder
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
154 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
155 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
156
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
157
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
158 subtitle* sub_read_file (char *filename) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
159 FILE *fd;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
160 int n_max;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
161 subtitle *first;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
162 subtitle * (*func[3])(FILE *fd,subtitle *dest)=
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
163 {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
164 sub_read_line_microdvd,
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
165 sub_read_line_subrip,
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
166 sub_read_line_third
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
167 };
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
168
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
169 fd=fopen (filename, "r"); if (!fd) return NULL;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
170
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
171 sub_format=sub_autodetect (fd);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
172 if (sub_format==-1) {printf ("SUB: Could not determine file format\n");return NULL;}
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
173 printf ("SUB: Detected subtitle file format: %i\n",sub_format);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
174
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
175 rewind (fd);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
176
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
177 sub_num=0;n_max=32;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
178 first=(subtitle *)malloc(n_max*sizeof(subtitle));
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
179 if(!first) return NULL;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
180
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
181 while(1){
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
182 subtitle *sub;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
183 if(sub_num>=n_max){
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
184 n_max+=16;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
185 first=realloc(first,n_max*sizeof(subtitle));
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
186 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
187 sub=func[sub_format](fd,&first[sub_num]);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
188 if(!sub) break; // EOF
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
189 if(sub==ERR) ++sub_errs; else ++sub_num; // Error vs. Valid
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
190 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
191
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
192 fclose(fd);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
193
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
194 // printf ("SUB: Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use");
269
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
195 printf ("SUB: Read %i subtitles", sub_num);
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
196 if (sub_errs) printf (", %i error(s).\n", sub_errs);
f5a7323af43f applied patch by lez
arpi_esp
parents: 258
diff changeset
197 else printf (".\n");
258
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
198
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
199 return first;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
200 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
201
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
202 #if 0
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
203 int main(int argc, char **argv) { // for testing
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
204
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
205 int i,j;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
206 subtitle *subs;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
207 subtitle *egysub;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
208
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
209 if(argc<2){
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
210 printf("\nUsage: subreader filename.sub\n\n");
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
211 exit(1);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
212 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
213
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
214 subs=sub_get_subtitles(argv[1]);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
215 if(!subs){
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
216 printf("Couldn't load file... let's write a bugreport :)\n");
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
217 exit(1);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
218 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
219
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
220 for(j=0;j<sub_num;j++){
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
221 egysub=&subs[j];
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
222 printf ("%i line%c (%i-%i) ",
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
223 egysub->lines,
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
224 (1==egysub->lines)?' ':'s',
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
225 egysub->start,
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
226 egysub->end);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
227 for (i=0; i<egysub->lines; i++) {
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
228 printf ("%s%s",egysub->text[i], i==egysub->lines-1?"":" <BREAK> ");
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
229 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
230 printf ("\n");
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
231 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
232
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
233 printf ("Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use");
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
234 printf ("Read %i subtitles, %i errors.\n", sub_num, sub_errs);
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
235 return 0;
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
236 }
66017e126280 subtitles (.sub files) support
arpi_esp
parents:
diff changeset
237 #endif