From 1bf3f2bdaea6e593867d5b6b2e1425d88ee740d6 Mon Sep 17 00:00:00 2001 From: Bradley Bell Date: Sat, 14 Sep 2002 00:20:44 +0000 Subject: [PATCH] revert cfgets() and load_endlevel_data() to expect newline-terminated strings, fix load_game_data to read null-terminated string for Current_level_name --- cfile/cfile.c | 45 +++++++++++++++++++++------------------------ main/endlevel.c | 9 ++++----- main/gamesave.c | 15 +++++++++------ 3 files changed, 34 insertions(+), 35 deletions(-) diff --git a/cfile/cfile.c b/cfile/cfile.c index 6391e637..2b03e96b 100644 --- a/cfile/cfile.c +++ b/cfile/cfile.c @@ -1,4 +1,4 @@ -/* $Id: cfile.c,v 1.8 2002-08-27 04:05:29 btb Exp $ */ +/* $Id: cfile.c,v 1.9 2002-09-14 00:20:44 btb Exp $ */ /* THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO @@ -394,40 +394,37 @@ int cfgetc( CFILE * fp ) return c; } -/* - * read string terminated by zero or a platform's line ending. - * Martin: cleaned up line ending mess, and made it read - * zero-terminated strings (for descent 1 levels). - * assumed that no string has any zero's or other platform's line - * endings inside - * platform's line endings reference: UN*X: LF (10), Mac: CR (13), - * DOS: CR,LF - */ char * cfgets( char * buf, size_t n, CFILE * fp ) { char * t = buf; int i; int c; - for (i=0; iraw_position >= fp->size ) { - *buf = 0; - return NULL; - } - c = fgetc( fp->file ); - fp->raw_position++; - if (c == 0 || c == 10) // UN*X line ending or zero - break; - if (c == 13) { // it could be Mac or DOS line ending + for (i=0; iraw_position >= fp->size ) { + *buf = 0; + return NULL; + } c = fgetc( fp->file ); - if ( c == 10 ) { // DOS line ending + fp->raw_position++; + if (c == 0 || c == 10) // Unix line ending break; - } else { // Mac line ending, undo last character read + if (c == 13) { // Mac or DOS line ending + int c1; + + c1 = fgetc( fp->file ); fseek( fp->file, -1, SEEK_CUR); - break; + if ( c1 == 10 ) // DOS line ending + continue; + else // Mac line ending + break; } - } + } while ( c == 13 ); + if ( c == 13 ) // because cr-lf is a bad thing on the mac + c = '\n'; // and anyway -- 0xod is CR on mac, not 0x0a *buf++ = c; + if ( c=='\n' ) break; } *buf++ = 0; return t; diff --git a/main/endlevel.c b/main/endlevel.c index 945473d9..e8ca540c 100644 --- a/main/endlevel.c +++ b/main/endlevel.c @@ -17,7 +17,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -static char rcsid[] = "$Id: endlevel.c,v 1.9 2002-08-08 09:09:43 btb Exp $"; +static char rcsid[] = "$Id: endlevel.c,v 1.10 2002-09-14 00:20:44 btb Exp $"; #endif //#define SLEW_ON 1 @@ -1507,7 +1507,7 @@ try_again: while (cfgets(line,LINE_LEN,ifile)) { if (have_binary) { - for (i = 0; i < strlen(line); i++) { + for (i = 0; i < strlen(line) - 1; i++) { encode_rotate_left(&(line[i])); line[i] = line[i] ^ BITMAP_TBL_XOR; encode_rotate_left(&(line[i])); @@ -1534,17 +1534,16 @@ try_again: d_free(terrain_bm_instance.bm_data); Assert(terrain_bm_instance.bm_data == NULL); - + iff_error = iff_read_bitmap(p,&terrain_bm_instance,BM_LINEAR,pal); if (iff_error != IFF_NO_ERROR) { - mprintf((1, "File %s - IFF error: %s",p,iff_errormsg(iff_error))); Error("File %s - IFF error: %s",p,iff_errormsg(iff_error)); } terrain_bitmap = &terrain_bm_instance; gr_remap_bitmap_good( terrain_bitmap, pal, iff_transparent_color, -1); - + break; } diff --git a/main/gamesave.c b/main/gamesave.c index 27af2e74..1b455532 100644 --- a/main/gamesave.c +++ b/main/gamesave.c @@ -24,7 +24,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif #ifdef RCS -char gamesave_rcsid[] = "$Id: gamesave.c,v 1.16 2002-08-30 00:57:06 btb Exp $"; +char gamesave_rcsid[] = "$Id: gamesave.c,v 1.17 2002-09-14 00:20:44 btb Exp $"; #endif #include @@ -926,16 +926,19 @@ int load_game_data(CFILE *LoadFile) game_fileinfo.delta_light_sizeof = cfile_read_int(LoadFile); } - if (game_top_fileinfo.fileinfo_version >= 14) { //load mine filename - //@@char *p=Current_level_name; - //@@//must do read one char at a time, since no cfgets() - //@@do *p = cfgetc(LoadFile); while (*p++!=0); - + if (game_top_fileinfo.fileinfo_version >= 31) { //load mine filename + // read newline-terminated string, not sure what version this changed. cfgets(Current_level_name,sizeof(Current_level_name),LoadFile); if (Current_level_name[strlen(Current_level_name)-1] == '\n') Current_level_name[strlen(Current_level_name)-1] = 0; } + else if (game_top_fileinfo.fileinfo_version >= 14) { //load mine filename + // read null-terminated string + char *p=Current_level_name; + //must do read one char at a time, since no cfgets() + do *p = cfgetc(LoadFile); while (*p++!=0); + } else Current_level_name[0]=0; -- 2.39.2