HuntnGather – Diff between revs 1 and 2
?pathlinks?
Rev 1 | Rev 2 | |||
---|---|---|---|---|
Line 27... | Line 27... | |||
27 | |
27 | |
|
28 | #if !defined FALSE |
28 | #if !defined FALSE |
|
29 | #define FALSE 0; |
29 | #define FALSE 0; |
|
Line 30... | Line 30... | |||
30 | #endif |
30 | #endif |
|
- | 31 | |
||
Line 31... | Line 32... | |||
31 | |
32 | #define MAX_MEM 262144 |
|
32 | #define MAX_MEM 524288 |
33 | #define DEFAULT_DATABASE_FILE "S:gather.db" |
|
33 | |
34 | |
|
34 | /*************************************************************************/ |
35 | /*************************************************************************/ |
|
35 | /* Version string used for querrying the program version. */ |
36 | /* Version string used for querrying the program version. */ |
|
Line 36... | Line 37... | |||
36 | /*************************************************************************/ |
37 | /*************************************************************************/ |
|
37 | TEXT version_string[] = |
38 | TEXT version_string[] = |
|
38 | "\0$VER: Gather 1.2 "__DATE__" by Wizardry and Steamworks"; |
39 | "\0$VER: Gather 1.3 "__DATE__" by Wizardry and Steamworks"; |
|
39 | |
40 | |
|
Line 532... | Line 533... | |||
532 | if(tmp == NULL) { |
533 | if(tmp == NULL) { |
|
533 | free(tmp); |
534 | free(tmp); |
|
534 | continue; |
535 | continue; |
|
535 | } |
536 | } |
|
536 | if(tmpMin == NULL || strcmp(tmp, tmpMin) < 0) { |
537 | if(tmpMin == NULL || strcmp(tmp, tmpMin) < 0) { |
|
- | 538 | if(tmpMin != NULL) { |
||
- | 539 | // Free previous instance. |
||
- | 540 | free(tmpMin); |
||
- | 541 | } |
||
537 | tmpMin = (char *) malloc((strlen(tmp) + 1) * sizeof(char)); |
542 | tmpMin = (char *) malloc((strlen(tmp) + 1) * sizeof(char)); |
|
538 | sprintf(tmpMin, "%s", tmp); |
543 | sprintf(tmpMin, "%s", tmp); |
|
539 | // Remember the index of the file where the smallest entry has been found. |
544 | // Remember the index of the file where the smallest entry has been found. |
|
540 | idxMin = i; |
545 | idxMin = i; |
|
541 | free(tmp); |
546 | free(tmp); |
|
Line 605... | Line 610... | |||
605 | // Compute the amount of temporary files needed. |
610 | // Compute the amount of temporary files needed. |
|
606 | tmpFiles = dbSize / MAX_MEM; |
611 | tmpFiles = dbSize / MAX_MEM; |
|
Line 607... | Line 612... | |||
607 | |
612 | |
|
608 | // In case no temporary files are required, |
613 | // In case no temporary files are required, |
|
609 | // just sort the database and terminate. |
614 | // just sort the database and terminate. |
|
610 | if(tmpFiles == 0) { |
615 | if(tmpFiles <= 1) { |
|
611 | SortDatabase(dbFile); |
616 | SortDatabase(dbFile); |
|
612 | return; |
617 | return; |
|
Line 613... | Line 618... | |||
613 | } |
618 | } |
|
Line 635... | Line 640... | |||
635 | * |
640 | * |
|
636 | * Main entry point. |
641 | * Main entry point. |
|
637 | */ |
642 | */ |
|
638 | int main(int argc, char **argv) { |
643 | int main(int argc, char **argv) { |
|
639 | int option; |
644 | int option; |
|
- | 645 | char *dbFile; |
||
640 | struct stat path; |
646 | struct stat path; |
|
Line 641... | Line 647... | |||
641 | |
647 | |
|
642 | // Bind handler to SIGINT. |
648 | // Bind handler to SIGINT. |
|
Line -... | Line 649... | |||
- | 649 | signal(SIGINT, SignalHandler); |
||
643 | signal(SIGINT, SignalHandler); |
650 | |
|
644 | |
651 | dbFile = DEFAULT_DATABASE_FILE; |
|
- | 652 | while((option = getopt(argc, argv, "hqd:")) != -1) { |
||
- | 653 | switch(option) { |
||
- | 654 | case 'd': |
||
645 | while((option = getopt(argc, argv, "hq")) != -1) { |
655 | dbFile = optarg; |
|
646 | switch(option) { |
656 | break; |
|
647 | case 'q': |
657 | case 'q': |
|
648 | verbose = FALSE; |
658 | verbose = FALSE; |
|
649 | break; |
659 | break; |
|
650 | case 'h': |
660 | case 'h': |
|
651 | fprintf(stdout, "SYNTAX: %s [-q] DIRECTORY", argv[0]); |
661 | fprintf(stdout, "SYNTAX: %s [-q] [-d DATABASE] DIRECTORY\n", argv[0]); |
|
652 | break; |
662 | return 0; |
|
653 | case '?': |
663 | case '?': |
|
654 | fprintf(stderr, "Invalid option %ct.\n", optopt); |
664 | fprintf(stderr, "Invalid option %ct.\n", optopt); |
|
655 | fprintf(stdout, "SYNTAX: %s [-q] DIRECTORY\n", argv[0]); |
665 | fprintf(stdout, "SYNTAX: %s [-q] [-d DATABASE] DIRECTORY\n", argv[0]); |
|
656 | return 1; |
666 | return 1; |
|
Line 657... | Line 667... | |||
657 | } |
667 | } |
|
658 | } |
668 | } |
|
659 | |
669 | |
|
660 | if(optind > argc) { |
670 | if(optind > argc) { |
|
Line 661... | Line 671... | |||
661 | fprintf(stdout, "SYNTAX: %s [-q] DIRECTORY\n", argv[0]); |
671 | fprintf(stdout, "SYNTAX: %s [-q] [-d DATABASE] DIRECTORY\n", argv[0]); |
|
662 | return 1; |
- | ||
663 | } |
672 | return 1; |
|
664 | |
673 | } |
|
665 | stat(argv[optind], &path); |
674 | |
|
666 | |
675 | stat(argv[optind], &path); |
|
Line -... | Line 676... | |||
- | 676 | if(!S_ISDIR(path.st_mode)) { |
||
- | 677 | fprintf(stderr, "%s is not a directory.\n", argv[optind]); |
||
- | 678 | return 1; |
||
- | 679 | } |
||
667 | if(!S_ISDIR(path.st_mode)) { |
680 | |
|
668 | fprintf(stdout, "%s is not a directory.\n", argv[optind]); |
681 | if(verbose) { |
|
Line 669... | Line 682... | |||
669 | return 1; |
682 | fprintf(stdout, "Gathering to database file: %s\n", dbFile); |
|
670 | } |
683 | } |