Mercurial > mplayer.hg
comparison subreader.c @ 269:f5a7323af43f
applied patch by lez
author | arpi_esp |
---|---|
date | Sun, 01 Apr 2001 17:50:40 +0000 |
parents | 66017e126280 |
children | 7d544020e398 |
comparison
equal
deleted
inserted
replaced
268:0fcd79bb4c47 | 269:f5a7323af43f |
---|---|
1 /* | 1 /* |
2 * Subtitle reader with format autodetection | 2 * Subtitle reader with format autodetection |
3 * Mier nem muxik realloccal!?!?! - nekem muxik :) | |
4 * | 3 * |
5 * Written by laaz | 4 * Written by laaz |
6 * Some code cleanup & realloc() by A'rpi/ESP-team | 5 * Some code cleanup & realloc() by A'rpi/ESP-team |
7 */ | 6 */ |
8 | 7 |
52 | 51 |
53 do { | 52 do { |
54 if (!fgets (line, 1000, fd)) return NULL; | 53 if (!fgets (line, 1000, fd)) return NULL; |
55 } while (*line=='\n' || *line == '\r' || !*line); | 54 } while (*line=='\n' || *line == '\r' || !*line); |
56 | 55 |
57 if (sscanf (line, "{%i}{%i}%s", &(current->start), &(current->end),line2) <2) {return ERR;} | 56 if (sscanf (line, "{%d}{%d}%s", &(current->start), &(current->end),line2) <2) {return ERR;} |
58 | 57 |
59 p=line; | 58 p=line; |
60 while (*p++!='}'); | 59 while (*p++!='}'); |
61 while (*p++!='}'); | 60 while (*p++!='}'); |
62 | 61 |
79 | 78 |
80 bzero (current, sizeof(current)); | 79 bzero (current, sizeof(current)); |
81 | 80 |
82 while (!current->text[0]) { | 81 while (!current->text[0]) { |
83 if (!fgets (line, 1000, fd)) return NULL; | 82 if (!fgets (line, 1000, fd)) return NULL; |
84 if (sscanf (line, "%i:%i:%i.%i,%i:%i:%i.%i",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) continue; | 83 if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4) < 8) continue; |
85 current->start = a1*360000+a2*6000+a3*100+a4; | 84 current->start = a1*360000+a2*6000+a3*100+a4; |
86 current->end = b1*360000+b2*6000+b3*100+b4; | 85 current->end = b1*360000+b2*6000+b3*100+b4; |
87 | 86 |
88 if (!fgets (line, 1000, fd)) return NULL; | 87 if (!fgets (line, 1000, fd)) return NULL; |
89 | 88 |
108 | 107 |
109 bzero (current, sizeof(current)); | 108 bzero (current, sizeof(current)); |
110 | 109 |
111 while (!current->text[0]) { | 110 while (!current->text[0]) { |
112 if (!fgets (line, 1000, fd)) return NULL; | 111 if (!fgets (line, 1000, fd)) return NULL; |
113 if ((len=sscanf (line, "%i:%i:%i,%i --> %i:%i:%i,%i",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8) | 112 if ((len=sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d",&a1,&a2,&a3,&a4,&b1,&b2,&b3,&b4)) < 8) |
114 continue; | 113 continue; |
115 current->start = a1*360000+a2*6000+a3*100+a4/10; | 114 current->start = a1*360000+a2*6000+a3*100+a4/10; |
116 current->end = b1*360000+b2*6000+b3*100+b4/10; | 115 current->end = b1*360000+b2*6000+b3*100+b4/10; |
117 for (i=0; i<SUB_MAX_TEXT;) { | 116 for (i=0; i<SUB_MAX_TEXT;) { |
118 if (!fgets (line, 1000, fd)) return NULL; | 117 if (!fgets (line, 1000, fd)) break; |
119 len=0; | 118 len=0; |
120 for (p=line; *p!='\n' && *p!='\r' && *p; p++,len++); | 119 for (p=line; *p!='\n' && *p!='\r' && *p; p++,len++); |
121 if (len) { | 120 if (len) { |
122 current->text[i]=(char *)malloc (len+1); | 121 current->text[i]=(char *)malloc (len+1); |
123 if (!current->text[i]) return ERR; | 122 if (!current->text[i]) return ERR; |
142 j++; | 141 j++; |
143 if (!fgets (line, 1000, fd)) | 142 if (!fgets (line, 1000, fd)) |
144 return -1; | 143 return -1; |
145 | 144 |
146 // if (sscanf (line, "{%i}{%i}", &i, &i, p)==2) // ha valaki tudja miert 2, mondja mar el nekem ;) | 145 // if (sscanf (line, "{%i}{%i}", &i, &i, p)==2) // ha valaki tudja miert 2, mondja mar el nekem ;) |
147 if (sscanf (line, "{%i}{%i}", &i, &i)==2) // ha valaki tudja miert 2, mondja mar el nekem ;) | 146 if (sscanf (line, "{%d}{%d}", &i, &i)==2) // ha valaki tudja miert 2, mondja mar el nekem ;) |
148 {sub_uses_time=0;return 0;} | 147 {sub_uses_time=0;return 0;} |
149 if (sscanf (line, "%i:%i:%i.%i,%i:%i:%i.%i", &i, &i, &i, &i, &i, &i, &i, &i)==8) | 148 if (sscanf (line, "%d:%d:%d.%d,%d:%d:%d.%d", &i, &i, &i, &i, &i, &i, &i, &i)==8) |
150 {sub_uses_time=1;return 1;} | 149 {sub_uses_time=1;return 1;} |
151 if (sscanf (line, "%i:%i:%i,%i --> %i:%i:%i,%i", &i, &i, &i, &i, &i, &i, &i, &i)==8) | 150 if (sscanf (line, "%d:%d:%d,%d --> %d:%d:%d,%d", &i, &i, &i, &i, &i, &i, &i, &i)==8) |
152 {sub_uses_time=1;return 2;} | 151 {sub_uses_time=1;return 2;} |
153 if (j>100) return -1; // too many bad lines or bad coder | 152 if (j>100) return -1; // too many bad lines or bad coder |
154 } | 153 } |
155 } | 154 } |
156 | 155 |
190 } | 189 } |
191 | 190 |
192 fclose(fd); | 191 fclose(fd); |
193 | 192 |
194 // printf ("SUB: Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use"); | 193 // printf ("SUB: Subtitle format %s time.\n", sub_uses_time?"uses":"doesn't use"); |
195 printf ("SUB: Read %i subtitles, %i errors.\n", sub_num, sub_errs); | 194 printf ("SUB: Read %i subtitles", sub_num); |
195 if (sub_errs) printf (", %i error(s).\n", sub_errs); | |
196 else printf (".\n"); | |
196 | 197 |
197 return first; | 198 return first; |
198 } | 199 } |
199 | 200 |
200 #if 0 | 201 #if 0 |