/trunk/HuntnGather/Hunt/Hunt.c |
@@ -15,6 +15,7 @@ |
#include <sys/types.h> |
|
#if defined ___AmigaOS___ |
|
#include <proto/dos.h> |
#include <proto/exec.h> |
#include <proto/utility.h> |
@@ -25,9 +26,11 @@ |
#endif |
|
#if !defined ___HAVE_GETOPT___ |
#include "getopt.h" |
#include "/shared/getopt.h" |
#endif |
|
#include "/shared/utilities.h" |
|
#define PROGRAM_VERSION "1.7.4" |
|
#if defined ___AmigaOS___ |
@@ -38,43 +41,15 @@ |
"\0$VER: Hunt " PROGRAM_VERSION " "__DATE__" by Wizardry and Steamworks"; |
#endif |
|
#if !defined TRUE |
#define TRUE 1; |
#endif |
int PROGRAM_RUN = TRUE; |
int PROGRAM_VERBOSE = FALSE; |
|
#if !defined FALSE |
#define FALSE 0; |
#endif |
|
#define ASYNC_BUF 8192 |
#define NAME_BUF 32 |
#define PATH_BUF 128 |
#define DEFAULT_DATABASE_FILE "S:gather.db" |
|
int run = TRUE; |
|
void SignalHandler(int sig) { |
// Toggle the run flag to stop execution. |
run = FALSE; |
PROGRAM_RUN = FALSE; |
} |
|
/* |
* |
* Returns largest of strings. |
*/ |
#if defined ___AmigaOS___ |
LONG StringLenMax(char *a, char *b) { |
LONG p = strlen(a); |
LONG q = strlen(b); |
#else |
int StrlenMax(char *a, char *b) { |
int q = strlen(a); |
int p = strien(b); |
#endif |
return p > q ? p : q; |
} |
|
/* |
* Compare two strings. |
*/ |
#if defined ___AmigaOS___ |
@@ -120,8 +95,8 @@ |
success = FALSE; |
|
#if defined ___NOCASE_FS___ |
e = strupr(e); |
n = strupr(n); |
e = StrUpr(e); |
n = StrUpr(n); |
#endif |
|
// search for substring |
@@ -158,7 +133,7 @@ |
#else |
if((fp = fopen(dbFile, "r")) == NULL) { |
#endif |
fprintf(stderr, "Unable to open '%s' for reading.\n", dbFile); |
fprintf(stderr, "Could not open '%s' for reading.\n", dbFile); |
return; |
} |
|
@@ -173,14 +148,14 @@ |
total = 0; |
|
#if defined ___AsyncIO___ |
while(run && (c = ReadCharAsync(fp)) != -1) { |
while(PROGRAM_RUN && (c = ReadCharAsync(fp)) != -1) { |
#else |
while(run && fscanf(fp, "%c", &c) == 1) { |
while(PROGRAM_RUN && fscanf(fp, "%c", &c) == 1) { |
#endif |
#if defined ___AmigaOS___ |
// Check if CTRL+C was pressed and abort the program. |
if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) { |
run = FALSE; |
PROGRAM_RUN = FALSE; |
continue; |
} |
#endif |
@@ -274,12 +249,6 @@ |
} |
|
int main(int argc, char **argv) { |
#if defined ___AmigaOS___ |
struct FileInfoBlock *FIB; |
BPTR lock; |
#else |
struct stat dirStat; |
#endif |
int option; |
char *dbFile; |
|
@@ -308,40 +277,15 @@ |
return 1; |
} |
|
#if defined ___AmigaOS___ |
if((lock = Lock(dbFile, ACCESS_READ)) == NULL) { |
fprintf(stderr, "Path '%s' is not accessible.\n", dbFile); |
return 1; |
switch(GetFsType(dbFile)) { |
case UNKNOWN: |
case DIRECTORY: |
fprintf(stderr, "'%s' is not a file.\n", dbFile); |
return 1; |
case REGULAR: |
Hunt(dbFile, argv[optind]); |
break; |
} |
|
if((FIB = AllocDosObject(DOS_FIB, NULL)) == NULL) { |
fprintf(stderr, "Path '%s' file information block not accessible.\n", dbFile); |
UnLock(lock); |
return 1; |
} |
|
if(Examine(lock, FIB) == FALSE) { |
fprintf(stderr, "Path '%s' information unexaminable.\n", dbFile); |
FreeDosObject(DOS_FIB, FIB); |
UnLock(lock); |
return 1; |
} |
|
if(FIB->fib_DirEntryType > 0) { |
#else |
stat(dbFile, &dirStat); |
if(!S_ISREG(dirStat.st_mode)) { |
#endif |
fprintf(stderr, "'%s' is not a file.\n", dbFile); |
return 1; |
} |
|
#if defined ___AmigaOS___ |
FreeDosObject(DOS_FIB, FIB); |
UnLock(lock); |
#endif |
|
Hunt(dbFile, argv[optind]); |
|
return 0; |
} |