HuntnGather

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 48  →  ?path2? @ 49
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/HuntnGather/C/Gather
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/trunk/HuntnGather/C/Hunt
/trunk/HuntnGather/Hunt/Hunt.c
@@ -53,7 +53,7 @@
*
* Search the database for a matching string.
*/
void SearchDatabase(char *dbFile, char* needle) {
void SearchDatabaseExact(char *dbFile, char *needle) {
#if defined ___AsyncIO___
struct AsyncFile *fp;
#else
@@ -95,7 +95,15 @@
return;
}
 
if(StringMatch(entry->name, needle)) {
#if defined ___AmigaOS___
#if defined ___NOCASE_FS___
if(Strnicmp(entry->name, needle, StringLenMax(entry->name, needle)) == 0) {
#else
if(StrnCmp(entry->name, needle, StringLenMax(entry->name, needle)) == 0) {
#endif
#else
if(strstr(entry->name, needle) != NULL) {
#endif
fprintf(stdout, "%s\n", entry->path);
}
 
@@ -124,11 +132,112 @@
 
/*
*
* Search the database for a matching string.
*/
void SearchDatabasePattern(char *dbFile, UBYTE *pattern) {
#if defined ___AsyncIO___
struct AsyncFile *fp;
#else
FILE *fp;
#endif
dbEntry *entry;
dbLine *line = NULL;
 
// Open database file for reading.
#if defined ___AsyncIO___
if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) {
#else
if((fp = fopen(dbFile, "r")) == NULL) {
#endif
fprintf(stderr, "Could not open file '%s' for reading.\n", dbFile);
return;
}
 
while(PROGRAM_RUN && (line = ReadLine(fp)) != NULL) {
#if defined ___AmigaOS___
// Check if CTRL+C was pressed and abort the program.
if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
PROGRAM_RUN = FALSE;
continue;
}
#endif
 
if((entry = CreateDatabaseEntry(line)) == NULL) {
fprintf(stderr, "Unable to create database entry.\n");
free(line->string);
free(line);
line = NULL;
 
#if defined ___AsyncIO___
CloseAsync(fp);
#else
fclose(fp);
#endif
return;
}
 
if(MatchPatternNoCase(pattern, entry->name)) {
fprintf(stdout, "%s\n", entry->path);
}
 
free(entry->name);
free(entry->path);
free(entry);
entry = NULL;
 
free(line->string);
free(line);
line = NULL;
}
 
if(line != NULL) {
free(line->string);
free(line);
line = NULL;
}
 
#if defined ___AsyncIO___
CloseAsync(fp);
#else
fclose(fp);
#endif
}
 
/*
*
* Search the database for the matching string.
*/
void Hunt(char *dbFile, char *needle) {
#if defined ___AmigaOS___
UBYTE *pattern;
ULONG size;
 
#if defined ___NOCASE_FS___
StrUpr(needle);
#endif
 
size = strlen(needle) * 2 + 2;
 
if(pattern = AllocVec(size, MEMF_ANY|MEMF_CLEAR)) {
switch(ParsePatternNoCase(needle, pattern, (LONG)size)) {
case 1: // the needle contains wildcards
SearchDatabasePattern(dbFile, pattern);
break;
case 0: // no wildcards contained in needle
SearchDatabaseExact(dbFile, needle);
break;
case -1: // overflow condition
fprintf(stderr, "Pattern '%s' could not be parsed.\n", needle);
break;
}
FreeVec(pattern);
pattern = NULL;
return;
}
#endif
 
// Search the database for the matching string.
SearchDatabase(dbFile, needle);
SearchDatabaseExact(dbFile, needle);
}
 
void usage(char *name) {
/trunk/HuntnGather/shared/utilities.c
@@ -676,72 +676,7 @@
return entry;
}
 
/*
* Compare two strings.
*/
#if defined ___AmigaOS___
BOOL StringMatch(char *a, char *b) {
#else
int StringMatch(char *a, char *b) {
#endif
#if defined ___AmigaOS___
ULONG size;
BOOL success;
UBYTE *pattern;
char *e = a;
char *n = b;
 
#if defined ___NOCASE_FS___
StrUpr(e);
StrUpr(n);
#endif
 
// "must be at least 2 times as large plus 2 bytes"
size = strlen(n) * 2 + 2;
 
success = FALSE;
 
if(pattern = AllocVec(size, MEMF_ANY|MEMF_CLEAR)) {
switch(ParsePatternNoCase(n, pattern, (LONG)size)) {
case 1: // the pattern contains wildcards
success = MatchPatternNoCase(pattern, e);
 
break;
case 0: // no wildcards so fall back to exact name match
#if defined ___NOCASE_FS___
success = (Strnicmp(e, n, StringLenMax(e, n)) == 0);
#else
success = (StrnCmp(e, n, StringLenMax(e, n)) == 0);
#endif
 
break;
}
 
FreeVec(pattern);
pattern = NULL;
}
 
return success;
#else
int success;
char *e = a;
char *n = b;
 
success = FALSE;
 
#if defined ___NOCASE_FS___
StrUpr(e);
StrUpr(n);
#endif
 
// search for substring
success = strstr(e, n) != NULL;
 
return success;
#endif
}