/trunk/HuntnGather/Gather/Gather.c |
@@ -29,13 +29,14 @@ |
#define FALSE 0; |
#endif |
|
#define MAX_MEM 524288 |
#define MAX_MEM 262144 |
#define DEFAULT_DATABASE_FILE "S:gather.db" |
|
/*************************************************************************/ |
/* Version string used for querrying the program version. */ |
/*************************************************************************/ |
TEXT version_string[] = |
"\0$VER: Gather 1.2 "__DATE__" by Wizardry and Steamworks"; |
"\0$VER: Gather 1.3 "__DATE__" by Wizardry and Steamworks"; |
|
typedef struct { |
unsigned int dirs; |
@@ -534,6 +535,10 @@ |
continue; |
} |
if(tmpMin == NULL || strcmp(tmp, tmpMin) < 0) { |
if(tmpMin != NULL) { |
// Free previous instance. |
free(tmpMin); |
} |
tmpMin = (char *) malloc((strlen(tmp) + 1) * sizeof(char)); |
sprintf(tmpMin, "%s", tmp); |
// Remember the index of the file where the smallest entry has been found. |
@@ -607,7 +612,7 @@ |
|
// In case no temporary files are required, |
// just sort the database and terminate. |
if(tmpFiles == 0) { |
if(tmpFiles <= 1) { |
SortDatabase(dbFile); |
return; |
} |
@@ -637,40 +642,48 @@ |
*/ |
int main(int argc, char **argv) { |
int option; |
char *dbFile; |
struct stat path; |
|
// Bind handler to SIGINT. |
signal(SIGINT, SignalHandler); |
|
while((option = getopt(argc, argv, "hq")) != -1) { |
dbFile = DEFAULT_DATABASE_FILE; |
while((option = getopt(argc, argv, "hqd:")) != -1) { |
switch(option) { |
case 'd': |
dbFile = optarg; |
break; |
case 'q': |
verbose = FALSE; |
break; |
case 'h': |
fprintf(stdout, "SYNTAX: %s [-q] DIRECTORY", argv[0]); |
break; |
fprintf(stdout, "SYNTAX: %s [-q] [-d DATABASE] DIRECTORY\n", argv[0]); |
return 0; |
case '?': |
fprintf(stderr, "Invalid option %ct.\n", optopt); |
fprintf(stdout, "SYNTAX: %s [-q] DIRECTORY\n", argv[0]); |
fprintf(stdout, "SYNTAX: %s [-q] [-d DATABASE] DIRECTORY\n", argv[0]); |
return 1; |
} |
} |
|
if(optind > argc) { |
fprintf(stdout, "SYNTAX: %s [-q] DIRECTORY\n", argv[0]); |
fprintf(stdout, "SYNTAX: %s [-q] [-d DATABASE] DIRECTORY\n", argv[0]); |
return 1; |
} |
|
stat(argv[optind], &path); |
|
if(!S_ISDIR(path.st_mode)) { |
fprintf(stdout, "%s is not a directory.\n", argv[optind]); |
fprintf(stderr, "%s is not a directory.\n", argv[optind]); |
return 1; |
} |
|
if(verbose) { |
fprintf(stdout, "Gathering to database file: %s\n", dbFile); |
} |
|
// Gather. |
Gather("S:gather.db", argv[optind]); |
Gather(dbFile, argv[optind]); |
|
return 0; |
} |