HuntnGather – Diff between revs 27 and 28

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 27 Rev 28
Line 794... Line 794...
794 #if defined ___AsyncIO___ 794 #if defined ___AsyncIO___
795 struct AsyncFile *fp; 795 struct AsyncFile *fp;
796 #else 796 #else
797 FILE *fp; 797 FILE *fp;
798 #endif 798 #endif
-   799 #if defined ___AmigaOS___
799 stringStack *stack; 800 struct FileInfoBlock *FIBp, *FIBq;
800 stats *stats; 801 BPTR lockp, lockq;
-   802 #else
801 DIR *dir; 803 DIR *dir;
802 struct dirent *entry; 804 struct dirent *entry;
-   805 #endif
803 struct stat dirStat; 806 struct stat dirStat;
-   807  
-   808 stringStack *stack;
-   809 stats *stats;
804 int i; 810 int i;
805 char *path; 811 char *path;
806 char *subPath; 812 char *sub;
Line 807... Line 813...
807   813  
808 // Initialize metrics. 814 // Initialize metrics.
809 if((stats = malloc(sizeof(stats))) == NULL) { 815 if((stats = malloc(sizeof(stats))) == NULL) {
810 fprintf(stderr, "Memory allocation failure.\n"); 816 fprintf(stderr, "Memory allocation failure.\n");
Line 858... Line 864...
858 #endif 864 #endif
859 if((path = stringStackPop(stack)) == NULL) { 865 if((path = stringStackPop(stack)) == NULL) {
860 break; 866 break;
861 } 867 }
Line -... Line 868...
-   868  
862   869 #if defined ___AmigaOS___
863 if((dir = opendir(path)) == NULL) { 870 if((lockp = Lock(path, ACCESS_READ)) == NULL) {
864 fprintf(stderr, "Unable to open '%s' for reading.\n", path); 871 fprintf(stderr, "Could not lock path '%s' for reading.\n", path);
-   872 free(path);
865 break; 873 continue;
Line -... Line 874...
-   874 }
-   875  
-   876 if((FIBp = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) == NULL) {
-   877 fprintf(stderr, "Path '%s' info block allocation failure.\n", path);
-   878 UnLock(lockp);
-   879 free(path);
-   880 continue;
866 } 881 }
-   882  
867   883 if(Examine(lockp, FIBp) == FALSE) {
-   884 fprintf(stderr, "Path '%s' could not be examined.\n", path);
-   885 FreeDosObject(DOS_FIB, FIBp);
-   886 UnLock(lockp);
-   887 free(path);
-   888 continue;
-   889 }
868 while(run && (entry = readdir(dir)) != NULL) { 890  
869 #if defined ___AmigaOS___ 891 while(run && ExNext(lockp, FIBp)) {
870 // Check if CTRL+C was pressed and abort the program. 892 // Check if CTRL+C was pressed and abort the program.
871 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 893 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
872 run = FALSE; 894 run = FALSE;
-   895 continue;
-   896 }
-   897 #else
-   898  
-   899 if((dir = opendir(path)) == NULL) {
-   900 fprintf(stderr, "Unable to open '%s' for reading.\n", path);
-   901 free(path);
-   902 continue;
-   903 }
873 continue; 904  
874 } 905 while(run && (entry = readdir(dir)) != NULL) {
875 #endif 906 #endif
876 switch(path[strlen(path) - 1]) { 907 switch(path[strlen(path) - 1]) {
-   908 case '/':
-   909 case ':': // This is a drive path.
-   910 #if defined ___AmigaOS___
877 case '/': 911 if((sub = malloc(sizeof(path) + sizeof(FIBp->fib_FileName) + 1)) == NULL) {
-   912 #else
878 case ':': // This is a drive path. 913 if((sub = malloc(sizeof(path) + sizeof(entry->d_name) + 1)) == NULL) {
-   914 #endif
-   915 fprintf(stderr, "Memory allocation failure.\n");
-   916 #if defined ___AmigaOS___
-   917 FreeDosObject(DOS_FIB, FIBp);
879 if((subPath = malloc(sizeof(path) + sizeof(entry->d_name) + 1)) == NULL) { 918 UnLock(lockp);
-   919 #else
880 fprintf(stderr, "Memory allocation failure.\n"); 920 closedir(dir);
881 closedir(dir); 921 #endif
882 free(path); 922 free(path);
883 stringStackDestroy(stack); 923 stringStackDestroy(stack);
884 #if defined ___AsyncIO___ 924 #if defined ___AsyncIO___
885 CloseAsync(fp); 925 CloseAsync(fp);
886 #else 926 #else
887 fclose(fp); 927 fclose(fp);
888 #endif 928 #endif
-   929 return NULL;
-   930 }
-   931 #if defined ___AmigaOS___
889 return NULL; 932 sprintf(sub, "%s%s", path, FIBp->fib_FileName);
-   933 #else
890 } 934 sprintf(sub, "%s%s", path, entry->d_name);
891 sprintf(subPath, "%s%s", path, entry->d_name); 935 #endif
-   936 break;
-   937 default:
-   938 #if defined ___AmigaOS___
892 break; 939 if((sub = malloc(sizeof(path) + sizeof(FIBp->fib_FileName) + 1 + 1)) == NULL) {
-   940 #else
893 default: 941 if((sub = malloc(sizeof(path) + sizeof(entry->d_name) + 1 + 1)) == NULL) {
-   942 #endif
-   943 fprintf(stderr, "Memory allocation failure.\n");
-   944 #if defined ___AmigaOS___
-   945 FreeDosObject(DOS_FIB, FIBp);
894 if((subPath = malloc(sizeof(path) + sizeof(entry->d_name) + 1 + 1)) == NULL) { 946 UnLock(lockp);
-   947 #else
895 fprintf(stderr, "Memory allocation failure.\n"); 948 closedir(dir);
896 closedir(dir); 949 #endif
897 free(path); 950 free(path);
898 stringStackDestroy(stack); 951 stringStackDestroy(stack);
899 #if defined ___AsyncIO___ 952 #if defined ___AsyncIO___
900 CloseAsync(fp); 953 CloseAsync(fp);
901 #else 954 #else
902 fclose(fp); 955 fclose(fp);
903 #endif 956 #endif
-   957 return NULL;
-   958 }
-   959 #if defined ___AmigaOS___
904 return NULL; 960 sprintf(sub, "%s/%s", path, FIBp->fib_FileName);
-   961 #else
905 } 962 sprintf(sub, "%s/%s", path, entry->d_name);
906 sprintf(subPath, "%s/%s", path, entry->d_name); 963 #endif
-   964 break;
-   965 }
-   966  
-   967 #if defined ___AmigaOS___
-   968 if((lockq = Lock(sub, ACCESS_READ)) == NULL) {
-   969 fprintf(stderr, "Could not lock path '%s' for reading.\n", sub);
-   970 free(sub);
-   971 continue;
-   972 }
-   973  
-   974 if((FIBq = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) == NULL) {
-   975 fprintf(stderr, "Path '%s' info block allocation failure.\n", sub);
-   976 UnLock(lockq);
-   977 free(sub);
-   978 continue;
-   979 }
-   980  
-   981 if(Examine(lockq, FIBq) == FALSE) {
-   982 fprintf(stderr, "Path '%s' could not be examined.\n", sub);
-   983 FreeDosObject(DOS_FIB, FIBq);
-   984 UnLock(lockq);
-   985 free(sub);
-   986 continue;
-   987 }
-   988  
907 break; 989 if(FIBq->fib_DirEntryType > 0) {
908 } 990 #else
-   991 stat(sub, &dirStat);
909 stat(subPath, &dirStat); 992 if(S_ISDIR(dirStat.st_mode)) {
Line 910... Line 993...
910 if(S_ISDIR(dirStat.st_mode)) { 993 #endif
Line 911... Line 994...
911 stringStackPush(stack, subPath); 994 stringStackPush(stack, sub);
912   995  
913 ++stats->dirs; 996 ++stats->dirs;
914   997  
915 if(verbose) { 998 if(verbose) {
916 fprintf(stdout, 999 fprintf(stdout,
Line -... Line 1000...
-   1000 "Gathered %d directories and %d files.\r",
-   1001 stats->dirs,
-   1002 stats->files);
-   1003 }
917 "Gathered %d directories and %d files.\r", 1004  
918 stats->dirs, 1005 #if defined ___AmigaOS___
919 stats->files); 1006 FreeDosObject(DOS_FIB, FIBq);
Line -... Line 1007...
-   1007 UnLock(lockq);
-   1008 #endif
-   1009 free(sub);
-   1010 continue;
-   1011 }
920 } 1012  
-   1013 #if defined ___AmigaOS___
-   1014 FreeDosObject(DOS_FIB, FIBq);
-   1015 UnLock(lockq);
921   1016 #endif
922 free(subPath); 1017  
-   1018 #if defined ___NOCASE_FS___
923 continue; 1019 #if defined ___AmigaOS___
924 } 1020 strupr(FIBp->fib_FileName);
-   1021 #else
-   1022 strupr(entry->d_name);
-   1023 #endif
925   1024 #endif
-   1025 // Write to database file.
926 #if defined ___NOCASE_FS___ 1026 #if defined ___AsyncIO___
927 strupr(entry->d_name); 1027 #if defined ___AmigaOS___
928 #endif 1028 WriteAsync(fp, FIBp->fib_FileName, (LONG)strlen(FIBp->fib_FileName));
929 // Write to database file. 1029 #else
-   1030 WriteAsync(fp, entry->d_name, (LONG)strlen(entry->d_name));
-   1031 #endif
-   1032 WriteAsync(fp, "\t", 1);
930 #if defined ___AsyncIO___ 1033 WriteAsync(fp, sub, (LONG)strlen(sub));
-   1034 WriteAsync(fp, "\n", 1);
931 WriteAsync(fp, entry->d_name, (LONG)strlen(entry->d_name)); 1035 #else
932 WriteAsync(fp, "\t", 1); 1036 #if defined ___AmigaOS___
Line 933... Line 1037...
933 WriteAsync(fp, subPath, (LONG)strlen(subPath)); 1037 fprintf(fp, "%s\t%s\n", FIBp->fib_FileName, sub);
934 WriteAsync(fp, "\n", 1); 1038 #else
935 #else 1039 fprintf(fp, "%s\t%s\n", entry->d_name, sub);
936 fprintf(fp, "%s\t%s\n", entry->d_name, subPath); 1040 #endif
937 #endif 1041 #endif
938 ++stats->files; 1042 ++stats->files;
Line 939... Line 1043...
939   1043  
940 if(verbose) { 1044 if(verbose) {
Line -... Line 1045...
-   1045 fprintf(stdout,
-   1046 "Gathered %d directories and %d files.\r",
-   1047 stats->dirs,
-   1048 stats->files);
941 fprintf(stdout, 1049 }
-   1050  
942 "Gathered %d directories and %d files.\r", 1051 free(sub);
943 stats->dirs, 1052 }
Line 944... Line 1053...
944 stats->files); 1053  
945 } 1054 #if defined ___AmigaOS___
Line 1238... Line 1347...
1238 // If current minimum line is identical to previous minimum line then skip to remove duplicates. 1347 // If current minimum line is identical to previous minimum line then skip to remove duplicates.
1239 if(rem != NULL) { 1348 if(rem != NULL) {
1240 #if defined ___AmigaOS___ 1349 #if defined ___AmigaOS___
1241 if(StrnCmp(locale, min, rem, -1, SC_ASCII) == 0) { 1350 if(StrnCmp(locale, min, rem, -1, SC_ASCII) == 0) {
1242 #else 1351 #else
1243 if(strcmp(min, rem) == 0 { 1352 if(strcmp(min, rem) == 0) {
1244 #endif 1353 #endif
1245 free(min); 1354 free(min);
1246 continue; 1355 continue;
1247 } 1356 }
1248 } 1357 }
Line 1513... Line 1622...
1513 /* 1622 /*
1514 * 1623 *
1515 * Main entry point. 1624 * Main entry point.
1516 */ 1625 */
1517 int main(int argc, char **argv) { 1626 int main(int argc, char **argv) {
-   1627 #if defined ___AmigaOS___
-   1628 struct FileInfoBlock *FIB;
-   1629 BPTR lock;
-   1630 #else
-   1631 struct stat dirStat;
-   1632 #endif
1518 int option; 1633 int option;
1519 unsigned int i; 1634 unsigned int i;
1520 unsigned int count; 1635 unsigned int count;
1521 char *dbFile; 1636 char *dbFile;
1522 char *path; 1637 char *path;
1523 char **paths; 1638 char **paths;
1524 struct stat dirStat; -  
Line 1525... Line 1639...
1525   1639  
1526 // Bind handler to SIGINT. 1640 // Bind handler to SIGINT.
1527 #if !defined ___AmigaOS___ 1641 #if !defined ___AmigaOS___
1528 signal(SIGINT, SignalHandler); 1642 signal(SIGINT, SignalHandler);
Line 1572... Line 1686...
1572 if((paths = malloc((argc - optind) * sizeof(*paths))) == NULL) { 1686 if((paths = malloc((argc - optind) * sizeof(*paths))) == NULL) {
1573 fprintf(stderr, "Memory allocation failure.\n"); 1687 fprintf(stderr, "Memory allocation failure.\n");
1574 return 1; 1688 return 1;
1575 } 1689 }
1576 for(i = optind, count = 0; i < argc; ++i, ++count) { 1690 for(i = optind, count = 0; i < argc; ++i, ++count) {
1577 if((path = PathToAbsolute(argv[optind])) == NULL) { 1691 if((path = PathToAbsolute(argv[i])) == NULL) {
1578 fprintf(stderr, "Absolute path for '%s' failed to resolve.\n", argv[optind]); 1692 fprintf(stderr, "Absolute path for '%s' failed to resolve.\n", argv[optind]);
1579 continue; 1693 continue;
1580 } 1694 }
Line 1581... Line 1695...
1581   1695  
-   1696 // Check that the path is a directory.
-   1697 #if defined ___AmigaOS___
-   1698 if((lock = Lock(path, ACCESS_READ)) == NULL) {
-   1699 fprintf(stderr, "Path '%s' is not accessible.\n", path);
-   1700 free(path);
-   1701 continue;
-   1702 }
-   1703  
-   1704 if((FIB = AllocDosObject(DOS_FIB, NULL)) == NULL) {
-   1705 fprintf(stderr, "Path '%s' file information block not accessible.\n", path);
-   1706 UnLock(lock);
-   1707 free(path);
-   1708 continue;
-   1709 }
-   1710  
-   1711 if(Examine(lock, FIB) == FALSE) {
-   1712 fprintf(stderr, "Path '%s' information unexaminable.\n", path);
-   1713 UnLock(lock);
-   1714 FreeDosObject(DOS_FIB, FIB);
-   1715 free(path);
-   1716 continue;
-   1717 }
-   1718  
-   1719 if(FIB->fib_DirEntryType < 0) {
1582 // Check that the path is a directory. 1720 #else
1583 stat(path, &dirStat); 1721 stat(path, &dirStat);
-   1722 if(!S_ISDIR(dirStat.st_mode)) {
1584 if(!S_ISDIR(dirStat.st_mode)) { 1723 #endif
-   1724 fprintf(stderr, "Path '%s' is not a directory.\n", argv[optind]);
-   1725 #if defined ___AmigaOS___
-   1726 UnLock(lock);
-   1727 FreeDosObject(DOS_FIB, FIB);
1585 fprintf(stderr, "Path '%s' is not a directory.\n", argv[optind]); 1728 #endif
1586 free(path); 1729 free(path);
1587 return 1; 1730 return 1;
Line 1588... Line 1731...
1588 } 1731 }
Line 1594... Line 1737...
1594 // Add the path to the array of paths. 1737 // Add the path to the array of paths.
1595 if((paths[count] = malloc(strlen(path) * sizeof(*paths[count]))) == NULL) { 1738 if((paths[count] = malloc(strlen(path) * sizeof(*paths[count]))) == NULL) {
1596 fprintf(stderr, "Memory allocation failure."); 1739 fprintf(stderr, "Memory allocation failure.");
1597 return 1; 1740 return 1;
1598 } 1741 }
-   1742  
1599 sprintf(paths[count], "%s", path); 1743 sprintf(paths[count], "%s", path);
-   1744  
-   1745 #if defined ___AmigaOS___
-   1746 UnLock(lock);
-   1747 FreeDosObject(DOS_FIB, FIB);
-   1748 #endif
1600 free(path); 1749 free(path);
-   1750  
1601 } 1751 }
Line 1602... Line 1752...
1602   1752  
1603 if(verbose) { 1753 if(verbose) {
1604 fprintf(stdout, "Gathering to: '%s'\n", dbFile); 1754 fprintf(stdout, "Gathering to: '%s'\n", dbFile);