/trunk/HuntnGather/Hunt/Hunt.c/Hunt.c |
@@ -24,7 +24,7 @@ |
/* Version string used for querrying the program version. */ |
/*************************************************************************/ |
TEXT version_string[] = |
"\0$VER: Hunt 1.6 "__DATE__" by Wizardry and Steamworks"; |
"\0$VER: Hunt 1.7 "__DATE__" by Wizardry and Steamworks"; |
#endif |
|
#if !defined TRUE |
@@ -35,6 +35,8 @@ |
#define FALSE 0; |
#endif |
|
#define NAME_BUF 32 |
#define PATH_BUF 128 |
#define DEFAULT_DATABASE_FILE "S:gather.db" |
|
int run = TRUE; |
@@ -51,7 +53,7 @@ |
char *up; |
int i; |
|
up = (char *) malloc((strlen(str) + 1) * sizeof(char)); |
up = malloc((strlen(str) + 1) * sizeof(char)); |
sprintf(up, "%s", str); |
|
i = strlen(up); |
@@ -121,7 +123,9 @@ |
void SearchDatabase(char *dbFile, char* need) { |
FILE *fp; |
char *name; |
int name_size; |
char *path; |
int path_size; |
char c; |
int i; |
int side; |
@@ -133,8 +137,10 @@ |
return; |
} |
|
name = (char *) malloc(sizeof(char)); |
path = (char *) malloc(sizeof(char)); |
name_size = NAME_BUF; |
name = malloc(name_size * sizeof(char)); |
path_size = PATH_BUF; |
path = malloc(path_size * sizeof(char)); |
|
i = 0; |
side = 0; |
@@ -159,7 +165,8 @@ |
} |
if(name != NULL) { |
free(name); |
name = (char *) malloc(sizeof(char)); |
name_size = NAME_BUF; |
name = malloc(name_size * sizeof(char)); |
} |
--side; |
i = 0; |
@@ -171,7 +178,8 @@ |
} |
if(path != NULL) { |
free(path); |
path = (char *) malloc(sizeof(char)); |
path_size = PATH_BUF; |
path = malloc(path_size * sizeof(char)); |
} |
++side; |
i = 0; |
@@ -179,12 +187,20 @@ |
default: |
switch(side) { |
case 0: |
name = (char *) realloc(name, (i + 1 + 1) * sizeof(char)); |
if(strlen(name) == name_size) { |
name_size = 1.5 * name_size; |
name = realloc(name, name_size * sizeof(char)); |
} |
//name = realloc(name, (i + 1 + 1) * sizeof(char)); |
name[i] = c; |
name[i + 1] = '\0'; |
break; |
case 1: |
path = (char *) realloc(path, (i + 1 + 1) * sizeof(char)); |
if(strlen(path) == path_size) { |
path_size = 1.5 * path_size; |
path = realloc(path, path_size * sizeof(char)); |
} |
//path = realloc(path, (i + 1 + 1) * sizeof(char)); |
path[i] = c; |
path[i + 1] = '\0'; |
break; |
@@ -212,6 +228,19 @@ |
SearchDatabase(dbFile, need); |
} |
|
void usage(char *name) { |
fprintf(stdout, "Hunt & Gather - %s, a file index search tool. \n", name); |
fprintf(stdout, " \n"); |
fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN \n", name); |
fprintf(stdout, " \n"); |
fprintf(stdout, " -d DATABASE A path to a database generated by the \n"); |
fprintf(stdout, " Gather tool that should be searched. \n"); |
fprintf(stdout, " \n"); |
fprintf(stdout, "PATTERN is an AmigaOS DOS pattern to match file names. \n"); |
fprintf(stdout, " \n"); |
fprintf(stdout, "(c) 2021 Wizardry and Steamworks, MIT. \n"); |
} |
|
int main(int argc, char **argv) { |
int option; |
char *dbFile; |
@@ -227,17 +256,16 @@ |
dbFile = optarg; |
break; |
case 'h': |
fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN\n", argv[0]); |
usage(argv[0]); |
return 0; |
case '?': |
fprintf(stderr, "Invalid option %c.\n", optopt); |
fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN\n", argv[0]); |
fprintf(stderr, "Invalid option %c.\n", optopt);; |
return 1; |
} |
} |
|
if(optind >= argc) { |
fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN\n", argv[0]); |
usage(argv[0]); |
return 1; |
} |
|