HuntnGather – Diff between revs 30 and 31
?pathlinks?
Rev 30 | Rev 31 | |||
---|---|---|---|---|
Line 22... | Line 22... | |||
22 | |
22 | |
|
23 | #if defined ___AsyncIO___ |
23 | #if defined ___AsyncIO___ |
|
24 | #include <asyncio.h> |
24 | #include <asyncio.h> |
|
Line 25... | Line -... | |||
25 | #endif |
- | ||
26 | |
- | ||
27 | #include "StringStack.h" |
25 | #endif |
|
28 | |
26 | |
|
29 | #if !defined ___HAVE_GETOPT___ |
27 | #if !defined ___HAVE_GETOPT___ |
|
Line -... | Line 28... | |||
- | 28 | #include "getopt.h" |
||
- | 29 | #endif |
||
- | 30 | |
||
- | 31 | #include "StringStack.h" |
||
- | 32 | |
||
- | 33 | // MemLib memory debugging. |
||
- | 34 | #if defined MWDEBUG |
||
30 | #include "getopt.h" |
35 | #include "memwatch.h" |
|
Line 31... | Line 36... | |||
31 | #endif |
36 | #endif |
|
32 | |
37 | |
|
33 | #define PROGRAM_VERSION "1.7.4" |
38 | #define PROGRAM_VERSION "1.7.4" |
|
Line 91... | Line 96... | |||
91 | /* |
96 | /* |
|
92 | * |
97 | * |
|
93 | * Used for sorting database lines. |
98 | * Used for sorting database lines. |
|
94 | */ |
99 | */ |
|
95 | int QsortCompare(const void *a, const void *b) { |
100 | int QsortCompare(const void *a, const void *b) { |
|
96 | const char **p = (const char **)a; |
- | ||
97 | const char **q = (const char **)b; |
- | ||
98 | #if defined ___AmigaOS___ |
101 | #if defined ___AmigaOS___ |
|
- | 102 | return StrnCmp( |
||
- | 103 | locale, |
||
- | 104 | (STRPTR)(*(const char **)a), |
||
99 | return StrnCmp(locale, (STRPTR)*p, (STRPTR)*q, -1, SC_ASCII); |
105 | (STRPTR)*((const char **)b), |
|
- | 106 | -1, |
||
- | 107 | SC_ASCII |
||
- | 108 | ); |
||
100 | #else |
109 | #else |
|
101 | return strcmp(*p, *q); |
110 | return strcmp(*(const char **)a, *(const char **)b); |
|
102 | #endif |
111 | #endif |
|
103 | } |
112 | } |
|
Line 104... | Line 113... | |||
104 | |
113 | |
|
105 | /* |
114 | /* |
|
Line 367... | Line 376... | |||
367 | LONG c; |
376 | LONG c; |
|
368 | #else |
377 | #else |
|
369 | char *PeekLine(FILE *fp) { |
378 | char *PeekLine(FILE *fp) { |
|
370 | char c; |
379 | char c; |
|
371 | #endif |
380 | #endif |
|
372 | char *line; |
381 | char *line = NULL; |
|
- | 382 | char *real = NULL; |
||
373 | unsigned int size; |
383 | unsigned int size; |
|
374 | int i; |
384 | int i; |
|
Line 375... | Line 385... | |||
375 | |
385 | |
|
376 | size = LINE_BUF; |
386 | size = LINE_BUF; |
|
Line 410... | Line 420... | |||
410 | #endif |
420 | #endif |
|
411 | return line; |
421 | return line; |
|
412 | default: |
422 | default: |
|
413 | if(strlen(line) == size) { |
423 | if(strlen(line) == size) { |
|
414 | size = size * 1.5; |
424 | size = size * 1.5; |
|
415 | line = realloc(line, size * sizeof(*line)); |
425 | real = realloc(line, size * sizeof(*line)); |
|
- | 426 | if(real == NULL) { |
||
- | 427 | fprintf(stderr, "Memory reallocation failure.\n"); |
||
- | 428 | free(line); |
||
- | 429 | return NULL; |
||
- | 430 | } |
||
- | 431 | line = real; |
||
416 | } |
432 | } |
|
417 | line[i] = c; |
433 | line[i] = c; |
|
418 | line[i + 1] = '\0'; |
434 | line[i + 1] = '\0'; |
|
419 | break; |
435 | break; |
|
420 | } |
436 | } |
|
421 | ++i; |
437 | ++i; |
|
422 | } |
438 | } |
|
Line -... | Line 439... | |||
- | 439 | |
||
- | 440 | if(line != NULL) { |
||
- | 441 | free(line); |
||
- | 442 | } |
||
423 | |
443 | |
|
424 | return NULL; |
444 | return NULL; |
|
Line 425... | Line 445... | |||
425 | } |
445 | } |
|
426 | |
446 | |
|
Line 433... | Line 453... | |||
433 | LONG c; |
453 | LONG c; |
|
434 | #else |
454 | #else |
|
435 | char *ReadLine(FILE *fp) { |
455 | char *ReadLine(FILE *fp) { |
|
436 | char c; |
456 | char c; |
|
437 | #endif |
457 | #endif |
|
438 | char *line; |
458 | char *line = NULL; |
|
- | 459 | char *real = NULL; |
||
439 | unsigned int size; |
460 | unsigned int size; |
|
440 | unsigned int i; |
461 | unsigned int i; |
|
Line 441... | Line 462... | |||
441 | |
462 | |
|
442 | size = LINE_BUF; |
463 | size = LINE_BUF; |
|
Line 462... | Line 483... | |||
462 | case '\n': |
483 | case '\n': |
|
463 | return line; |
484 | return line; |
|
464 | default: |
485 | default: |
|
465 | if(strlen(line) == size) { |
486 | if(strlen(line) == size) { |
|
466 | size = size * 1.5; |
487 | size = size * 1.5; |
|
467 | line = realloc(line, size * sizeof(*line)); |
488 | real = realloc(line, size * sizeof(*line)); |
|
- | 489 | if(real == NULL) { |
||
- | 490 | fprintf(stderr, "Memory reallocation failure.\n"); |
||
- | 491 | free(line); |
||
- | 492 | return NULL; |
||
- | 493 | } |
||
- | 494 | line = real; |
||
468 | } |
495 | } |
|
469 | line[i] = c; |
496 | line[i] = c; |
|
470 | line[i + 1] = '\0'; |
497 | line[i + 1] = '\0'; |
|
471 | break; |
498 | break; |
|
472 | } |
499 | } |
|
473 | ++i; |
500 | ++i; |
|
474 | } |
501 | } |
|
Line -... | Line 502... | |||
- | 502 | |
||
- | 503 | if(line != NULL) { |
||
- | 504 | free(line); |
||
- | 505 | } |
||
475 | |
506 | |
|
476 | return NULL; |
507 | return NULL; |
|
Line 477... | Line 508... | |||
477 | } |
508 | } |
|
478 | |
509 | |
|
Line 634... | Line 665... | |||
634 | |
665 | |
|
635 | rem = malloc(strlen(lines[i]) + 1); |
666 | rem = malloc(strlen(lines[i]) + 1); |
|
636 | sprintf(rem, "%s", lines[i]); |
667 | sprintf(rem, "%s", lines[i]); |
|
Line -... | Line 668... | |||
- | 668 | } |
||
- | 669 | |
||
- | 670 | if(rem != NULL) { |
||
- | 671 | free(rem); |
||
637 | } |
672 | } |
|
638 | |
673 | |
|
639 | #if defined ___AsyncIO___ |
674 | #if defined ___AsyncIO___ |
|
640 | CloseAsync(fp); |
675 | CloseAsync(fp); |
|
641 | #else |
676 | #else |
|
Line 645... | Line 680... | |||
645 | |
680 | |
|
646 | /* |
681 | /* |
|
647 | * |
682 | * |
|
648 | * Create a database entry from a line of text. |
683 | * Create a database entry from a line of text. |
|
649 | */ |
684 | */ |
|
650 | dbEntry* CreateDataseEntry(char *line) { |
685 | dbEntry* CreateDatabaseEntry(char *line) { |
|
651 | dbEntry *entry; |
686 | dbEntry *entry; |
|
652 | char *ptr; |
687 | char *ptr; |
|
653 | unsigned int side; |
688 | unsigned int side; |
|
654 | unsigned int i; |
689 | unsigned int i; |
|
Line 657... | Line 692... | |||
657 | if((entry = malloc(1 * sizeof(*entry))) == NULL) { |
692 | if((entry = malloc(1 * sizeof(*entry))) == NULL) { |
|
658 | fprintf(stderr, "Memory allocation failure.\n"); |
693 | fprintf(stderr, "Memory allocation failure.\n"); |
|
659 | return NULL; |
694 | return NULL; |
|
660 | } |
695 | } |
|
Line 661... | Line 696... | |||
661 | |
696 | |
|
662 | if((entry->name = malloc(strlen(line) * sizeof(*entry->name))) == NULL) { |
697 | if((entry->name = malloc((strlen(line) + 1) * sizeof(*entry->name))) == NULL) { |
|
663 | fprintf(stderr, "Memory allocation failure.\n"); |
698 | fprintf(stderr, "Memory allocation failure.\n"); |
|
664 | return NULL; |
699 | return NULL; |
|
Line 665... | Line 700... | |||
665 | } |
700 | } |
|
666 | |
701 | |
|
667 | if((entry->path = malloc(strlen(line) * sizeof(*entry->path))) == NULL) { |
702 | if((entry->path = malloc((strlen(line) + 1) * sizeof(*entry->path))) == NULL) { |
|
668 | fprintf(stderr, "Memory allocation failure.\n"); |
703 | fprintf(stderr, "Memory allocation failure.\n"); |
|
Line 669... | Line 704... | |||
669 | return NULL; |
704 | return NULL; |
|
670 | } |
705 | } |
|
671 | |
706 | |
|
672 | for(ptr = line, side = 0, i = 0, j = 0; run && *ptr != '\0'; ++ptr) { |
707 | for(ptr = line, side = 0, i = 0, j = 0; run && *ptr != '\0'; ++ptr) { |
|
673 | #if defined ___AmigaOS___ |
708 | #if defined ___AmigaOS___ |
|
674 | // Check if CTRL+C was pressed and abort the program. |
709 | // Check if CTRL+C was pressed and abort the program. |
|
675 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
710 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
|
676 | run = FALSE; |
711 | run = FALSE; |
|
677 | continue; |
712 | continue; |
|
Line 711... | Line 746... | |||
711 | #else |
746 | #else |
|
712 | FILE *fp; |
747 | FILE *fp; |
|
713 | #endif |
748 | #endif |
|
714 | dbArray *array; |
749 | dbArray *array; |
|
715 | dbEntry *entry; |
750 | dbEntry *entry; |
|
716 | char *line; |
751 | char *line = NULL; |
|
- | 752 | char *real = NULL; |
||
717 | unsigned int count; |
753 | unsigned int count; |
|
Line 718... | Line -... | |||
718 | |
- | ||
719 | if((array = malloc(1 * sizeof(*array))) == NULL) { |
- | ||
720 | fprintf(stderr, "Memory allocation failure.\n"); |
- | ||
721 | return NULL; |
- | ||
722 | } |
- | ||
723 | |
754 | |
|
724 | // Open database file for reading. |
755 | // Open database file for reading. |
|
725 | #if defined ___AsyncIO___ |
756 | #if defined ___AsyncIO___ |
|
726 | if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { |
757 | if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) { |
|
727 | #else |
758 | #else |
|
728 | if((fp = fopen(dbFile, "r")) == NULL) { |
759 | if((fp = fopen(dbFile, "r")) == NULL) { |
|
729 | #endif |
760 | #endif |
|
730 | fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); |
761 | fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); |
|
731 | return NULL; |
762 | return NULL; |
|
Line -... | Line 763... | |||
- | 763 | } |
||
- | 764 | |
||
- | 765 | if((array = malloc(1 * sizeof(*array))) == NULL) { |
||
- | 766 | fprintf(stderr, "Memory allocation failure.\n"); |
||
- | 767 | #if defined ___AsyncIO___ |
||
- | 768 | CloseAsync(fp); |
||
- | 769 | #else |
||
- | 770 | fclose(fp); |
||
- | 771 | #endif |
||
- | 772 | return NULL; |
||
732 | } |
773 | } |
|
733 | |
774 | |
|
734 | count = 0; |
775 | count = 0; |
|
735 | while(run && (line = ReadLine(fp)) != NULL) { |
776 | while(run && (line = ReadLine(fp)) != NULL) { |
|
736 | #if defined ___AmigaOS___ |
777 | #if defined ___AmigaOS___ |
|
737 | // Check if CTRL+C was pressed and abort the program. |
778 | // Check if CTRL+C was pressed and abort the program. |
|
738 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
779 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
|
739 | run = FALSE; |
780 | run = FALSE; |
|
740 | continue; |
781 | continue; |
|
741 | } |
782 | } |
|
742 | #endif |
783 | #endif |
|
- | 784 | if((entry = CreateDatabaseEntry(line)) == NULL) { |
||
743 | if((entry = CreateDataseEntry(line)) == NULL) { |
785 | fprintf(stderr, "Unable to create database entry.\n"); |
|
744 | fprintf(stderr, "Unable to create database entry.\n"); |
786 | free(line); |
|
745 | #if defined ___AsyncIO___ |
787 | #if defined ___AsyncIO___ |
|
746 | CloseAsync(fp); |
788 | CloseAsync(fp); |
|
747 | #else |
789 | #else |
|
748 | fclose(fp); |
790 | fclose(fp); |
|
749 | #endif |
791 | #endif |
|
Line 750... | Line 792... | |||
750 | return NULL; |
792 | return NULL; |
|
751 | } |
793 | } |
|
- | 794 | |
||
- | 795 | // Load up the name and path into the database variable. |
||
- | 796 | real = realloc(array->database, (count + 1) * sizeof(*array->database)); |
||
- | 797 | if(real == NULL) { |
||
- | 798 | fprintf(stderr, "Memory reallocation failure.\n"); |
||
- | 799 | free(entry->name); |
||
- | 800 | free(entry->path); |
||
- | 801 | free(entry); |
||
- | 802 | free(line); |
||
- | 803 | #if defined ___AsyncIO___ |
||
- | 804 | CloseAsync(fp); |
||
- | 805 | #else |
||
- | 806 | fclose(fp); |
||
- | 807 | #endif |
||
- | 808 | return NULL; |
||
752 | |
809 | } |
|
753 | // Load up the name and path into the database variable. |
810 | array->database = real; |
|
- | 811 | |
||
- | 812 | if((array->database[count] = malloc((strlen(entry->name) + strlen(entry->path) + 1 + 1) * sizeof(*array->database[count]))) == NULL) { |
||
754 | array->database = realloc(array->database, (count + 1) * sizeof(*array->database)); |
813 | fprintf(stderr, "Memory allocation failure.\n"); |
|
755 | if((array->database[count] = malloc((strlen(entry->name) + strlen(entry->path) + 1 + 1) * sizeof(*array->database[count]))) == NULL) { |
814 | free(entry->name); |
|
756 | fprintf(stderr, "Memory allocation failure.\n"); |
815 | free(entry->path); |
|
757 | free(entry); |
816 | free(entry); |
|
758 | free(line); |
817 | free(line); |
|
Line 772... | Line 831... | |||
772 | free(entry); |
831 | free(entry); |
|
Line 773... | Line 832... | |||
773 | |
832 | |
|
774 | free(line); |
833 | free(line); |
|
Line -... | Line 834... | |||
- | 834 | } |
||
- | 835 | |
||
- | 836 | if(line != NULL) { |
||
- | 837 | free(line); |
||
775 | } |
838 | } |
|
776 | |
839 | |
|
777 | #if defined ___AsyncIO___ |
840 | #if defined ___AsyncIO___ |
|
778 | CloseAsync(fp); |
841 | CloseAsync(fp); |
|
779 | #else |
842 | #else |
|
Line 833... | Line 896... | |||
833 | DIR *dir; |
896 | DIR *dir; |
|
834 | struct dirent *entry; |
897 | struct dirent *entry; |
|
835 | struct stat dirStat; |
898 | struct stat dirStat; |
|
836 | #endif |
899 | #endif |
|
837 | stringStack *stack; |
900 | stringStack *stack; |
|
838 | stats *stats; |
901 | stats *stats = NULL; |
|
839 | int i; |
902 | int i; |
|
840 | char *path; |
903 | char *path; |
|
841 | char *sub; |
904 | char *sub; |
|
Line 842... | Line -... | |||
842 | |
- | ||
843 | // Initialize metrics. |
- | ||
844 | if((stats = malloc(sizeof(*stats))) == NULL) { |
- | ||
845 | fprintf(stderr, "Memory allocation failure.\n"); |
- | ||
846 | return NULL; |
- | ||
847 | } |
- | ||
848 | |
- | ||
849 | stats->dirs = 0; |
- | ||
850 | stats->files = 0; |
- | ||
851 | |
905 | |
|
852 | #if defined ___AsyncIO___ |
906 | #if defined ___AsyncIO___ |
|
853 | if((fp = OpenAsync(dbFile, MODE_APPEND, ASYNC_BUF)) == NULL) { |
907 | if((fp = OpenAsync(dbFile, MODE_APPEND, ASYNC_BUF)) == NULL) { |
|
854 | #else |
908 | #else |
|
855 | if((fp = fopen(dbFile, "a")) == NULL) { |
909 | if((fp = fopen(dbFile, "a")) == NULL) { |
|
856 | #endif |
910 | #endif |
|
857 | fprintf(stderr, "Unable to open '%s' for writing.\n", dbFile); |
911 | fprintf(stderr, "Unable to open '%s' for writing.\n", dbFile); |
|
858 | return stats; |
912 | return NULL; |
|
Line 859... | Line 913... | |||
859 | } |
913 | } |
|
860 | |
914 | |
|
861 | if(verbose) { |
915 | if(verbose) { |
|
Line -... | Line 916... | |||
- | 916 | fprintf(stdout, "Collecting files...\r"); |
||
- | 917 | } |
||
- | 918 | |
||
- | 919 | // Initialize metrics. |
||
- | 920 | if((stats = malloc(sizeof(*stats))) == NULL) { |
||
- | 921 | fprintf(stderr, "Memory allocation failure.\n"); |
||
- | 922 | #if defined ___AsyncIO___ |
||
- | 923 | CloseAsync(fp); |
||
- | 924 | #else |
||
- | 925 | fclose(fp); |
||
- | 926 | #endif |
||
- | 927 | return NULL; |
||
- | 928 | } |
||
- | 929 | |
||
862 | fprintf(stdout, "Collecting files...\r"); |
930 | stats->dirs = 0; |
|
863 | } |
931 | stats->files = 0; |
|
864 | |
932 | |
|
865 | // Push the first path onto the stack. |
933 | // Push the first path onto the stack. |
|
866 | stack = stringStackCreate(count); |
934 | stack = stringStackCreate(count); |
|
Line 904... | Line 972... | |||
904 | |
972 | |
|
905 | while(run && ExNext(lockp, FIBp)) { |
973 | while(run && ExNext(lockp, FIBp)) { |
|
906 | // Check if CTRL+C was pressed and abort the program. |
974 | // Check if CTRL+C was pressed and abort the program. |
|
907 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
975 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
|
908 | run = FALSE; |
- | ||
909 | FreeDosObject(DOS_FIB, FIBp); |
- | ||
910 | UnLock(lockp); |
- | ||
911 | free(path); |
976 | run = FALSE; |
|
912 | break; |
977 | continue; |
|
913 | } |
978 | } |
|
Line 914... | Line 979... | |||
914 | #else |
979 | #else |
|
915 | |
980 | |
|
Line 1247... | Line 1312... | |||
1247 | struct AsyncFile **tp; |
1312 | struct AsyncFile **tp; |
|
1248 | #else |
1313 | #else |
|
1249 | FILE *fp; |
1314 | FILE *fp; |
|
1250 | FILE **tp; |
1315 | FILE **tp; |
|
1251 | #endif |
1316 | #endif |
|
1252 | int i; |
1317 | unsigned int i; |
|
1253 | int j; |
1318 | unsigned int j; |
|
1254 | char *tmp; |
1319 | char *tmp; |
|
1255 | char *rem; |
1320 | char *rem; |
|
1256 | char *min; |
1321 | char *min; |
|
1257 | int count; |
1322 | int count; |
|
Line 1460... | Line 1525... | |||
1460 | #else |
1525 | #else |
|
1461 | FILE *fp; |
1526 | FILE *fp; |
|
1462 | FILE *tp; |
1527 | FILE *tp; |
|
1463 | #endif |
1528 | #endif |
|
1464 | char *line; |
1529 | char *line; |
|
- | 1530 | unsigned int lines; |
||
1465 | int i; |
1531 | int i; |
|
1466 | dbEntry *entry; |
1532 | dbEntry *entry; |
|
Line 1467... | Line 1533... | |||
1467 | |
1533 | |
|
1468 | // Open database file for reading. |
1534 | // Open database file for reading. |
|
Line 1491... | Line 1557... | |||
1491 | #endif |
1557 | #endif |
|
Line 1492... | Line 1558... | |||
1492 | |
1558 | |
|
1493 | return; |
1559 | return; |
|
Line -... | Line 1560... | |||
- | 1560 | } |
||
- | 1561 | |
||
- | 1562 | if(verbose) { |
||
- | 1563 | fprintf(stdout, "Removing lines...\r"); |
||
- | 1564 | } |
||
1494 | } |
1565 | |
|
1495 | |
1566 | lines = 0; |
|
1496 | while(run && (line = ReadLine(fp)) != NULL) { |
1567 | while(run && (line = ReadLine(fp)) != NULL) { |
|
1497 | #if defined ___AmigaOS___ |
1568 | #if defined ___AmigaOS___ |
|
1498 | // Check if CTRL+C was pressed and abort the program. |
1569 | // Check if CTRL+C was pressed and abort the program. |
|
1499 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
1570 | if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
|
1500 | run = FALSE; |
1571 | run = FALSE; |
|
1501 | continue; |
1572 | continue; |
|
1502 | } |
1573 | } |
|
1503 | #endif |
1574 | #endif |
|
- | 1575 | if((entry = CreateDatabaseEntry(line)) == NULL) { |
||
1504 | if((entry = CreateDataseEntry(line)) == NULL) { |
1576 | fprintf(stderr, "Unable to create database entry.\n"); |
|
1505 | fprintf(stderr, "Unable to create database entry.\n"); |
1577 | free(line); |
|
- | 1578 | continue; |
||
1506 | continue; |
1579 | } |
|
1507 | } |
1580 | |
|
- | 1581 | for(i = 0; i < count; ++i) { |
||
- | 1582 | if(PathCompare(entry->path, paths[i]) == TRUE) { |
||
- | 1583 | ++lines; |
||
- | 1584 | if(verbose) { |
||
1508 | for(i = 0; i < count; ++i) { |
1585 | fprintf(stdout, "Removing lines: %d\r", lines); |
|
1509 | if(PathCompare(entry->path, paths[i]) == TRUE) { |
1586 | } |
|
1510 | continue; |
1587 | continue; |
|
1511 | } |
1588 | } |
|
1512 | #if defined ___AsyncIO___ |
1589 | #if defined ___AsyncIO___ |
|
Line 1516... | Line 1593... | |||
1516 | fprintf(tp, "%s\n", line); |
1593 | fprintf(tp, "%s\n", line); |
|
1517 | #endif |
1594 | #endif |
|
1518 | break; |
1595 | break; |
|
1519 | } |
1596 | } |
|
Line -... | Line 1597... | |||
- | 1597 | |
||
- | 1598 | |
||
- | 1599 | free(entry->name); |
||
1520 | |
1600 | free(entry->path); |
|
- | 1601 | free(entry); |
||
1521 | free(entry); |
1602 | |
|
1522 | free(line); |
1603 | free(line); |
|
Line -... | Line 1604... | |||
- | 1604 | } |
||
- | 1605 | |
||
- | 1606 | if(verbose) { |
||
- | 1607 | fprintf(stdout, "\n"); |
||
Line 1523... | Line 1608... | |||
1523 | } |
1608 | } |
|
1524 | |
1609 | |
|
1525 | |
1610 | |
|
1526 | #if defined ___AsyncIO___ |
1611 | #if defined ___AsyncIO___ |
|
Line 1583... | Line 1668... | |||
1583 | |
1668 | |
|
1584 | // Write "tmpLines" to temporary files in "tmpNames" from "dbFile". |
1669 | // Write "tmpLines" to temporary files in "tmpNames" from "dbFile". |
|
Line 1585... | Line 1670... | |||
1585 | WriteTemporaryFiles(dbFile, tmpNames, tmpFiles, tmpLines, dbLines); |
1670 | WriteTemporaryFiles(dbFile, tmpNames, tmpFiles, tmpLines, dbLines); |
|
1586 | |
1671 | |
|
1587 | // Sort the temporary files. |
1672 | // Sort the temporary files. |
|
1588 | for(i = 0; run && i < tmpFiles; ++i) { |
1673 | for(i = 0; i < tmpFiles; ++i) { |
|
Line 1589... | Line 1674... | |||
1589 | SortDatabase(tmpNames[i]); |
1674 | SortDatabase(tmpNames[i]); |
|
1590 | } |
1675 | } |
|
Line 1591... | Line 1676... | |||
1591 | |
1676 | |
|
1592 | // Merge all the temporary files to the database file. |
1677 | // Merge all the temporary files to the database file. |
|
Line -... | Line 1678... | |||
- | 1678 | MergeTemporaryFiles(dbFile, tmpNames, tmpFiles, dbLines); |
||
1593 | MergeTemporaryFiles(dbFile, tmpNames, tmpFiles, dbLines); |
1679 | |
|
1594 | |
1680 | // Remove all temporary files. |
|
Line 1595... | Line 1681... | |||
1595 | // Remove all temporary files. |
1681 | RemoveFiles(tmpNames, tmpFiles); |
|
1596 | RemoveFiles(tmpNames, tmpFiles); |
1682 | |
|
Line 1612... | Line 1698... | |||
1612 | |
1698 | |
|
1613 | // Overwrite the database file with the filtered paths. |
1699 | // Overwrite the database file with the filtered paths. |
|
Line 1614... | Line 1700... | |||
1614 | CopyFile(tmpName, dbFile); |
1700 | CopyFile(tmpName, dbFile); |
|
1615 | |
1701 | |
|
- | 1702 | // Remove temporary file. |
||
- | 1703 | if(RemoveFile(tmpName) == FALSE) { |
||
- | 1704 | fprintf(stderr, "Temporary file could not be removed.\n"); |
||
1616 | // Remove temporary file. |
1705 | return; |
|
Line 1617... | Line 1706... | |||
1617 | RemoveFile(tmpName); |
1706 | } |
|
1618 | } |
1707 | } |
|
1619 | |
1708 | |
|
Line 1705... | Line 1794... | |||
1705 | // Go through all supplied arguments and add paths to search. |
1794 | // Go through all supplied arguments and add paths to search. |
|
1706 | if((paths = malloc((argc - optind) * sizeof(*paths))) == NULL) { |
1795 | if((paths = malloc((argc - optind) * sizeof(*paths))) == NULL) { |
|
1707 | fprintf(stderr, "Memory allocation failure.\n"); |
1796 | fprintf(stderr, "Memory allocation failure.\n"); |
|
1708 | return 1; |
1797 | return 1; |
|
1709 | } |
1798 | } |
|
- | 1799 | |
||
- | 1800 | count = 0; |
||
1710 | for(i = optind, count = 0; i < argc; ++i, ++count) { |
1801 | for(i = optind, count = 0; i < argc; ++i) { |
|
1711 | if((path = PathToAbsolute(argv[i])) == NULL) { |
1802 | if((path = PathToAbsolute(argv[i])) == NULL) { |
|
1712 | fprintf(stderr, "Absolute path for '%s' failed to resolve.\n", argv[optind]); |
1803 | fprintf(stderr, "Absolute path for '%s' failed to resolve.\n", argv[optind]); |
|
1713 | continue; |
1804 | continue; |
|
1714 | } |
1805 | } |
|
Line 1759... | Line 1850... | |||
1759 | fprintf(stderr, "Memory allocation failure."); |
1850 | fprintf(stderr, "Memory allocation failure."); |
|
1760 | return 1; |
1851 | return 1; |
|
1761 | } |
1852 | } |
|
Line 1762... | Line 1853... | |||
1762 | |
1853 | |
|
- | 1854 | sprintf(paths[count], "%s", path); |
||
Line 1763... | Line 1855... | |||
1763 | sprintf(paths[count], "%s", path); |
1855 | ++count; |
|
1764 | |
1856 | |
|
1765 | #if defined ___AmigaOS___ |
1857 | #if defined ___AmigaOS___ |
|
1766 | UnLock(lock); |
1858 | UnLock(lock); |
|
1767 | FreeDosObject(DOS_FIB, FIB); |
1859 | FreeDosObject(DOS_FIB, FIB); |
|
Line 1768... | Line 1860... | |||
1768 | #endif |
1860 | #endif |
|
Line -... | Line 1861... | |||
- | 1861 | free(path); |
||
- | 1862 | |
||
- | 1863 | } |
||
- | 1864 | |
||
- | 1865 | if(count == 0) { |
||
- | 1866 | fprintf(stderr, "No valid paths are available.\n"); |
||
1769 | free(path); |
1867 | free(paths); |
|
1770 | |
1868 | return 1; |
|
1771 | } |
1869 | } |
|
Line 1772... | Line 1870... | |||
1772 | |
1870 | |
|
1773 | if(verbose) { |
1871 | if(verbose) { |
|
1774 | fprintf(stdout, "Gathering to: '%s'\n", dbFile); |
1872 | fprintf(stdout, "Gathering to: '%s'\n", dbFile); |
|
Line 1775... | Line -... | |||
1775 | } |
- | ||
1776 | |
1873 | } |
|
1777 | #if defined ___AmigaOS___ |
1874 | |
|
1778 | locale = OpenLocale(NULL); |
1875 | #if defined ___AmigaOS___ |
|
1779 | #endif |
1876 | locale = OpenLocale(NULL); |
|
1780 | |
1877 | #endif |
|
1781 | // Gather. |
1878 | |
|
- | 1879 | switch(operation) { |
||
- | 1880 | case CREATE: |
||
- | 1881 | if(verbose) { |
||
1782 | switch(operation) { |
1882 | fprintf(stdout, "Removing '%s' and creating a new database.\n", dbFile); |
|
1783 | case CREATE: |
1883 | } |
|
1784 | if(verbose) { |
1884 | if(RemoveFile(dbFile) == FALSE) { |
|
1785 | fprintf(stdout, "Removing '%s' and creating a new database.\n", dbFile); |
1885 | fprintf(stderr, "File '%s' could not be removed.\n", dbFile); |
|
1786 | } |
1886 | break; |
|
Line 1796... | Line 1896... | |||
1796 | fprintf(stdout, "Removing files from database...\n"); |
1896 | fprintf(stdout, "Removing files from database...\n"); |
|
1797 | } |
1897 | } |
|
1798 | RemoveDatabaseFiles(dbFile, paths, count); |
1898 | RemoveDatabaseFiles(dbFile, paths, count); |
|
1799 | break; |
1899 | break; |
|
1800 | default: |
1900 | default: |
|
- | 1901 | fprintf(stderr, "Unknown operation.\n"); |
||
1801 | break; |
1902 | break; |
|
1802 | } |
1903 | } |
|
Line 1803... | Line 1904... | |||
1803 | |
1904 | |
|
1804 | #if defined ___AmigaOS___ |
1905 | #if defined ___AmigaOS___ |
|
1805 | CloseLocale(locale); |
1906 | CloseLocale(locale); |
|
Line 1806... | Line 1907... | |||
1806 | #endif |
1907 | #endif |
|
Line -... | Line 1908... | |||
- | 1908 | |
||
- | 1909 | free(paths); |
||
- | 1910 | |
||
- | 1911 | #if defined MWDEBUG |
||
- | 1912 | /* Generate a memory usage report */ |
||
1807 | |
1913 | MWReport("At end of main()", MWR_FULL); |
|
1808 | free(paths); |
1914 | #endif |