Magellan Linux

Contents of /trunk/transcode/patches/transcode-1.0.3-bigdir.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 618 - (show annotations) (download)
Thu May 29 09:17:35 2008 UTC (15 years, 11 months ago) by niro
File size: 10742 byte(s)
-fixes for 1.0.3

1 Submitted By: Chipster <chipster19@free.fr>
2 Date: 2007-06-02
3 Initial Package Version: 1.0.3
4 Upstream Status: Unknown
5 Origin: http://mirror.linux.org.mt/mirror/gentoo-portage/media-video/transcode/files
6 Description:
7
8 --- transcode-1.0.3/import/iodump.c.old 2005-07-04 09:09:34.000000000 +0200
9 +++ transcode-1.0.3/import/iodump.c 2005-11-20 23:35:22.000000000 +0100
10 @@ -52,139 +52,217 @@
11
12 static int verbose_flag=TC_QUIET;
13
14 -static DIR *dir=NULL;
15 +typedef struct tcdirlist_ TCDirList;
16 +struct tcdirlist_ {
17 + DIR *dir; /* for internal use */
18 +
19 + const char *dir_name; /* saved base path */
20 + const char *path_sep; /* optional *nix path separator */
21 +
22 + char filename[PATH_MAX + 2];
23 + /*
24 + * full path of file actually under focus + optional separator +
25 + * final string terminator
26 + */
27 + char **entries;
28 + /* array of full PATHs of files in scanned dirlist */
29 +
30 + int nfiles; /* (current) number of files in dirlist */
31 + int findex; /* index of file under focus */
32 + int buffered;
33 + /* boolean flag: above array of file in directory is valid? */
34 +};
35
36 -static char filename[PATH_MAX+2];
37
38 -static char **rbuf_ptr;
39 -
40 -static int nfiles=0, findex=0, buffered=0;
41 -
42 -int open_directory(char *dir_name)
43 +static int compare_name(const void *file1_ptr, const void *file2_ptr)
44 {
45 - if((dir = opendir(dir_name))==NULL) return(-1);
46 - return(0);
47 + return strcoll(*(const char **)file1_ptr, *(const char **)file2_ptr);
48 }
49
50 -static char *scan_directory(char *dir_name)
51 -{
52 - struct dirent *dent;
53 - char *end_of_dir;
54 - int len;
55 -
56 - if (dir_name == 0) return NULL;
57 - if (dir == 0) return NULL;
58 -
59 - len = strlen( dir_name );
60 - end_of_dir = &dir_name[ len - 1 ];
61 -
62 - if ( *end_of_dir != '/' ) {
63 - end_of_dir++;
64 - *end_of_dir = '/';
65 - end_of_dir++;
66 - *end_of_dir = 0;
67 - }
68 -
69 - switch(buffered) {
70 -
71 - case 0:
72 -
73 - while((dent = readdir( dir ))!=NULL) {
74 -
75 - if((strncmp(dent->d_name, ".", 1)==0) || (strcmp(dent->d_name, "..")==0))
76 - continue;
77 -
78 - snprintf(filename, sizeof(filename), "%s%s", dir_name, dent->d_name);
79 +static int tc_dirlist_next(TCDirList *tcdir)
80 +{
81 + struct dirent *dent = NULL;
82 + int have_file = 0;
83
84 - //counter
85 - ++nfiles;
86 -
87 - return(filename);
88 - }
89 -
90 - break;
91 -
92 - case 1:
93 -
94 - if (findex < nfiles) {
95 - return(rbuf_ptr[findex++]);
96 - } else {
97 - return(NULL);
98 - }
99 + if (tcdir == NULL) {
100 + return -1;
101 + }
102
103 - break;
104 - }
105 -
106 - return(NULL);
107 + do {
108 + dent = readdir(tcdir->dir);
109 + if (dent == NULL) {
110 + break; /* all entries in dirlist have been processed */
111 + }
112 +
113 + if ((strncmp(dent->d_name, ".", 1) != 0)
114 + && (strcmp(dent->d_name, "..") != 0)) {
115 + /* discard special files */
116 + have_file = 1;
117 + }
118 +
119 + } while (!have_file);
120 +
121 + if (have_file) {
122 + int res = snprintf(tcdir->filename, sizeof(tcdir->filename),
123 + "%s%s%s", tcdir->dir_name, tcdir->path_sep,
124 + dent->d_name);
125 + /* enforce string terminator */
126 + tcdir->filename[sizeof(tcdir->filename)] = '\0';
127 + tc_test_string(__FILE__, __LINE__,
128 + sizeof(tcdir->filename), res, errno);
129 + return 0;
130 + }
131 + return 1;
132 }
133
134 -
135 -static int compare_name(char **file1_ptr, char **file2_ptr)
136 +static int tc_dirlist_sortbuf(TCDirList *tcdir)
137 {
138 - return strcoll(*file1_ptr, *file2_ptr);
139 -}
140 + int n = 0;
141
142 + if (tcdir == NULL) {
143 + return -1;
144 + }
145
146 -int sortbuf_directory(char *dir_name)
147 -{
148 - struct dirent *dent;
149 - char *end_of_dir;
150 - int n, len;
151 + tcdir->entries = malloc(tcdir->nfiles * sizeof(char *));
152 + if (tcdir->entries == NULL) {
153 + fprintf(stderr, "(%s) can't allocate memory for "
154 + "directory entries\n", __FILE__);
155 + return -1;
156 + }
157
158 - int (*func) ();
159 -
160 - if (dir_name == 0) return(-1);
161 - if (dir == 0) return(-1);
162 - if(nfiles == 0) return(-1);
163 -
164 - len = strlen( dir_name );
165 - end_of_dir = &dir_name[ len - 1 ];
166 -
167 - if ( *end_of_dir != '/' ) {
168 - end_of_dir++;
169 - *end_of_dir = '/';
170 - end_of_dir++;
171 - *end_of_dir = 0;
172 - }
173 -
174 - if((rbuf_ptr = (char **) calloc(nfiles, sizeof(char *)))==NULL) {
175 - perror("out of memory");
176 - return(-1);
177 - }
178 -
179 - n=0;
180 + while (tc_dirlist_next(tcdir) == 0) {
181 + tcdir->entries[n] = strdup(tcdir->filename);
182 + if (tcdir->entries[n] == NULL) {
183 + fprintf(stderr, "(%s) can't memorize dirlist entry "
184 + "for '%s'\n", __FILE__,
185 + tcdir->filename);
186 + }
187 + n++;
188 + }
189
190 - while((dent = readdir( dir ))!=NULL) {
191 -
192 - if((strncmp(dent->d_name, ".", 1)==0) || (strcmp(dent->d_name, "..")==0))
193 - continue;
194 -
195 - snprintf(filename, sizeof(filename), "%s%s", dir_name, dent->d_name);
196 - rbuf_ptr[n++] = strdup(filename);
197 - }
198 -
199 - // sorting
200 + qsort(tcdir->entries, tcdir->nfiles, sizeof(char *), compare_name);
201
202 - func = compare_name;
203 + tcdir->buffered = 1;
204 + tcdir->findex = 0;
205
206 - qsort(rbuf_ptr, nfiles, sizeof(char *), func);
207 + return 0;
208 +}
209 +
210 +static int tc_dirlist_set_path_sep(TCDirList *tcdir)
211 +{
212 + size_t len = 0;
213 + char end_of_dir;
214
215 - buffered=1;
216 - findex=0;
217 + len = strlen(tcdir->dir_name);
218 + if (len == 0) {
219 + return -1;
220 + }
221
222 - return(0);
223 + end_of_dir = tcdir->dir_name[len - 1];
224 + if (end_of_dir == '/') {
225 + tcdir->path_sep = "";
226 + } else {
227 + tcdir->path_sep = "/";
228 + }
229 +
230 + return 0;
231 +}
232 +
233 +static int tc_dirlist_file_count(TCDirList *tcdir)
234 +{
235 + if (tcdir == NULL) {
236 + return -1;
237 + }
238 + return tcdir->nfiles;
239 }
240
241
242 -void close_directory()
243 +static int tc_dirlist_open(TCDirList *tcdir, const char *dirname)
244 +{
245 + int ret;
246 +
247 + if (tcdir == NULL) {
248 + return -1;
249 + }
250 +
251 + tcdir->filename[0] = '\0';
252 + tcdir->entries = NULL;
253 + tcdir->nfiles = 0;
254 + tcdir->findex = 0;
255 + tcdir->buffered = 0;
256 + tcdir->dir_name = dirname;
257 +
258 + ret = tc_dirlist_set_path_sep(tcdir);
259 + if (ret != 0) {
260 + return ret;
261 + }
262 +
263 + tcdir->dir = opendir(dirname);
264 + if (tcdir->dir == NULL) {
265 + return -1;
266 + }
267 +
268 + rewinddir(tcdir->dir);
269 + while (tc_dirlist_next(tcdir) == 0) {
270 + tcdir->nfiles++;
271 + }
272 + rewinddir(tcdir->dir);
273 +
274 + return 0;
275 +}
276 +
277 +static void tc_dirlist_close(TCDirList *tcdir)
278 {
279 - if(dir!=NULL) closedir(dir);
280 - dir=NULL;
281 + if (tcdir != NULL) {
282 + if (tcdir->buffered == 1) {
283 + int i = 0;
284 + for (i = 0; i < tcdir->nfiles; i++) {
285 + if (tcdir->entries[i] != NULL) {
286 + /* should be always true */
287 + free(tcdir->entries[i]);
288 + tcdir->nfiles--;
289 + }
290 + }
291 +
292 + if (tcdir->entries != NULL) {
293 + /* should be always true */
294 + free(tcdir->entries);
295 + }
296 +
297 + if (tcdir->nfiles > 0) {
298 + /* should never happen */
299 + fprintf(stderr, "(%s) left out %i directory entries",
300 + __FILE__, tcdir->nfiles);
301 + }
302 + }
303 +
304 + if (tcdir->dir != NULL) {
305 + closedir(tcdir->dir);
306 + tcdir->dir = NULL;
307 + }
308 + }
309 }
310
311 -void freebuf_directory()
312 +static char *tc_dirlist_scan(TCDirList *tcdir)
313 {
314 - free(rbuf_ptr);
315 + char *ret = NULL;
316 +
317 + if (tcdir == NULL) {
318 + return NULL;
319 + }
320 +
321 + if (tcdir->buffered == 0) {
322 + if (tc_dirlist_next(tcdir) == 0) {
323 + ret = tcdir->filename;
324 + }
325 + } else { /* tcdir->buffered == 0 */
326 + /* buffered */
327 + if (tcdir->findex < tcdir->nfiles) {
328 + ret = tcdir->entries[tcdir->findex++];
329 + }
330 + }
331 +
332 + return ret;
333 }
334
335 /* ------------------------------------------------------------
336 @@ -203,6 +281,7 @@
337
338 info_t ipipe_avi;
339
340 + TCDirList tcdir;
341 #ifdef NET_STREAM
342 struct sockaddr_in sin;
343 struct hostent *hp;
344 @@ -326,13 +405,13 @@
345
346 //PASS 1: check file type - file order not important
347
348 - if((open_directory(ipipe->name))<0) {
349 + if(tc_dirlist_open(&tcdir, ipipe->name)<0) {
350 fprintf(stderr, "(%s) unable to open directory \"%s\"\n", __FILE__, ipipe->name);
351 exit(1);
352 } else if(verbose_flag & TC_DEBUG)
353 fprintf(stderr, "(%s) scanning directory \"%s\"\n", __FILE__, ipipe->name);
354
355 - while((name=scan_directory(ipipe->name))!=NULL) {
356 + while((name=tc_dirlist_scan(&tcdir))!=NULL) {
357
358 if((ipipe->fd_in = open(name, O_RDONLY))<0) {
359 perror("file open");
360 @@ -386,7 +465,7 @@
361 } // check itype
362 } // process files
363
364 - close_directory();
365 + tc_dirlist_close(&tcdir);
366
367 if(!found) {
368 fprintf(stderr,"\nerror: no valid files found in %s\n", name);
369 @@ -398,17 +477,17 @@
370
371 //PASS 2: dump files in correct order
372
373 - if((open_directory(ipipe->name))<0) {
374 + if(tc_dirlist_open(&tcdir, ipipe->name)<0) {
375 fprintf(stderr, "(%s) unable to sort directory entries\"%s\"\n", __FILE__, name);
376 exit(1);
377 }
378
379 - if((sortbuf_directory(ipipe->name))<0) {
380 + if(tc_dirlist_sortbuf(&tcdir)<0) {
381 fprintf(stderr, "(%s) unable to sort directory entries\"%s\"\n", __FILE__, name);
382 exit(1);
383 }
384
385 - while((name=scan_directory(ipipe->name))!=NULL) {
386 + while((name=tc_dirlist_scan(&tcdir))!=NULL) {
387
388 if((ipipe->fd_in = open(name, O_RDONLY))<0) {
389 perror("file open");
390 @@ -480,9 +559,8 @@
391 close(ipipe->fd_in);
392
393 }//process files
394 -
395 - close_directory();
396 - freebuf_directory();
397 +
398 + tc_dirlist_close(&tcdir);
399
400 break;
401 }
402 @@ -492,24 +570,25 @@
403 int fileinfo_dir(char *dname, int *fd, long *magic)
404 {
405 char *name=NULL;
406 + TCDirList tcdir;
407
408 //check file type - file order not important
409
410 - if((open_directory(dname))<0) {
411 + if(tc_dirlist_open(&tcdir, dname)<0) {
412 fprintf(stderr, "(%s) unable to open directory \"%s\"\n", __FILE__, dname);
413 exit(1);
414 } else if(verbose_flag & TC_DEBUG)
415
416 fprintf(stderr, "(%s) scanning directory \"%s\"\n", __FILE__, dname);
417
418 - if((name=scan_directory(dname))==NULL) return(-1);
419 + if((name=tc_dirlist_scan(&tcdir))==NULL) return(-1);
420
421 if((*fd= open(name, O_RDONLY))<0) {
422 perror("open file");
423 return(-1);
424 }
425
426 - close_directory();
427 + tc_dirlist_close(&tcdir);
428
429 //first valid magic must be the same for all
430 //files to follow, but is not checked here