HuntnGather

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 41  →  ?path2? @ 43
/trunk/HuntnGather/shared/utilities.c
@@ -64,7 +64,11 @@
*
* Converts a string to case.
*/
#if defined ___AmigaOS___
void StrUpr(UBYTE *s) {
#else
void StrUpr(char *s) {
#endif
while(*s != '\0') {
#if defined ___AmigaOS___
*s = ToUpper(*s);
@@ -509,9 +513,9 @@
}
 
/*
*
* Delete a file.
*/
*
* Delete a file.
*/
#if defined ___AmigaOS___
BOOL RemoveFile(char *name) {
return DeleteFile(name);
@@ -540,16 +544,15 @@
*
* Copies a file to another file by name.
*/
void CopyFile(char *a, char *b) {
void CopyLines(char *a, char *b) {
#if defined ___AsyncIO___
struct AsyncFile *ap;
struct AsyncFile *bp;
LONG c;
#else
FILE *ap;
FILE *bp;
char c;
#endif
dbLine *line = NULL;
 
// Open database file for writing.
#if defined ___AsyncIO___
@@ -579,11 +582,7 @@
return;
}
 
#if defined ___AsyncIO___
while(PROGRAM_RUN && (c = ReadCharAsync(ap)) != -1) {
#else
while(PROGRAM_RUN && fscanf(ap, "%c", &c) == 1) {
#endif
while(PROGRAM_RUN && (line = ReadLine(ap)) != NULL) {
#if defined ___AmigaOS___
// Check if CTRL+C was pressed and abort the program.
if(SetSignal(0L, SIGBREAKF_CTRL_C) & SIGBREAKF_CTRL_C) {
@@ -591,16 +590,25 @@
continue;
}
#endif
 
#if defined ___AsyncIO___
if(WriteCharAsync(bp, (UBYTE)c) != 1) {
WriteAsync(bp, line->string, line->length);
WriteAsync(bp, "\n", 1);
#else
if(fprintf(bp, "%c", c) != 1) {
fprintf(bp, "%s\n", line->string);
#endif
fprintf(stderr, "Could not write to file '%s'.\n", b);
break;
}
 
free(line->string);
free(line);
line = NULL;
}
 
if(line != NULL) {
free(line->string);
free(line);
line = NULL;
}
 
#if defined ___AsyncIO___
CloseAsync(ap);
CloseAsync(bp);
@@ -680,23 +688,30 @@
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(b) * 2 + 2;
size = strlen(n) * 2 + 2;
 
success = FALSE;
 
if(pattern = AllocVec(size, MEMF_ANY|MEMF_CLEAR)) {
switch(ParsePatternNoCase(b, pattern, (LONG)size)) {
switch(ParsePatternNoCase(n, pattern, (LONG)size)) {
case 1: // the pattern contains wildcards
success = MatchPatternNoCase(pattern, a);
success = MatchPatternNoCase(pattern, e);
 
break;
case 0: // no wildcards so fall back to exact name match
#if defined ___NOCASE_FS___
success = (Strnicmp(a, b, StringLenMax(a, b)) == 0);
success = (Strnicmp(e, n, StringLenMax(e, n)) == 0);
#else
success = (StrnCmp(a, b, StringLenMax(a, b)) == 0);
success = (StrnCmp(e, n, StringLenMax(e, n)) == 0);
#endif
 
break;
/trunk/HuntnGather/shared/utilities.h
@@ -10,7 +10,8 @@
#define FALSE 0;
#endif
 
#define ASYNC_BUF 8192
/* 32768b empirically shows a doubling of speed compared to lower values */
#define ASYNC_BUF 32768
#define MAX_MEM 262144
#define LINE_BUF 256
#define DEFAULT_DATABASE_FILE "S:gather.db"
@@ -58,11 +59,13 @@
extern BOOL PathCompare(char *path, char *look);
extern BOOL RemoveFile(char *name);
extern BOOL StringMatch(char *a, char *b);
extern void StrUpr(UBYTE *s);
#else
extern int StrlenMax(char *a, char *b);
extern int PathCompare(char *path, char *look);
extern int RemoveFile(char *name);
extern int StringMatch(char *a, char *b);
extern void StrUpr(char *s);
#endif
 
#if defined ___AsyncIO___
@@ -75,7 +78,6 @@
extern dbLine *ReadLine(FILE *fp);
#endif
 
extern void StrUpr(char *);
extern FS_TYPE GetFsType(char *path);
extern int CountFileLines(char *dbFile);
extern int GetFileSize(char *dbFile);
@@ -83,6 +85,6 @@
extern char *CreateTemporaryFile(void);
extern VECTOR *CreateTemporaryFiles(int files);
extern void RemoveFiles(VECTOR *names);
extern void CopyFile(char *a, char *b);
extern void CopyLines(char *a, char *b);
 
extern dbEntry* CreateDatabaseEntry(dbLine *line);