HuntnGather – Diff between revs 32 and 33

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 32 Rev 33
Line 16... Line 16...
16   16  
17 #if defined ___AmigaOS___ 17 #if defined ___AmigaOS___
18 #include <proto/dos.h> 18 #include <proto/dos.h>
19 #include <proto/exec.h> 19 #include <proto/exec.h>
-   20 #include <proto/locale.h>
20 #include <proto/locale.h> 21 #include <clib/utility_protos.h>
Line 21... Line 22...
21 #endif 22 #endif
22   23  
23 #if defined ___AsyncIO___ 24 #if defined ___AsyncIO___
Line 24... Line 25...
24 #include <asyncio.h> 25 #include <asyncio.h>
25 #endif 26 #endif
26   27  
Line 27... Line 28...
27 #if !defined ___HAVE_GETOPT___ 28 #if !defined ___HAVE_GETOPT___
-   29 #include "/shared/getopt.h"
Line 28... Line 30...
28 #include "getopt.h" 30 #endif
Line 29... Line 31...
29 #endif 31  
30   32 #include "StringStack.h"
Line 38... Line 40...
38 /*************************************************************************/ 40 /*************************************************************************/
39 TEXT version_string[] = 41 TEXT version_string[] =
40 "\0$VER: Gather " PROGRAM_VERSION " "__DATE__" by Wizardry and Steamworks"; 42 "\0$VER: Gather " PROGRAM_VERSION " "__DATE__" by Wizardry and Steamworks";
41 #endif 43 #endif
Line 42... Line 44...
42   44  
43 #if !defined TRUE -  
44 #define TRUE 1; -  
45 #endif -  
46   -  
47 #if !defined FALSE -  
48 #define FALSE 0; -  
49 #endif -  
50   -  
51 #define ASYNC_BUF 8192 45 int PROGRAM_RUN = TRUE;
52 #define MAX_MEM 262144 -  
53 #define LINE_BUF 256 -  
54 #define DEFAULT_DATABASE_FILE "S:gather.db" -  
55   -  
56 typedef struct { -  
57 unsigned int dirs; -  
58 unsigned int files; -  
59 } stats; -  
60   -  
61 typedef struct { -  
62 char *name; -  
63 char *path; -  
64 } dbEntry; -  
65   -  
66 typedef struct { -  
67 char **database; 46 int PROGRAM_VERBOSE = TRUE;
68 unsigned int count; -  
Line 69... Line -...
69 } dbArray; -  
70   -  
71 enum MODE { -  
72 NONE, -  
73 GATHER, -  
74 REMOVE, -  
75 CREATE -  
76 } operation; -  
77   -  
78 unsigned int run = TRUE; -  
79 unsigned int verbose = TRUE; 47 int maxmem = MAX_MEM;
80 unsigned int maxmem = MAX_MEM; 48  
81 // Define global locale for string compare. 49 // Define global locale for string compare.
82 #if defined ___AmigaOS___ 50 #if defined ___AmigaOS___
Line 83... Line 51...
83 struct Locale *locale; 51 struct Locale *locale;
84 #endif 52 #endif
85   53  
86 void SignalHandler(int sig) { 54 void SignalHandler(int sig) {
Line 87... Line 55...
87 // Toggle the run flag to stop execution. 55 /* Toggle the run flag to stop execution. */
88 run = FALSE; 56 PROGRAM_RUN = FALSE;
89 } 57 }
Line 106... Line 74...
106 #endif 74 #endif
107 } 75 }
Line 108... Line 76...
108   76  
109 /* 77 /*
110 * -  
111 * Gets the absolute path to file by name. -  
112 */ -  
113 char *PathToAbsolute(char *path) { -  
114 char *abs; -  
115 #if defined ___AmigaOS___ -  
116 BPTR lock; -  
117 #endif -  
118   -  
119 #if defined ___AmigaOS___ -  
120 if((abs = malloc(PATH_MAX * sizeof(*abs))) == NULL) { -  
121 fprintf(stderr, "Memory allocation failure.\n"); -  
122 return NULL; -  
123 } -  
124 if((lock = Lock(path, SHARED_LOCK)) == 0) { -  
125 fprintf(stderr, "Lock on %s failed.\n", path); -  
126 return NULL; -  
127 } -  
128 if(NameFromLock(lock, abs, PATH_MAX) == FALSE) { -  
129 fprintf(stderr, "Lock on %s failed.\n", path); -  
130 UnLock(lock); -  
131 return NULL; -  
132 } -  
133 UnLock(lock); -  
134 #else -  
135 //abs = realpath(path, NULL); -  
136 if((abs = malloc((strlen(path) + 1) * sizeof(*abs))) == NULL) { -  
137 fprintf(stderr, "Memory allocation failure.\n"); -  
138 return NULL; -  
139 } -  
140 sprintf(abs, "%s", path); -  
141 #endif -  
142   -  
143 return abs; -  
144 } -  
145   -  
146 /* -  
147 * 78 *
148 * Compares path parts for equality. -  
149 */ -  
150 #if defined ___AmigaOS___ -  
151 BOOL PathCompare(char *path, char *look) { -  
152 #else -  
153 int PathCompare(char *path, char *look) { -  
154 #endif -  
155 char *a; -  
156 char *b; -  
157   -  
158 for(a = path, b = look; *a != '\0' && *b != '\0'; ++a, ++b) { -  
159 if(*b != '\0' && *a != *b) { -  
160 return FALSE; -  
161 } -  
162 } -  
163   -  
164 return *b == '\0'; -  
165 } -  
166   -  
167 /* -  
168 * -  
169 * Gets the size of a file by name. 79 * Sorts a database file lexicographically.
170 */ 80 */
171 int GetFileSize(char *dbFile) { 81 void SortDatabase(char *dbFile, int lines) {
172 #if defined ___AsyncIO___ 82 #if defined ___AsyncIO___
173 struct AsyncFile *fp; -  
174 LONG size; 83 struct AsyncFile *fp;
175 #else 84 #else
176 FILE *fp; -  
177 int size; 85 FILE *fp;
-   86 #endif
-   87 char **database;
-   88 dbEntry *entry;
-   89 char *line = NULL;
-   90 char *rem;
-   91 int count;
Line -... Line 92...
-   92 int i;
178 #endif 93  
179   94 // Open database file for reading.
180 #if defined ___AsyncIO___ 95 #if defined ___AsyncIO___
181 if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { 96 if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) {
182 #else 97 #else
183 if((fp = fopen(dbFile, "r")) == NULL) { 98 if((fp = fopen(dbFile, "r")) == NULL) {
184 #endif 99 #endif
185 fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); 100 fprintf(stderr, "Could not open file '%s' for reading.\n", dbFile);
Line -... Line 101...
-   101 return;
-   102 }
186 return -1; 103  
187 } -  
188   -  
189 #if defined ___AsyncIO___ -  
190 if(SeekAsync(fp, 0, MODE_END) == -1) { -  
191 #else -  
192 if(fseek(fp, 0L, SEEK_END) != 0) { -  
193 #endif -  
194 fprintf(stderr, "Seek in file %s failed.\n", dbFile); -  
195 #if defined ___AsyncIO___ -  
196 CloseAsync(fp); -  
197 #else -  
198 fclose(fp); -  
199 #endif -  
200 return -1; -  
201 } -  
202 #if defined ___AsyncIO___ 104 if((database = malloc(lines * sizeof(*database))) == NULL) {
203 if((size = SeekAsync(fp, 0, MODE_CURRENT)) == -1) { -  
204 fprintf(stderr, "Seek in file %s failed.\n", dbFile); -  
205 CloseAsync(fp); -  
206 return -1; -  
207 } -  
208 #else -  
209 size = ftell(fp); -  
210 #endif -  
211   -  
212 #if defined ___AsyncIO___ -  
213 CloseAsync(fp); -  
214 #else -  
215 fclose(fp); -  
216 #endif -  
217   -  
218 return size; -  
219 } -  
220   -  
221 /* -  
222 * -  
223 * Counts the lines of a file. -  
224 */ -  
225 int CountFileLines(char *dbFile) { -  
226 #if defined ___AsyncIO___ 105 fprintf(stderr, "Memory allocation failure.\n");
227 struct AsyncFile *fp; 106 #if defined ___AsyncIO___
228 LONG c; -  
229 #else -  
230 FILE *fp; -  
231 char c; -  
232 #endif -  
233 int lines; -  
234   -  
235 #if defined ___AsyncIO___ -  
236 if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { 107 CloseAsync(fp);
237 #else -  
238 if((fp = fopen(dbFile, "r")) == NULL) { 108 #else
239 #endif 109 fclose(fp);
Line 240... Line -...
240 fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); -  
241 return -1; 110 #endif
242 } 111 return;
243   112 }
Line 244... Line 113...
244 lines = 0; 113  
245 if(verbose) { 114 if(PROGRAM_VERBOSE) {
246 fprintf(stdout, "Lines in '%s' so far: %d\r", dbFile, lines); -  
247 } -  
248   -  
249 #if defined ___AsyncIO___ 115 fprintf(stdout, "Reading lines from file '%s' to array...\n", dbFile);
250 while(run && (c = ReadCharAsync(fp)) != -1) { 116 }
251 #else 117  
252 while(run && fscanf(fp, "%c", &c) == 1) { 118 count = 0;
253 #endif 119 while(PROGRAM_RUN && (line = ReadLine(fp)) != NULL) {
254 #if defined ___AmigaOS___ 120 #if defined ___AmigaOS___
255 // Check if CTRL+C was pressed and abort the program. 121 // Check if CTRL+C was pressed and abort the program.
256 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { -  
257 run = FALSE; -  
258 continue; -  
259 } -  
260 #endif 122 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
261 switch(c) { 123 PROGRAM_RUN = FALSE;
262 case '\n': -  
263 ++lines; 124 continue;
264   -  
265 if(verbose) { -  
266 fprintf(stdout, "Lines in '%s' so far: %d\r", dbFile, lines); -  
267 } 125 }
268 break; 126 #endif
269 } 127 if((entry = CreateDatabaseEntry(line)) == NULL) {
270 } 128 fprintf(stderr, "Unable to create database entry.\n");
271   -  
272 #if defined ___AsyncIO___ -  
273 CloseAsync(fp); -  
274 #else -  
275 fclose(fp); -  
276 #endif -  
277   -  
278 if(verbose) { -  
279 fprintf(stdout, "\n"); -  
280 } -  
281   -  
282 return lines; -  
283 } -  
284   -  
285 /* -  
286 * -  
287 * Creates a temporary file and returns its name. -  
288 */ -  
289 char *CreateTemporaryFile(void) { -  
290 char *name; -  
291   -  
292 name = tmpnam(NULL); -  
293   -  
294 return name; -  
295 } -  
296   -  
297 /* -  
298 * -  
299 * Create multiple temporary files and return their names. -  
300 */ -  
301 char **CreateTemporaryFiles(int files) { -  
302 char **tmpNames; -  
303 int count; -  
304   -  
305 if((tmpNames = malloc(files * sizeof(*tmpNames))) == NULL) { -  
306 fprintf(stderr, "Memory allocation failure.\n"); -  
307 return NULL; -  
308 } -  
309   -  
310 if(verbose) { -  
311 fprintf(stdout, "Creating temporary files...\r"); -  
312 } -  
313   -  
314 count = files; -  
315 while(run && --count > -1) { -  
316 #if defined ___AmigaOS___ -  
317 // Check if CTRL+C was pressed and abort the program. 129 free(line);
318 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { -  
319 run = FALSE; -  
320 continue; 130 #if defined ___AsyncIO___
321 } -  
322 #endif 131 CloseAsync(fp);
323 tmpNames[count] = CreateTemporaryFile(); -  
324   -  
325 if(verbose) { -  
326 fprintf(stdout, "Creating temporary files: %d%%\r", 100 - (int)(((float)count / files) * 100.0)); -  
327 } -  
Line -... Line 132...
-   132 #else
-   133 fclose(fp);
328 } 134 #endif
329   -  
330 if(verbose) { -  
331 fprintf(stdout, "\n"); -  
332 } -  
333   135 return;
334 return tmpNames; 136 }
335 } 137  
336   138 if((database[count] = malloc((strlen(entry->name) + strlen(entry->path) + 1 + 1) * sizeof(*database[count]))) == NULL) {
337   139 fprintf(stderr, "Memory allocation failure.\n");
338 /* -  
339 * -  
340 * Skips a line in a file. 140 free(entry->name);
341 */ -  
342 #if defined ___AsyncIO___ -  
343 void SkipLine(struct AsyncFile *fp) { -  
344 LONG c; -  
345 while(run && (c = ReadCharAsync(fp)) != -1) { -  
346 #else -  
347 void SkipLine(FILE *fp) { -  
348 char c; -  
349 while(run && fscanf(fp, "%c", &c) == 1) { 141 free(entry->path);
350 #endif -  
351 #if defined ___AmigaOS___ 142 free(entry);
352 // Check if CTRL+C was pressed and abort the program. -  
353 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { -  
354 run = FALSE; 143 free(line);
355 continue; 144 #if defined ___AsyncIO___
356 } -  
357 #endif -  
Line 358... Line -...
358 switch(c) { -  
359 case '\n': -  
360 return; -  
361 } -  
362 } -  
363 } -  
364   -  
365 /* -  
366 * -  
367 * Peeks at a line from a file. -  
368 */ -  
369 #if defined ___AsyncIO___ -  
370 char *PeekLine(struct AsyncFile *fp) { -  
371 LONG c; -  
372 #else -  
373 char *PeekLine(FILE *fp) { -  
374 char c; -  
375 #endif -  
376 char *line = NULL; 145 CloseAsync(fp);
377 char *real = NULL; 146 #else
378 unsigned int size; -  
Line 379... Line -...
379 int i; -  
380   147 fclose(fp);
381 size = LINE_BUF; -  
382 if((line = malloc(size * sizeof(*line))) == NULL) { -  
383 fprintf(stderr, "Memory allocation failure.\n"); -  
384 return NULL; -  
385 } -  
386   -  
387 i = 0; -  
388 #if defined ___AsyncIO___ -  
389 while(run && (c = ReadCharAsync(fp)) != -1) { -  
390 #else -  
391 while(run && fscanf(fp, "%c", &c) == 1) { -  
392 #endif -  
393 #if defined ___AmigaOS___ -  
394 // Check if CTRL+C was pressed and abort the program. -  
395 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { -  
396 run = FALSE; -  
397 continue; -  
398 } 148 #endif
399 #endif 149 return;
400 switch(c) { -  
401 case '\n': -  
402 // Rewind the file by the number of read characters. -  
403 #if defined ___AsyncIO___ -  
404 if(SeekAsync(fp, -(i + 1), MODE_CURRENT) == -1) { 150 }
405 fprintf(stderr, "Could not seek in file.\n"); -  
406 free(line); -  
407 return NULL; -  
408 } -  
409 #else -  
410 if(fseek(fp, -(i + 1), SEEK_CUR) != 0) { -  
411 fprintf(stderr, "Could not seek in file.\n"); -  
412 free(line); -  
413 return NULL; -  
414 } -  
415 #endif -  
416 return line; -  
417 default: -  
418 if(strlen(line) == size) { -  
419 size = size * 1.5; -  
420 real = realloc(line, size * sizeof(*line)); -  
421 if(real == NULL) { -  
422 fprintf(stderr, "Memory reallocation failure.\n"); -  
423 free(line); -  
424 return NULL; -  
425 } -  
Line 426... Line -...
426 line = real; -  
427 } 151  
428 line[i] = c; 152 sprintf(database[count], "%s\t%s", entry->name, entry->path);
Line 429... Line -...
429 line[i + 1] = '\0'; -  
430 break; -  
431 } -  
432 ++i; -  
433 } -  
434   -  
435 if(line != NULL) { -  
436 free(line); -  
437 } -  
438   -  
439 return NULL; -  
440 } -  
441   -  
442 /* -  
443 * -  
444 * Read a line from a file. -  
445 */ -  
446 #if defined ___AsyncIO___ -  
447 char *ReadLine(struct AsyncFile *fp) { -  
448 LONG c; -  
449 #else -  
450 char *ReadLine(FILE *fp) { -  
451 char c; -  
452 #endif -  
453 char *line = NULL; -  
454 char *real = NULL; -  
455 unsigned int size; -  
456 unsigned int i; -  
457   -  
458 size = LINE_BUF; -  
459 if((line = malloc(size * sizeof(*line))) == NULL) { -  
460 fprintf(stderr, "Memory allication failure.\n"); -  
461 return NULL; -  
462 } -  
463   -  
464 i = 0; -  
465 #if defined ___AsyncIO___ -  
466 while(run && (c = ReadCharAsync(fp)) != -1) { -  
467 #else -  
468 while(run && fscanf(fp, "%c", &c) == 1) { -  
469 #endif -  
470 #if defined ___AmigaOS___ -  
471 // Check if CTRL+C was pressed and abort the program. -  
472 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { -  
473 run = FALSE; -  
474 continue; -  
475 } -  
476 #endif -  
477 switch(c) { -  
478 case '\n': -  
479 return line; -  
480 default: -  
481 if(strlen(line) == size) { -  
482 size = size * 1.5; -  
483 real = realloc(line, size * sizeof(*line)); -  
484 if(real == NULL) { -  
485 fprintf(stderr, "Memory reallocation failure.\n"); -  
486 free(line); -  
487 return NULL; -  
488 } 153 ++count;
489 line = real; 154  
490 } 155 // Free the database entry.
Line 491... Line -...
491 line[i] = c; -  
492 line[i + 1] = '\0'; -  
493 break; -  
494 } -  
495 ++i; -  
496 } -  
497   -  
498 if(line != NULL) { -  
499 free(line); -  
500 } -  
501   -  
502 return NULL; -  
503 } -  
504   -  
505 /* -  
506 * -  
507 * Delete a file. -  
508 */ -  
509 #if defined ___AmigaOS___ -  
510 BOOL RemoveFile(char *name) { -  
511 return DeleteFile(name); -  
512 #else -  
513 int RemoveFile(char *name) { -  
514 return remove(name) == 0; -  
515 #endif -  
516 } -  
517   -  
518 /* -  
519 * -  
520 * Deletes files. -  
521 */ -  
522 void RemoveFiles(char **names, int count) { -  
523 unsigned int i; -  
524 for(i = 0; i < count; ++i) { -  
525 if(RemoveFile(names[i]) == FALSE) { -  
526 fprintf(stderr, "Unable to remove %s...\n", names[i]); -  
527 continue; 156 free(entry->name);
528 } -  
529 fprintf(stderr, "Removing file: %s\n", names[i]); 157 free(entry->path);
530 } -  
531 } 158 free(entry);
532   -  
533 /* 159  
534 * -  
535 * Copies a file to another file by name. 160 free(line);
Line 536... Line -...
536 */ -  
537 void CopyFile(char *a, char *b) { 161 }
538 #if defined ___AsyncIO___ -  
539 struct AsyncFile *ap; -  
540 struct AsyncFile *bp; -  
541 LONG c; -  
542 #else 162  
543 FILE *ap; -  
544 FILE *bp; 163 if(line != NULL) {
Line 545... Line 164...
545 char c; 164 free(line);
546 #endif -  
547   -  
548 // Open database file for writing. -  
549 #if defined ___AsyncIO___ -  
550 if((ap = OpenAsync(a, MODE_READ, ASYNC_BUF)) == NULL) { -  
551 #else 165 }
552 if((ap = fopen(a, "r")) == NULL) { -  
553 #endif -  
554 fprintf(stderr, "Unable to open '%s' for reading.\n", a); -  
555 return; -  
556 } -  
557   -  
558 // Open temporary file for reading. -  
559 #if defined ___AsyncIO___ -  
560 if((bp = OpenAsync(b, MODE_WRITE, ASYNC_BUF)) == NULL) { -  
561 #else -  
Line 562... Line -...
562 if((bp = fopen(b, "w")) == NULL) { -  
563 #endif -  
564 fprintf(stderr, "Unable to open file '%s' for writing.\n", b); -  
565   -  
566 // Close database file. -  
567 #if defined ___AsyncIO___ 166  
568 CloseAsync(ap); -  
569 #else -  
570 fclose(ap); -  
571 #endif -  
572   -  
573 return; -  
574 } -  
575   -  
576 #if defined ___AsyncIO___ -  
577 while(run && (c = ReadCharAsync(ap)) != -1) { -  
578 #else -  
579 while(run && fscanf(ap, "%c", &c) == 1) { 167 #if defined ___AsyncIO___
580 #endif -  
581 #if defined ___AmigaOS___ -  
582 // Check if CTRL+C was pressed and abort the program. 168 CloseAsync(fp);
Line 583... Line -...
583 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { -  
584 run = FALSE; -  
585 continue; -  
586 } -  
587 #endif -  
588 #if defined ___AsyncIO___ -  
589 if(WriteCharAsync(bp, (UBYTE)c) != 1) { -  
590 #else -  
591 if(fprintf(bp, "%c", c) != 1) { -  
592 #endif -  
593 fprintf(stderr, "Unable to write to '%s'.\n", b); -  
594 break; -  
595 } -  
596 } -  
597   -  
598 #if defined ___AsyncIO___ -  
599 CloseAsync(ap); -  
600 CloseAsync(bp); -  
601 #else -  
602 fclose(ap); -  
603 fclose(bp); -  
604 #endif -  
605 } 169 #else
606   170 fclose(fp);
607 /* 171 #endif
608 * 172  
609 * Write lines to a file. 173 if(PROGRAM_VERBOSE) {
610 */ 174 fprintf(stdout, "Sorting %d lines in '%s'...\n", count, dbFile);
611 void WriteLinesToFile(char *dbFile, char **lines, unsigned int count) { 175 }
612 #if defined ___AsyncIO___ 176  
613 struct AsyncFile *fp; 177 // Sort the database.
Line 614... Line 178...
614 #else 178 qsort(database, (unsigned int)count, sizeof(char *), QsortCompare);
615 FILE *fp; 179  
616 #endif 180 if(PROGRAM_VERBOSE) {
617 unsigned int i; 181 fprintf(stdout, "Writing %d sorted lines to '%s'...\n", count, dbFile);
618 char *rem; 182 }
619   183  
620 // Write the database lines back to the database. 184 // Write the database lines back to the database.
621 #if defined ___AsyncIO___ 185 #if defined ___AsyncIO___
622 if((fp = OpenAsync(dbFile, MODE_WRITE, ASYNC_BUF)) == NULL) { 186 if((fp = OpenAsync(dbFile, MODE_WRITE, ASYNC_BUF)) == NULL) {
Line 623... Line 187...
623 #else 187 #else
624 if((fp = fopen(dbFile, "w")) == NULL) { 188 if((fp = fopen(dbFile, "w")) == NULL) {
625 #endif 189 #endif
626 fprintf(stderr, "Unable to open '%s' for writing.\n", dbFile); 190 fprintf(stderr, "Could not open file '%s' for writing.\n", dbFile);
627 return; 191 return;
628 } 192 }
629   193  
630 rem = NULL; 194 rem = NULL;
631 for(i = 0; i < count; ++i) { 195 for(i = 0; PROGRAM_RUN && i < count; ++i) {
Line 632... Line 196...
632 #if defined ___AmigaOS___ 196 #if defined ___AmigaOS___
633 // Check if CTRL+C was pressed and abort the program. 197 // Check if CTRL+C was pressed and abort the program.
634 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 198 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
635 run = FALSE; 199 PROGRAM_RUN = FALSE;
636 continue; 200 continue;
637 } 201 }
Line 638... Line 202...
638 #endif 202 #endif
639   203  
640 if(rem != NULL) { 204 if(rem != NULL) {
Line 641... Line 205...
641 #if defined ___AmigaOS___ 205 #if defined ___AmigaOS___
642 if(StrnCmp(locale, lines[i], rem, -1, SC_ASCII) == 0) { 206 if(StrnCmp(locale, database[i], rem, -1, SC_ASCII) == 0) {
643 #else 207 #else
Line 644... Line 208...
644 if(strcmp(lines[i], rem) == 0) { 208 if(strcmp(database[i], rem) == 0) {
645 #endif 209 #endif
646 continue; 210 continue;
Line 669... Line 233...
669 #if defined ___AsyncIO___ 233 #if defined ___AsyncIO___
670 CloseAsync(fp); 234 CloseAsync(fp);
671 #else 235 #else
672 fclose(fp); 236 fclose(fp);
673 #endif 237 #endif
674 } -  
675   -  
676 /* -  
677 * -  
678 * Create a database entry from a line of text. -  
679 */ -  
680 dbEntry* CreateDatabaseEntry(char *line) { -  
681 dbEntry *entry; -  
682 char *ptr; -  
683 unsigned int side; -  
684 unsigned int i; -  
685 unsigned int j; -  
686   -  
687 if((entry = malloc(1 * sizeof(*entry))) == NULL) { -  
688 fprintf(stderr, "Memory allocation failure.\n"); -  
689 return NULL; -  
690 } -  
691   -  
692 if((entry->name = malloc((strlen(line) + 1) * sizeof(*entry->name))) == NULL) { -  
693 fprintf(stderr, "Memory allocation failure.\n"); -  
694 return NULL; -  
695 } -  
696   -  
697 if((entry->path = malloc((strlen(line) + 1) * sizeof(*entry->path))) == NULL) { -  
698 fprintf(stderr, "Memory allocation failure.\n"); -  
699 return NULL; -  
700 } -  
701   -  
702 for(ptr = line, side = 0, i = 0, j = 0; run && *ptr != '\0'; ++ptr) { -  
703 #if defined ___AmigaOS___ -  
704 // Check if CTRL+C was pressed and abort the program. -  
705 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { -  
706 run = FALSE; -  
707 continue; -  
708 } -  
709 #endif -  
710 switch(*ptr) { -  
711 case '\t': -  
712 entry->name[i] = '\0'; -  
713 ++side; -  
714 break; -  
715 case '\n': -  
716 entry->path[j] = '\0'; -  
717 return entry; -  
718 default: -  
719 switch(side) { -  
720 case 0: -  
721 entry->name[i++] = *ptr; -  
722 break; -  
723 case 1: -  
724 entry->path[j++] = *ptr; -  
725 break; -  
726 } -  
727 break; -  
728 } -  
729 } -  
730   -  
731 return entry; -  
732 } -  
733   -  
734 /* -  
735 * -  
736 * -  
737 */ -  
738 dbArray *GetDatabaseArray(char *dbFile) { -  
739 #if defined ___AsyncIO___ -  
740 struct AsyncFile *fp; -  
741 #else -  
742 FILE *fp; -  
743 #endif -  
744 dbArray *array; -  
745 char **real = NULL; -  
746 dbEntry *entry; -  
747 char *line = NULL; -  
748 unsigned int count; -  
749   -  
750 // Open database file for reading. -  
751 #if defined ___AsyncIO___ -  
752 if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { -  
753 #else -  
754 if((fp = fopen(dbFile, "r")) == NULL) { -  
755 #endif -  
756 fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); -  
757 return NULL; -  
758 } -  
Line 759... Line 238...
759   238  
760 if((array = malloc(1 * sizeof(*array))) == NULL) { 239 if(PROGRAM_VERBOSE) {
761 fprintf(stderr, "Memory allocation failure.\n"); -  
762 #if defined ___AsyncIO___ -  
763 CloseAsync(fp); -  
764 #else -  
765 fclose(fp); -  
766 #endif -  
767 return NULL; 240 fprintf(stdout, "Disposing %d lines of file '%s'...\n", count, dbFile);
Line 768... Line -...
768 } -  
769   -  
770 count = 0; -  
771 while(run && (line = ReadLine(fp)) != NULL) { -  
772 #if defined ___AmigaOS___ -  
773 // Check if CTRL+C was pressed and abort the program. -  
774 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { -  
775 run = FALSE; -  
776 continue; -  
777 } -  
778 #endif -  
779 if((entry = CreateDatabaseEntry(line)) == NULL) { -  
780 fprintf(stderr, "Unable to create database entry.\n"); -  
781 free(line); -  
782 #if defined ___AsyncIO___ -  
783 CloseAsync(fp); -  
784 #else -  
785 fclose(fp); -  
786 #endif -  
787 return NULL; -  
788 } -  
789   -  
790 // Load up the name and path into the database variable. -  
791 real = realloc(array->database, (count + 1) * sizeof(*array->database)); -  
792 if(real == NULL) { -  
793 fprintf(stderr, "Memory reallocation failure.\n"); -  
794 free(entry->name); -  
795 free(entry->path); -  
796 free(entry); -  
797 free(line); -  
798 #if defined ___AsyncIO___ -  
799 CloseAsync(fp); -  
800 #else -  
801 fclose(fp); -  
802 #endif -  
803 return NULL; -  
804 } -  
805 array->database = real; -  
806   -  
807 if((array->database[count] = malloc((strlen(entry->name) + strlen(entry->path) + 1 + 1) * sizeof(*array->database[count]))) == NULL) { -  
808 fprintf(stderr, "Memory allocation failure.\n"); -  
809 free(entry->name); -  
810 free(entry->path); -  
811 free(entry); -  
812 free(line); -  
813 #if defined ___AsyncIO___ -  
814 CloseAsync(fp); -  
815 #else -  
816 fclose(fp); -  
817 #endif -  
818 return NULL; -  
819 } -  
820 sprintf(array->database[count], "%s\t%s", entry->name, entry->path); -  
821 ++count; 241 }
822   -  
823 // Free the database entry. -  
824 free(entry->name); -  
825 free(entry->path); -  
826 free(entry); -  
827   -  
828 free(line); -  
829 } 242  
830   243 // Free up database.
831 if(line != NULL) { 244 for(i = 0; i < count; ++i) {
Line 832... Line -...
832 free(line); -  
833 } -  
834   -  
835 #if defined ___AsyncIO___ -  
836 CloseAsync(fp); -  
837 #else -  
838 fclose(fp); -  
839 #endif -  
840   -  
841 array->count = count; -  
842 return array; -  
843 } -  
844   -  
845 /* -  
846 * -  
847 * Sorts a database file lexicographically. -  
848 */ -  
849 void SortDatabase(char *dbFile) { -  
850 dbArray *array; -  
851 int i; -  
852   -  
853 if(verbose) { -  
854 fprintf(stdout, "Sorting '%s'...\n", dbFile); -  
855 } -  
856   -  
857 // Retrieve the database as an array. -  
858 if((array = GetDatabaseArray(dbFile)) == NULL) { -  
859 fprintf(stderr, "Unable to read '%s' as a database file.\n", dbFile); -  
860 return; -  
861 } -  
862   -  
863 // Sort the database. -  
864 qsort(array->database, array->count, sizeof(char *), QsortCompare); -  
865   -  
866 // Write back the database to the database file. -  
867 WriteLinesToFile(dbFile, array->database, array->count); -  
868   245 free(database[i]);
869 // Deallocate all the lines. -  
870 for(i = 0; i < array->count; ++i) { -  
871 free(array->database[i]); -  
872 } 246 }
Line 873... Line 247...
873   247  
874 free(array); 248 free(database);
875 } 249 }
876   250  
877 /* 251 /*
878 * 252 *
879 * Updates a database file "dbFile". 253 * Updates a database file "dbFile".
880 */ 254 */
881 stats *CollectFiles(char *dbFile, char **paths, unsigned int count) { 255 dbStats *CollectFiles(char *dbFile, char **paths, int count) {
882 #if defined ___AsyncIO___ 256 #if defined ___AsyncIO___
883 struct AsyncFile *fp; 257 struct AsyncFile *fp;
884 #else 258 #else
885 FILE *fp; 259 FILE *fp;
886 #endif 260 #endif
887 #if defined ___AmigaOS___ 261 #if defined ___AmigaOS___
888 struct FileInfoBlock *FIBp, *FIBq; 262 struct FileInfoBlock *FIB;
889 BPTR lockp, lockq; 263 BPTR lock;
890 #else 264 #else
891 DIR *dir; 265 DIR *dir;
892 struct dirent *entry; 266 struct dirent *entry;
893 struct stat dirStat; 267 struct stat dirStat;
894 #endif 268 #endif
895 stringStack *stack; 269 stringStack *stack;
Line 896... Line 270...
896 stats *stats = NULL; 270 dbStats *stats = NULL;
897 int i; 271 int i;
898 char *path; 272 char *path;
899 char *sub; 273 char *sub;
900   274  
901 #if defined ___AsyncIO___ 275 #if defined ___AsyncIO___
902 if((fp = OpenAsync(dbFile, MODE_APPEND, ASYNC_BUF)) == NULL) { 276 if((fp = OpenAsync(dbFile, MODE_APPEND, ASYNC_BUF)) == NULL) {
903 #else 277 #else
Line 904... Line 278...
904 if((fp = fopen(dbFile, "a")) == NULL) { 278 if((fp = fopen(dbFile, "a")) == NULL) {
905 #endif 279 #endif
906 fprintf(stderr, "Unable to open '%s' for writing.\n", dbFile); 280 fprintf(stderr, "Could not open file '%s' for writing.\n", dbFile);
Line 907... Line 281...
907 return NULL; 281 return NULL;
908 } 282 }
Line 922... Line 296...
922 return NULL; 296 return NULL;
923 } 297 }
Line 924... Line 298...
924   298  
925 stats->dirs = 0; 299 stats->dirs = 0;
-   300 stats->files = 0;
-   301 stats->lines = 0;
Line 926... Line 302...
926 stats->files = 0; 302 stats->size = 0;
927   303  
928 // Push the first path onto the stack. 304 // Push the first path onto the stack.
929 stack = stringStackCreate(count); 305 stack = stringStackCreate((unsigned int)count);
930 for(i = 0; run && i < count; ++i) { 306 for(i = 0; PROGRAM_RUN && i < count; ++i) {
Line 931... Line 307...
931 stringStackPush(stack, paths[i]); 307 stringStackPush(stack, paths[i]);
932 } 308 }
933   309  
934 while(run && !stringStackIsEmpty(stack)) { 310 while(PROGRAM_RUN && !stringStackIsEmpty(stack)) {
935 #if defined ___AmigaOS___ 311 #if defined ___AmigaOS___
936 // Check if CTRL+C was pressed and abort the program. 312 // Check if CTRL+C was pressed and abort the program.
937 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 313 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
938 run = FALSE; 314 PROGRAM_RUN = FALSE;
939 continue; 315 continue;
940 } 316 }
941 #endif 317 #endif
Line 942... Line 318...
942 if((path = stringStackPop(stack)) == NULL) { 318 if((path = stringStackPop(stack)) == NULL) {
943 break; 319 break;
944 } 320 }
945   321  
946 #if defined ___AmigaOS___ 322 #if defined ___AmigaOS___
947 if((lockp = Lock(path, ACCESS_READ)) == NULL) { 323 if((lock = Lock(path, ACCESS_READ)) == NULL) {
Line 948... Line 324...
948 fprintf(stderr, "Could not lock path '%s' for reading.\n", path); 324 fprintf(stderr, "Could not lock path '%s' for reading.\n", path);
949 free(path); 325 free(path);
950 continue; 326 continue;
951 } 327 }
952   328  
953 if((FIBp = AllocDosObject(DOS_FIB, NULL)) == NULL) { 329 if((FIB = AllocDosObject(DOS_FIB, NULL)) == NULL) {
Line 954... Line 330...
954 fprintf(stderr, "Path '%s' info block allocation failure.\n", path); 330 fprintf(stderr, "File information block for path '%s' could not be allocated.\n", path);
955 UnLock(lockp); 331 UnLock(lock);
956 free(path); 332 free(path);
957 continue; 333 continue;
958 } 334 }
959   335  
960 if(Examine(lockp, FIBp) == FALSE) { 336 if(Examine(lock, FIB) == FALSE) {
Line 961... Line 337...
961 fprintf(stderr, "Path '%s' could not be examined.\n", path); 337 fprintf(stderr, "Path '%s' could not be examined.\n", path);
962 FreeDosObject(DOS_FIB, FIBp); 338 FreeDosObject(DOS_FIB, FIB);
963 UnLock(lockp); 339 UnLock(lock);
964 free(path); 340 free(path);
965 continue; 341 continue;
966 } 342 }
967   343  
Line 968... Line 344...
968 while(run && ExNext(lockp, FIBp)) { 344 while(PROGRAM_RUN && ExNext(lock, FIB)) {
969 // Check if CTRL+C was pressed and abort the program. 345 // Check if CTRL+C was pressed and abort the program.
970 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 346 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
971 run = FALSE; 347 PROGRAM_RUN = FALSE;
972 continue; 348 continue;
Line 973... Line 349...
973 } 349 }
974 #else 350 #else
975   351  
976 if((dir = opendir(path)) == NULL) { 352 if((dir = opendir(path)) == NULL) {
977 fprintf(stderr, "Unable to open '%s' for reading.\n", path); 353 fprintf(stderr, "Directory '%s' could not be opened.\n", path);
978 free(path); 354 free(path);
979 continue; 355 continue;
980 } 356 }
981   357  
982 while(run && (entry = readdir(dir)) != NULL) { 358 while(PROGRAM_RUN && (entry = readdir(dir)) != NULL) {
983 #endif 359 #endif
984 switch(path[strlen(path) - 1]) { 360 switch(path[strlen(path) - 1]) {
985 case '/': 361 case '/':
986 case ':': // This is a drive path. 362 case ':': // This is a drive path.
987 #if defined ___AmigaOS___ 363 #if defined ___AmigaOS___
988 if((sub = malloc(strlen(path) + strlen(FIBp->fib_FileName) + 1)) == NULL) { 364 if((sub = malloc(strlen(path) + strlen(FIB->fib_FileName) + 1)) == NULL) {
989 #else 365 #else
990 if((sub = malloc(strlen(path) + strlen(entry->d_name) + 1)) == NULL) { 366 if((sub = malloc(strlen(path) + strlen(entry->d_name) + 1)) == NULL) {
991 #endif 367 #endif
Line 1004... Line 380...
1004 fclose(fp); 380 fclose(fp);
1005 #endif 381 #endif
1006 return NULL; 382 return NULL;
1007 } 383 }
1008 #if defined ___AmigaOS___ 384 #if defined ___AmigaOS___
1009 sprintf(sub, "%s%s", path, FIBp->fib_FileName); 385 sprintf(sub, "%s%s", path, FIB->fib_FileName);
1010 #else 386 #else
1011 sprintf(sub, "%s%s", path, entry->d_name); 387 sprintf(sub, "%s%s", path, entry->d_name);
1012 #endif 388 #endif
1013 break; 389 break;
1014 default: 390 default:
1015 #if defined ___AmigaOS___ 391 #if defined ___AmigaOS___
1016 if((sub = malloc(strlen(path) + strlen(FIBp->fib_FileName) + 1 + 1)) == NULL) { 392 if((sub = malloc(strlen(path) + strlen(FIB->fib_FileName) + 1 + 1)) == NULL) {
1017 #else 393 #else
1018 if((sub = malloc(strlen(path) + strlen(entry->d_name) + 1 + 1)) == NULL) { 394 if((sub = malloc(strlen(path) + strlen(entry->d_name) + 1 + 1)) == NULL) {
1019 #endif 395 #endif
1020 fprintf(stderr, "Memory allocation failure.\n"); 396 fprintf(stderr, "Memory allocation failure.\n");
1021 #if defined ___AmigaOS___ 397 #if defined ___AmigaOS___
1022 FreeDosObject(DOS_FIB, FIBp); 398 FreeDosObject(DOS_FIB, FIB);
1023 UnLock(lockp); 399 UnLock(lock);
1024 #else 400 #else
1025 closedir(dir); 401 closedir(dir);
1026 #endif 402 #endif
1027 free(path); 403 free(path);
1028 stringStackDestroy(stack); 404 stringStackDestroy(stack);
Line 1032... Line 408...
1032 fclose(fp); 408 fclose(fp);
1033 #endif 409 #endif
1034 return NULL; 410 return NULL;
1035 } 411 }
1036 #if defined ___AmigaOS___ 412 #if defined ___AmigaOS___
1037 sprintf(sub, "%s/%s", path, FIBp->fib_FileName); 413 sprintf(sub, "%s/%s", path, FIB->fib_FileName);
1038 #else 414 #else
1039 sprintf(sub, "%s/%s", path, entry->d_name); 415 sprintf(sub, "%s/%s", path, entry->d_name);
1040 #endif 416 #endif
1041 break; 417 break;
1042 } 418 }
Line -... Line 419...
-   419  
-   420 switch(GetFsType(sub)) {
-   421 case UNKNOWN:
-   422 free(sub);
-   423 continue;
-   424 case REGULAR:
Line 1043... Line -...
1043   -  
1044   -  
1045 #if defined ___AmigaOS___ -  
1046 if((lockq = Lock(sub, ACCESS_READ)) == NULL) { -  
1047 fprintf(stderr, "Could not lock path '%s' for reading.\n", sub); -  
1048 free(sub); -  
1049 continue; -  
1050 } -  
1051   -  
1052 if((FIBq = AllocDosObject(DOS_FIB, NULL)) == NULL) { -  
1053 fprintf(stderr, "Path '%s' info block allocation failure.\n", sub); -  
1054 UnLock(lockq); -  
1055 free(sub); -  
1056 continue; -  
1057 } -  
1058   -  
1059 if(Examine(lockq, FIBq) == FALSE) { -  
1060 fprintf(stderr, "Path '%s' could not be examined.\n", sub); -  
1061 FreeDosObject(DOS_FIB, FIBq); -  
1062 UnLock(lockq); -  
1063 free(sub); -  
1064 continue; -  
1065 } -  
1066   -  
1067 if(FIBq->fib_DirEntryType > 0) { -  
1068 #else -  
1069 stat(sub, &dirStat); -  
1070 if(S_ISDIR(dirStat.st_mode)) { -  
1071 #endif -  
1072 stringStackPush(stack, sub); -  
1073   -  
1074 ++stats->dirs; 425 ++stats->files;
1075   426  
1076 if(verbose) { 427 if(PROGRAM_VERBOSE) {
1077 fprintf(stdout, 428 fprintf(stdout,
1078 "Gathered %d directories and %d files.\r", 429 "Gathered %d directories and %d files.\r",
1079 stats->dirs, 430 stats->dirs,
1080 stats->files); -  
1081 } -  
1082   -  
1083 #if defined ___AmigaOS___ 431 stats->files);
1084 FreeDosObject(DOS_FIB, FIBq); -  
1085 UnLock(lockq); 432 }
1086 #endif 433 break;
1087 free(sub); -  
Line 1088... Line -...
1088 continue; -  
1089 } -  
1090   434 case DIRECTORY:
1091 #if defined ___AmigaOS___ -  
Line -... Line 435...
-   435 stringStackPush(stack, sub);
-   436  
-   437 ++stats->dirs;
-   438  
1092 FreeDosObject(DOS_FIB, FIBq); 439 if(PROGRAM_VERBOSE) {
-   440 fprintf(stdout,
Line 1093... Line 441...
1093 UnLock(lockq); 441 "Gathered %d directories and %d files.\r",
1094 #endif -  
1095   -  
1096 ++stats->files; -  
1097   442 stats->dirs,
1098 if(verbose) { 443 stats->files);
Line 1099... Line 444...
1099 fprintf(stdout, 444 }
1100 "Gathered %d directories and %d files.\r", 445  
1101 stats->dirs, 446 free(sub);
1102 stats->files); 447 continue;
1103 } 448 }
1104   449  
1105 #if defined ___NOCASE_FS___ 450 #if defined ___NOCASE_FS___
Line 1106... Line -...
1106 #if defined ___AmigaOS___ -  
1107 strupr(FIBp->fib_FileName); 451 #if defined ___AmigaOS___
1108 #else 452 StrUpr(FIB->fib_FileName);
1109 strupr(entry->d_name); 453 #else
1110 #endif 454 StrUpr(entry->d_name);
-   455 #endif
1111 #endif 456 #endif
1112   457  
-   458 // Write to database file.
1113   459 #if defined ___AsyncIO___
1114 // Write to database file. 460 #if defined ___AmigaOS___
-   461 WriteAsync(fp, FIB->fib_FileName, (LONG)strlen(FIB->fib_FileName));
1115 #if defined ___AsyncIO___ 462 stats->size = stats->size + strlen(FIB->fib_FileName);
-   463 #else
1116 #if defined ___AmigaOS___ 464 WriteAsync(fp, entry->d_name, (LONG)strlen(entry->d_name));
-   465 stats->size = stats->size + strlen(entry->d_name);
1117 WriteAsync(fp, FIBp->fib_FileName, (LONG)strlen(FIBp->fib_FileName)); 466 #endif
1118 #else 467 WriteAsync(fp, "\t", 1);
1119 WriteAsync(fp, entry->d_name, (LONG)strlen(entry->d_name)); 468 ++stats->size;
-   469 WriteAsync(fp, sub, (LONG)strlen(sub));
1120 #endif 470 stats->size = stats->size + strlen(sub);
1121 WriteAsync(fp, "\t", 1); 471 WriteAsync(fp, "\n", 1);
-   472 ++stats->size;
1122 WriteAsync(fp, sub, (LONG)strlen(sub)); 473 #else
1123 WriteAsync(fp, "\n", 1); 474 #if defined ___AmigaOS___
-   475 fprintf(fp, "%s\t%s\n", FIB->fib_FileName, sub);
-   476 stats->size = stats->size + strlen(FIB->fib_FileName) + strlen(sub) + 1 + 1 + 1;
-   477 #else
1124 #else 478 fprintf(fp, "%s\t%s\n", entry->d_name, sub);
1125 #if defined ___AmigaOS___ 479 stats->size = stats->size + strlen(entry->d_name) + strlen(sub) + 1 + 1 + 1;
Line 1126... Line 480...
1126 fprintf(fp, "%s\t%s\n", FIBp->fib_FileName, sub); 480 #endif
1127 #else 481 #endif
1128 fprintf(fp, "%s\t%s\n", entry->d_name, sub); 482  
1129 #endif 483 ++stats->lines;
1130 #endif 484  
1131 free(sub); 485 free(sub);
1132 } 486 }
1133   487  
Line 1134... Line 488...
1134 #if defined ___AmigaOS___ 488 #if defined ___AmigaOS___
1135 FreeDosObject(DOS_FIB, FIBp); 489 FreeDosObject(DOS_FIB, FIB);
1136 UnLock(lockp); 490 UnLock(lock);
Line 1137... Line 491...
1137 #else 491 #else
Line 1174... Line 528...
1174 #if defined ___AsyncIO___ 528 #if defined ___AsyncIO___
1175 if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { 529 if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) {
1176 #else 530 #else
1177 if((fp = fopen(dbFile, "r")) == NULL) { 531 if((fp = fopen(dbFile, "r")) == NULL) {
1178 #endif 532 #endif
1179 fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); 533 fprintf(stderr, "Could not open file '%s' for reading.\n", dbFile);
1180 return; 534 return;
1181 } 535 }
Line 1182... Line 536...
1182   536  
1183 #if defined ___AsyncIO___ 537 #if defined ___AsyncIO___
1184 if((tp = OpenAsync(tmpNames[--tmpFiles], MODE_WRITE, ASYNC_BUF)) == NULL) { 538 if((tp = OpenAsync(tmpNames[--tmpFiles], MODE_WRITE, ASYNC_BUF)) == NULL) {
1185 #else 539 #else
1186 if((tp = fopen(tmpNames[--tmpFiles], "w")) == NULL) { 540 if((tp = fopen(tmpNames[--tmpFiles], "w")) == NULL) {
1187 #endif 541 #endif
1188 fprintf(stderr, "Unable to open '%s' for writing.\n", tmpNames[tmpFiles]); 542 fprintf(stderr, "Could not open file '%s' for writing.\n", tmpNames[tmpFiles]);
1189 #if defined ___AsyncIO___ 543 #if defined ___AsyncIO___
1190 CloseAsync(fp); 544 CloseAsync(fp);
1191 #else 545 #else
1192 fclose(fp); 546 fclose(fp);
1193 #endif 547 #endif
1194 return; 548 return;
Line 1195... Line 549...
1195 } 549 }
1196   550  
1197 if(verbose) { 551 if(PROGRAM_VERBOSE) {
Line 1198... Line 552...
1198 fprintf(stdout, "Writing to temporary files...\r"); 552 fprintf(stdout, "Writing to temporary files...\r");
1199 } 553 }
1200   554  
1201 write = 0; 555 write = 0;
1202 lines = 0; 556 lines = 0;
1203 #if defined ___AsyncIO___ 557 #if defined ___AsyncIO___
1204 while(run && (c = ReadCharAsync(fp)) != -1) { 558 while(PROGRAM_RUN && (c = ReadCharAsync(fp)) != -1) {
1205 #else 559 #else
1206 while(run && fscanf(fp, "%c", &c) == 1) { 560 while(PROGRAM_RUN && fscanf(fp, "%c", &c) == 1) {
1207 #endif 561 #endif
1208 #if defined ___AmigaOS___ 562 #if defined ___AmigaOS___
1209 // Check if CTRL+C was pressed and abort the program. 563 // Check if CTRL+C was pressed and abort the program.
1210 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 564 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
1211 run = FALSE; 565 PROGRAM_RUN = FALSE;
1212 continue; 566 continue;
1213 } 567 }
1214 #endif 568 #endif
1215 switch(c) { 569 switch(c) {
Line 1216... Line 570...
1216 case '\n': 570 case '\n':
1217 // Increment the total written lines. 571 // Increment the total written lines.
1218 ++write; 572 ++write;
Line 1219... Line 573...
1219   573  
1220 if(verbose) { 574 if(PROGRAM_VERBOSE) {
Line 1250... Line 604...
1250 if((tp = OpenAsync(tmpNames[--tmpFiles], MODE_WRITE, ASYNC_BUF)) == NULL) { 604 if((tp = OpenAsync(tmpNames[--tmpFiles], MODE_WRITE, ASYNC_BUF)) == NULL) {
1251 #else 605 #else
1252 fclose(tp); 606 fclose(tp);
1253 if((tp = fopen(tmpNames[--tmpFiles], "w")) == NULL) { 607 if((tp = fopen(tmpNames[--tmpFiles], "w")) == NULL) {
1254 #endif 608 #endif
1255 fprintf(stderr, "Unable to open '%s' for writing.\n", tmpNames[tmpFiles]); 609 fprintf(stderr, "Could not open '%s' for writing.\n", tmpNames[tmpFiles]);
1256 #if defined ___AsyncIO___ 610 #if defined ___AsyncIO___
1257 CloseAsync(fp); 611 CloseAsync(fp);
1258 #else 612 #else
1259 fclose(fp); 613 fclose(fp);
1260 #endif 614 #endif
Line 1268... Line 622...
1268 #if defined ___AsyncIO___ 622 #if defined ___AsyncIO___
1269 if(WriteCharAsync(tp, (UBYTE)c) != 1) { 623 if(WriteCharAsync(tp, (UBYTE)c) != 1) {
1270 #else 624 #else
1271 if(fprintf(tp, "%c", c) != 1) { 625 if(fprintf(tp, "%c", c) != 1) {
1272 #endif 626 #endif
1273 fprintf(stderr, "Unable to write to '%s'.\n", tmpNames[tmpFiles]); 627 fprintf(stderr, "Could not write to file '%s'.\n", tmpNames[tmpFiles]);
1274 #if defined ___AsyncIO___ 628 #if defined ___AsyncIO___
1275 CloseAsync(tp); 629 CloseAsync(tp);
1276 CloseAsync(fp); 630 CloseAsync(fp);
1277 #else 631 #else
1278 fclose(tp); 632 fclose(tp);
Line 1282... Line 636...
1282 } 636 }
1283 break; 637 break;
1284 } 638 }
1285 } 639 }
Line 1286... Line 640...
1286   640  
1287 if(verbose) { 641 if(PROGRAM_VERBOSE) {
1288 fprintf(stdout, "\n"); 642 fprintf(stdout, "\n");
Line 1289... Line 643...
1289 } 643 }
1290   644  
Line 1307... Line 661...
1307 struct AsyncFile **tp; 661 struct AsyncFile **tp;
1308 #else 662 #else
1309 FILE *fp; 663 FILE *fp;
1310 FILE **tp; 664 FILE **tp;
1311 #endif 665 #endif
1312 unsigned int i; 666 int i;
1313 unsigned int j; 667 int j;
1314 char *tmp; 668 char *tmp;
1315 char *rem; 669 char *rem;
1316 char *min; 670 char *min;
1317 int count; 671 int count;
Line 1318... Line 672...
1318   672  
1319 #if defined ___AsyncIO___ 673 #if defined ___AsyncIO___
1320 if((fp = OpenAsync(dbFile, MODE_WRITE, ASYNC_BUF)) == NULL) { 674 if((fp = OpenAsync(dbFile, MODE_WRITE, ASYNC_BUF)) == NULL) {
1321 #else 675 #else
1322 if((fp = fopen(dbFile, "w")) == NULL) { 676 if((fp = fopen(dbFile, "w")) == NULL) {
1323 #endif 677 #endif
1324 fprintf(stderr, "Unable to open '%s' for writing.\n", dbFile); 678 fprintf(stderr, "Could not open file '%s' for writing.\n", dbFile);
1325 return; 679 return;
Line 1326... Line 680...
1326 } 680 }
1327   681  
Line 1341... Line 695...
1341 #if defined ___AsyncIO___ 695 #if defined ___AsyncIO___
1342 if((tp[i] = OpenAsync(tmpNames[i], MODE_READ, ASYNC_BUF)) == NULL) { 696 if((tp[i] = OpenAsync(tmpNames[i], MODE_READ, ASYNC_BUF)) == NULL) {
1343 #else 697 #else
1344 if((tp[i] = fopen(tmpNames[i], "r")) == NULL) { 698 if((tp[i] = fopen(tmpNames[i], "r")) == NULL) {
1345 #endif 699 #endif
1346 fprintf(stderr, "Unable to open '%s' for reading.\n", tmpNames[i]); 700 fprintf(stderr, "Could not open file '%s' for reading.\n", tmpNames[i]);
1347 // Close all temporary files. 701 // Close all temporary files.
1348 while(--i > -1) { 702 while(--i > -1) {
1349 #if defined ___AsyncIO___ 703 #if defined ___AsyncIO___
1350 CloseAsync(tp[i]); 704 CloseAsync(tp[i]);
1351 #else 705 #else
Line 1359... Line 713...
1359 #endif 713 #endif
1360 return; 714 return;
1361 } 715 }
1362 } 716 }
Line 1363... Line 717...
1363   717  
1364 if(verbose) { 718 if(PROGRAM_VERBOSE) {
1365 fprintf(stdout, "Merging all files...\r"); 719 fprintf(stdout, "Merging all files...\r");
Line 1366... Line 720...
1366 } 720 }
1367   721  
1368 rem = NULL; 722 rem = NULL;
1369 count = lines; 723 count = lines;
1370 j = 0; 724 j = 0;
1371 while(run && --count > -1) { 725 while(PROGRAM_RUN && --count > -1) {
1372 #if defined ___AmigaOS___ 726 #if defined ___AmigaOS___
1373 // Check if CTRL+C was pressed and abort the program. 727 // Check if CTRL+C was pressed and abort the program.
1374 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 728 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
1375 run = FALSE; 729 PROGRAM_RUN = FALSE;
1376 continue; 730 continue;
1377 } 731 }
1378 #endif 732 #endif
1379 // Find the smallest line in all temporary files. 733 // Find the smallest line in all temporary files.
1380 if(verbose) { 734 if(PROGRAM_VERBOSE) {
Line 1381... Line 735...
1381 fprintf(stdout, "Merging all files: %d%%.\r", 100 - (int)(((float)count / lines) * 100.0)); 735 fprintf(stdout, "Merging all files: %d%%.\r", 100 - (int)(((float)count / lines) * 100.0));
1382 } 736 }
Line 1395... Line 749...
1395 if(min != NULL) { 749 if(min != NULL) {
1396 // Free previous instance. 750 // Free previous instance.
1397 free(min); 751 free(min);
1398 } 752 }
1399 if((min = malloc((strlen(tmp) + 1) * sizeof(*min))) == NULL) { 753 if((min = malloc((strlen(tmp) + 1) * sizeof(*min))) == NULL) {
1400 fprintf(stderr, "Memory allication failure.\n"); 754 fprintf(stderr, "Memory allocation failure.\n");
1401 free(tmp); 755 free(tmp);
1402 if(min != NULL) { 756 if(min != NULL) {
1403 free(min); 757 free(min);
1404 } 758 }
1405 if(rem != NULL) { 759 if(rem != NULL) {
Line 1466... Line 820...
1466 if(rem != NULL) { 820 if(rem != NULL) {
1467 free(rem); 821 free(rem);
1468 } 822 }
Line 1469... Line 823...
1469   823  
1470 // Write out any remaining contents from the temporary files. 824 // Write out any remaining contents from the temporary files.
1471 for(i = 0; run && i < files; ++i) { 825 for(i = 0; PROGRAM_RUN && i < files; ++i) {
1472 #if defined ___AmigaOS___ 826 #if defined ___AmigaOS___
1473 // Check if CTRL+C was pressed and abort the program. 827 // Check if CTRL+C was pressed and abort the program.
1474 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 828 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
1475 run = FALSE; 829 PROGRAM_RUN = FALSE;
1476 continue; 830 continue;
1477 } 831 }
1478 #endif 832 #endif
1479 tmp = ReadLine(tp[i]); 833 tmp = ReadLine(tp[i]);
Line 1496... Line 850...
1496 #else 850 #else
1497 fclose(tp[i]); 851 fclose(tp[i]);
1498 #endif 852 #endif
1499 } 853 }
Line 1500... Line -...
1500   -  
1501 if(verbose) { -  
1502 fprintf(stdout, "\n"); -  
1503 } -  
1504   854  
1505 #if defined ___AsyncIO___ 855 #if defined ___AsyncIO___
1506 CloseAsync(fp); 856 CloseAsync(fp);
1507 #else 857 #else
1508 fclose(fp); 858 fclose(fp);
-   859 #endif
-   860  
-   861 if(PROGRAM_VERBOSE) {
-   862 fprintf(stdout, "\n");
1509 #endif 863 }
Line 1510... Line 864...
1510 } 864 }
1511   865  
1512 /* 866 /*
1513 * 867 *
1514 * Filter the paths inside the database with provided paths. 868 * Filter the paths inside the database with provided paths.
1515 */ 869 */
1516 void FilterDatabasePaths(char *dbFile, char *tmpName, char **paths, unsigned int count) { 870 void FilterDatabasePaths(char *dbFile, char *tmpName, char **paths, int count) {
1517 #if defined ___AsyncIO___ 871 #if defined ___AsyncIO___
1518 struct AsyncFile *fp; 872 struct AsyncFile *fp;
1519 struct AsyncFile *tp; 873 struct AsyncFile *tp;
1520 #else 874 #else
1521 FILE *fp; 875 FILE *fp;
1522 FILE *tp; 876 FILE *tp;
1523 #endif 877 #endif
1524 char *line; 878 char *line;
1525 unsigned int lines; 879 int lines;
Line 1526... Line 880...
1526 int i; 880 int i;
1527 dbEntry *entry; 881 dbEntry *entry;
1528   882  
1529 // Open database file for reading. 883 // Open database file for reading.
1530 #if defined ___AsyncIO___ 884 #if defined ___AsyncIO___
1531 if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { 885 if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) {
1532 #else 886 #else
1533 if((fp = fopen(dbFile, "r")) == NULL) { 887 if((fp = fopen(dbFile, "r")) == NULL) {
1534 #endif 888 #endif
Line 1535... Line 889...
1535 fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); 889 fprintf(stderr, "Could not open file '%s' for reading.\n", dbFile);
1536 return; 890 return;
1537 } 891 }
1538   892  
1539 // Open temporary file for writing. 893 // Open temporary file for writing.
1540 #if defined ___AsyncIO___ 894 #if defined ___AsyncIO___
1541 if((tp = OpenAsync(tmpName, MODE_WRITE, ASYNC_BUF)) == NULL) { 895 if((tp = OpenAsync(tmpName, MODE_WRITE, ASYNC_BUF)) == NULL) {
Line 1542... Line 896...
1542 #else 896 #else
1543 if((tp = fopen(tmpName, "w")) == NULL) { 897 if((tp = fopen(tmpName, "w")) == NULL) {
1544 #endif 898 #endif
1545 fprintf(stderr, "Unable to open '%s' for writing.\n", tmpName); 899 fprintf(stderr, "Copuld not open file '%s' for writing.\n", tmpName);
Line 1552... Line 906...
1552 #endif 906 #endif
Line 1553... Line 907...
1553   907  
1554 return; 908 return;
Line 1555... Line 909...
1555 } 909 }
1556   910  
1557 if(verbose) { 911 if(PROGRAM_VERBOSE) {
Line 1558... Line 912...
1558 fprintf(stdout, "Removing lines...\r"); 912 fprintf(stdout, "Removing lines...\r");
1559 } 913 }
1560   914  
1561 lines = 0; 915 lines = 0;
1562 while(run && (line = ReadLine(fp)) != NULL) { 916 while(PROGRAM_RUN && (line = ReadLine(fp)) != NULL) {
1563 #if defined ___AmigaOS___ 917 #if defined ___AmigaOS___
1564 // Check if CTRL+C was pressed and abort the program. 918 // Check if CTRL+C was pressed and abort the program.
1565 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 919 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
1566 run = FALSE; 920 PROGRAM_RUN = FALSE;
1567 continue; 921 continue;
1568 } 922 }
Line 1574... Line 928...
1574 } 928 }
Line 1575... Line 929...
1575   929  
1576 for(i = 0; i < count; ++i) { 930 for(i = 0; i < count; ++i) {
1577 if(PathCompare(entry->path, paths[i]) == TRUE) { 931 if(PathCompare(entry->path, paths[i]) == TRUE) {
1578 ++lines; 932 ++lines;
1579 if(verbose) { 933 if(PROGRAM_VERBOSE) {
1580 fprintf(stdout, "Removing lines: %d\r", lines); 934 fprintf(stdout, "Removing lines: %d.\r", lines);
1581 } 935 }
1582 continue; 936 continue;
1583 } 937 }
1584 #if defined ___AsyncIO___ 938 #if defined ___AsyncIO___
Line 1596... Line 950...
1596 free(entry); 950 free(entry);
Line 1597... Line 951...
1597   951  
1598 free(line); 952 free(line);
Line 1599... Line -...
1599 } -  
1600   -  
1601 if(verbose) { -  
1602 fprintf(stdout, "\n"); -  
1603 } -  
1604   953 }
1605   954  
1606 #if defined ___AsyncIO___ 955 #if defined ___AsyncIO___
1607 CloseAsync(fp); 956 CloseAsync(fp);
1608 CloseAsync(tp); 957 CloseAsync(tp);
1609 #else 958 #else
1610 fclose(fp); 959 fclose(fp);
-   960 fclose(tp);
-   961 #endif
-   962  
-   963 if(PROGRAM_VERBOSE) {
1611 fclose(tp); 964 fprintf(stdout, "\n");
Line 1612... Line 965...
1612 #endif 965 }
1613 } 966 }
1614   967  
1615 /* 968 /*
1616 * 969 *
1617 * Indexes a "path" by creating a database "dbFile". 970 * Indexes a "path" by creating a database "dbFile".
1618 */ 971 */
1619 void GatherDatabaseFiles(char *dbFile, char **paths, unsigned int count) { -  
1620 stats *stats; -  
1621 char **tmpNames; 972 void GatherDatabaseFiles(char *dbFile, char **paths, int count) {
1622 int dbSize; 973 dbStats *stats;
1623 int dbLines; 974 char **tmpNames;
Line 1624... Line 975...
1624 int tmpFiles; 975 int tmpFiles;
1625 int tmpLines; 976 int tmpLines;
1626 int i; 977 int i;
1627   978  
1628 // Generate the database file from the supplied paths. 979 // Generate the database file from the supplied paths.
1629 if((stats = CollectFiles(dbFile, paths, count)) == NULL) { -  
Line 1630... Line 980...
1630 fprintf(stderr, "Collecting files failed.\n"); 980 if((stats = CollectFiles(dbFile, paths, count)) == NULL) {
1631 return; -  
1632 } -  
1633 free(stats); -  
1634   -  
1635 // Compute the amount of temporary files needed. -  
1636 dbSize = GetFileSize(dbFile); 981 fprintf(stderr, "Collecting files failed.\n");
Line 1637... Line 982...
1637 if(dbSize == -1) { 982 return;
1638 fprintf(stderr, "File size for '%s' failed.\n", dbFile); 983 }
1639 return; 984  
1640 } 985 // Calculate the total number of temporary files required.
1641 tmpFiles = dbSize / maxmem; 986 tmpFiles = stats->size / maxmem;
1642   987  
1643 /* In case no temporary files are required, 988 /* In case no temporary files are required,
Line 1644... Line -...
1644 * just sort the database and terminate. -  
1645 */ -  
1646 if(tmpFiles <= 1) { -  
1647 SortDatabase(dbFile); 989 * just sort the database and terminate.
1648 return; -  
1649 } 990 */
Line 1650... Line 991...
1650   991 if(tmpFiles < 2) {
1651 // Get the database metrics. 992 SortDatabase(dbFile, stats->lines);
1652 dbLines = CountFileLines(dbFile); 993 return;
1653 if(dbLines == -1) { 994 }
1654 fprintf(stderr, "Counting lines of '%s' failed.\n", dbFile); 995  
Line 1655... Line 996...
1655 } 996 // Calculate the number of lines per temporary file.
1656 tmpLines = dbLines / tmpFiles; 997 tmpLines = stats->lines / tmpFiles;
Line 1657... Line 998...
1657   998  
1658 // Create temporary files. 999 // Create temporary files.
-   1000 if((tmpNames = CreateTemporaryFiles(tmpFiles)) == NULL) {
1659 if((tmpNames = CreateTemporaryFiles(tmpFiles)) == NULL) { 1001 fprintf(stderr, "Unable to create temporary files.\n");
1660 fprintf(stderr, "Unable to create temporary files.\n"); 1002 return;
Line 1661... Line 1003...
1661 return; 1003 }
1662 } 1004  
Line 1663... Line 1005...
1663   1005 // Write "tmpLines" to temporary files in "tmpNames" from "dbFile".
1664 // Write "tmpLines" to temporary files in "tmpNames" from "dbFile". 1006 WriteTemporaryFiles(dbFile, tmpNames, tmpFiles, tmpLines, stats->lines);
Line 1665... Line 1007...
1665 WriteTemporaryFiles(dbFile, tmpNames, tmpFiles, tmpLines, dbLines); 1007  
1666   1008 // Sort the temporary files.
-   1009 for(i = 0; i < tmpFiles; ++i) {
-   1010 tmpLines = CountFileLines(tmpNames[i]);
-   1011 SortDatabase(tmpNames[i], tmpLines);
1667 // Sort the temporary files. 1012 }
Line 1668... Line 1013...
1668 for(i = 0; i < tmpFiles; ++i) { 1013  
1669 SortDatabase(tmpNames[i]); 1014 // Merge all the temporary files to the database file.
Line 1670... Line 1015...
1670 } 1015 MergeTemporaryFiles(dbFile, tmpNames, tmpFiles, stats->lines);
1671   1016  
1672 // Merge all the temporary files to the database file. 1017 // Remove all temporary files.
Line 1726... Line 1071...
1726 /* 1071 /*
1727 * 1072 *
1728 * Main entry point. 1073 * Main entry point.
1729 */ 1074 */
1730 int main(int argc, char **argv) { 1075 int main(int argc, char **argv) {
1731 #if defined ___AmigaOS___ -  
1732 struct FileInfoBlock *FIB; -  
1733 BPTR lock; -  
1734 #else -  
1735 struct stat dirStat; -  
1736 #endif -  
1737 int option; 1076 int option;
1738 unsigned int i; 1077 int i;
1739 unsigned int count; 1078 int count;
1740 char *dbFile; 1079 char *dbFile;
1741 char *path; 1080 char *path;
1742 char **paths; 1081 char **paths;
-   1082 OPERATION operation = NONE;
Line 1743... Line 1083...
1743   1083  
1744 // Bind handler to SIGINT. 1084 // Bind handler to SIGINT.
1745 #if !defined ___AmigaOS___ 1085 #if !defined ___AmigaOS___
1746 signal(SIGINT, SignalHandler); 1086 signal(SIGINT, SignalHandler);
Line 1763... Line 1103...
1763 break; 1103 break;
1764 case 'd': 1104 case 'd':
1765 dbFile = optarg; 1105 dbFile = optarg;
1766 break; 1106 break;
1767 case 'q': 1107 case 'q':
1768 verbose = FALSE; 1108 PROGRAM_VERBOSE = FALSE;
1769 break; 1109 break;
1770 case 'h': 1110 case 'h':
1771 usage(argv[0]); 1111 usage(argv[0]);
1772 return 0; 1112 return 0;
1773 case '?': 1113 case '?':
Line 1797... Line 1137...
1797 if((path = PathToAbsolute(argv[i])) == NULL) { 1137 if((path = PathToAbsolute(argv[i])) == NULL) {
1798 fprintf(stderr, "Absolute path for '%s' failed to resolve.\n", argv[optind]); 1138 fprintf(stderr, "Absolute path for '%s' failed to resolve.\n", argv[optind]);
1799 continue; 1139 continue;
1800 } 1140 }
Line 1801... Line -...
1801   -  
1802 // Check that the path is a directory. -  
1803 #if defined ___AmigaOS___ -  
1804 if((lock = Lock(path, ACCESS_READ)) == NULL) { -  
1805 fprintf(stderr, "Path '%s' is not accessible.\n", path); 1141  
1806 free(path); -  
1807 continue; -  
1808 } -  
1809   -  
1810 if((FIB = AllocDosObject(DOS_FIB, NULL)) == NULL) { -  
1811 fprintf(stderr, "Path '%s' file information block not accessible.\n", path); 1142 switch(GetFsType(path)) {
1812 UnLock(lock); 1143 case UNKNOWN:
1813 free(path); -  
1814 continue; -  
1815 } -  
1816   -  
1817 if(Examine(lock, FIB) == FALSE) { 1144 case REGULAR:
1818 fprintf(stderr, "Path '%s' information unexaminable.\n", path); -  
1819 UnLock(lock); -  
1820 FreeDosObject(DOS_FIB, FIB); 1145 fprintf(stderr, "Path '%s' is not a directory.\n", path);
1821 free(path); 1146 free(path);
1822 continue; -  
1823 } -  
1824   -  
1825 if(FIB->fib_DirEntryType < 0) { -  
1826 #else -  
1827 stat(path, &dirStat); -  
1828 if(!S_ISDIR(dirStat.st_mode)) { -  
1829 #endif -  
1830 fprintf(stderr, "Path '%s' is not a directory.\n", argv[optind]); -  
1831 #if defined ___AmigaOS___ 1147 continue;
1832 UnLock(lock); -  
1833 FreeDosObject(DOS_FIB, FIB); -  
1834 #endif 1148 break;
1835 free(path); 1149 case DIRECTORY:
1836 return 1; 1150 break;
Line 1837... Line 1151...
1837 } 1151 }
1838   1152  
1839 if(verbose) { 1153 if(PROGRAM_VERBOSE) {
Line 1840... Line 1154...
1840 fprintf(stdout, "Will process path: '%s'\n", path); 1154 fprintf(stdout, "Will process path: '%s'\n", path);
1841 } 1155 }
Line 1847... Line 1161...
1847 } 1161 }
Line 1848... Line 1162...
1848   1162  
1849 sprintf(paths[count], "%s", path); 1163 sprintf(paths[count], "%s", path);
Line 1850... Line -...
1850 ++count; -  
1851   -  
1852 #if defined ___AmigaOS___ -  
1853 UnLock(lock); -  
1854 FreeDosObject(DOS_FIB, FIB); 1164 ++count;
Line 1855... Line 1165...
1855 #endif 1165  
Line 1856... Line 1166...
1856 free(path); 1166 free(path);
1857   1167  
1858 } 1168 }
1859   1169  
1860 if(count == 0) { 1170 if(count == 0) {
Line 1861... Line 1171...
1861 fprintf(stderr, "No valid paths are available.\n"); 1171 fprintf(stderr, "No valid paths are available.\n");
1862 free(paths); 1172 free(paths);
1863 return 1; 1173 return 1;
Line 1864... Line 1174...
1864 } 1174 }
1865   1175  
1866 if(verbose) { 1176 if(PROGRAM_VERBOSE) {
Line 1867... Line 1177...
1867 fprintf(stdout, "Gathering to: '%s'\n", dbFile); 1177 fprintf(stdout, "Gathering to: '%s'\n", dbFile);
1868 } 1178 }
1869   1179  
1870 #if defined ___AmigaOS___ 1180 #if defined ___AmigaOS___
1871 locale = OpenLocale(NULL); 1181 locale = OpenLocale(NULL);
1872 #endif 1182 #endif
1873   1183  
1874 switch(operation) { 1184 switch(operation) {
1875 case CREATE: 1185 case CREATE:
1876 if(verbose) { 1186 if(PROGRAM_VERBOSE) {
1877 fprintf(stdout, "Removing '%s' and creating a new database.\n", dbFile); 1187 fprintf(stdout, "Removing '%s' and creating a new database.\n", dbFile);
1878 } 1188 }
1879 if(RemoveFile(dbFile) == FALSE) { 1189 if(RemoveFile(dbFile) == FALSE) {
1880 fprintf(stderr, "File '%s' could not be removed.\n", dbFile); 1190 fprintf(stderr, "File '%s' could not be removed.\n", dbFile);
1881 break; 1191 break;
1882 } 1192 }
1883 case GATHER: 1193 case GATHER:
1884 if(verbose) { 1194 if(PROGRAM_VERBOSE) {
1885 fprintf(stdout, "Gathering files to database...\n"); 1195 fprintf(stdout, "Gathering files to database...\n");
1886 } 1196 }
1887 GatherDatabaseFiles(dbFile, paths, count); 1197 GatherDatabaseFiles(dbFile, paths, count);
1888 break; 1198 break;
Line 1901... Line 1211...
1901 CloseLocale(locale); 1211 CloseLocale(locale);
1902 #endif 1212 #endif
Line 1903... Line 1213...
1903   1213  
Line 1904... Line -...
1904 free(paths); -  
1905   -  
1906 #if defined MWDEBUG -  
1907 /* Generate a memory usage report */ -  
1908 MWReport("At end of main()", MWR_FULL); -  
1909 #endif 1214 free(paths);
1910   1215