convert file i/o to cfile
authorBradley Bell <btb@icculus.org>
Mon, 16 Jun 2003 06:57:34 +0000 (06:57 +0000)
committerBradley Bell <btb@icculus.org>
Mon, 16 Jun 2003 06:57:34 +0000 (06:57 +0000)
16 files changed:
2d/pcx.c
ChangeLog
include/strio.h
main/ai.c
main/ai.h
main/config.c
main/movie.c
main/newdemo.c
main/newmenu.c
main/piggy.c
main/polyobj.c
main/scores.c
main/state.c
main/text.c
misc/args.c
misc/strio.c

index 1a113c2..f665c65 100644 (file)
--- a/2d/pcx.c
+++ b/2d/pcx.c
@@ -1,4 +1,4 @@
-/* $Id: pcx.c,v 1.7 2003-02-28 09:56:10 btb Exp $ */
+/* $Id: pcx.c,v 1.8 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -58,8 +58,8 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include "poly_acc.h"
 #endif
 
-int pcx_encode_byte(ubyte byt, ubyte cnt, FILE * fid);
-int pcx_encode_line(ubyte *inBuff, int inLen, FILE * fp);
+int pcx_encode_byte(ubyte byt, ubyte cnt, CFILE *fid);
+int pcx_encode_line(ubyte *inBuff, int inLen, CFILE *fp);
 
 /* PCX Header data type */
 typedef struct {
@@ -354,7 +354,7 @@ int pcx_write_bitmap( char * filename, grs_bitmap * bmp, ubyte * palette )
        int i;
        ubyte data;
        PCXHeader header;
-       FILE * PCXfile;
+       CFILE *PCXfile;
 
        memset( &header, 0, PCXHEADER_SIZE );
 
@@ -367,26 +367,28 @@ int pcx_write_bitmap( char * filename, grs_bitmap * bmp, ubyte * palette )
        header.Ymax = bmp->bm_h-1;
        header.BytesPerLine = bmp->bm_w;
 
-       PCXfile = fopen( filename , "wb" );
+       PCXfile = cfopen(filename, "wb");
        if ( !PCXfile )
                return PCX_ERROR_OPENING;
 
-       if ( fwrite( &header, PCXHEADER_SIZE, 1, PCXfile ) != 1 )       {
-               fclose( PCXfile );
+       if (cfwrite(&header, PCXHEADER_SIZE, 1, PCXfile) != 1)
+       {
+               cfclose(PCXfile);
                return PCX_ERROR_WRITING;
        }
 
        for (i=0; i<bmp->bm_h; i++ )    {
                if (!pcx_encode_line( &bmp->bm_data[bmp->bm_rowsize*i], bmp->bm_w, PCXfile ))   {
-                       fclose( PCXfile );
+                       cfclose(PCXfile);
                        return PCX_ERROR_WRITING;
                }
        }
 
        // Mark an extended palette
        data = 12;
-       if (fwrite( &data, 1, 1, PCXfile )!=1)  {
-               fclose( PCXfile );
+       if (cfwrite(&data, 1, 1, PCXfile) != 1)
+       {
+               cfclose(PCXfile);
                return PCX_ERROR_WRITING;
        }
 
@@ -394,23 +396,23 @@ int pcx_write_bitmap( char * filename, grs_bitmap * bmp, ubyte * palette )
        for (i=0; i<768; i++ )
                palette[i] <<= 2;
 
-       retval = fwrite( palette, 768, 1, PCXfile );
+       retval = cfwrite(palette, 768, 1, PCXfile);
 
        for (i=0; i<768; i++ )
                palette[i] >>= 2;
 
        if (retval !=1) {
-               fclose( PCXfile );
+               cfclose(PCXfile);
                return PCX_ERROR_WRITING;
        }
 
-       fclose( PCXfile );
+       cfclose(PCXfile);
        return PCX_ERROR_NONE;
 
 }
 
 // returns number of bytes written into outBuff, 0 if failed
-int pcx_encode_line(ubyte *inBuff, int inLen, FILE * fp)
+int pcx_encode_line(ubyte *inBuff, int inLen, CFILE *fp)
 {
        ubyte this, last;
        int srcIndex, i;
@@ -451,17 +453,17 @@ int pcx_encode_line(ubyte *inBuff, int inLen, FILE * fp)
 
 // subroutine for writing an encoded byte pair
 // returns count of bytes written, 0 if error
-int pcx_encode_byte(ubyte byt, ubyte cnt, FILE * fid)
+int pcx_encode_byte(ubyte byt, ubyte cnt, CFILE *fid)
 {
        if (cnt) {
                if ( (cnt==1) && (0xc0 != (0xc0 & byt)) )       {
-                       if(EOF == putc((int)byt, fid))
+                       if(EOF == cfputc((int)byt, fid))
                                return 0;       // disk write error (probably full)
                        return 1;
                } else {
-                       if(EOF == putc((int)0xC0 | cnt, fid))
+                       if(EOF == cfputc((int)0xC0 | cnt, fid))
                                return 0;       // disk write error
-                       if(EOF == putc((int)byt, fid))
+                       if(EOF == cfputc((int)byt, fid))
                                return 0;       // disk write error
                        return 2;
                }
index 0a92f6a..60e9d68 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2003-06-15  Bradley Bell  <btb@icculus.org>
+
+       * 2d/pcx.c, include/strio.h, main/ai.c, main/ai.h, main/config.c,
+       main/movie.c, main/newdemo.c, main/newmenu.c, main/piggy.c,
+       main/polyobj.c, main/scores.c, main/state.c, main/text.c,
+       misc/args.c, misc/strio.c: convert file i/o to cfile
+
 2003-06-14  Bradley Bell  <btb@icculus.org>
 
        * include/cfile.h, cfile/cfile.c: implemented cfile wrappers for
index d2a662e..a81bc48 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef _STRIO_H
 #define _STRIO_H
 
-char *fsplitword(FILE *f, char splitchar);
+char *fsplitword(CFILE *f, char splitchar);
 char *splitword(char *s, char splitchar);
 
 #endif
index eb82ae0..53d510f 100644 (file)
--- a/main/ai.c
+++ b/main/ai.c
@@ -1,4 +1,4 @@
-/* $Id: ai.c,v 1.5 2003-03-14 21:24:03 btb Exp $ */
+/* $Id: ai.c,v 1.6 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -268,7 +268,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include <conf.h>
 #endif
 
-char ai_rcsid[] = "$Id: ai.c,v 1.5 2003-03-14 21:24:03 btb Exp $";
+char ai_rcsid[] = "$Id: ai.c,v 1.6 2003-06-16 06:57:34 btb Exp $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -1824,79 +1824,79 @@ void init_robots_for_level(void)
        Boss_dying_start_time = 0;
 }
 
-int ai_save_state( FILE * fp )
+int ai_save_state(CFILE *fp)
 {
-       fwrite( &Ai_initialized, sizeof(int), 1, fp );
-       fwrite( &Overall_agitation, sizeof(int), 1, fp );
-       fwrite( Ai_local_info, sizeof(ai_local)*MAX_OBJECTS, 1, fp );
-       fwrite( Point_segs, sizeof(point_seg)*MAX_POINT_SEGS, 1, fp );
-       fwrite( Ai_cloak_info, sizeof(ai_cloak_info)*MAX_AI_CLOAK_INFO, 1, fp );
-       fwrite( &Boss_cloak_start_time, sizeof(fix), 1, fp );
-       fwrite( &Boss_cloak_end_time , sizeof(fix), 1, fp );
-       fwrite( &Last_teleport_time , sizeof(fix), 1, fp );
-       fwrite( &Boss_teleport_interval, sizeof(fix), 1, fp );
-       fwrite( &Boss_cloak_interval, sizeof(fix), 1, fp );
-       fwrite( &Boss_cloak_duration, sizeof(fix), 1, fp );
-       fwrite( &Last_gate_time, sizeof(fix), 1, fp );
-       fwrite( &Gate_interval, sizeof(fix), 1, fp );
-       fwrite( &Boss_dying_start_time, sizeof(fix), 1, fp );
-       fwrite( &Boss_dying, sizeof(int), 1, fp );
-       fwrite( &Boss_dying_sound_playing, sizeof(int), 1, fp );
-       fwrite( &Boss_hit_time, sizeof(fix), 1, fp );
-       // -- MK, 10/21/95, unused! -- fwrite( &Boss_been_hit, sizeof(int), 1, fp );
-
-       fwrite( &Escort_kill_object, sizeof(Escort_kill_object), 1, fp);
-       fwrite( &Escort_last_path_created, sizeof(Escort_last_path_created), 1, fp);
-       fwrite( &Escort_goal_object, sizeof(Escort_goal_object), 1, fp);
-       fwrite( &Escort_special_goal, sizeof(Escort_special_goal), 1, fp);
-       fwrite( &Escort_goal_index, sizeof(Escort_goal_index), 1, fp);
-       fwrite( &Stolen_items, sizeof(Stolen_items[0])*MAX_STOLEN_ITEMS, 1, fp);
+       cfwrite(&Ai_initialized, sizeof(int), 1, fp);
+       cfwrite(&Overall_agitation, sizeof(int), 1, fp);
+       cfwrite(Ai_local_info, sizeof(ai_local), MAX_OBJECTS, fp);
+       cfwrite(Point_segs, sizeof(point_seg), MAX_POINT_SEGS, fp);
+       cfwrite(Ai_cloak_info, sizeof(ai_cloak_info), MAX_AI_CLOAK_INFO, fp);
+       cfwrite(&Boss_cloak_start_time, sizeof(fix), 1, fp);
+       cfwrite(&Boss_cloak_end_time , sizeof(fix), 1, fp);
+       cfwrite(&Last_teleport_time , sizeof(fix), 1, fp);
+       cfwrite(&Boss_teleport_interval, sizeof(fix), 1, fp);
+       cfwrite(&Boss_cloak_interval, sizeof(fix), 1, fp);
+       cfwrite(&Boss_cloak_duration, sizeof(fix), 1, fp);
+       cfwrite(&Last_gate_time, sizeof(fix), 1, fp);
+       cfwrite(&Gate_interval, sizeof(fix), 1, fp);
+       cfwrite(&Boss_dying_start_time, sizeof(fix), 1, fp);
+       cfwrite(&Boss_dying, sizeof(int), 1, fp);
+       cfwrite(&Boss_dying_sound_playing, sizeof(int), 1, fp);
+       cfwrite(&Boss_hit_time, sizeof(fix), 1, fp);
+       // -- MK, 10/21/95, unused! -- cfwrite( &Boss_been_hit, sizeof(int), 1, fp);
+
+       cfwrite(&Escort_kill_object, sizeof(Escort_kill_object), 1, fp);
+       cfwrite(&Escort_last_path_created, sizeof(Escort_last_path_created), 1, fp);
+       cfwrite(&Escort_goal_object, sizeof(Escort_goal_object), 1, fp);
+       cfwrite(&Escort_special_goal, sizeof(Escort_special_goal), 1, fp);
+       cfwrite(&Escort_goal_index, sizeof(Escort_goal_index), 1, fp);
+       cfwrite(&Stolen_items, sizeof(Stolen_items[0]), MAX_STOLEN_ITEMS, fp);
 
        { int temp;
        temp = Point_segs_free_ptr - Point_segs;
-       fwrite( &temp, sizeof(int), 1, fp );
+       cfwrite(&temp, sizeof(int), 1, fp);
        }
 
-       fwrite(&Num_boss_teleport_segs, sizeof(Num_boss_teleport_segs), 1, fp);
-       fwrite(&Num_boss_gate_segs, sizeof(Num_boss_gate_segs), 1, fp);
+       cfwrite(&Num_boss_teleport_segs, sizeof(Num_boss_teleport_segs), 1, fp);
+       cfwrite(&Num_boss_gate_segs, sizeof(Num_boss_gate_segs), 1, fp);
 
        if (Num_boss_gate_segs)
-               fwrite(Boss_gate_segs, sizeof(Boss_gate_segs[0]), Num_boss_gate_segs, fp);
+               cfwrite(Boss_gate_segs, sizeof(Boss_gate_segs[0]), Num_boss_gate_segs, fp);
 
        if (Num_boss_teleport_segs)
-               fwrite(Boss_teleport_segs, sizeof(Boss_teleport_segs[0]), Num_boss_teleport_segs, fp);
+               cfwrite(Boss_teleport_segs, sizeof(Boss_teleport_segs[0]), Num_boss_teleport_segs, fp);
 
        return 1;
 }
 
-int ai_restore_state( FILE * fp, int version )
+int ai_restore_state(CFILE *fp, int version)
 {
-       fread( &Ai_initialized, sizeof(int), 1, fp );
-       fread( &Overall_agitation, sizeof(int), 1, fp );
-       fread( Ai_local_info, sizeof(ai_local)*MAX_OBJECTS, 1, fp );
-       fread( Point_segs, sizeof(point_seg)*MAX_POINT_SEGS, 1, fp );
-       fread( Ai_cloak_info, sizeof(ai_cloak_info)*MAX_AI_CLOAK_INFO, 1, fp );
-       fread( &Boss_cloak_start_time, sizeof(fix), 1, fp );
-       fread( &Boss_cloak_end_time , sizeof(fix), 1, fp );
-       fread( &Last_teleport_time , sizeof(fix), 1, fp );
-       fread( &Boss_teleport_interval, sizeof(fix), 1, fp );
-       fread( &Boss_cloak_interval, sizeof(fix), 1, fp );
-       fread( &Boss_cloak_duration, sizeof(fix), 1, fp );
-       fread( &Last_gate_time, sizeof(fix), 1, fp );
-       fread( &Gate_interval, sizeof(fix), 1, fp );
-       fread( &Boss_dying_start_time, sizeof(fix), 1, fp );
-       fread( &Boss_dying, sizeof(int), 1, fp );
-       fread( &Boss_dying_sound_playing, sizeof(int), 1, fp );
-       fread( &Boss_hit_time, sizeof(fix), 1, fp );
-       // -- MK, 10/21/95, unused! -- fread( &Boss_been_hit, sizeof(int), 1, fp );
+       cfread(&Ai_initialized, sizeof(int), 1, fp);
+       cfread(&Overall_agitation, sizeof(int), 1, fp);
+       cfread(Ai_local_info, sizeof(ai_local), MAX_OBJECTS, fp);
+       cfread(Point_segs, sizeof(point_seg), MAX_POINT_SEGS, fp);
+       cfread(Ai_cloak_info, sizeof(ai_cloak_info), MAX_AI_CLOAK_INFO, fp);
+       cfread(&Boss_cloak_start_time, sizeof(fix), 1, fp);
+       cfread(&Boss_cloak_end_time , sizeof(fix), 1, fp);
+       cfread(&Last_teleport_time , sizeof(fix), 1, fp);
+       cfread(&Boss_teleport_interval, sizeof(fix), 1, fp);
+       cfread(&Boss_cloak_interval, sizeof(fix), 1, fp);
+       cfread(&Boss_cloak_duration, sizeof(fix), 1, fp);
+       cfread(&Last_gate_time, sizeof(fix), 1, fp);
+       cfread(&Gate_interval, sizeof(fix), 1, fp);
+       cfread(&Boss_dying_start_time, sizeof(fix), 1, fp);
+       cfread(&Boss_dying, sizeof(int), 1, fp);
+       cfread(&Boss_dying_sound_playing, sizeof(int), 1, fp);
+       cfread(&Boss_hit_time, sizeof(fix), 1, fp);
+       // -- MK, 10/21/95, unused! -- cfread(&Boss_been_hit, sizeof(int), 1, fp);
 
        if (version >= 8) {
-               fread( &Escort_kill_object, sizeof(Escort_kill_object), 1, fp);
-               fread( &Escort_last_path_created, sizeof(Escort_last_path_created), 1, fp);
-               fread( &Escort_goal_object, sizeof(Escort_goal_object), 1, fp);
-               fread( &Escort_special_goal, sizeof(Escort_special_goal), 1, fp);
-               fread( &Escort_goal_index, sizeof(Escort_goal_index), 1, fp);
-               fread( &Stolen_items, sizeof(Stolen_items[0])*MAX_STOLEN_ITEMS, 1, fp);
+               cfread(&Escort_kill_object, sizeof(Escort_kill_object), 1, fp);
+               cfread(&Escort_last_path_created, sizeof(Escort_last_path_created), 1, fp);
+               cfread(&Escort_goal_object, sizeof(Escort_goal_object), 1, fp);
+               cfread(&Escort_special_goal, sizeof(Escort_special_goal), 1, fp);
+               cfread(&Escort_goal_index, sizeof(Escort_goal_index), 1, fp);
+               cfread(&Stolen_items, sizeof(Stolen_items[0]), MAX_STOLEN_ITEMS, fp);
        } else {
                int i;
 
@@ -1914,20 +1914,20 @@ int ai_restore_state( FILE * fp, int version )
 
        if (version >= 15) {
                int temp;
-               fread( &temp, sizeof(int), 1, fp );
+               cfread(&temp, sizeof(int), 1, fp);
                Point_segs_free_ptr = &Point_segs[temp];
        } else
                ai_reset_all_paths();
 
        if (version >= 21) {
-               fread(&Num_boss_teleport_segs, sizeof(Num_boss_teleport_segs), 1, fp);
-               fread(&Num_boss_gate_segs, sizeof(Num_boss_gate_segs), 1, fp);
+               cfread(&Num_boss_teleport_segs, sizeof(Num_boss_teleport_segs), 1, fp);
+               cfread(&Num_boss_gate_segs, sizeof(Num_boss_gate_segs), 1, fp);
 
                if (Num_boss_gate_segs)
-                       fread(Boss_gate_segs, sizeof(Boss_gate_segs[0]), Num_boss_gate_segs, fp);
+                       cfread(Boss_gate_segs, sizeof(Boss_gate_segs[0]), Num_boss_gate_segs, fp);
 
                if (Num_boss_teleport_segs)
-                       fread(Boss_teleport_segs, sizeof(Boss_teleport_segs[0]), Num_boss_teleport_segs, fp);
+                       cfread(Boss_teleport_segs, sizeof(Boss_teleport_segs[0]), Num_boss_teleport_segs, fp);
        } else {
                // -- Num_boss_teleport_segs = 1;
                // -- Num_boss_gate_segs = 1;
index 91b605e..856a0b6 100644 (file)
--- a/main/ai.h
+++ b/main/ai.h
@@ -1,4 +1,4 @@
-/* $Id: ai.h,v 1.5 2003-03-27 01:23:18 btb Exp $ */
+/* $Id: ai.h,v 1.6 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -448,8 +448,8 @@ extern void init_thief_for_level();
 
 extern int Escort_goal_object;
 
-extern int ai_save_state( FILE * fp );
-extern int ai_restore_state( FILE * fp, int version );
+extern int ai_save_state(CFILE *fp);
+extern int ai_restore_state(CFILE *fp, int version);
 
 extern int Buddy_objnum, Buddy_allowed_to_talk;
 
index b1dfb42..8181dad 100644 (file)
@@ -48,7 +48,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 
 
 #ifdef RCS
-static char rcsid[] = "$Id: config.c,v 1.6 2003-03-22 04:04:47 btb Exp $";
+static char rcsid[] = "$Id: config.c,v 1.7 2003-06-16 06:57:34 btb Exp $";
 #endif
 
 ubyte Config_digi_volume = 8;
@@ -185,7 +185,7 @@ void CheckMovieAttributes()
 
 int ReadConfigFile()
 {
-       FILE *infile;
+       CFILE *infile;
        char line[80], *token, *value, *ptr;
        ubyte gamma;
        int joy_axis_min[7];
@@ -226,14 +226,15 @@ int ReadConfigFile()
        SaveMovieHires = MovieHires;
        save_redbook_enabled = Redbook_enabled;
 
-       infile = fopen("descent.cfg", "rt");
+       infile = cfopen("descent.cfg", "rt");
        if (infile == NULL) {
                WIN(CheckMovieAttributes());
                return 1;
        }
-       while (!feof(infile)) {
+       while (!cfeof(infile))
+       {
                memset(line, 0, 80);
-               fgets(line, 80, infile);
+               cfgets(line, 80, infile);
                ptr = &(line[0]);
                while (isspace(*ptr))
                        ptr++;
@@ -328,7 +329,7 @@ int ReadConfigFile()
                }
        }
 
-       fclose(infile);
+       cfclose(infile);
 
 #ifdef WINDOWS
        for (i=0;i<4;i++)
@@ -401,11 +402,12 @@ int ReadConfigFile()
        } else
                digi_driver_board               = digi_driver_board;
 #else
-       infile = fopen("descentw.cfg", "rt");
+       infile = cfopen("descentw.cfg", "rt");
        if (infile) {
-               while (!feof(infile)) {
+               while (!cfeof(infile))
+               {
                        memset(line, 0, 80);
-                       fgets(line, 80, infile);
+                       cfgets(line, 80, infile);
                        ptr = &(line[0]);
                        while (isspace(*ptr))
                                ptr++;
@@ -425,7 +427,7 @@ int ReadConfigFile()
                                }
                        }
                }
-               fclose(infile);
+               cfclose(infile);
        }
 #endif
 
@@ -434,7 +436,7 @@ int ReadConfigFile()
 
 int WriteConfigFile()
 {
-       FILE *infile;
+       CFILE *infile;
        char str[256];
        int joy_axis_min[7];
        int joy_axis_center[7];
@@ -452,66 +454,66 @@ int WriteConfigFile()
    }
 #endif
 
-       infile = fopen("descent.cfg", "wt");
+       infile = cfopen("descent.cfg", "wt");
        if (infile == NULL) {
                return 1;
        }
        /*sprintf (str, "%s=0x%x\n", digi_dev8_str, Config_digi_type);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=0x%x\n", digi_dev16_str, digi_driver_board_16);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=0x%x\n", digi_port_str, digi_driver_port);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", digi_irq_str, digi_driver_irq);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", digi_dma8_str, Config_digi_dma);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", digi_dma16_str, digi_driver_dma_16);
-       fputs(str, infile);*/
+       cfputs(str, infile);*/
        sprintf (str, "%s=%d\n", digi_volume_str, Config_digi_volume);
-       fputs(str, infile);
+       cfputs(str, infile);
        /*sprintf (str, "%s=0x%x\n", midi_dev_str, Config_midi_type);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=0x%x\n", midi_port_str, digi_midi_port);
-       fputs(str, infile);*/
+       cfputs(str, infile);*/
        sprintf (str, "%s=%d\n", midi_volume_str, Config_midi_volume);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", redbook_enabled_str, FindArg("-noredbook")?save_redbook_enabled:Redbook_enabled);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", redbook_volume_str, Config_redbook_volume);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", stereo_rev_str, Config_channels_reversed);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", gamma_level_str, gamma);
-       fputs(str, infile);
+       cfputs(str, infile);
        if (Detail_level == NUM_DETAIL_LEVELS-1)
                sprintf (str, "%s=%d,%d,%d,%d,%d,%d,%d\n", detail_level_str, Detail_level,
                                Object_complexity,Object_detail,Wall_detail,Wall_render_depth,Debris_amount,SoundChannels);
        else
                sprintf (str, "%s=%d\n", detail_level_str, Detail_level);
-       fputs(str, infile);
+       cfputs(str, infile);
 
        sprintf (str, "%s=%d,%d,%d,%d\n", joystick_min_str, joy_axis_min[0], joy_axis_min[1], joy_axis_min[2], joy_axis_min[3] );
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d,%d,%d,%d\n", joystick_cen_str, joy_axis_center[0], joy_axis_center[1], joy_axis_center[2], joy_axis_center[3] );
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d,%d,%d,%d\n", joystick_max_str, joy_axis_max[0], joy_axis_max[1], joy_axis_max[2], joy_axis_max[3] );
-       fputs(str, infile);
+       cfputs(str, infile);
 
        sprintf (str, "%s=%s\n", last_player_str, Players[Player_num].callsign );
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%s\n", last_mission_str, config_last_mission );
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", config_vr_type_str, Config_vr_type );
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", config_vr_resolution_str, Config_vr_resolution );
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", config_vr_tracking_str, Config_vr_tracking );
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf (str, "%s=%d\n", movie_hires_str, (FindArg("-nohires") || FindArg("-nohighres") || FindArg("-lowresmovies"))?SaveMovieHires:MovieHires);
-       fputs(str, infile);
+       cfputs(str, infile);
 
-       fclose(infile);
+       cfclose(infile);
 
 #ifdef WINDOWS
 {
@@ -521,23 +523,23 @@ int WriteConfigFile()
 
        joy_get_cal_vals(joy_axis_min, joy_axis_center, joy_axis_max);
        
-       infile = fopen("descentw.cfg", "wt");
+       infile = cfopen("descentw.cfg", "wt");
        if (infile == NULL) return 1;
 
        sprintf(str, "%s=%d,%d,%d,%d,%d,%d,%d\n", joystick_min_str, 
                        joy_axis_min[0], joy_axis_min[1], joy_axis_min[2], joy_axis_min[3],
                        joy_axis_min[4], joy_axis_min[5], joy_axis_min[6]);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf(str, "%s=%d,%d,%d,%d,%d,%d,%d\n", joystick_cen_str, 
                        joy_axis_center[0], joy_axis_center[1], joy_axis_center[2], joy_axis_center[3],
                        joy_axis_center[4], joy_axis_center[5], joy_axis_center[6]);
-       fputs(str, infile);
+       cfputs(str, infile);
        sprintf(str, "%s=%d,%d,%d,%d,%d,%d,%d\n", joystick_max_str, 
                        joy_axis_max[0], joy_axis_max[1], joy_axis_max[2], joy_axis_max[3],
                        joy_axis_max[4], joy_axis_max[5], joy_axis_max[6]);
-       fputs(str, infile);
+       cfputs(str, infile);
 
-       fclose(infile);
+       cfclose(infile);
 }
        CheckMovieAttributes();
 #endif
@@ -578,7 +580,7 @@ int WriteConfigFile()
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: config.c,v 1.6 2003-03-22 04:04:47 btb Exp $";
+static char rcsid[] = "$Id: config.c,v 1.7 2003-06-16 06:57:34 btb Exp $";
 #endif
 
 #define MAX_CTB_LEN    512
index 1c68dee..2c43f02 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: movie.c,v 1.26 2003-06-10 04:46:16 btb Exp $ */
+/* $Id: movie.c,v 1.27 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -17,7 +17,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: movie.c,v 1.26 2003-06-10 04:46:16 btb Exp $";
+static char rcsid[] = "$Id: movie.c,v 1.27 2003-06-16 06:57:34 btb Exp $";
 #endif
 
 #define DEBUG_LEVEL CON_NORMAL
@@ -47,7 +47,6 @@ static char rcsid[] = "$Id: movie.c,v 1.26 2003-06-10 04:46:16 btb Exp $";
 #include "menu.h"
 #include "libmve.h"
 #include "text.h"
-#include "fileutil.h"
 #include "screens.h"
 
 extern int MenuHiresAvailable;
@@ -645,7 +644,7 @@ void draw_subtitles(int frame_num)
 }
 
 
-movielib *init_new_movie_lib(char *filename,FILE *fp)
+movielib *init_new_movie_lib(char *filename, CFILE *fp)
 {
        int nfiles,offset;
        int i,n;
@@ -653,7 +652,7 @@ movielib *init_new_movie_lib(char *filename,FILE *fp)
 
        //read movie file header
 
-       nfiles = file_read_int(fp);             //get number of files
+       nfiles = cfile_read_int(fp);        //get number of files
 
        //table = d_malloc(sizeof(*table) + sizeof(ml_entry)*nfiles);
        MALLOC(table, movielib, 1);
@@ -667,11 +666,11 @@ movielib *init_new_movie_lib(char *filename,FILE *fp)
        for (i=0;i<nfiles;i++) {
                int len;
 
-               n = fread( table->movies[i].name, 13, 1, fp );
+               n = cfread(table->movies[i].name, 13, 1, fp);
                if ( n != 1 )
                        break;          //end of file (probably)
 
-               len = file_read_int(fp);
+               len = cfile_read_int(fp);
 
                table->movies[i].len = len;
                table->movies[i].offset = offset;
@@ -680,7 +679,7 @@ movielib *init_new_movie_lib(char *filename,FILE *fp)
 
        }
 
-       fclose(fp);
+       cfclose(fp);
 
        table->flags = 0;
 
@@ -689,7 +688,7 @@ movielib *init_new_movie_lib(char *filename,FILE *fp)
 }
 
 
-movielib *init_old_movie_lib(char *filename,FILE *fp)
+movielib *init_old_movie_lib(char *filename, CFILE *fp)
 {
        int nfiles,size;
        int i;
@@ -703,18 +702,18 @@ movielib *init_old_movie_lib(char *filename,FILE *fp)
        while( 1 ) {
                int len;
 
-               i = fread( table->movies[nfiles].name, 13, 1, fp );
+               i = cfread(table->movies[nfiles].name, 13, 1, fp);
                if ( i != 1 )
                        break;          //end of file (probably)
 
-               i = fread( &len, 4, 1, fp );
+               i = cfread(&len, 4, 1, fp);
                if ( i != 1 )
                        Error("error reading movie library <%s>",filename);
 
                table->movies[nfiles].len = INTEL_INT(len);
-               table->movies[nfiles].offset = ftell( fp );
+               table->movies[nfiles].offset = cftell(fp);
 
-               fseek( fp, INTEL_INT(len), SEEK_CUR );          //skip data
+               cfseek(fp, INTEL_INT(len), SEEK_CUR);       //skip data
 
                nfiles++;
        }
@@ -730,7 +729,7 @@ movielib *init_old_movie_lib(char *filename,FILE *fp)
 
        table->n_movies = nfiles;
 
-       fclose(fp);
+       cfclose(fp);
 
        table->flags = 0;
 
@@ -745,30 +744,22 @@ movielib *init_movie_lib(char *filename)
        //note: this based on cfile_init_hogfile()
 
        char id[4];
-       FILE * fp;
+       CFILE *fp;
 
-       fp = fopen( filename, "rb" );
-
-       if ((fp == NULL) && (AltHogdir_initialized)) {
-               char temp[128];
-               strcpy(temp, AltHogDir);
-               strcat(temp, "/");
-               strcat(temp, filename);
-               fp = fopen(temp, "rb");
-       }
+       fp = cfopen(filename, "rb");
 
        if ( fp == NULL )
                return NULL;
 
-       fread( id, 4, 1, fp );
+       cfread(id, 4, 1, fp);
        if ( !strncmp( id, "DMVL", 4 ) )
                return init_new_movie_lib(filename,fp);
        else if ( !strncmp( id, "DHF", 3 ) ) {
-               fseek(fp,-1,SEEK_CUR);          //old file had 3 char id
+               cfseek(fp,-1,SEEK_CUR);         //old file had 3 char id
                return init_old_movie_lib(filename,fp);
        }
        else {
-               fclose(fp);
+               cfclose(fp);
                return NULL;
        }
 }
@@ -969,18 +960,6 @@ int search_movie_lib(movielib *lib,char *filename,int must_have)
                                movie_handle = filehandle = open(lib->name, O_RDONLY);
 #endif
 
-                               if ((filehandle == -1) && (AltHogdir_initialized)) {
-                                       char temp[128];
-                                       strcpy(temp, AltHogDir);
-                                       strcat(temp, "/");
-                                       strcat(temp, lib->name);
-#ifdef O_BINARY
-                                       movie_handle = filehandle = open(temp, O_RDONLY | O_BINARY);
-#else
-                                       movie_handle = filehandle = open(temp, O_RDONLY);
-#endif
-                               }
-
                                if (must_have && from_cd && filehandle == -1) {         //didn't get file!
 
                                        if (request_cd() == -1)         //ESC from requester
index b3f3ca1..2ada7d1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: newdemo.c,v 1.12 2003-03-18 02:31:16 btb Exp $ */
+/* $Id: newdemo.c,v 1.13 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -17,6 +17,9 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
  * Code to make a complete demo playback system.
  *
  * $Log: not supported by cvs2svn $
+ * Revision 1.12  2003/03/18 02:31:16  btb
+ * simplify DEMO_FILENAME macro
+ *
  * Revision 1.11  2003/03/17 07:59:11  btb
  * also look in shared data dir for demos
  *
@@ -920,15 +923,15 @@ byte First_time_playback=1;
 fix JasonPlaybackTotal=0;
 
 
-FILE *infile;
-FILE *outfile=NULL;
+CFILE *infile;
+CFILE *outfile = NULL;
 
 int newdemo_get_percent_done() {
        if ( Newdemo_state == ND_STATE_PLAYBACK ) {
-               return (ftell(infile)*100)/Newdemo_size;
+               return (cftell(infile) * 100) / Newdemo_size;
        }
        if ( Newdemo_state == ND_STATE_RECORDING ) {
-               return ftell(outfile);
+               return cftell(outfile);
        }
        return 0;
 }
@@ -968,8 +971,8 @@ void my_extract_shortpos(object *objp, shortpos *spp)
 int newdemo_read( void *buffer, int elsize, int nelem )
 {
        int num_read;
-       num_read = fread( buffer,elsize,nelem, infile );
-       if (ferror(infile) || feof(infile))
+       num_read = cfread(buffer, elsize, nelem, infile);
+       if (cferror(infile) || cfeof(infile))
                nd_bad_read = -1;
 
        return num_read;
@@ -995,7 +998,7 @@ int newdemo_write( void *buffer, int elsize, int nelem )
        frame_bytes_written += total_size;
        Newdemo_num_written += total_size;
        Assert(outfile != NULL);
-       num_written = fwrite( buffer, elsize, nelem, outfile );
+       num_written = cfwrite(buffer, elsize, nelem, outfile);
        //if ((Newdemo_num_written > Newdemo_size) && !Newdemo_no_space) {
        //      Newdemo_no_space=1;
        //      newdemo_stop_recording();
@@ -2140,7 +2143,7 @@ int newdemo_read_demo_start(int rnd_demo)
 {
        byte i, version, game_type, laser_level;
        char c, energy, shield;
-       char text[50], current_mission[9];
+       char text[128], current_mission[9];
 
        nd_read_byte(&c);
        if ((c != ND_EVENT_START_DEMO) || nd_bad_read) {
@@ -3157,7 +3160,7 @@ int newdemo_read_frame_information()
 
                case ND_EVENT_EOF: {
                        done=-1;
-                       fseek(infile, -1, SEEK_CUR);        // get back to the EOF marker
+                       cfseek(infile, -1, SEEK_CUR);        // get back to the EOF marker
                        Newdemo_at_eof = 1;
                        NewdemoFrameCount++;
                        break;
@@ -3185,7 +3188,7 @@ void newdemo_goto_beginning()
 {
        //if (NewdemoFrameCount == 0)
        //      return;
-       fseek(infile, 0, SEEK_SET);
+       cfseek(infile, 0, SEEK_SET);
        Newdemo_vcr_state = ND_STATE_PLAYBACK;
        if (newdemo_read_demo_start(0))
                newdemo_stop_playback();
@@ -3204,7 +3207,7 @@ void newdemo_goto_end()
        ubyte energy, shield, c;
        int i, loc, bint;
 
-       fseek(infile, -2, SEEK_END);
+       cfseek(infile, -2, SEEK_END);
        nd_read_byte(&level);
 
        if ((level < Last_secret_level) || (level > Last_level)) {
@@ -3220,12 +3223,12 @@ void newdemo_goto_end()
        if (level != Current_level_num)
                LoadLevel(level,1);
 
-       fseek(infile, -4, SEEK_END);
+       cfseek(infile, -4, SEEK_END);
        nd_read_short(&byte_count);
-       fseek(infile, -2 - byte_count, SEEK_CUR);
+       cfseek(infile, -2 - byte_count, SEEK_CUR);
 
        nd_read_short(&frame_length);
-       loc = ftell(infile);
+       loc = cftell(infile);
        if (Newdemo_game_mode & GM_MULTI)
                nd_read_byte(&Newdemo_players_cloaked);
        else
@@ -3277,11 +3280,11 @@ void newdemo_goto_end()
                nd_read_int(&(Players[Player_num].score));
        }
 
-       fseek(infile, loc, SEEK_SET);
-       fseek(infile, -frame_length, SEEK_CUR);
+       cfseek(infile, loc, SEEK_SET);
+       cfseek(infile, -frame_length, SEEK_CUR);
        nd_read_int(&NewdemoFrameCount);            // get the frame count
        NewdemoFrameCount--;
-       fseek(infile, 4, SEEK_CUR);
+       cfseek(infile, 4, SEEK_CUR);
        Newdemo_vcr_state = ND_STATE_PLAYBACK;
        newdemo_read_frame_information();           // then the frame information
        Newdemo_vcr_state = ND_STATE_PAUSED;
@@ -3295,9 +3298,9 @@ void newdemo_back_frames(int frames)
 
        for (i = 0; i < frames; i++)
        {
-               fseek(infile, -10, SEEK_CUR);
+               cfseek(infile, -10, SEEK_CUR);
                nd_read_short(&last_frame_length);
-               fseek(infile, 8 - last_frame_length, SEEK_CUR);
+               cfseek(infile, 8 - last_frame_length, SEEK_CUR);
 
                if (!Newdemo_at_eof && newdemo_read_frame_information() == -1) {
                        newdemo_stop_playback();
@@ -3306,9 +3309,9 @@ void newdemo_back_frames(int frames)
                if (Newdemo_at_eof)
                        Newdemo_at_eof = 0;
 
-               fseek(infile, -10, SEEK_CUR);
+               cfseek(infile, -10, SEEK_CUR);
                nd_read_short(&last_frame_length);
-               fseek(infile, 8 - last_frame_length, SEEK_CUR);
+               cfseek(infile, 8 - last_frame_length, SEEK_CUR);
        }
 
 }
@@ -3503,7 +3506,7 @@ void newdemo_playback_one_frame()
                else
                        frames_back = 1;
                if (Newdemo_at_eof) {
-                       fseek(infile, 11, SEEK_CUR);
+                       cfseek(infile, 11, SEEK_CUR);
                }
                newdemo_back_frames(frames_back);
 
@@ -3674,15 +3677,15 @@ void newdemo_start_recording()
        Newdemo_num_written = 0;
        Newdemo_no_space=0;
        Newdemo_state = ND_STATE_RECORDING;
-       outfile = fopen( DEMO_FILENAME, "wb" );
+       outfile = cfopen(DEMO_FILENAME, "wb");
 
 #ifndef MACINTOSH
        if (outfile == NULL && errno == ENOENT) {   //dir doesn't exist?
 #else
        if (outfile == NULL) {                      //dir doesn't exist and no errno on mac!
 #endif
-               d_mkdir(DEMO_DIR); //try making directory
-               outfile = fopen( DEMO_FILENAME, "wb" );
+               cfile_mkdir(DEMO_DIR); //try making directory
+               outfile = cfopen(DEMO_FILENAME, "wb");
        }
 
        if (outfile == NULL)
@@ -3767,8 +3770,8 @@ void newdemo_stop_recording()
        nd_write_byte(Current_level_num);
        nd_write_byte(ND_EVENT_EOF);
 
-       l = ftell(outfile);
-       fclose(outfile);
+       l = cftell(outfile);
+       cfclose(outfile);
        outfile = NULL;
        Newdemo_state = ND_STATE_NORMAL;
        gr_palette_load( gr_palette );
@@ -3818,12 +3821,12 @@ try_again:
                        strcat(save_file, ".dem");
                } else
                        sprintf (save_file, "%stmp%d.dem", DEMO_DIR, tmpcnt++);
-               remove(save_file);
-               rename(DEMO_FILENAME, save_file);
+               cfile_delete(save_file);
+               cfile_rename(DEMO_FILENAME, save_file);
                return;
        }
        if (exit == -1) {               // pressed ESC
-               remove(DEMO_FILENAME);      // might as well remove the file
+               cfile_delete(DEMO_FILENAME);      // might as well remove the file
                return;                     // return without doing anything
        }
 
@@ -3842,10 +3845,14 @@ try_again:
        else
                strcat(fullname, m[0].text);
        strcat(fullname, ".dem");
-       remove(fullname);
-       rename(DEMO_FILENAME, fullname);
+       cfile_delete(fullname);
+       cfile_rename(DEMO_FILENAME, fullname);
 }
 
+
+extern char AltHogDir[64];
+extern char AltHogdir_initialized;
+
 //returns the number of demo files on the disk
 int newdemo_count_demos()
 {
@@ -3933,14 +3940,7 @@ void newdemo_start_playback(char * filename)
 
        strcat(filename2,filename);
 
-       infile = fopen( filename2, "rb" );
-
-       if (infile==NULL && AltHogdir_initialized) {
-               strcpy(filename2, AltHogDir);
-               strcat(filename2, "/" DEMO_DIR);
-               strcat(filename2, filename);
-               infile = fopen( filename2, "rb" );
-       }
+       infile = cfopen(filename2, "rb");
 
        if (infile==NULL) {
                mprintf( (0, "Error reading '%s'\n", filename ));
@@ -3954,7 +3954,7 @@ void newdemo_start_playback(char * filename)
        strncpy(nd_save_callsign, Players[Player_num].callsign, CALLSIGN_LEN);
        Viewer = ConsoleObject = &Objects[0];   // play properly as if console player
        if (newdemo_read_demo_start(rnd_demo)) {
-               fclose(infile);
+               cfclose(infile);
                return;
        }
 
@@ -3962,7 +3962,7 @@ void newdemo_start_playback(char * filename)
        Newdemo_state = ND_STATE_PLAYBACK;
        Newdemo_vcr_state = ND_STATE_PLAYBACK;
        Newdemo_old_cockpit = Cockpit_mode;
-       Newdemo_size = filelength(fileno(infile));
+       Newdemo_size = cfilelength(infile);
        nd_bad_read = 0;
        Newdemo_at_eof = 0;
        NewdemoFrameCount = 0;
@@ -3977,7 +3977,7 @@ void newdemo_start_playback(char * filename)
 
 void newdemo_stop_playback()
 {
-       fclose( infile );
+       cfclose(infile);
        Newdemo_state = ND_STATE_NORMAL;
 #ifdef NETWORK
        change_playernum_to(0);             //this is reality
@@ -3996,15 +3996,15 @@ void newdemo_stop_playback()
 
 void newdemo_strip_frames(char *outname, int bytes_to_strip)
 {
-       FILE *outfile;
+       CFILE *outfile;
        char *buf;
        int total_size, bytes_done, read_elems, bytes_back;
        int trailer_start, loc1, loc2, stop_loc, bytes_to_read;
        short last_frame_length;
 
        bytes_done = 0;
-       total_size = filelength(fileno(infile));
-       outfile = fopen(outname, "wb");
+       total_size = cfilelength(infile);
+       outfile = cfopen(outname, "wb");
        if (outfile == NULL) {
                newmenu_item m[1];
 
@@ -4019,45 +4019,45 @@ void newdemo_strip_frames(char *outname, int bytes_to_strip)
 
                m[ 0].type = NM_TYPE_TEXT; m[ 0].text = "Can't malloc output buffer";
                newmenu_do( NULL, NULL, 1, m, NULL );
-               fclose(outfile);
+               cfclose(outfile);
                newdemo_stop_playback();
                return;
        }
        newdemo_goto_end();
-       trailer_start = ftell(infile);
-       fseek(infile, 11, SEEK_CUR);
+       trailer_start = cftell(infile);
+       cfseek(infile, 11, SEEK_CUR);
        bytes_back = 0;
        while (bytes_back < bytes_to_strip) {
-               loc1 = ftell(infile);
-               //fseek(infile, -10, SEEK_CUR);
+               loc1 = cftell(infile);
+               //cfseek(infile, -10, SEEK_CUR);
                //nd_read_short(&last_frame_length);
-               //fseek(infile, 8 - last_frame_length, SEEK_CUR);
+               //cfseek(infile, 8 - last_frame_length, SEEK_CUR);
                newdemo_back_frames(1);
-               loc2 = ftell(infile);
+               loc2 = cftell(infile);
                bytes_back += (loc1 - loc2);
        }
-       fseek(infile, -10, SEEK_CUR);
+       cfseek(infile, -10, SEEK_CUR);
        nd_read_short(&last_frame_length);
-       fseek(infile, -3, SEEK_CUR);
-       stop_loc = ftell(infile);
-       fseek(infile, 0, SEEK_SET);
+       cfseek(infile, -3, SEEK_CUR);
+       stop_loc = cftell(infile);
+       cfseek(infile, 0, SEEK_SET);
        while (stop_loc > 0) {
                if (stop_loc < BUF_SIZE)
                        bytes_to_read = stop_loc;
                else
                        bytes_to_read = BUF_SIZE;
-               read_elems = fread(buf, 1, bytes_to_read, infile);
-               fwrite(buf, 1, read_elems, outfile);
+               read_elems = cfread(buf, 1, bytes_to_read, infile);
+               cfwrite(buf, 1, read_elems, outfile);
                stop_loc -= read_elems;
        }
-       stop_loc = ftell(outfile);
-       fseek(infile, trailer_start, SEEK_SET);
-       while ((read_elems = fread(buf, 1, BUF_SIZE, infile)) != 0)
-               fwrite(buf, 1, read_elems, outfile);
-       fseek(outfile, stop_loc, SEEK_SET);
-       fseek(outfile, 1, SEEK_CUR);
-       fwrite(&last_frame_length, 2, 1, outfile);
-       fclose(outfile);
+       stop_loc = cftell(outfile);
+       cfseek(infile, trailer_start, SEEK_SET);
+       while ((read_elems = cfread(buf, 1, BUF_SIZE, infile)) != 0)
+               cfwrite(buf, 1, read_elems, outfile);
+       cfseek(outfile, stop_loc, SEEK_SET);
+       cfseek(outfile, 1, SEEK_CUR);
+       cfwrite(&last_frame_length, 2, 1, outfile);
+       cfclose(outfile);
        newdemo_stop_playback();
 
 }
index 44e989e..79a9eeb 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: newmenu.c,v 1.20 2003-06-06 19:04:27 btb Exp $ */
+/* $Id: newmenu.c,v 1.21 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -2578,7 +2578,7 @@ void delete_player_saved_games(char * name)
 #else
                sprintf( filename, ":Players:%s.sg%d", name, i );
 #endif
-               unlink( filename );
+               cfile_delete(filename);
        }
 }
 
@@ -2586,6 +2586,9 @@ void delete_player_saved_games(char * name)
 
 int MakeNewPlayerFile(int allow_abort);
 
+extern char AltHogDir[64];
+extern char AltHogdir_initialized;
+
 int newmenu_get_filename( char * title, char * filespec, char * filename, int allow_abort_flag )
 {
        int i;
@@ -2935,7 +2938,7 @@ RePaintNewmenuFile:
                                        }
                                        #endif
                                
-                                       ret = unlink( name );
+                                       ret = cfile_delete(name);
                                        if (player_mode)
                                                *p = 0;
 
@@ -3289,7 +3292,7 @@ ExitFileMenu:
 // 
 //     if ( *keypress = KEY_CTRLED+KEY_D )     {
 //             if ( *nitems > 1 )      {
-//                     unlink( items[*citem] );                // Delete the file
+//                     cfile_delete(items[*citem]);    // Delete the file
 //                     for (i=*citem; i<*nitems-1; i++ )       {
 //                             items[i] = items[i+1];
 //                     }
index fe21e4d..53f49c7 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: piggy.c,v 1.31 2003-03-29 22:35:00 btb Exp $ */
+/* $Id: piggy.c,v 1.32 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -386,7 +386,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: piggy.c,v 1.31 2003-03-29 22:35:00 btb Exp $";
+static char rcsid[] = "$Id: piggy.c,v 1.32 2003-06-16 06:57:34 btb Exp $";
 #endif
 
 
@@ -847,7 +847,7 @@ CFILE *copy_pigfile_from_cd(char *filename)
 
        if( !FileFindFirst( "*.pig", &find ) ) {
                do      {
-                       remove(find.name);
+                       cfile_delete(find.name);
                } while( !FileFindNext( &find ) );
                FileFindClose();
        }
@@ -869,7 +869,7 @@ CFILE *copy_pigfile_from_cd(char *filename)
                if (ret != EXIT_SUCCESS) {
 
                        //delete file, so we don't leave partial file
-                       remove(filename);
+                       cfile_delete(filename);
 
                        #ifndef MACINTOSH
                        if (request_cd() == -1)
index 8e11e78..1c029aa 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: polyobj.c,v 1.14 2003-03-29 22:35:00 btb Exp $ */
+/* $Id: polyobj.c,v 1.15 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -17,7 +17,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: polyobj.c,v 1.14 2003-03-29 22:35:00 btb Exp $";
+static char rcsid[] = "$Id: polyobj.c,v 1.15 2003-06-16 06:57:34 btb Exp $";
 #endif
 
 #include <stdio.h>
@@ -294,7 +294,7 @@ polymodel *read_model_file(polymodel *pm,char *filename,robot_info *r)
        if ((ifile=cfopen(filename,"rb"))==NULL) 
                Error("Can't open file <%s>",filename);
 
-       Assert(ifile->size <= MODEL_BUF_SIZE);
+       Assert(cfilelength(ifile) <= MODEL_BUF_SIZE);
 
        Pof_addr = 0;
        Pof_file_end = cfread(model_buf, 1, cfilelength(ifile), ifile);
@@ -521,10 +521,10 @@ int read_model_guns(char *filename,vms_vector *gun_points, vms_vector *gun_dirs,
        if ((ifile=cfopen(filename,"rb"))==NULL) 
                Error("Can't open file <%s>",filename);
 
-       Assert(ifile->size <= MODEL_BUF_SIZE);
+       Assert(cfilelength(ifile) <= MODEL_BUF_SIZE);
 
        Pof_addr = 0;
-       Pof_file_end = cfread(model_buf, 1, ifile->size, ifile);
+       Pof_file_end = cfread(model_buf, 1, cfilelength(ifile), ifile);
        cfclose(ifile);
 
        id = pof_read_int(model_buf);
index 163e75c..a3f9139 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: scores.c,v 1.3 2003-03-15 14:17:52 btb Exp $ */
+/* $Id: scores.c,v 1.4 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -276,7 +276,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include "strutil.h"
 
 #define VERSION_NUMBER                 1
-#define SCORES_FILENAME        "DESCENT.HI"
+#define SCORES_FILENAME        "descent.hi"
 #define COOL_MESSAGE_LEN       50
 #define MAX_HIGH_SCORES        10
 
@@ -339,13 +339,13 @@ char * get_scores_filename()
 
 void scores_read()
 {
-       FILE * fp;
+       CFILE *fp;
        int fsize;
 
        // clear score array...
        memset( &Scores, 0, sizeof(all_scores) );
 
-       fp = fopen( get_scores_filename(), "rb" );
+       fp = cfopen(get_scores_filename(), "rb");
        if (fp==NULL) {
                int i;
 
@@ -367,15 +367,15 @@ void scores_read()
                return;
        }
                
-       fsize = filelength( fileno( fp ));
+       fsize = cfilelength(fp);
 
        if ( fsize != sizeof(all_scores) )      {
-               fclose(fp);
+               cfclose(fp);
                return;
        }
        // Read 'em in...
-       fread( &Scores, sizeof(all_scores),1, fp );
-       fclose(fp);
+       cfread(&Scores, sizeof(all_scores), 1, fp);
+       cfclose(fp);
 
        if ( (Scores.version!=VERSION_NUMBER)||(Scores.signature[0]!='D')||(Scores.signature[1]!='H')||(Scores.signature[2]!='S') )     {
                memset( &Scores, 0, sizeof(all_scores) );
@@ -385,9 +385,9 @@ void scores_read()
 
 void scores_write()
 {
-       FILE * fp;
+       CFILE *fp;
 
-       fp = fopen( get_scores_filename(), "wb" );
+       fp = cfopen(get_scores_filename(), "wb");
        if (fp==NULL) {
                nm_messagebox( TXT_WARNING, 1, TXT_OK, "%s\n'%s'", TXT_UNABLE_TO_OPEN, get_scores_filename()  );
                return;
@@ -397,8 +397,8 @@ void scores_write()
        Scores.signature[1]='H';
        Scores.signature[2]='S';
        Scores.version = VERSION_NUMBER;
-       fwrite( &Scores,sizeof(all_scores),1, fp );
-       fclose(fp);
+       cfwrite(&Scores,sizeof(all_scores),1, fp);
+       cfclose(fp);
 }
 
 void int_to_string( int number, char *dest )
@@ -690,7 +690,7 @@ WIN(DDGRUNLOCK(dd_grd_curcanv));
                        if ( citem < 0 )                {
                                // Reset scores...
                                if ( nm_messagebox( NULL, 2,  TXT_NO, TXT_YES, TXT_RESET_HIGH_SCORES )==1 )     {
-                                       remove( get_scores_filename() );
+                                       cfile_delete(get_scores_filename());
                                        gr_palette_fade_out( gr_palette, 32, 0 );
                                        goto ReshowScores;
                                }
index c084a8d..6438647 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: state.c,v 1.8 2003-04-11 23:51:48 btb Exp $ */
+/* $Id: state.c,v 1.9 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -225,7 +225,7 @@ void rpad_string( char * string, int max_chars )
 
 int state_get_save_file(char * fname, char * dsc, int multi )
 {
-       FILE * fp;
+       CFILE *fp;
        int i, choice, version;
        newmenu_item m[NUM_SAVES+2];
        char filename[NUM_SAVES+1][30];
@@ -248,24 +248,24 @@ int state_get_save_file(char * fname, char * dsc, int multi )
                        sprintf( filename[i], ":Players:%s.mg%x", Players[Player_num].callsign, i );
                        #endif
                valid = 0;
-               fp = fopen( filename[i], "rb" );
+               fp = cfopen(filename[i], "rb");
                if ( fp ) {
                        //Read id
-                       fread( id, sizeof(char)*4, 1, fp );
+                       cfread(id, sizeof(char)*4, 1, fp);
                        if ( !memcmp( id, dgss_id, 4 )) {
                                //Read version
-                               fread( &version, sizeof(int), 1, fp );
+                               cfread(&version, sizeof(int), 1, fp);
                                if (version >= STATE_COMPATIBLE_VERSION)        {
                                        // Read description
-                                       fread( desc[i], sizeof(char)*DESC_LENGTH, 1, fp );
+                                       cfread(desc[i], sizeof(char)*DESC_LENGTH, 1, fp);
                                        //rpad_string( desc[i], DESC_LENGTH-1 );
                                        // Read thumbnail
                                        //sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H );
-                                       //fread( sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp );
+                                       //cfread(sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
                                        valid = 1;
                                }
                        } 
-                       fclose(fp);
+                       cfclose(fp);
                }
                if (!valid) {
                        strcpy( desc[i], TXT_EMPTY );
@@ -296,7 +296,7 @@ extern int Current_display_mode;
 
 int state_get_restore_file(char * fname, int multi)
 {
-       FILE * fp;
+       CFILE *fp;
        int i, choice, version, nsaves;
        newmenu_item m[NUM_SAVES+2];
        char filename[NUM_SAVES+1][30];
@@ -321,31 +321,31 @@ int state_get_restore_file(char * fname, int multi)
                        sprintf( filename[i], ":Players:%s.mg%x", Players[Player_num].callsign, i );
                        #endif
                valid = 0;
-               fp = fopen( filename[i], "rb" );
+               fp = cfopen(filename[i], "rb");
                if ( fp ) {
                        //Read id
-                       fread( id, sizeof(char)*4, 1, fp );
+                       cfread(id, sizeof(char)*4, 1, fp);
                        if ( !memcmp( id, dgss_id, 4 )) {
                                //Read version
-                               fread( &version, sizeof(int), 1, fp );
+                               cfread(&version, sizeof(int), 1, fp);
                                if (version >= STATE_COMPATIBLE_VERSION)        {
                                        // Read description
-                                       fread( desc[i], sizeof(char)*DESC_LENGTH, 1, fp );
+                                       cfread(desc[i], sizeof(char)*DESC_LENGTH, 1, fp);
                                        //rpad_string( desc[i], DESC_LENGTH-1 );
                                        m[i+1].type = NM_TYPE_MENU; m[i+1].text = desc[i];
                                        // Read thumbnail
                                        sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H );
-                                       fread( sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp );
+                                       cfread(sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
                                        if (version >= 9) {
                                                ubyte pal[256*3];
-                                               fread( pal, 3, 256, fp);
+                                               cfread(pal, 3, 256, fp);
                                                gr_remap_bitmap_good( sc_bmp[i], pal, -1, -1 );
                                        }
                                        nsaves++;
                                        valid = 1;
                                } 
                        }
-                       fclose(fp);
+                       cfclose(fp);
                } 
                if (!valid) {
                        strcpy( desc[i], TXT_EMPTY );
@@ -396,20 +396,6 @@ int state_get_restore_file(char * fname, int multi)
 
 #define        DESC_OFFSET     8
 
-//     -----------------------------------------------------------------------------------
-//     Return true if the file named *filename exists, else return false.
-int file_exists(char *filename)
-{
-       FILE    *fp;
-
-       if ((fp = fopen(filename, "rb")) != NULL) {
-               fclose(fp);
-               return 1;
-       }
-
-       return 0;
-}
-
 #define        CF_BUF_SIZE     1024
 
 //     -----------------------------------------------------------------------------------
@@ -417,39 +403,40 @@ int file_exists(char *filename)
 int copy_file(char *old_file, char *new_file)
 {
        byte    buf[CF_BUF_SIZE];
-       FILE    *in_file, *out_file;
+       CFILE   *in_file, *out_file;
 
-       out_file = fopen(new_file, "wb");
+       out_file = cfopen(new_file, "wb");
 
        if (out_file == NULL)
                return -1;
 
-       in_file = fopen(old_file, "rb");
+       in_file = cfopen(old_file, "rb");
 
        if (in_file == NULL)
                return -2;
 
-       while (!feof(in_file)) {
+       while (!cfeof(in_file))
+       {
                int bytes_read;
 
-               bytes_read = fread(buf, 1, CF_BUF_SIZE, in_file);
-               if (ferror(in_file))
+               bytes_read = cfread(buf, 1, CF_BUF_SIZE, in_file);
+               if (cferror(in_file))
                        Error("Cannot read from file <%s>: %s", old_file, strerror(errno));
 
-               Assert(bytes_read == CF_BUF_SIZE || feof(in_file));
+               Assert(bytes_read == CF_BUF_SIZE || cfeof(in_file));
 
-               fwrite(buf, 1, bytes_read, out_file);
+               cfwrite(buf, 1, bytes_read, out_file);
 
-               if (ferror(out_file))
+               if (cferror(out_file))
                        Error("Cannot write to file <%s>: %s", new_file, strerror(errno));
        }
 
-       if (fclose(in_file)) {
-               fclose(out_file);
+       if (cfclose(in_file)) {
+               cfclose(out_file);
                return -3;
        }
 
-       if (fclose(out_file))
+       if (cfclose(out_file))
                return -4;
 
        return 0;
@@ -496,7 +483,7 @@ int state_save_all(int between_levels, int secret_save, char *filename_override)
        //      return to the base level.
        if (secret_save && (Control_center_destroyed)) {
                mprintf((0, "Deleting secret.sgb so player can't return to base level.\n"));
-               unlink(SECRETB_FILENAME);
+               cfile_delete(SECRETB_FILENAME);
                return 0;
        }
 
@@ -541,13 +528,15 @@ int state_save_all(int between_levels, int secret_save, char *filename_override)
 
                        mprintf((0, "Trying to copy secret.sgc to %s.\n", temp_fname));
 
-                       if (file_exists(temp_fname)) {
+                       if (cfexist(temp_fname))
+                       {
                                mprintf((0, "Deleting file %s\n", temp_fname));
-                               rval = unlink(temp_fname);
+                               rval = cfile_delete(temp_fname);
                                Assert(rval == 0);      //      Oops, error deleting file in temp_fname.
                        }
 
-                       if (file_exists(SECRETC_FILENAME)) {
+                       if (cfexist(SECRETC_FILENAME))
+                       {
                                mprintf((0, "Copying secret.sgc to %s.\n", temp_fname));
                                rval = copy_file(SECRETC_FILENAME, temp_fname);
                                Assert(rval == 0);      //      Oops, error copying temp_fname to secret.sgc!
@@ -557,9 +546,9 @@ int state_save_all(int between_levels, int secret_save, char *filename_override)
 
        //      Save file we're going to save over in last slot and call "[autosave backup]"
        if (!filename_override) {
-               FILE    *tfp;
+               CFILE *tfp;
        
-               tfp = fopen( filename, "r+b" );
+               tfp = cfopen(filename, "rb");
 
                if ( tfp ) {
                        char    newname[128];
@@ -570,11 +559,11 @@ int state_save_all(int between_levels, int secret_save, char *filename_override)
                        sprintf( newname, ":Players:%s.sg%x", Players[Player_num].callsign, NUM_SAVES );
                        #endif
                        
-                       fseek( tfp, DESC_OFFSET, SEEK_SET);
-                       fwrite( "[autosave backup]", sizeof(char)*DESC_LENGTH, 1, tfp );
-                       fclose(tfp);
-                       unlink(newname);
-                       rename(filename, newname);
+                       cfseek(tfp, DESC_OFFSET, SEEK_SET);
+                       cfwrite("[autosave backup]", sizeof(char)*DESC_LENGTH, 1, tfp);
+                       cfclose(tfp);
+                       cfile_delete(newname);
+                       cfile_rename(filename, newname);
                }
        }
        
@@ -589,7 +578,7 @@ extern      fix     Flash_effect, Time_flash_last_played;
 int state_save_all_sub(char *filename, char *desc, int between_levels)
 {
        int i,j;
-       FILE * fp;
+       CFILE *fp;
        grs_canvas * cnv;
        #ifdef POLY_ACC
        grs_canvas cnv2,*save_cnv2;
@@ -610,7 +599,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
                Int3();
        #endif
 
-       fp = fopen( filename, "wb" );
+       fp = cfopen(filename, "wb");
        if ( !fp ) {
                if ( !(Game_mode & GM_MULTI) )
                        nm_messagebox(NULL, 1, TXT_OK, "Error writing savegame.\nPossibly out of disk\nspace.");
@@ -619,14 +608,14 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
        }
 
 //Save id
-       fwrite( dgss_id, sizeof(char)*4, 1, fp );
+       cfwrite(dgss_id, sizeof(char)*4, 1, fp);
 
 //Save version
        i = STATE_VERSION;
-       fwrite( &i, sizeof(int), 1, fp );
+       cfwrite(&i, sizeof(int), 1, fp);
 
 //Save description
-       fwrite( desc, sizeof(char)*DESC_LENGTH, 1, fp );
+       cfwrite(desc, sizeof(char) * DESC_LENGTH, 1, fp);
        
 // Save the current screen shot...
 
@@ -693,7 +682,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
 
                                        pal = gr_palette;
 
-                                       fwrite( cnv->cv_bitmap.bm_data, THUMBNAIL_W*THUMBNAIL_H, 1, fp );
+                                       cfwrite(cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
 
                        #if defined(POLY_ACC)
                                        PA_DFX (pa_alpha_always());     
@@ -716,7 +705,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
                        gr_set_current_canvas( cnv );
                        render_frame(0, 0);
                        pal = gr_palette;
-                       fwrite( cnv->cv_bitmap.bm_data, THUMBNAIL_W*THUMBNAIL_H, 1, fp );
+                       cfwrite(cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
                        
                        #if defined(POLY_ACC)
                                PAEnabled = savePAEnabled;
@@ -730,68 +719,68 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
                        gr_set_current_canvas(cnv_save)
                );
                gr_free_canvas( cnv );
-               fwrite( pal, 3, 256, fp);
+               cfwrite(pal, 3, 256, fp);
        }
        else
        {
                ubyte color = 0;
                for ( i=0; i<THUMBNAIL_W*THUMBNAIL_H; i++ )
-                       fwrite( &color, sizeof(ubyte), 1, fp );         
+                       cfwrite(&color, sizeof(ubyte), 1, fp);
        } 
 
 // Save the Between levels flag...
-       fwrite( &between_levels, sizeof(int), 1, fp );
+       cfwrite(&between_levels, sizeof(int), 1, fp);
 
 // Save the mission info...
         mprintf ((0,"HEY! Mission name is %s\n",Mission_list[Current_mission_num].filename));
-       fwrite( &Mission_list[Current_mission_num], sizeof(char)*9, 1, fp );
+       cfwrite(&Mission_list[Current_mission_num], sizeof(char), 9, fp);
 
 //Save level info
-       fwrite( &Current_level_num, sizeof(int), 1, fp );
-       fwrite( &Next_level_num, sizeof(int), 1, fp );
+       cfwrite(&Current_level_num, sizeof(int), 1, fp);
+       cfwrite(&Next_level_num, sizeof(int), 1, fp);
 
 //Save GameTime
-       fwrite( &GameTime, sizeof(fix), 1, fp );
+       cfwrite(&GameTime, sizeof(fix), 1, fp);
 
 // If coop save, save all
 #ifdef NETWORK
    if (Game_mode & GM_MULTI_COOP)
         {
-               fwrite (&state_game_id,sizeof(int),1,fp);
-               fwrite (&Netgame,sizeof(netgame_info),1,fp);            
-               fwrite (&NetPlayers,sizeof(AllNetPlayers_info),1,fp);
-               fwrite (&N_players,sizeof(int),1,fp);
-               fwrite (&Player_num,sizeof(int),1,fp);
+               cfwrite(&state_game_id, sizeof(int), 1, fp);
+               cfwrite(&Netgame, sizeof(netgame_info), 1, fp);
+               cfwrite(&NetPlayers, sizeof(AllNetPlayers_info), 1, fp);
+               cfwrite(&N_players, sizeof(int), 1, fp);
+               cfwrite(&Player_num, sizeof(int), 1, fp);
                for (i=0;i<N_players;i++)
-                fwrite (&Players[i],sizeof(player),1,fp);
+                       cfwrite(&Players[i], sizeof(player), 1, fp);
 
 #ifdef RISKY_PROPOSITION
-          fwrite (&robot_controlled[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fwrite (&robot_agitation[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fwrite (&robot_controlled_time[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fwrite (&robot_last_send_time[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fwrite (&robot_last_message_time[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fwrite (&robot_send_pending[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fwrite (&robot_fired[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
+               cfwrite(&robot_controlled[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfwrite(&robot_agitation[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfwrite(&robot_controlled_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfwrite(&robot_last_send_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfwrite(&robot_last_message_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfwrite(&robot_send_pending[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfwrite(&robot_fired[0], 4, MAX_ROBOTS_CONTROLLED, fp);
  
       for (i=0;i<MAX_ROBOTS_CONTROLLED;i++)
-                  fwrite (robot_fire_buf[i][0],18+3,1,fp);
+                       cfwrite(robot_fire_buf[i][0], 18 + 3, 1, fp);
 #endif
 
         }
 #endif
 
 //Save player info
-       fwrite( &Players[Player_num], sizeof(player), 1, fp );
+       cfwrite(&Players[Player_num], sizeof(player), 1, fp);
 
 // Save the current weapon info
-       fwrite( &Primary_weapon, sizeof(byte), 1, fp );
-       fwrite( &Secondary_weapon, sizeof(byte), 1, fp );
+       cfwrite(&Primary_weapon, sizeof(byte), 1, fp);
+       cfwrite(&Secondary_weapon, sizeof(byte), 1, fp);
 
 // Save the difficulty level
-       fwrite( &Difficulty_level, sizeof(int), 1, fp );
+       cfwrite(&Difficulty_level, sizeof(int), 1, fp);
 // Save cheats enabled
-       fwrite (&Cheats_enabled,sizeof(int),1,fp);
+       cfwrite(&Cheats_enabled, sizeof(int), 1, fp);
 
        if ( !between_levels )  {
 
@@ -817,103 +806,104 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
        
        //Save object info
                i = Highest_object_index+1;
-               fwrite( &i, sizeof(int), 1, fp );
-               fwrite( Objects, sizeof(object)*i, 1, fp );
+               cfwrite(&i, sizeof(int), 1, fp);
+               cfwrite(Objects, sizeof(object), i, fp);
                
        //Save wall info
                i = Num_walls;
-               fwrite( &i, sizeof(int), 1, fp );
-               fwrite( Walls, sizeof(wall)*i, 1, fp );
+               cfwrite(&i, sizeof(int), 1, fp);
+               cfwrite(Walls, sizeof(wall), i, fp);
 
        //Save exploding wall info
                i = MAX_EXPLODING_WALLS;
-               fwrite( &i, sizeof(int), 1, fp);
-               fwrite( expl_wall_list, sizeof(*expl_wall_list), i, fp );
+               cfwrite(&i, sizeof(int), 1, fp);
+               cfwrite(expl_wall_list, sizeof(*expl_wall_list), i, fp);
        
        //Save door info
                i = Num_open_doors;
-               fwrite( &i, sizeof(int), 1, fp );
-               fwrite( ActiveDoors, sizeof(active_door)*i, 1, fp );
+               cfwrite(&i, sizeof(int), 1, fp );
+               cfwrite(ActiveDoors, sizeof(active_door), i, fp);
        
        //Save cloaking wall info
                i = Num_cloaking_walls;
-               fwrite( &i, sizeof(int), 1, fp );
-               fwrite( CloakingWalls, sizeof(cloaking_wall), i, fp );
+               cfwrite(&i, sizeof(int), 1, fp );
+               cfwrite(CloakingWalls, sizeof(cloaking_wall), i, fp);
        
        //Save trigger info
-               fwrite( &Num_triggers, sizeof(int), 1, fp );
-               fwrite( Triggers, sizeof(trigger)*Num_triggers, 1, fp );
+               cfwrite(&Num_triggers, sizeof(int), 1, fp);
+               cfwrite(Triggers, sizeof(trigger), Num_triggers, fp);
        
        //Save tmap info
                for (i=0; i<=Highest_segment_index; i++ )       {
                        for (j=0; j<6; j++ )    {
-                               fwrite( &Segments[i].sides[j].wall_num, sizeof(short), 1, fp );
-                               fwrite( &Segments[i].sides[j].tmap_num, sizeof(short), 1, fp );
-                               fwrite( &Segments[i].sides[j].tmap_num2, sizeof(short), 1, fp );
+                               cfwrite(&Segments[i].sides[j].wall_num, sizeof(short), 1, fp);
+                               cfwrite(&Segments[i].sides[j].tmap_num, sizeof(short), 1, fp);
+                               cfwrite(&Segments[i].sides[j].tmap_num2, sizeof(short), 1, fp);
                        }
                }
        
        // Save the fuelcen info
-               fwrite( &Control_center_destroyed, sizeof(int), 1, fp );
-               fwrite( &Countdown_timer, sizeof(int), 1, fp );
-               fwrite( &Num_robot_centers, sizeof(int), 1, fp );
-               fwrite( RobotCenters, sizeof(matcen_info)*Num_robot_centers, 1, fp );
-               fwrite( &ControlCenterTriggers, sizeof(control_center_triggers), 1, fp );
-               fwrite( &Num_fuelcenters, sizeof(int), 1, fp );
-               fwrite( Station, sizeof(FuelCenter)*Num_fuelcenters, 1, fp );
+               cfwrite(&Control_center_destroyed, sizeof(int), 1, fp);
+               cfwrite(&Countdown_timer, sizeof(int), 1, fp);
+               cfwrite(&Num_robot_centers, sizeof(int), 1, fp);
+               cfwrite(RobotCenters, sizeof(matcen_info), Num_robot_centers, fp);
+               cfwrite(&ControlCenterTriggers, sizeof(control_center_triggers), 1, fp);
+               cfwrite(&Num_fuelcenters, sizeof(int), 1, fp);
+               cfwrite(Station, sizeof(FuelCenter), Num_fuelcenters, fp);
        
        // Save the control cen info
-               fwrite( &Control_center_been_hit, sizeof(int), 1, fp );
-               fwrite( &Control_center_player_been_seen, sizeof(int), 1, fp );
-               fwrite( &Control_center_next_fire_time, sizeof(int), 1, fp );
-               fwrite( &Control_center_present, sizeof(int), 1, fp );
-               fwrite( &Dead_controlcen_object_num, sizeof(int), 1, fp );
+               cfwrite(&Control_center_been_hit, sizeof(int), 1, fp);
+               cfwrite(&Control_center_player_been_seen, sizeof(int), 1, fp);
+               cfwrite(&Control_center_next_fire_time, sizeof(int), 1, fp);
+               cfwrite(&Control_center_present, sizeof(int), 1, fp);
+               cfwrite(&Dead_controlcen_object_num, sizeof(int), 1, fp);
        
        // Save the AI state
                ai_save_state( fp );
        
        // Save the automap visited info
-               fwrite( Automap_visited, sizeof(ubyte)*MAX_SEGMENTS, 1, fp );
+               cfwrite(Automap_visited, sizeof(ubyte) * MAX_SEGMENTS, 1, fp);
 
        }
-       fwrite( &state_game_id, sizeof(uint), 1, fp );
-       fwrite( &Laser_rapid_fire, sizeof(int), 1, fp );
-       fwrite( &Lunacy, sizeof(int), 1, fp );          //      Yes, writing this twice.  Removed the Ugly robot system, but didn't want to change savegame format.
-       fwrite( &Lunacy, sizeof(int), 1, fp );
+       cfwrite(&state_game_id, sizeof(uint), 1, fp);
+       cfwrite(&Laser_rapid_fire, sizeof(int), 1, fp);
+       cfwrite(&Lunacy, sizeof(int), 1, fp);           //      Yes, writing this twice.  Removed the Ugly robot system, but didn't want to change savegame format.
+       cfwrite(&Lunacy, sizeof(int), 1, fp);
 
        // Save automap marker info
 
-       fwrite(MarkerObject,sizeof(MarkerObject),1,fp);
-       fwrite(MarkerOwner,sizeof(MarkerOwner),1,fp);
-       fwrite(MarkerMessage,sizeof(MarkerMessage),1,fp);
+       cfwrite(MarkerObject, sizeof(MarkerObject), 1, fp);
+       cfwrite(MarkerOwner, sizeof(MarkerOwner), 1, fp);
+       cfwrite(MarkerMessage, sizeof(MarkerMessage), 1, fp);
 
-       fwrite (&Afterburner_charge,sizeof(fix),1,fp);
+       cfwrite(&Afterburner_charge, sizeof(fix), 1, fp);
 
        //save last was super information
-       fwrite(&Primary_last_was_super,sizeof(Primary_last_was_super),1,fp);
-       fwrite(&Secondary_last_was_super,sizeof(Secondary_last_was_super),1,fp);
+       cfwrite(&Primary_last_was_super, sizeof(Primary_last_was_super), 1, fp);
+       cfwrite(&Secondary_last_was_super, sizeof(Secondary_last_was_super), 1, fp);
 
        //      Save flash effect stuff
-       fwrite( &Flash_effect, sizeof(int), 1, fp );
-       fwrite( &Time_flash_last_played, sizeof(int), 1, fp );
-       fwrite( &PaletteRedAdd, sizeof(int), 1, fp);
-       fwrite( &PaletteGreenAdd, sizeof(int), 1, fp);
-       fwrite( &PaletteBlueAdd, sizeof(int), 1, fp);
+       cfwrite(&Flash_effect, sizeof(int), 1, fp);
+       cfwrite(&Time_flash_last_played, sizeof(int), 1, fp);
+       cfwrite(&PaletteRedAdd, sizeof(int), 1, fp);
+       cfwrite(&PaletteGreenAdd, sizeof(int), 1, fp);
+       cfwrite(&PaletteBlueAdd, sizeof(int), 1, fp);
 
-       fwrite(Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS, fp);
+       cfwrite(Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS, fp);
 
-       fwrite(&First_secret_visit, sizeof(First_secret_visit), 1, fp);
+       cfwrite(&First_secret_visit, sizeof(First_secret_visit), 1, fp);
 
-       fwrite(&Omega_charge, sizeof(Omega_charge), 1, fp);
+       cfwrite(&Omega_charge, sizeof(Omega_charge), 1, fp);
        
-       if ( ferror(fp) ) {
+       if (cferror(fp))
+       {
                if ( !(Game_mode & GM_MULTI) ) {
                        nm_messagebox(NULL, 1, TXT_OK, "Error writing savegame.\nPossibly out of disk\nspace.");
-                       fclose(fp);
-                       unlink(filename);
+                       cfclose(fp);
+                       cfile_delete(filename);
                }
        } else  {
-               fclose(fp);
+               cfclose(fp);
 
                #ifdef MACINTOSH                // set the type and creator of the saved game file
                {
@@ -1006,12 +996,13 @@ int state_restore_all(int in_game, int secret_restore, char *filename_override)
 
                        mprintf((0, "Trying to copy %s to secret.sgc.\n", temp_fname));
 
-                       if (file_exists(temp_fname)) {
+                       if (cfexist(temp_fname))
+                       {
                                mprintf((0, "Copying %s to secret.sgc\n", temp_fname));
                                rval = copy_file(temp_fname, SECRETC_FILENAME);
                                Assert(rval == 0);      //      Oops, error copying temp_fname to secret.sgc!
                        } else
-                               unlink(SECRETC_FILENAME);
+                               cfile_delete(SECRETC_FILENAME);
                }
        }
 
@@ -1053,7 +1044,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
        int ObjectStartLocation;
        int version,i, j, segnum;
        object * obj;
-       FILE *fp;
+       CFILE *fp;
        int current_level, next_level;
        int between_levels;
        char mission[16];
@@ -1072,53 +1063,53 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
                Int3();
        #endif
 
-       fp = fopen( filename, "rb" );
+       fp = cfopen(filename, "rb");
        if ( !fp ) return 0;
 
 //Read id
-       fread( id, sizeof(char)*4, 1, fp );
+       cfread(id, sizeof(char)*4, 1, fp);
        if ( memcmp( id, dgss_id, 4 )) {
-               fclose(fp);
+               cfclose(fp);
                return 0;
        }
 
 //Read version
-       fread( &version, sizeof(int), 1, fp );
+       cfread(&version, sizeof(int), 1, fp);
        if (version < STATE_COMPATIBLE_VERSION) {
-               fclose(fp);
+               cfclose(fp);
                return 0;
        }
 
 // Read description
-       fread( desc, sizeof(char)*DESC_LENGTH, 1, fp );
+       cfread(desc, sizeof(char) * DESC_LENGTH, 1, fp);
 
 // Skip the current screen shot...
-        fseek( fp, THUMBNAIL_W*THUMBNAIL_H, SEEK_CUR );
+       cfseek(fp, THUMBNAIL_W*THUMBNAIL_H, SEEK_CUR);
 
 // And now...skip the goddamn palette stuff that somebody forgot to add
-        fseek( fp, 768, SEEK_CUR );
+       cfseek(fp, 768, SEEK_CUR);
 
 // Read the Between levels flag...
-        fread( &between_levels, sizeof(int), 1, fp );
+       cfread(&between_levels, sizeof(int), 1, fp);
 
        Assert(between_levels == 0);    //between levels save ripped out
 
 // Read the mission info...
-       fread( mission, sizeof(char)*9, 1, fp );
+       cfread(mission, sizeof(char), 9, fp);
         mprintf ((0,"Missionname to load = %s\n",mission));
 
        if (!load_mission_by_name( mission ))   {
                nm_messagebox( NULL, 1, "Ok", "Error!\nUnable to load mission\n'%s'\n", mission );
-               fclose(fp);
+               cfclose(fp);
                return 0;
        }
 
 //Read level info
-       fread( &current_level, sizeof(int), 1, fp );
-       fread( &next_level, sizeof(int), 1, fp );
+       cfread(&current_level, sizeof(int), 1, fp);
+       cfread(&next_level, sizeof(int), 1, fp);
 
 //Restore GameTime
-       fread( &GameTime, sizeof(fix), 1, fp );
+       cfread(&GameTime, sizeof(fix), 1, fp);
 
 // Start new game....
        if (!multi)     {
@@ -1140,24 +1131,24 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
 #ifdef NETWORK
    if (Game_mode & GM_MULTI)
         {
-               fread (&state_game_id,sizeof(int),1,fp);
-               fread (&Netgame,sizeof(netgame_info),1,fp);             
-               fread (&NetPlayers,sizeof(AllNetPlayers_info),1,fp);
-               fread (&nplayers,sizeof(N_players),1,fp);
-               fread (&Player_num,sizeof(Player_num),1,fp);
+               cfread(&state_game_id,sizeof(int), 1, fp);
+               cfread(&Netgame,sizeof(netgame_info), 1, fp);
+               cfread(&NetPlayers,sizeof(AllNetPlayers_info), 1, fp);
+               cfread(&nplayers,sizeof(N_players), 1, fp);
+               cfread(&Player_num,sizeof(Player_num), 1, fp);
                for (i=0;i<nplayers;i++)
-                fread (&restore_players[i],sizeof(player),1,fp);
+                       cfread(&restore_players[i], sizeof(player), 1, fp);
 #ifdef RISKY_PROPOSITION
-          fread (&robot_controlled[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fread (&robot_agitation[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fread (&robot_controlled_time[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fread (&robot_last_send_time[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fread (&robot_last_message_time[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fread (&robot_send_pending[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
-          fread (&robot_fired[0],4*MAX_ROBOTS_CONTROLLED,1,fp);
+               cfread(&robot_controlled[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfread(&robot_agitation[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfread(&robot_controlled_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfread(&robot_last_send_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfread(&robot_last_message_time[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfread(&robot_send_pending[0], 4, MAX_ROBOTS_CONTROLLED, fp);
+               cfread(&robot_fired[0], 4, MAX_ROBOTS_CONTROLLED, fp);
  
       for (i=0;i<MAX_ROBOTS_CONTROLLED;i++)
-                  fread (&robot_fire_buf[i][0],21,1,fp);
+                       cfread(&robot_fire_buf[i][0], 21, 1, fp);
 #endif
 
           for (i=0;i<nplayers;i++)
@@ -1196,7 +1187,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
                if (secret_restore) {
                        player  dummy_player;
 
-                       fread( &dummy_player, sizeof(player), 1, fp );
+                       cfread(&dummy_player, sizeof(player), 1, fp);
                        if (secret_restore == 1) {              //      This means he didn't die, so he keeps what he got in the secret level.
                                Players[Player_num].level = dummy_player.level;
                                Players[Player_num].last_score = dummy_player.last_score;
@@ -1216,7 +1207,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
                                Players[Player_num] = dummy_player;
                        }
                } else {
-                       fread( &Players[Player_num], sizeof(player), 1, fp );
+                       cfread(&Players[Player_num], sizeof(player), 1, fp);
                }
        }
        strcpy( Players[Player_num].callsign, org_callsign );
@@ -1226,32 +1217,32 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
                Players[Player_num].level = next_level;
 
 // Restore the weapon states
-       fread( &Primary_weapon, sizeof(byte), 1, fp );
-       fread( &Secondary_weapon, sizeof(byte), 1, fp );
+       cfread(&Primary_weapon, sizeof(byte), 1, fp);
+       cfread(&Secondary_weapon, sizeof(byte), 1, fp);
 
        select_weapon(Primary_weapon, 0, 0, 0);
        select_weapon(Secondary_weapon, 1, 0, 0);
 
 // Restore the difficulty level
-       fread( &Difficulty_level, sizeof(int), 1, fp );
+       cfread(&Difficulty_level, sizeof(int), 1, fp);
 
 // Restore the cheats enabled flag
  
-   fread (&Cheats_enabled,sizeof(int),1,fp);
+       cfread(&Cheats_enabled, sizeof(int), 1, fp);
 
        if ( !between_levels )  {
                Do_appearance_effect = 0;                       // Don't do this for middle o' game stuff.
 
-               ObjectStartLocation = ftell( fp );
+               ObjectStartLocation = cftell(fp);
                //Clear out all the objects from the lvl file
                for (segnum=0; segnum <= Highest_segment_index; segnum++)
                        Segments[segnum].objects = -1;
                reset_objects(1);
        
                //Read objects, and pop 'em into their respective segments.
-               fread( &i, sizeof(int), 1, fp );
+               cfread(&i, sizeof(int), 1, fp);
                Highest_object_index = i-1;
-               fread( Objects, sizeof(object)*i, 1, fp );
+               cfread(Objects, sizeof(object), i, fp);
        
                Object_next_signature = 0;
                for (i=0; i<=Highest_object_index; i++ )        {
@@ -1291,9 +1282,9 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
                }
 
                //Restore wall info
-               fread( &i, sizeof(int), 1, fp );
+               cfread(&i, sizeof(int), 1, fp);
                Num_walls = i;
-               fread( Walls, sizeof(wall)*Num_walls, 1, fp );
+               cfread(Walls, sizeof(wall), Num_walls, fp);
 
                //now that we have the walls, check if any sounds are linked to
                //walls that are now open
@@ -1304,55 +1295,55 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
 
                //Restore exploding wall info
                if (version >= 10) {
-                       fread( &i, sizeof(int), 1, fp );
-                       fread( expl_wall_list, sizeof(*expl_wall_list), i, fp );
+                       cfread(&i, sizeof(int), 1, fp);
+                       cfread(expl_wall_list, sizeof(*expl_wall_list), i, fp);
                }
 
                //Restore door info
-               fread( &i, sizeof(int), 1, fp );
+               cfread(&i, sizeof(int), 1, fp);
                Num_open_doors = i;
-               fread( ActiveDoors, sizeof(active_door)*Num_open_doors, 1, fp );
+               cfread(ActiveDoors, sizeof(active_door), Num_open_doors, fp);
        
                if (version >= 14) {            //Restore cloaking wall info
-                       fread( &i, sizeof(int), 1, fp );
+                       cfread(&i, sizeof(int), 1, fp);
                        Num_cloaking_walls = i;
-                       fread( CloakingWalls, sizeof(cloaking_wall), Num_cloaking_walls, fp );
+                       cfread(CloakingWalls, sizeof(cloaking_wall), Num_cloaking_walls, fp);
                }
        
                //Restore trigger info
-               fread( &Num_triggers, sizeof(int), 1, fp );
-               fread( Triggers, sizeof(trigger)*Num_triggers, 1, fp );
+               cfread(&Num_triggers, sizeof(int), 1, fp);
+               cfread(Triggers, sizeof(trigger), Num_triggers, fp);
        
                //Restore tmap info
                for (i=0; i<=Highest_segment_index; i++ )       {
                        for (j=0; j<6; j++ )    {
-                               fread( &Segments[i].sides[j].wall_num, sizeof(short), 1, fp );
-                               fread( &Segments[i].sides[j].tmap_num, sizeof(short), 1, fp );
-                               fread( &Segments[i].sides[j].tmap_num2, sizeof(short), 1, fp );
+                               cfread(&Segments[i].sides[j].wall_num, sizeof(short), 1, fp);
+                               cfread(&Segments[i].sides[j].tmap_num, sizeof(short), 1, fp);
+                               cfread(&Segments[i].sides[j].tmap_num2, sizeof(short), 1, fp);
                        }
                }
        
                //Restore the fuelcen info
-               fread( &Control_center_destroyed, sizeof(int), 1, fp );
-               fread( &Countdown_timer, sizeof(int), 1, fp );
-               fread( &Num_robot_centers, sizeof(int), 1, fp );
-               fread( RobotCenters, sizeof(matcen_info)*Num_robot_centers, 1, fp );
-               fread( &ControlCenterTriggers, sizeof(control_center_triggers), 1, fp );
-               fread( &Num_fuelcenters, sizeof(int), 1, fp );
-               fread( Station, sizeof(FuelCenter)*Num_fuelcenters, 1, fp );
+               cfread(&Control_center_destroyed, sizeof(int), 1, fp);
+               cfread(&Countdown_timer, sizeof(int), 1, fp);
+               cfread(&Num_robot_centers, sizeof(int), 1, fp);
+               cfread(RobotCenters, sizeof(matcen_info), Num_robot_centers, fp);
+               cfread(&ControlCenterTriggers, sizeof(control_center_triggers), 1, fp);
+               cfread(&Num_fuelcenters, sizeof(int), 1, fp);
+               cfread(Station, sizeof(FuelCenter), Num_fuelcenters, fp);
        
                // Restore the control cen info
-               fread( &Control_center_been_hit, sizeof(int), 1, fp );
-               fread( &Control_center_player_been_seen, sizeof(int), 1, fp );
-               fread( &Control_center_next_fire_time, sizeof(int), 1, fp );
-               fread( &Control_center_present, sizeof(int), 1, fp );
-               fread( &Dead_controlcen_object_num, sizeof(int), 1, fp );
+               cfread(&Control_center_been_hit, sizeof(int), 1, fp);
+               cfread(&Control_center_player_been_seen, sizeof(int), 1, fp);
+               cfread(&Control_center_next_fire_time, sizeof(int), 1, fp);
+               cfread(&Control_center_present, sizeof(int), 1, fp);
+               cfread(&Dead_controlcen_object_num, sizeof(int), 1, fp);
        
                // Restore the AI state
                ai_restore_state( fp, version );
        
                // Restore the automap visited info
-               fread( Automap_visited, sizeof(ubyte)*MAX_SEGMENTS, 1, fp );
+               cfread( Automap_visited, sizeof(ubyte), MAX_SEGMENTS, fp);
 
                //      Restore hacked up weapon system stuff.
                Fusion_next_sound_time = GameTime;
@@ -1365,28 +1356,28 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
        state_game_id = 0;
 
        if ( version >= 7 )     {
-               fread( &state_game_id, sizeof(uint), 1, fp );
-               fread( &Laser_rapid_fire, sizeof(int), 1, fp );
-               fread( &Lunacy, sizeof(int), 1, fp );           //      Yes, writing this twice.  Removed the Ugly robot system, but didn't want to change savegame format.
-               fread( &Lunacy, sizeof(int), 1, fp );
+               cfread(&state_game_id, sizeof(uint), 1, fp);
+               cfread(&Laser_rapid_fire, sizeof(int), 1, fp);
+               cfread(&Lunacy, sizeof(int), 1, fp);            //      Yes, writing this twice.  Removed the Ugly robot system, but didn't want to change savegame format.
+               cfread(&Lunacy, sizeof(int), 1, fp);
                if ( Lunacy )
                        do_lunacy_on();
        }
 
        if (version >= 17) {
-               fread(MarkerObject,sizeof(MarkerObject),1,fp);
-               fread(MarkerOwner,sizeof(MarkerOwner),1,fp);
-               fread(MarkerMessage,sizeof(MarkerMessage),1,fp);
+               cfread(MarkerObject, sizeof(MarkerObject), 1, fp);
+               cfread(MarkerOwner, sizeof(MarkerOwner), 1, fp);
+               cfread(MarkerMessage, sizeof(MarkerMessage), 1, fp);
        }
        else {
                int num,dummy;
 
                // skip dummy info
 
-               fread (&num,sizeof(int),1,fp);                  //was NumOfMarkers
-               fread (&dummy,sizeof(int),1,fp);                        //was CurMarker
+               cfread(&num, sizeof(int), 1, fp);       //was NumOfMarkers
+               cfread(&dummy, sizeof(int), 1, fp);     //was CurMarker
 
-               fseek( fp, num * (sizeof(vms_vector) + 40), SEEK_CUR );
+               cfseek(fp, num * (sizeof(vms_vector) + 40), SEEK_CUR);
 
                for (num=0;num<NUM_MARKERS;num++)
                        MarkerObject[num] = -1;
@@ -1394,24 +1385,24 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
 
        if (version>=11) {
                if (secret_restore != 1)
-                       fread (&Afterburner_charge,sizeof(fix),1,fp);
+                       cfread(&Afterburner_charge, sizeof(fix), 1, fp);
                else {
                        fix     dummy_fix;
-                       fread (&dummy_fix,sizeof(fix),1,fp);
+                       cfread(&dummy_fix,sizeof(fix), 1, fp);
                }
        }
        if (version>=12) {
                //read last was super information
-               fread(&Primary_last_was_super,sizeof(Primary_last_was_super),1,fp);
-               fread(&Secondary_last_was_super,sizeof(Secondary_last_was_super),1,fp);
+               cfread(&Primary_last_was_super, sizeof(Primary_last_was_super), 1, fp);
+               cfread(&Secondary_last_was_super, sizeof(Secondary_last_was_super), 1, fp);
        }
 
        if (version >= 12) {
-               fread( &Flash_effect, sizeof(int), 1, fp );
-               fread( &Time_flash_last_played, sizeof(int), 1, fp );
-               fread( &PaletteRedAdd, sizeof(int), 1, fp);
-               fread( &PaletteGreenAdd, sizeof(int), 1, fp);
-               fread( &PaletteBlueAdd, sizeof(int), 1, fp);
+               cfread(&Flash_effect, sizeof(int), 1, fp);
+               cfread(&Time_flash_last_played, sizeof(int), 1, fp);
+               cfread(&PaletteRedAdd, sizeof(int), 1, fp);
+               cfread(&PaletteGreenAdd, sizeof(int), 1, fp);
+               cfread(&PaletteBlueAdd, sizeof(int), 1, fp);
        } else {
                Flash_effect = 0;
                Time_flash_last_played = 0;
@@ -1422,7 +1413,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
 
        //      Load Light_subtracted
        if (version >= 16) {
-               fread(Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS, fp);
+               cfread(Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS, fp);
                apply_all_changed_light();
                compute_all_static_light();     //      set static_light field in segment struct.  See note at that function.
        } else {
@@ -1433,7 +1424,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
    
        if (!secret_restore) {
                if (version >= 20) {
-                       fread(&First_secret_visit, sizeof(First_secret_visit), 1, fp);
+                       cfread(&First_secret_visit, sizeof(First_secret_visit), 1, fp);
                        mprintf((0, "File: [%s] Read First_secret_visit: New value = %i\n", filename, First_secret_visit));
                } else
                        First_secret_visit = 1;
@@ -1443,14 +1434,14 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
        if (version >= 22)
        {
                if (secret_restore != 1)
-                       fread (&Omega_charge,sizeof(fix),1,fp);
+                       cfread(&Omega_charge,sizeof(fix), 1, fp);
                else {
                        fix     dummy_fix;
-                       fread (&dummy_fix,sizeof(fix),1,fp);
+                       cfread(&dummy_fix,sizeof(fix), 1, fp);
                }
        }
 
-       fclose(fp);
+       cfclose(fp);
  
 #ifdef NETWORK
    if (Game_mode & GM_MULTI)   // Get rid of ships that aren't 
@@ -1509,7 +1500,7 @@ void compute_all_static_light(void)
 int state_get_game_id(char *filename)
 {
        int version;
-       FILE *fp;
+       CFILE *fp;
        int between_levels;
        char mission[16];
        char desc[DESC_LENGTH+1];
@@ -1518,47 +1509,47 @@ int state_get_game_id(char *filename)
 
 mprintf((0, "Restoring multigame from [%s]\n", filename));
 
-       fp = fopen( filename, "rb" );
+       fp = cfopen(filename, "rb");
        if ( !fp ) return 0;
 
 //Read id
-       fread( id, sizeof(char)*4, 1, fp );
+       cfread(id, sizeof(char)*4, 1, fp);
        if ( memcmp( id, dgss_id, 4 )) {
-               fclose(fp);
+               cfclose(fp);
                return 0;
        }
 
 //Read version
-       fread( &version, sizeof(int), 1, fp );
+       cfread(&version, sizeof(int), 1, fp);
        if (version < STATE_COMPATIBLE_VERSION) {
-               fclose(fp);
+               cfclose(fp);
                return 0;
        }
 
 // Read description
-       fread( desc, sizeof(char)*DESC_LENGTH, 1, fp );
+       cfread(desc, sizeof(char)*DESC_LENGTH, 1, fp);
 
 // Skip the current screen shot...
-        fseek( fp, THUMBNAIL_W*THUMBNAIL_H, SEEK_CUR );
+       cfseek(fp, THUMBNAIL_W*THUMBNAIL_H, SEEK_CUR);
 
 // And now...skip the palette stuff that somebody forgot to add
-        fseek( fp, 768, SEEK_CUR );
+       cfseek(fp, 768, SEEK_CUR);
 
 // Read the Between levels flag...
-       fread( &between_levels, sizeof(int), 1, fp );
+       cfread(&between_levels, sizeof(int), 1, fp);
 
        Assert(between_levels == 0);    //between levels save ripped out
 
 // Read the mission info...
-       fread( mission, sizeof(char)*9, 1, fp );
+       cfread(mission, sizeof(char), 9, fp);
 //Read level info
-       fread( &dumbint, sizeof(int), 1, fp );
-       fread( &dumbint, sizeof(int), 1, fp );
+       cfread(&dumbint, sizeof(int), 1, fp);
+       cfread(&dumbint, sizeof(int), 1, fp);
 
 //Restore GameTime
-       fread( &dumbint, sizeof(fix), 1, fp );
+       cfread(&dumbint, sizeof(fix), 1, fp);
 
-       fread (&state_game_id,sizeof(int),1,fp);
+       cfread(&state_game_id, sizeof(int), 1, fp);
 
        return (state_game_id);
  }
index ac63215..2d63d18 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: text.c,v 1.8 2003-04-07 23:36:34 btb Exp $ */
+/* $Id: text.c,v 1.9 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -65,10 +65,9 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: text.c,v 1.8 2003-04-07 23:36:34 btb Exp $";
+static char rcsid[] = "$Id: text.c,v 1.9 2003-06-16 06:57:34 btb Exp $";
 #endif
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
index 8a91a44..0e70fea 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: args.c,v 1.8 2003-02-18 20:35:35 btb Exp $ */
+/* $Id: args.c,v 1.9 2003-06-16 06:57:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -57,12 +57,13 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: args.c,v 1.8 2003-02-18 20:35:35 btb Exp $";
+static char rcsid[] = "$Id: args.c,v 1.9 2003-06-16 06:57:34 btb Exp $";
 #endif
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+
+#include "cfile.h"
 #include "u_mem.h"
 #include "strio.h"
 #include "strutil.h"
@@ -90,7 +91,7 @@ void args_exit(void)
 void InitArgs( int argc,char **argv )
 {
        int i;
-       FILE *f;
+       CFILE *f;
        char *line,*word;
        
        Num_args=0;
@@ -104,12 +105,13 @@ void InitArgs( int argc,char **argv )
                        strlwr( Args[i]  );  // Convert all args to lowercase
        }
        if((i=FindArg("-ini")))
-               f=fopen(Args[i+1],"rt");
+               f = cfopen(Args[i+1], "rt");
        else
-               f=fopen("d2x.ini","rt");
+               f = cfopen("d2x.ini", "rt");
        
        if(f) {
-               while(!feof(f)) {
+               while(!cfeof(f))
+               {
                        line=fsplitword(f,'\n');
                        word=splitword(line,' ');
                        
@@ -120,7 +122,7 @@ void InitArgs( int argc,char **argv )
                        
                        d_free(line); d_free(word);
                }
-               fclose(f);
+               cfclose(f);
        }
        
        atexit(args_exit);
index 0326ca2..4727e71 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: strio.c,v 1.3 2003-02-18 20:35:35 btb Exp $ */
+/* $Id: strio.c,v 1.4 2003-06-16 06:57:34 btb Exp $ */
 /*
  * strio.c: string/file manipulation functions by Victor Rachels
  */
@@ -7,14 +7,15 @@
 #include <conf.h>
 #endif
 
-#include <stdio.h>
 #include <stdlib.h>
+
+#include "cfile.h"
 #include "strio.h"
 //added on 9/16/98 by adb to add memory tracking for this module
 #include "u_mem.h"
 //end additions - adb
 
-char* fsplitword(FILE *f, char splitchar)
+char* fsplitword(CFILE *f, char splitchar)
 {
  int x,y,mem,memx;
  char *word,*buf;
@@ -22,9 +23,9 @@ char* fsplitword(FILE *f, char splitchar)
   mem=memx*256;
   word=(char *) d_malloc(sizeof(char) * mem);
   x=0;
-  word[x]=fgetc(f);
-   while(word[x]!=splitchar && !feof(f))
-    {
+  word[x] = cfgetc(f);
+  while(word[x] != splitchar && !cfeof(f))
+  {
      x++;
       if(x==mem)
        {
@@ -36,8 +37,8 @@ char* fsplitword(FILE *f, char splitchar)
          word[y]=buf[y];
        d_free(buf);
        }
-     word[x]=fgetc(f);
-    }
+     word[x] = cfgetc(f);
+  }
   word[x]=0;
   return word;
 }