From f649046f331a8bc787f220cb949548d9896f2941 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sun, 5 Oct 2003 22:35:47 +0000 Subject: [PATCH] better handling of CRLF text files (when that is the native format) --- ChangeLog | 3 +++ cfile/cfile.c | 17 ++++++----------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5352d742..380a85aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2003-10-05 Bradley Bell + * cfile/cfile.c: better handling of CRLF text files (when that is + the native format) + * utilities/hogcreate.c, utilities/hogextract.c, utilities/mvlcreate.c, utilities/mvlextract.c: use binary mode for reading/writing files diff --git a/cfile/cfile.c b/cfile/cfile.c index 42aa62e9..46a85553 100644 --- a/cfile/cfile.c +++ b/cfile/cfile.c @@ -1,4 +1,4 @@ -/* $Id: cfile.c,v 1.20 2003-10-04 20:03:11 btb Exp $ */ +/* $Id: cfile.c,v 1.21 2003-10-05 22:35:47 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -531,7 +531,7 @@ CFILE * cfopen(char * filename, char * mode ) return NULL; } cfile->file = fp; - cfile->size = filelength( fileno(fp) ); + cfile->size = ffilelength(fp); cfile->lib_offset = 0; cfile->raw_position = 0; return cfile; @@ -596,9 +596,7 @@ int cfgetc( CFILE * fp ) c = getc( fp->file ); if (c!=EOF) - fp->raw_position++; - -// Assert( fp->raw_position==(ftell(fp->file)-fp->lib_offset) ); + fp->raw_position = ftell(fp->file)-fp->lib_offset; return c; } @@ -646,17 +644,14 @@ char * cfgets( char * buf, size_t n, CFILE * fp ) *buf = 0; return NULL; } - c = fgetc( fp->file ); - if (c == EOF) - break; - fp->raw_position++; + c = cfgetc(fp); if (c == 0 || c == 10) // Unix line ending break; if (c == 13) { // Mac or DOS line ending int c1; - c1 = fgetc( fp->file ); - fseek( fp->file, -1, SEEK_CUR); + c1 = cfgetc(fp); + cfseek(fp, -1, SEEK_CUR); if ( c1 == 10 ) // DOS line ending continue; else // Mac line ending -- 2.39.2