HuntnGather

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 40  →  ?path2? @ 41
/trunk/HuntnGather/shared/utilities.c
@@ -130,17 +130,54 @@
 
/*
*
* Get the size of a file.
*/
int GetFileSize(char *dbFile) {
#if defined ___AsyncIO___
struct AsyncFile *fp;
#else
FILE *fp;
#endif
int size;
 
#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 -1;
}
 
#if defined ___AsyncIO___
SeekAsync(fp, 0, MODE_END);
size = SeekAsync(fp, 0, MODE_CURRENT);
#else
fseek(fp, 0L, SEEK_END);
size = ftell(fp);
#endif
 
#if defined ___AsyncIO___
CloseAsync(fp);
#else
fclose(fp);
#endif
 
return size;
}
 
/*
*
* Counts the lines of a file.
*/
int CountFileLines(char *dbFile) {
#if defined ___AsyncIO___
struct AsyncFile *fp;
LONG c;
#else
FILE *fp;
char c;
#endif
int lines;
dbLine *line = NULL;
 
#if defined ___AsyncIO___
if((fp = OpenAsync(dbFile, MODE_READ, ASYNC_BUF)) == NULL) {
@@ -151,16 +188,12 @@
return -1;
}
 
lines = 0;
if(PROGRAM_VERBOSE) {
fprintf(stdout, "Counting lines in '%s'...\r", dbFile);
}
 
#if defined ___AsyncIO___
while(PROGRAM_RUN && (c = ReadCharAsync(fp)) != -1) {
#else
while(PROGRAM_RUN && fscanf(fp, "%c", &c) == 1) {
#endif
lines = 0;
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) {
@@ -168,17 +201,24 @@
continue;
}
#endif
switch(c) {
case '\n':
++lines;
 
if(PROGRAM_VERBOSE) {
fprintf(stdout, "Counting lines in '%s': %d.\r", dbFile, lines);
}
break;
++lines;
 
if(PROGRAM_VERBOSE) {
fprintf(stdout, "Counting lines in '%s': %d.\r", dbFile, lines);
}
 
free(line->string);
free(line);
line = NULL;
}
 
if(line != NULL) {
free(line->string);
free(line);
line = NULL;
}
 
#if defined ___AsyncIO___
CloseAsync(fp);
#else