HuntnGather

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 18  →  ?path2? @ 19
/trunk/HuntnGather/Hunt/Hunt.c
@@ -19,12 +19,14 @@
#include "getopt.h"
#endif
 
#define PROGRAM_VERSION "1.7.2"
 
#if defined ___AmigaOS___
/*************************************************************************/
/* Version string used for querrying the program version. */
/*************************************************************************/
TEXT version_string[] =
"\0$VER: Hunt 1.7 "__DATE__" by Wizardry and Steamworks";
"\0$VER: Hunt " PROGRAM_VERSION " "__DATE__" by Wizardry and Steamworks";
#endif
 
#if !defined TRUE
@@ -54,24 +56,29 @@
ULONG size;
int success;
UBYTE *pattern;
char *upe = name;
char *upn = need;
 
#if !defined ___NOCASE_FS___
strupr(need);
strupr(name);
#if defined ___NOCASE_FS___
upe = strupr(upe);
upn = strupr(upn);
#endif
 
size = strlen(need) * 3;
// "must be at least 2 times as large plus 2 bytes"
size = strlen(upn) * 2 + 2;
 
success = FALSE;
 
if(pattern = AllocVec(size, MEMF_ANY|MEMF_CLEAR)) {
switch(ParsePatternNoCase(upn, pattern, (LONG)size)) {
case 1: // the pattern contains wildcards
success = MatchPatternNoCase(pattern, upe);
 
if(ParsePatternNoCase(need, pattern, (LONG)size) > 0) {
success = MatchPatternNoCase(pattern, name);
break;
case 0: // no wildcards so fall back to exact name match
success = (strstr(upe, upn) != NULL);
 
FreeVec(pattern);
 
return success;
break;
}
 
FreeVec(pattern);
@@ -80,18 +87,18 @@
return success;
#else
int success;
char *upe = name;
char *upn = need;
 
success = FALSE;
 
#if !defined ___NOCASE_FS___
strupr(need);
strupr(name);
#if defined ___NOCASE_FS___
upe = strupr(upe);
upn = strupr(upn);
#endif
 
success = (strstr(name, need) != NULL);
success = (strstr(upe, upn) != NULL);
 
free(upe);
free(upn);
return success;
#endif
}
@@ -119,9 +126,9 @@
}
 
name_size = NAME_BUF;
name = malloc(name_size * sizeof(char));
name = malloc(name_size * sizeof(*name));
path_size = PATH_BUF;
path = malloc(path_size * sizeof(char));
path = malloc(path_size * sizeof(*path));
 
i = 0;
side = 0;
@@ -147,7 +154,7 @@
if(name != NULL) {
free(name);
name_size = NAME_BUF;
name = malloc(name_size * sizeof(char));
name = malloc(name_size * sizeof(*name));
}
--side;
i = 0;
@@ -160,7 +167,7 @@
if(path != NULL) {
free(path);
path_size = PATH_BUF;
path = malloc(path_size * sizeof(char));
path = malloc(path_size * sizeof(*name));
}
++side;
i = 0;
@@ -170,9 +177,9 @@
case 0:
if(strlen(name) == name_size) {
name_size = 1.5 * name_size;
name = realloc(name, name_size * sizeof(char));
name = realloc(name, name_size * sizeof(*name));
}
//name = realloc(name, (i + 1 + 1) * sizeof(char));
//name = realloc(name, (i + 1 + 1) * sizeof(*name));
name[i] = c;
name[i + 1] = '\0';
break;
@@ -179,9 +186,9 @@
case 1:
if(strlen(path) == path_size) {
path_size = 1.5 * path_size;
path = realloc(path, path_size * sizeof(char));
path = realloc(path, path_size * sizeof(*path));
}
//path = realloc(path, (i + 1 + 1) * sizeof(char));
//path = realloc(path, (i + 1 + 1) * sizeof(*path));
path[i] = c;
path[i + 1] = '\0';
break;
@@ -211,6 +218,7 @@
 
void usage(char *name) {
fprintf(stdout, "Hunt & Gather - %s, a file index search tool. \n", name);
fprintf(stdout, "Version: %s \n", PROGRAM_VERSION);
fprintf(stdout, " \n");
fprintf(stdout, "SYNTAX: %s [-d DATABASE] PATTERN \n", name);
fprintf(stdout, " \n");