HuntnGather – Diff between revs 29 and 30

Subversion Repositories:
Rev:
Show entire fileIgnore whitespace
Rev 29 Rev 30
Line 126... Line 126...
126 UnLock(lock); 126 UnLock(lock);
127 return NULL; 127 return NULL;
128 } 128 }
129 UnLock(lock); 129 UnLock(lock);
130 #else 130 #else
131 abs = realpath(path, NULL); 131 //abs = realpath(path, NULL);
-   132 if((abs = malloc((strlen(path) + 1) * sizeof(*abs))) == NULL) {
-   133 fprintf(stderr, "Memory allocation failure.\n");
-   134 return NULL;
-   135 }
-   136 sprintf(abs, "%s", path);
132 #endif 137 #endif
Line 133... Line 138...
133   138  
134 return abs; 139 return abs;
Line 178... Line 183...
178 } 183 }
Line 179... Line 184...
179   184  
180 #if defined ___AsyncIO___ 185 #if defined ___AsyncIO___
181 if(SeekAsync(fp, 0, MODE_END) == -1) { 186 if(SeekAsync(fp, 0, MODE_END) == -1) {
182 #else 187 #else
183 if(fseek(fp, 0L, SEEK_END) == 0) { 188 if(fseek(fp, 0L, SEEK_END) != 0) {
184 #endif 189 #endif
185 fprintf(stderr, "Seek in file %s failed.\n", dbFile); 190 fprintf(stderr, "Seek in file %s failed.\n", dbFile);
186 #if defined ___AsyncIO___ 191 #if defined ___AsyncIO___
187 CloseAsync(fp); 192 CloseAsync(fp);
Line 231... Line 236...
231 fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); 236 fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile);
232 return -1; 237 return -1;
233 } 238 }
Line 234... Line 239...
234   239  
-   240 lines = 0;
-   241 if(verbose) {
-   242 fprintf(stdout, "Lines in '%s' so far: %d\r", dbFile, lines);
-   243 }
235 lines = 0; 244  
236 #if defined ___AsyncIO___ 245 #if defined ___AsyncIO___
237 while(run && (c = ReadCharAsync(fp)) != -1) { 246 while(run && (c = ReadCharAsync(fp)) != -1) {
238 #else 247 #else
239 while(run && fscanf(fp, "%c", &c) == 1) { 248 while(run && fscanf(fp, "%c", &c) == 1) {
Line 246... Line 255...
246 } 255 }
247 #endif 256 #endif
248 switch(c) { 257 switch(c) {
249 case '\n': 258 case '\n':
250 ++lines; 259 ++lines;
-   260  
-   261 if(verbose) {
-   262 fprintf(stdout, "Lines in '%s' so far: %d\r", dbFile, lines);
-   263 }
251 break; 264 break;
252 } 265 }
253 } 266 }
Line 254... Line 267...
254   267  
255 #if defined ___AsyncIO___ 268 #if defined ___AsyncIO___
256 CloseAsync(fp); 269 CloseAsync(fp);
257 #else 270 #else
258 fclose(fp); 271 fclose(fp);
Line -... Line 272...
-   272 #endif
-   273  
-   274 if(verbose) {
-   275 fprintf(stdout, "\n");
259 #endif 276 }
260   277  
Line 261... Line 278...
261 return lines; 278 return lines;
262 } 279 }
Line 383... Line 400...
383 fprintf(stderr, "Could not seek in file.\n"); 400 fprintf(stderr, "Could not seek in file.\n");
384 free(line); 401 free(line);
385 return NULL; 402 return NULL;
386 } 403 }
387 #else 404 #else
388 fseek(fp, -(i + 1), SEEK_CUR); 405 if(fseek(fp, -(i + 1), SEEK_CUR) != 0) {
-   406 fprintf(stderr, "Could not seek in file.\n");
-   407 free(line);
-   408 return NULL;
-   409 }
389 #endif 410 #endif
390 return line; 411 return line;
391 default: 412 default:
392 if(strlen(line) == size) { 413 if(strlen(line) == size) {
393 size = size * 1.5; 414 size = size * 1.5;
Line 496... Line 517...
496 FILE *ap; 517 FILE *ap;
497 FILE *bp; 518 FILE *bp;
498 char c; 519 char c;
499 #endif 520 #endif
Line 500... Line -...
500   -  
501   521  
502 // Open database file for writing. 522 // Open database file for writing.
503 #if defined ___AsyncIO___ 523 #if defined ___AsyncIO___
504 if((ap = OpenAsync(a, MODE_READ, ASYNC_BUF)) == NULL) { 524 if((ap = OpenAsync(a, MODE_READ, ASYNC_BUF)) == NULL) {
505 #else 525 #else
Line 511... Line 531...
511   531  
512 // Open temporary file for reading. 532 // Open temporary file for reading.
513 #if defined ___AsyncIO___ 533 #if defined ___AsyncIO___
514 if((bp = OpenAsync(b, MODE_WRITE, ASYNC_BUF)) == NULL) { 534 if((bp = OpenAsync(b, MODE_WRITE, ASYNC_BUF)) == NULL) {
515 #else 535 #else
516 if((bp = fopen(b, "w+")) == NULL) { 536 if((bp = fopen(b, "w")) == NULL) {
517 #endif 537 #endif
Line 518... Line 538...
518 fprintf(stderr, "Unable to open file '%s' for writing.\n", b); 538 fprintf(stderr, "Unable to open file '%s' for writing.\n", b);
519   539  
Line 532... Line 552...
532 #else 552 #else
533 while(run && fscanf(ap, "%c", &c) == 1) { 553 while(run && fscanf(ap, "%c", &c) == 1) {
534 #endif 554 #endif
535 #if defined ___AmigaOS___ 555 #if defined ___AmigaOS___
536 // Check if CTRL+C was pressed and abort the program. 556 // Check if CTRL+C was pressed and abort the program.
537 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 557 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
538 run = FALSE; 558 run = FALSE;
539 continue; 559 continue;
540 } 560 }
541 #endif 561 #endif
542 #if defined ___AsyncIO___ 562 #if defined ___AsyncIO___
Line 566... Line 586...
566 #if defined ___AsyncIO___ 586 #if defined ___AsyncIO___
567 struct AsyncFile *fp; 587 struct AsyncFile *fp;
568 #else 588 #else
569 FILE *fp; 589 FILE *fp;
570 #endif 590 #endif
571 int i; 591 unsigned int i;
572 char *rem; 592 char *rem;
Line 573... Line 593...
573   593  
574 // Write the database lines back to the database. 594 // Write the database lines back to the database.
575 #if defined ___AsyncIO___ 595 #if defined ___AsyncIO___
Line 583... Line 603...
583   603  
584 rem = NULL; 604 rem = NULL;
585 for(i = 0; i < count; ++i) { 605 for(i = 0; i < count; ++i) {
586 #if defined ___AmigaOS___ 606 #if defined ___AmigaOS___
587 // Check if CTRL+C was pressed and abort the program. 607 // Check if CTRL+C was pressed and abort the program.
588 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 608 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
589 run = FALSE; 609 run = FALSE;
590 continue; 610 continue;
591 } 611 }
Line 744... Line 764...
744 return NULL; 764 return NULL;
745 } 765 }
746 sprintf(array->database[count], "%s\t%s", entry->name, entry->path); 766 sprintf(array->database[count], "%s\t%s", entry->name, entry->path);
747 ++count; 767 ++count;
Line -... Line 768...
-   768  
-   769 // Free the database entry.
-   770 free(entry->name);
748   771 free(entry->path);
-   772 free(entry);
749 free(entry); 773  
750 free(line); 774 free(line);
Line 751... Line 775...
751 } 775 }
752   776  
Line 764... Line 788...
764 * 788 *
765 * Sorts a database file lexicographically. 789 * Sorts a database file lexicographically.
766 */ 790 */
767 void SortDatabase(char *dbFile) { 791 void SortDatabase(char *dbFile) {
768 dbArray *array; 792 dbArray *array;
-   793 int i;
Line 769... Line 794...
769   794  
770 if(verbose) { 795 if(verbose) {
771 fprintf(stdout, "Sorting '%s'...\n", dbFile); 796 fprintf(stdout, "Sorting '%s'...\n", dbFile);
Line 781... Line 806...
781 qsort(array->database, array->count, sizeof(char *), QsortCompare); 806 qsort(array->database, array->count, sizeof(char *), QsortCompare);
Line 782... Line 807...
782   807  
783 // Write back the database to the database file. 808 // Write back the database to the database file.
Line -... Line 809...
-   809 WriteLinesToFile(dbFile, array->database, array->count);
-   810  
-   811 // Deallocate all the lines.
-   812 for(i = 0; i < array->count; ++i) {
-   813 free(array->database[i]);
784 WriteLinesToFile(dbFile, array->database, array->count); 814 }
785   815  
Line 786... Line 816...
786 free(array); 816 free(array);
787 } 817 }
Line 809... Line 839...
809 int i; 839 int i;
810 char *path; 840 char *path;
811 char *sub; 841 char *sub;
Line 812... Line 842...
812   842  
813 // Initialize metrics. 843 // Initialize metrics.
814 if((stats = malloc(sizeof(stats))) == NULL) { 844 if((stats = malloc(sizeof(*stats))) == NULL) {
815 fprintf(stderr, "Memory allocation failure.\n"); 845 fprintf(stderr, "Memory allocation failure.\n");
816 return NULL; 846 return NULL;
Line 817... Line 847...
817 } 847 }
818   848  
Line 819... Line 849...
819 stats->dirs = 0; 849 stats->dirs = 0;
820 stats->files = 0; 850 stats->files = 0;
821   851  
822 #if defined ___AsyncIO___ 852 #if defined ___AsyncIO___
823 if((fp = OpenAsync(dbFile, MODE_APPEND, ASYNC_BUF)) == NULL) { 853 if((fp = OpenAsync(dbFile, MODE_APPEND, ASYNC_BUF)) == NULL) {
824 #else 854 #else
825 if((fp = fopen(dbFile, "r+")) == NULL) { 855 if((fp = fopen(dbFile, "a")) == NULL) {
826 #endif 856 #endif
Line 827... Line -...
827 fprintf(stderr, "Unable to open '%s' for writing.\n", dbFile); -  
828 return stats; -  
829 } -  
830   -  
831 // Seek to the end of the database. -  
832 #if defined ___AsyncIO___ -  
833 if(SeekAsync(fp, 0, MODE_END) == -1) { -  
834 #else -  
835 if(fseek(fp, 0, SEEK_END) == 0) { -  
836 #endif -  
837 fprintf(stderr, "Unable to seek in '%s' for appending.\n", dbFile); -  
838 #if defined ___AsyncIO___ -  
839 CloseAsync(fp); -  
840 #else -  
841 fclose(fp); -  
842 #endif 857 fprintf(stderr, "Unable to open '%s' for writing.\n", dbFile);
843 return stats; 858 return stats;
844 } 859 }
Line 845... Line 860...
845   860  
Line 870... Line 885...
870 fprintf(stderr, "Could not lock path '%s' for reading.\n", path); 885 fprintf(stderr, "Could not lock path '%s' for reading.\n", path);
871 free(path); 886 free(path);
872 continue; 887 continue;
873 } 888 }
Line 874... Line 889...
874   889  
875 if((FIBp = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) == NULL) { 890 if((FIBp = AllocDosObject(DOS_FIB, NULL)) == NULL) {
876 fprintf(stderr, "Path '%s' info block allocation failure.\n", path); 891 fprintf(stderr, "Path '%s' info block allocation failure.\n", path);
877 UnLock(lockp); 892 UnLock(lockp);
878 free(path); 893 free(path);
879 continue; 894 continue;
Line 889... Line 904...
889   904  
890 while(run && ExNext(lockp, FIBp)) { 905 while(run && ExNext(lockp, FIBp)) {
891 // Check if CTRL+C was pressed and abort the program. 906 // Check if CTRL+C was pressed and abort the program.
892 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { 907 if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
-   908 run = FALSE;
-   909 FreeDosObject(DOS_FIB, FIBp);
-   910 UnLock(lockp);
893 run = FALSE; 911 free(path);
894 continue; 912 break;
895 } 913 }
Line 896... Line 914...
896 #else 914 #else
897   915  
Line 905... Line 923...
905 #endif 923 #endif
906 switch(path[strlen(path) - 1]) { 924 switch(path[strlen(path) - 1]) {
907 case '/': 925 case '/':
908 case ':': // This is a drive path. 926 case ':': // This is a drive path.
909 #if defined ___AmigaOS___ 927 #if defined ___AmigaOS___
910 if((sub = malloc(sizeof(path) + sizeof(FIBp->fib_FileName) + 1)) == NULL) { 928 if((sub = malloc(strlen(path) + strlen(FIBp->fib_FileName) + 1)) == NULL) {
911 #else 929 #else
912 if((sub = malloc(sizeof(path) + sizeof(entry->d_name) + 1)) == NULL) { 930 if((sub = malloc(strlen(path) + strlen(entry->d_name) + 1)) == NULL) {
913 #endif 931 #endif
914 fprintf(stderr, "Memory allocation failure.\n"); 932 fprintf(stderr, "Memory allocation failure.\n");
915 #if defined ___AmigaOS___ 933 #if defined ___AmigaOS___
916 FreeDosObject(DOS_FIB, FIBp); 934 FreeDosObject(DOS_FIB, FIBp);
917 UnLock(lockp); 935 UnLock(lockp);
Line 933... Line 951...
933 sprintf(sub, "%s%s", path, entry->d_name); 951 sprintf(sub, "%s%s", path, entry->d_name);
934 #endif 952 #endif
935 break; 953 break;
936 default: 954 default:
937 #if defined ___AmigaOS___ 955 #if defined ___AmigaOS___
938 if((sub = malloc(sizeof(path) + sizeof(FIBp->fib_FileName) + 1 + 1)) == NULL) { 956 if((sub = malloc(strlen(path) + strlen(FIBp->fib_FileName) + 1 + 1)) == NULL) {
939 #else 957 #else
940 if((sub = malloc(sizeof(path) + sizeof(entry->d_name) + 1 + 1)) == NULL) { 958 if((sub = malloc(strlen(path) + strlen(entry->d_name) + 1 + 1)) == NULL) {
941 #endif 959 #endif
942 fprintf(stderr, "Memory allocation failure.\n"); 960 fprintf(stderr, "Memory allocation failure.\n");
943 #if defined ___AmigaOS___ 961 #if defined ___AmigaOS___
944 FreeDosObject(DOS_FIB, FIBp); 962 FreeDosObject(DOS_FIB, FIBp);
945 UnLock(lockp); 963 UnLock(lockp);
Line 961... Line 979...
961 sprintf(sub, "%s/%s", path, entry->d_name); 979 sprintf(sub, "%s/%s", path, entry->d_name);
962 #endif 980 #endif
963 break; 981 break;
964 } 982 }
Line -... Line 983...
-   983  
965   984  
966 #if defined ___AmigaOS___ 985 #if defined ___AmigaOS___
967 if((lockq = Lock(sub, ACCESS_READ)) == NULL) { 986 if((lockq = Lock(sub, ACCESS_READ)) == NULL) {
968 fprintf(stderr, "Could not lock path '%s' for reading.\n", sub); 987 fprintf(stderr, "Could not lock path '%s' for reading.\n", sub);
969 free(sub); 988 free(sub);
970 continue; 989 continue;
Line 971... Line 990...
971 } 990 }
972   991  
973 if((FIBq = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, NULL)) == NULL) { 992 if((FIBq = AllocDosObject(DOS_FIB, NULL)) == NULL) {
974 fprintf(stderr, "Path '%s' info block allocation failure.\n", sub); 993 fprintf(stderr, "Path '%s' info block allocation failure.\n", sub);
975 UnLock(lockq); 994 UnLock(lockq);
976 free(sub); 995 free(sub);
Line 1012... Line 1031...
1012 #if defined ___AmigaOS___ 1031 #if defined ___AmigaOS___
1013 FreeDosObject(DOS_FIB, FIBq); 1032 FreeDosObject(DOS_FIB, FIBq);
1014 UnLock(lockq); 1033 UnLock(lockq);
1015 #endif 1034 #endif
Line -... Line 1035...
-   1035  
-   1036 ++stats->files;
-   1037  
-   1038 if(verbose) {
-   1039 fprintf(stdout,
-   1040 "Gathered %d directories and %d files.\r",
-   1041 stats->dirs,
-   1042 stats->files);
-   1043 }
1016   1044  
1017 #if defined ___NOCASE_FS___ 1045 #if defined ___NOCASE_FS___
1018 #if defined ___AmigaOS___ 1046 #if defined ___AmigaOS___
1019 strupr(FIBp->fib_FileName); 1047 strupr(FIBp->fib_FileName);
1020 #else 1048 #else
1021 strupr(entry->d_name); 1049 strupr(entry->d_name);
1022 #endif 1050 #endif
-   1051 #endif
-   1052  
1023 #endif 1053  
1024 // Write to database file. 1054 // Write to database file.
1025 #if defined ___AsyncIO___ 1055 #if defined ___AsyncIO___
1026 #if defined ___AmigaOS___ 1056 #if defined ___AmigaOS___
1027 WriteAsync(fp, FIBp->fib_FileName, (LONG)strlen(FIBp->fib_FileName)); 1057 WriteAsync(fp, FIBp->fib_FileName, (LONG)strlen(FIBp->fib_FileName));
Line 1036... Line 1066...
1036 fprintf(fp, "%s\t%s\n", FIBp->fib_FileName, sub); 1066 fprintf(fp, "%s\t%s\n", FIBp->fib_FileName, sub);
1037 #else 1067 #else
1038 fprintf(fp, "%s\t%s\n", entry->d_name, sub); 1068 fprintf(fp, "%s\t%s\n", entry->d_name, sub);
1039 #endif 1069 #endif
1040 #endif 1070 #endif
1041 ++stats->files; -  
1042   -  
1043 if(verbose) { -  
1044 fprintf(stdout, -  
1045 "Gathered %d directories and %d files.\r", -  
1046 stats->dirs, -  
1047 stats->files); -  
1048 } -  
1049   -  
1050 free(sub); 1071 free(sub);
1051 } 1072 }
Line 1052... Line 1073...
1052   1073  
1053 #if defined ___AmigaOS___ 1074 #if defined ___AmigaOS___
Line 1732... Line 1753...
1732 if(verbose) { 1753 if(verbose) {
1733 fprintf(stdout, "Will process path: '%s'\n", path); 1754 fprintf(stdout, "Will process path: '%s'\n", path);
1734 } 1755 }
Line 1735... Line 1756...
1735   1756  
1736 // Add the path to the array of paths. 1757 // Add the path to the array of paths.
1737 if((paths[count] = malloc(strlen(path) * sizeof(*paths[count]))) == NULL) { 1758 if((paths[count] = malloc((strlen(path) + 1) * sizeof(*paths[count]))) == NULL) {
1738 fprintf(stderr, "Memory allocation failure."); 1759 fprintf(stderr, "Memory allocation failure.");
1739 return 1; 1760 return 1;
Line 1740... Line 1761...
1740 } 1761 }