merged physfs branch
authorBradley Bell <btb@icculus.org>
Wed, 1 Dec 2004 12:48:13 +0000 (12:48 +0000)
committerBradley Bell <btb@icculus.org>
Wed, 1 Dec 2004 12:48:13 +0000 (12:48 +0000)
43 files changed:
2d/pcx.c
ChangeLog
Makefile.am
arch/linux/Makefile.am
arch/linux/findfile.c [deleted file]
arch/ogl/gr.c
arch/win32/Makefile.am
arch/win32/findfile.c [deleted file]
cfile/.cvsignore [deleted file]
cfile/Makefile.am [deleted file]
cfile/cfile.c [deleted file]
configure.ac
include/args.h
include/cfile.h
include/d_io.h [deleted file]
include/findfile.h [deleted file]
include/ignorecase.h [new file with mode: 0644]
include/physfsrwops.h [new file with mode: 0644]
include/physfsx.h [new file with mode: 0644]
include/strio.h
main/ai.c
main/ai.h
main/cntrlcen.c
main/config.c
main/gameseq.c
main/inferno.c
main/kludge.c
main/menu.c
main/mission.c
main/movie.c
main/network.c
main/newdemo.c
main/newmenu.c
main/piggy.c
main/playsave.c
main/scores.c
main/state.c
misc/Makefile.am
misc/args.c
misc/d_io.c [deleted file]
misc/ignorecase.c [new file with mode: 0644]
misc/physfsrwops.c [new file with mode: 0644]
misc/strio.c

index 6c2a608..40caa82 100644 (file)
--- a/2d/pcx.c
+++ b/2d/pcx.c
@@ -1,4 +1,4 @@
-/* $Id: pcx.c,v 1.9 2004-08-28 23:17:45 schaffner Exp $ */
+/* $Id: pcx.c,v 1.10 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -38,9 +38,10 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #if defined(POLY_ACC)
 #include "poly_acc.h"
 #endif
+#include "physfsx.h"
 
-int pcx_encode_byte(ubyte byt, ubyte cnt, CFILE *fid);
-int pcx_encode_line(ubyte *inBuff, int inLen, CFILE *fp);
+int pcx_encode_byte(ubyte byt, ubyte cnt, PHYSFS_file *fid);
+int pcx_encode_line(ubyte *inBuff, int inLen, PHYSFS_file *fp);
 
 /* PCX Header data type */
 typedef struct {
@@ -335,7 +336,7 @@ int pcx_write_bitmap( char * filename, grs_bitmap * bmp, ubyte * palette )
        int i;
        ubyte data;
        PCXHeader header;
-       CFILE *PCXfile;
+       PHYSFS_file *PCXfile;
 
        memset( &header, 0, PCXHEADER_SIZE );
 
@@ -348,28 +349,28 @@ int pcx_write_bitmap( char * filename, grs_bitmap * bmp, ubyte * palette )
        header.Ymax = bmp->bm_h-1;
        header.BytesPerLine = bmp->bm_w;
 
-       PCXfile = cfopen(filename, "wb");
+       PCXfile = PHYSFS_openWrite(filename);
        if ( !PCXfile )
                return PCX_ERROR_OPENING;
 
-       if (cfwrite(&header, PCXHEADER_SIZE, 1, PCXfile) != 1)
+       if (PHYSFS_write(PCXfile, &header, PCXHEADER_SIZE, 1) != 1)
        {
-               cfclose(PCXfile);
+               PHYSFS_close(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 ))   {
-                       cfclose(PCXfile);
+                       PHYSFS_close(PCXfile);
                        return PCX_ERROR_WRITING;
                }
        }
 
        // Mark an extended palette
        data = 12;
-       if (cfwrite(&data, 1, 1, PCXfile) != 1)
+       if (PHYSFS_write(PCXfile, &data, 1, 1) != 1)
        {
-               cfclose(PCXfile);
+               PHYSFS_close(PCXfile);
                return PCX_ERROR_WRITING;
        }
 
@@ -377,23 +378,23 @@ int pcx_write_bitmap( char * filename, grs_bitmap * bmp, ubyte * palette )
        for (i=0; i<768; i++ )
                palette[i] <<= 2;
 
-       retval = cfwrite(palette, 768, 1, PCXfile);
+       retval = PHYSFS_write(PCXfile, palette, 768, 1);
 
        for (i=0; i<768; i++ )
                palette[i] >>= 2;
 
        if (retval !=1) {
-               cfclose(PCXfile);
+               PHYSFS_close(PCXfile);
                return PCX_ERROR_WRITING;
        }
 
-       cfclose(PCXfile);
+       PHYSFS_close(PCXfile);
        return PCX_ERROR_NONE;
 
 }
 
 // returns number of bytes written into outBuff, 0 if failed
-int pcx_encode_line(ubyte *inBuff, int inLen, CFILE *fp)
+int pcx_encode_line(ubyte *inBuff, int inLen, PHYSFS_file *fp)
 {
        ubyte this, last;
        int srcIndex, i;
@@ -434,17 +435,17 @@ int pcx_encode_line(ubyte *inBuff, int inLen, CFILE *fp)
 
 // subroutine for writing an encoded byte pair
 // returns count of bytes written, 0 if error
-int pcx_encode_byte(ubyte byt, ubyte cnt, CFILE *fid)
+int pcx_encode_byte(ubyte byt, ubyte cnt, PHYSFS_file *fid)
 {
        if (cnt) {
                if ( (cnt==1) && (0xc0 != (0xc0 & byt)) )       {
-                       if(EOF == cfputc((int)byt, fid))
+                       if(EOF == PHYSFSX_putc(fid, (int)byt))
                                return 0;       // disk write error (probably full)
                        return 1;
                } else {
-                       if(EOF == cfputc((int)0xC0 | cnt, fid))
+                       if(EOF == PHYSFSX_putc(fid, (int)0xC0 | cnt))
                                return 0;       // disk write error
-                       if(EOF == cfputc((int)byt, fid))
+                       if(EOF == PHYSFSX_putc(fid, (int)byt))
                                return 0;       // disk write error
                        return 2;
                }
index ed9199c..ad59f69 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,123 @@
+2004-12-01  Chris Taylor  <c.taylor@student.curtin.edu.au>
+
+       * arch/ogl/gr.c: make write_bmp use PhysicsFS
+
+       * include/args.h, misc/args.c: new AppendArgs function. This
+       separates the copying of the arguments passed to main() from the
+       reading of the arguments file
+
+       * include/cfile.h: Use portable PHYSFSX_getRealPath function, Use
+       the flexible cfgets, Fix compiling issues in MPW.
+
+       * include/physfsx.h: PHYSFSX_readU8 isn't endian friendly when
+       reading into an int, so it's removed completely.  PHYSFSX_getc was
+       removed, because it's only use in misc/strio.c was removed.  Put
+       in PHYSFSX_getRealPath, which recognises platform-specific
+       separators and doesn't use snprintf (MPW doesn't have it).  MPW
+       doesn't have statfs.
+
+       * main/inferno.c: Remove use of open_movie_file.  Read the
+       arguments file from the base directory, if there is one.  Set up
+       D2X's write directory, including replacing any tilde at the start
+       of the path (if there is one) with the string returned by
+       PHYSFS_getUserDir(). This applies to all platforms. On Unix the
+       default is still ~/.d2x.  Check if the write directory has to be
+       created.  Read the arguments file in this write directory if there
+       is one.  If there's still no write directory, set it to the base
+       directory. Won't set it to the current directory if this fails,
+       because of the issue of which character to use for which platform.
+
+       * main/playsave.c: Use PHYSFS_readSLE32 instead of
+       PHYSFS_readULE32 due to compiling issues in MPW.  Use
+       cfile_read_short instead of PHYSFS_readULE16 because of both
+       compiling and endian issues.  cfile_read_byte instead of
+       PHYSFSX_readU8.  Write a dummy structure instead of seeking when
+       NETWORK isn't defined
+
+2004-12-01  Bradley Bell  <btb@icculus.org>
+
+       * include/physfsx.h, include/strio.h, main/cntrlcen.c,
+       main/inferno.c, main/newmenu.c, misc/args.c, misc/strio.c: more
+       physfs additions
+
+       * main/newmenu.c: fix player file deletion
+
+       * include/physfsx.h: fix statfs includes for OS X
+
+       * main/inferno.c, main/network.c: misc physfs conversions
+
+       * arch/linux/Makefile.am, arch/linux/findfile.c,
+       arch/win32/Makefile.am, arch/win32/findfile.c,
+       include/findfile.h, main/kludge.c, main/mission.c,
+       main/newmenu.c, main/piggy.c: get rid of findfile stuff
+
+       * main/gameseq.c, main/menu.c, main/newmenu.c: improved demo/plr
+       loading
+
+       * main/state.c: improve savegame load/save
+
+       * main/movie.c: make -nomovies friendlier
+
+       * 2d/pcx.c, include/physfsx.h: use physfs for writing pcx files
+
+       * include/d_io.h, include/physfsx.h, main/inferno.c,
+       main/newdemo.c, main/scores.c, misc/Makefile.am, misc/d_io.c: get
+       rid of d_io stuff.
+
+       * main/scores.c: use physfs for scores file
+
+       * main/playsave.c: improve player loading
+
+       * main/movie.c: improve movie loading
+
+       * main/mission.c: improve mission loading
+
+       * main/ai.c, main/ai.h, main/gameseq.c, main/newmenu.c,
+       main/state.c: use physfs for savegames
+
+       * README: minor update
+
+       * main/newdemo.c: use physfs for demos
+
+       * include/physfsx.h: added PHYSFSX_rename function
+
+       * main/gameseq.c, main/mission.c, main/movie.c: make movies use
+       physfs/rwops, add libmve callbacks
+
+       * include/physfsrwops.h, misc/Makefile.am, misc/physfsrwops.c:
+       added physfsrwops stuff
+
+       * include/cfile.h: added cfile_close wrapper
+
+       * main/mission.c, main/newmenu.c: use PHYSFS to load missions,
+       player files
+
+       * include/ignorecase.h, misc/Makefile.am, misc/ignorecase.c: added
+       ignorecase stuff
+
+       * main/config.c: use physfs to read config file
+
+       * include/physfsx.h: added gets and puts functions
+
+       * include/cfile.h: correct seek return value
+
+       * main/config.c, main/playsave.c: use physfs to write
+       config/player files
+
+       * include/physfsx.h: added my physfs extensions
+
+       * main/inferno.c: physfs initialization stuff
+
+       * configure.ac: add check for physfs lib
+
+       * include/cfile.h: made cfile into a wrapper for physfs
+
+       * main/mission.c, main/movie.c, main/newdemo.c, main/newmenu.c:
+       disabled althogdir stuff (shouldn't be needed w/physfs)
+
+       * Makefile.am, cfile/.cvsignore, cfile/Makefile.am, cfile/cfile.c,
+       configure.ac: drop cfile stuff
+
 2004-11-30  Chris Taylor  <c.taylor@student.curtin.edu.au>
 
        * D2X.make: Don't use D2XFolder, because the userdir can now be
index f97b0ec..93de79d 100644 (file)
@@ -1,4 +1,4 @@
-DIST_SUBDIRS = 2d 3d maths mem cfile console iff texmap misc arch main libmve utilities
+DIST_SUBDIRS = 2d 3d arch console iff libmve main maths mem misc texmap utilities
 
 SUBDIRS = ${DIST_SUBDIRS} @D2X_SUBDIRS@
 
@@ -32,7 +32,7 @@ d2x_gl_SOURCES =
 d2x_svga_SOURCES =
 d2x_ggi_SOURCES =
 
-d2x_LDADD = ${LD_KLUDGE} main/libmain.a ${EDITOR_LIBS} 3d/lib3d.a 2d/lib2d.a ${ARCH_LIBS} libmve/libmve.a mem/libmem.a cfile/libcfile.a iff/libiff.a texmap/libtexmap.a misc/libmisc.a maths/libmaths.a ${CONSOLE_LIBS}
+d2x_LDADD = ${LD_KLUDGE} main/libmain.a ${EDITOR_LIBS} 3d/lib3d.a 2d/lib2d.a ${ARCH_LIBS} libmve/libmve.a mem/libmem.a iff/libiff.a texmap/libtexmap.a misc/libmisc.a maths/libmaths.a ${CONSOLE_LIBS}
 
 if MINGW32
 if USE_NETWORK
index 381e17a..74aef03 100644 (file)
@@ -18,7 +18,7 @@ if USE_LINUX_JOY
 JOYSTICK_SRCS = joystick.c joydefs.c
 endif
 
-libarch_linux_a_SOURCES = ${NETWORK_SRCS} ${IPX_SRCS} ${KALI_SRCS} ${JOYSTICK_SRCS} findfile.c init.c
+libarch_linux_a_SOURCES = ${NETWORK_SRCS} ${IPX_SRCS} ${KALI_SRCS} ${JOYSTICK_SRCS} init.c
 
 EXTRA_libarch_linux_a_SOURCES = \
 ipx_bsd.c ipx_kali.c ipx_mcast4.c ipx_udp.c linuxnet.c ukali.c \
diff --git a/arch/linux/findfile.c b/arch/linux/findfile.c
deleted file mode 100644 (file)
index d8adadc..0000000
+++ /dev/null
@@ -1,66 +0,0 @@
-/* $Id: findfile.c,v 1.7 2003-03-13 00:20:21 btb Exp $ */
-/*
- *
- * Linux findfile functions
- *
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <conf.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include <glob.h>
-#include "findfile.h"
-#include "u_mem.h"
-#include "error.h"
-
-/* KLUDGE ALERT: evil globals */
-static glob_t glob_a;
-static int glob_whichfile;
-
-int FileFindFirst(char *search_str, FILEFINDSTRUCT *ffstruct)
-{
-  int r;
-  char *t;
-
-  Assert(search_str != NULL);
-  Assert(ffstruct != NULL);
-
-  r = glob(search_str, 0, NULL, &glob_a);
-  if (r) return 1;
-
-  if (! glob_a.gl_pathc) return 1;
-
-  glob_whichfile = 0;
-  
-  t = strrchr(glob_a.gl_pathv[glob_whichfile], '/');
-  if (t == NULL) t = glob_a.gl_pathv[glob_whichfile]; else t++;
-  strncpy(ffstruct->name, t, 255);
-  ffstruct->size = strlen(ffstruct->name); 
-  
-  return 0;
-}
-
-int FileFindNext(FILEFINDSTRUCT *ffstruct)
-{
-  char *t;
-  
-  glob_whichfile++;
-
-  if (glob_whichfile >= glob_a.gl_pathc) return -1;
-
-  t = strrchr(glob_a.gl_pathv[glob_whichfile], '/');
-  if (t == NULL) t = glob_a.gl_pathv[glob_whichfile]; else t++;
-  strncpy(ffstruct->name, t, 255);
-  ffstruct->size = strlen(ffstruct->name); 
-  return 0;
-}
-
-int FileFindClose(void)
-{
- globfree(&glob_a);
- return 0;
-}
index da04bce..6be7770 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: gr.c,v 1.36 2004-11-14 09:34:23 schaffner Exp $ */
+/* $Id: gr.c,v 1.37 2004-12-01 12:48:13 btb Exp $ */
 /*
  *
  * OGL video functions. - Added 9/15/99 Matthew Mueller
@@ -45,6 +45,7 @@
 #include "mono.h"
 #include "args.h"
 #include "key.h"
+#include "physfsx.h"
 
 #define DECLARE_VARS
 #include "internal.h"
@@ -724,9 +725,9 @@ void gr_palette_read(ubyte * pal)
 //writes out an uncompressed RGB .tga file
 //if we got really spiffy, we could optionally link in libpng or something, and use that.
 void write_bmp(char *savename,int w,int h,unsigned char *buf){
-       CFILE *f;
+       PHYSFS_file *f;
 
-       f = cfopen(savename, "wb");
+       f = PHYSFS_openWrite(savename);
                
        if (f>=0){
                GLubyte    targaMagic[12] = { 0, //no identification field
@@ -739,11 +740,11 @@ void write_bmp(char *savename,int w,int h,unsigned char *buf){
                int x,y;
                
                //write .TGA header.
-               cfwrite (targaMagic,sizeof(targaMagic),1,f);
-               cfile_write_short (w,f);
-        cfile_write_short (h,f);
-               cfile_write_byte (24,f);//24 bpp
-               cfile_write_byte (0,f);//no attribute bits, origin is lowerleft, no interleave
+               PHYSFS_write(f, targaMagic, sizeof(targaMagic), 1);
+               PHYSFS_writeSLE32(f, w);
+               PHYSFS_writeSLE32(f, h);
+               PHYSFSX_writeU8(f, 24); // 24 bpp
+               PHYSFSX_writeU8(f, 0);  // no attribute bits, origin is lowerleft, no interleave
                
                s=buf;
                for (y=0;y<h;y++){//TGAs use BGR ordering of data.
@@ -757,14 +758,14 @@ void write_bmp(char *savename,int w,int h,unsigned char *buf){
                x=0;y=w*h*3;
                while (y > 0)
                {
-                       r=cfwrite(buf+x,1,y,f);
+                       r = PHYSFS_write(f, buf + x, 1, y);
                        if (r<=0){
                                mprintf((0,"screenshot error, couldn't write to %s (err %i)\n",savename,errno));
                                break;
                        }
                        x+=r;y-=r;
                }
-               cfclose(f);
+               PHYSFS_close(f);
        }else{
                mprintf((0,"screenshot error, couldn't open %s (err %i)\n",savename,errno));
        }
index 48cfe18..65f6196 100644 (file)
@@ -8,7 +8,7 @@ if USE_NETWORK
 NETWORK_SRCS = ipx_mcast4.c ipx_win.c ipx_udp.c winnet.c
 endif
 
-libarch_win32_a_SOURCES = ${NETWORK_SRCS} findfile.c hmpfile.c midi.c mingw_init.c
+libarch_win32_a_SOURCES = ${NETWORK_SRCS} hmpfile.c midi.c mingw_init.c
 
 EXTRA_libarch_win32_a_SOURCES = ipx_mcast4.c ipx_win.c ipx_udp.c winnet.c
 
diff --git a/arch/win32/findfile.c b/arch/win32/findfile.c
deleted file mode 100644 (file)
index d270ba8..0000000
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
-THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
-SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
-END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
-ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
-IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
-SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
-FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
-CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
-COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <conf.h>
-#endif
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-#include "findfile.h"
-
-
-//     Global Variables        ----------------------------------------------------------
-
-static HANDLE  _FindFileHandle = INVALID_HANDLE_VALUE;
-
-#ifdef _WIN32_WCE
-static char *UnicodeToAsc(const wchar_t *w_str)
-{
-       char *str = NULL;
-
-       if (w_str != NULL)
-    {
-               int len = wcslen(w_str) + 1;
-               str = (char *)malloc(len);
-
-               if (WideCharToMultiByte(CP_ACP, 0, w_str, -1, str, len, NULL, NULL) == 0)
-               {   //Conversion failed
-                       free(str);
-                       return NULL;
-               }
-               else
-               {   //Conversion successful
-                       return(str);
-               }
-       }
-       else
-       {   //Given NULL string
-               return NULL;
-       }
-}
-
-static wchar_t *AscToUnicode(const char *str)
-{
-       wchar_t *w_str = NULL;
-       if (str != NULL)
-       {
-               int len = strlen(str) + 1;
-               w_str = (wchar_t *)malloc(sizeof(wchar_t) * len);
-               if (MultiByteToWideChar(CP_ACP, 0, str, -1, w_str, len) == 0)
-               {
-                       free(w_str);
-                       return NULL;
-               }
-               else
-               {
-                       return(w_str);
-               }
-       }
-       else
-       {
-               return NULL;
-       }
-}
-#else
-# define UnicodeToAsc(x) (x)
-# define AscToUnicode(x) ((LPSTR)x)
-#endif
-
-//     Functions
-
-int    FileFindFirst(char *search_str, FILEFINDSTRUCT *ffstruct)
-{
-       WIN32_FIND_DATA find;
-
-       _FindFileHandle = FindFirstFile(AscToUnicode(search_str), &find);
-       if (_FindFileHandle == INVALID_HANDLE_VALUE) return 1;
-       else {
-               ffstruct->size = find.nFileSizeLow;
-               strcpy(ffstruct->name, UnicodeToAsc(find.cFileName));
-               return 0; 
-       }
-}
-
-
-int    FileFindNext(FILEFINDSTRUCT *ffstruct)
-{
-       WIN32_FIND_DATA find;
-
-       if (!FindNextFile(_FindFileHandle, &find)) return 1;
-       else {
-               ffstruct->size = find.nFileSizeLow;
-               strcpy(ffstruct->name, UnicodeToAsc(find.cFileName));
-               return 0;
-       }
-}
-
-int    FileFindClose(void)
-{
-       if (!FindClose(_FindFileHandle)) return 1;
-       else return 0;
-}
-
-
-#if 0
-int GetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct)
-{
-       FILETIME filetime;
-       int retval;
-
-       retval = GetFileTime((HANDLE)filehandle, NULL, NULL, &filetime);
-       if (retval) {
-               FileTimeToDosDateTime(&filetime, &ftstruct->date, &ftstruct->time);
-               return 0;
-       }
-       else return 1;
-}
-
-
-//returns 0 if no error
-int SetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct)
-{
-       FILETIME ft;
-       int retval;
-
-       DosDateTimeToFileTime(ftstruct->date, ftstruct->time, &ft);
-       retval = SetFileTime((HANDLE)filehandle, NULL, NULL, &ft);      
-       if (retval) return 0;
-       else return 1;
-}
-#endif
diff --git a/cfile/.cvsignore b/cfile/.cvsignore
deleted file mode 100644 (file)
index 70845e0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Makefile.in
diff --git a/cfile/Makefile.am b/cfile/Makefile.am
deleted file mode 100644 (file)
index b5f1c6e..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-noinst_LIBRARIES = libcfile.a
-INCLUDES = -I $(top_srcdir)/include
-
-libcfile_a_SOURCES = cfile.c
diff --git a/cfile/cfile.c b/cfile/cfile.c
deleted file mode 100644 (file)
index 48dc4ad..0000000
+++ /dev/null
@@ -1,752 +0,0 @@
-/* $Id: cfile.c,v 1.32 2004-10-23 16:28:32 schaffner Exp $ */
-/*
-THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
-SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
-END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
-ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
-IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
-SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
-FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
-CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
-COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
-*/
-
-/*
- *
- * Functions for accessing compressed files.
- * (Actually, the files are not compressed, but concatenated within hogfiles)
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <conf.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#ifdef _WIN32_WCE
-# include <windows.h>
-#elif defined(macintosh)
-# include <Files.h>
-# include <CFURL.h>
-#else
-# include <sys/stat.h>
-#endif
-
-#include "pstypes.h"
-#include "u_mem.h"
-#include "strutil.h"
-#include "d_io.h"
-#include "error.h"
-#include "cfile.h"
-#include "byteswap.h"
-
-/* a file (if offset == 0) or a part of a hog file */
-struct CFILE {
-       FILE    *file;
-       int     size;
-       int     offset;
-       int     raw_position;
-};
-
-struct file_in_hog {
-       char    name[13];
-       int     offset;
-       int     length;
-};
-
-#define MAX_FILES_IN_HOG 300
-
-/* a hog file is an archive, like a tar file */
-typedef struct {
-       char filename[64];
-       int num_files;
-       struct file_in_hog files[MAX_FILES_IN_HOG];
-} hog;
-
-hog *builtin_hog = NULL;
-hog *alt_hog = NULL;
-hog *d1_hog = NULL;
-
-void free_builtin_hog() { if (builtin_hog) d_free (builtin_hog); }
-void free_alt_hog() { if (alt_hog) d_free (alt_hog); }
-void free_d1_hog() { if (d1_hog) d_free (d1_hog); }
-
-char AltHogDir[64];
-char AltHogdir_initialized = 0;
-
-// routine to take a DOS path and turn it into a macintosh
-// pathname.  This routine is based on the fact that we should
-// see a \ character in the dos path.  The sequence .\ a tthe
-// beginning of a path is turned into a :
-
-// routine to take a POSIX style path and turn it into a pre OS X
-// pathname.  This routine uses CFURL's. This function is necessary
-// because even though fopen exists in StdCLib
-// it must take a path in the OS native format.
-
-#ifdef macintosh
-void macify_posix_path(char *posix_path, char *mac_path)
-{
-    CFURLRef   url;
-
-    url = CFURLCreateWithBytes (kCFAllocatorDefault, (ubyte *) posix_path, strlen(posix_path), GetApplicationTextEncoding(), NULL);
-    CFURLGetFileSystemRepresentation (url, 0, (ubyte *) mac_path, 255);
-    CFRelease(url);
-}
-#endif
-
-void cfile_use_alternate_hogdir( char * path )
-{
-       if ( path )     {
-               strcpy( AltHogDir, path );
-               AltHogdir_initialized = 1;
-       } else {
-               AltHogdir_initialized = 0;
-       }
-}
-
-//in case no one installs one
-int default_error_counter=0;
-
-//ptr to counter of how many critical errors
-int *critical_error_counter_ptr=&default_error_counter;
-
-//tell cfile about your critical error counter
-void cfile_set_critical_error_counter_ptr(int *ptr)
-{
-       critical_error_counter_ptr = ptr;
-
-}
-
-
-FILE * cfile_get_filehandle( char * filename, char * mode )
-{
-    FILE * fp;
-    char temp[128];
-#ifdef macintosh
-    char mac_path[256];
-#endif
-
-    *critical_error_counter_ptr = 0;
-#ifdef macintosh
-    macify_posix_path(filename, mac_path);
-    fp = fopen( mac_path, mode );
-#else
-    fp = fopen( filename, mode );
-#endif
-    if ( fp && *critical_error_counter_ptr )   {
-        fclose(fp);
-        fp = NULL;
-    }
-    if ( (fp==NULL) && (AltHogdir_initialized) )       {
-        strcpy( temp, AltHogDir );
-        strcat( temp, "/");
-        strcat( temp, filename );
-        *critical_error_counter_ptr = 0;
-#ifdef macintosh
-        macify_posix_path(temp, mac_path);
-        fp = fopen( mac_path, mode );
-#else
-        fp = fopen( temp, mode );
-#endif
-        if ( fp && *critical_error_counter_ptr )       {
-            fclose(fp);
-            fp = NULL;
-        }
-    }
-    return fp;
-}
-
-hog * cfile_init_hogfile (char *fname)
-{
-       char id[4];
-       FILE * fp;
-       int i, len;
-       hog *new_hog;
-
-       fp = cfile_get_filehandle (fname, "rb");
-       if (fp == NULL)
-               return 0;
-
-       // verify that it is really a Descent Hog File
-       fread( id, 3, 1, fp );
-       if ( strncmp( id, "DHF", 3 ) )  {
-               fclose(fp);
-               return NULL;
-       }
-
-       new_hog = (hog *) d_malloc (sizeof (hog));
-
-       new_hog->num_files = 0;
-       strcpy (new_hog->filename, fname);
-
-       // read file name or reach EOF
-       while (! feof (fp)) {
-               if (new_hog->num_files >= MAX_FILES_IN_HOG) {
-                       fclose (fp);
-                       d_free (new_hog);
-                       Error ("Exceeded max. number of files in hog (%d).\n",
-                              MAX_FILES_IN_HOG);
-               }
-               i = fread (new_hog->files[new_hog->num_files].name, 13, 1, fp);
-               if (i != 1)
-                       break; // we assume it is EOF, so it is OK
-               
-               i = fread( &len, 4, 1, fp );
-               if (i != 1)
-                       break;
-               new_hog->files[new_hog->num_files].length = INTEL_INT (len);
-               new_hog->files[new_hog->num_files].offset = ftell (fp);
-               // skip over embedded file:
-               i = fseek (fp, INTEL_INT (len), SEEK_CUR);
-               new_hog->num_files++;
-       }
-       fclose (fp);
-       return new_hog;
-}
-
-// Opens builtin hog given its filename. Returns 1 on success.
-int cfile_init(char *hogname)
-{
-       Assert (builtin_hog == NULL);
-
-       builtin_hog = cfile_init_hogfile (hogname);
-       atexit (free_builtin_hog);
-       return builtin_hog != NULL ? 1 : 0;
-}
-
-
-int cfile_size(char *hogname)
-{
-       CFILE *fp;
-       int size;
-
-       fp = cfopen(hogname, "rb");
-       if (fp == NULL)
-               return -1;
-       size = ffilelength(fp->file);
-       cfclose(fp);
-       return size;
-}
-
-FILE * cfile_find_in_hog (char * name, int * length, hog *my_hog) {
-       FILE * fp;
-       int i;
-       for (i = 0; i < my_hog->num_files; i++ )
-               if (! stricmp (my_hog->files[i].name, name)) {
-                       fp = cfile_get_filehandle (my_hog->filename, "rb");
-                       if (fp == NULL)
-                               return NULL;
-                       fseek (fp,  my_hog->files[i].offset, SEEK_SET);
-                       *length = my_hog->files[i].length;
-                       return fp;
-               }
-       return NULL;
-}
-
-/*
- * return handle for file called "name", embedded in one of the hogfiles
- */
-FILE * cfile_find_embedded_file (char * name, int * length)
-{
-       FILE * fp;
-       if (alt_hog) {
-               fp = cfile_find_in_hog (name, length, alt_hog);
-               if (fp)
-                       return fp;
-       }
-
-       if (builtin_hog) {
-               fp = cfile_find_in_hog (name, length, builtin_hog);
-               if (fp)
-                       return fp;
-       }
-
-       if (d1_hog) {
-               fp = cfile_find_in_hog (name, length, d1_hog);
-               if (fp)
-                       return fp;
-       }
-
-       return NULL;
-}
-
-int cfile_use_alternate_hogfile (char * name)
-{
-       if (alt_hog) {
-               d_free (alt_hog);
-               alt_hog = NULL;
-       }
-       if (name) {
-               alt_hog = cfile_init_hogfile (name);
-               atexit (free_alt_hog);
-               if (alt_hog)
-                       return 1; // success
-       }
-       return 0;
-}
-
-/* we use the d1 hog for d1 textures... */
-int cfile_use_descent1_hogfile( char * name )
-{
-       if (d1_hog) {
-               d_free (d1_hog);
-               d1_hog = NULL;
-       }
-       if (name) {
-               d1_hog = cfile_init_hogfile (name);
-               atexit (free_d1_hog);
-               if (d1_hog)
-                       return 1; // success
-       }
-       return 0;
-}
-
-// cfeof() Tests for end-of-file on a stream
-//
-// returns a nonzero value after the first read operation that attempts to read
-// past the end of the file. It returns 0 if the current position is not end of file.
-// There is no error return.
-
-int cfeof(CFILE *cfile)
-{
-       Assert(cfile != NULL);
-
-       Assert(cfile->file != NULL);
-
-    return (cfile->raw_position >= cfile->size);
-}
-
-
-int cferror(CFILE *cfile)
-{
-       return ferror(cfile->file);
-}
-
-
-int cfexist( char * filename )
-{
-       int length;
-       FILE *fp;
-
-
-       if (filename[0] != '\x01')
-               fp = cfile_get_filehandle( filename, "rb" );            // Check for non-hog file first...
-       else {
-               fp = NULL;              //don't look in dir, only in hogfile
-               filename++;
-       }
-
-       if ( fp )       {
-               fclose(fp);
-               return 1;
-       }
-
-       fp = cfile_find_embedded_file (filename, &length);
-       if ( fp )       {
-               fclose(fp);
-               return 2;               // file found in hog
-       }
-
-       return 0;               // Couldn't find it.
-}
-
-
-// Deletes a file.
-int cfile_delete(char *filename)
-{
-#ifndef _WIN32_WCE
-       return remove(filename);
-#else
-       return !DeleteFile(filename);
-#endif
-}
-
-
-// Rename a file.
-int cfile_rename(char *oldname, char *newname)
-{
-#ifndef _WIN32_WCE
-       return rename(oldname, newname);
-#else
-       return !MoveFile(oldname, newname);
-#endif
-}
-
-
-// Make a directory.
-int cfile_mkdir(char *pathname)
-{
-#ifdef _WIN32
-# ifdef _WIN32_WCE
-       return !CreateDirectory(pathname, NULL);
-# else
-       return _mkdir(pathname);
-# endif
-#elif defined(macintosh)
-    char       mac_path[256];
-    Str255     pascal_path;
-    long       dirID;  // Insists on returning this
-
-    macify_posix_path(pathname, mac_path);
-    CopyCStringToPascal(mac_path, pascal_path);
-    return DirCreate(0, 0, pascal_path, &dirID);
-#else
-       return mkdir(pathname, 0755);
-#endif
-}
-
-
-CFILE * cfopen(char * filename, char * mode )
-{
-       int length;
-       FILE * fp;
-       CFILE *cfile;
-
-       if (filename[0] != '\x01')
-               fp = cfile_get_filehandle( filename, mode );            // Check for non-hog file first...
-       else {
-               fp = NULL;              //don't look in dir, only in hogfile
-               filename++;
-       }
-
-       if ( !fp ) {
-               fp = cfile_find_embedded_file (filename, &length);
-               if ( !fp )
-                       return NULL;            // No file found
-               if (stricmp(mode, "rb"))
-                       Error("mode must be rb for files in hog.\n");
-               cfile = d_malloc ( sizeof(CFILE) );
-               if ( cfile == NULL ) {
-                       fclose(fp);
-                       return NULL;
-               }
-               cfile->file = fp;
-               cfile->size = length;
-               cfile->offset = ftell( fp );
-               cfile->raw_position = 0;
-               return cfile;
-       } else {
-               cfile = d_malloc ( sizeof(CFILE) );
-               if ( cfile == NULL ) {
-                       fclose(fp);
-                       return NULL;
-               }
-               cfile->file = fp;
-               cfile->size = ffilelength(fp);
-               cfile->offset = 0;
-               cfile->raw_position = 0;
-               return cfile;
-       }
-}
-
-int cfilelength( CFILE *fp )
-{
-       return fp->size;
-}
-
-
-// cfwrite() writes to the file
-//
-// returns:   number of full elements actually written
-//
-//
-int cfwrite(void *buf, int elsize, int nelem, CFILE *cfile)
-{
-       int items_written;
-
-       Assert(cfile != NULL);
-       Assert(buf != NULL);
-       Assert(elsize > 0);
-
-       Assert(cfile->file != NULL);
-       Assert(cfile->offset == 0);
-
-       items_written = fwrite(buf, elsize, nelem, cfile->file);
-       cfile->raw_position = ftell(cfile->file);
-
-       return items_written;
-}
-
-
-// cfputc() writes a character to a file
-//
-// returns:   success ==> returns character written
-//            error   ==> EOF
-//
-int cfputc(int c, CFILE *cfile)
-{
-       int char_written;
-
-       Assert(cfile != NULL);
-
-       Assert(cfile->file != NULL);
-       Assert(cfile->offset == 0);
-
-       char_written = fputc(c, cfile->file);
-       cfile->raw_position = ftell(cfile->file);
-
-       return char_written;
-}
-
-
-int cfgetc( CFILE * fp )
-{
-       int c;
-
-       if (fp->raw_position >= fp->size ) return EOF;
-
-       c = getc( fp->file );
-       if (c!=EOF)
-               fp->raw_position = ftell(fp->file)-fp->offset;
-
-       return c;
-}
-
-
-// cfputs() writes a string to a file
-//
-// returns:   success ==> non-negative value
-//            error   ==> EOF
-//
-int cfputs(char *str, CFILE *cfile)
-{
-       int ret;
-
-       Assert(cfile != NULL);
-       Assert(str != NULL);
-
-       Assert(cfile->file != NULL);
-
-       ret = fputs(str, cfile->file);
-       cfile->raw_position = ftell(cfile->file);
-
-       return ret;
-}
-
-
-char * cfgets( char * buf, size_t n, CFILE * fp )
-{
-       int i;
-       int c;
-
-#if 0 // don't use the standard fgets, because it will only handle the native line-ending style
-       if (fp->offset == 0) // This is not an archived file
-       {
-               t = fgets(buf, n, fp->file);
-               fp->raw_position = ftell(fp->file);
-               return t;
-       }
-#endif
-
-       for (i=0; i<n-1; i++ ) {
-               do {
-                       if (fp->raw_position >= fp->size ) {
-                               *buf = 0;
-                               return NULL;
-                       }
-                       c = cfgetc(fp);
-                       if (c == 0 || c == 10)        // Unix line ending
-                               break;
-                       if (c == 13) {      // Mac or DOS line ending
-                               int c1;
-
-                               c1 = cfgetc(fp);
-                               if (c1 != EOF)  // The file could end with a Mac line ending
-                                       cfseek(fp, -1, SEEK_CUR);
-                               if ( c1 == 10 ) // DOS line ending
-                                       continue;
-                               else            // Mac line ending
-                                       break;
-                       }
-               } while ( c == 13 );
-               if ( c == 13 )  // because cr-lf is a bad thing on the mac
-                       c = '\n';   // and anyway -- 0xod is CR on mac, not 0x0a
-               if ( c=='\n' ) break;
-               *buf++ = c;
-       }
-       *buf++ = 0;
-       return  buf;
-}
-
-size_t cfread( void * buf, size_t elsize, size_t nelem, CFILE * fp ) 
-{
-       unsigned int i, size;
-
-       size = elsize * nelem;
-       if ( size < 1 ) return 0;
-
-       i = fread ( buf, 1, size, fp->file );
-       fp->raw_position += i;
-       return i/elsize;
-}
-
-
-int cftell( CFILE *fp )        
-{
-       return fp->raw_position;
-}
-
-int cfseek( CFILE *fp, long int offset, int where )
-{
-       int c, goal_position;
-
-       switch( where ) {
-       case SEEK_SET:
-               goal_position = offset;
-               break;
-       case SEEK_CUR:
-               goal_position = fp->raw_position+offset;
-               break;
-       case SEEK_END:
-               goal_position = fp->size+offset;
-               break;
-       default:
-               return 1;
-       }       
-       c = fseek( fp->file, fp->offset + goal_position, SEEK_SET );
-       fp->raw_position = ftell(fp->file)-fp->offset;
-       return c;
-}
-
-int cfclose(CFILE *fp)
-{
-       int result;
-
-       result = fclose(fp->file);
-       d_free(fp);
-
-       return result;
-}
-
-// routines to read basic data types from CFILE's.  Put here to
-// simplify mac/pc reading from cfiles.
-
-int cfile_read_int(CFILE *file)
-{
-       int32_t i;
-
-       if (cfread( &i, sizeof(i), 1, file) != 1)
-               Error( "Error reading int in cfile_read_int()" );
-
-       i = INTEL_INT(i);
-       return i;
-}
-
-short cfile_read_short(CFILE *file)
-{
-       int16_t s;
-
-       if (cfread( &s, sizeof(s), 1, file) != 1)
-               Error( "Error reading short in cfile_read_short()" );
-
-       s = INTEL_SHORT(s);
-       return s;
-}
-
-sbyte cfile_read_byte(CFILE *file)
-{
-       sbyte b;
-
-       if (cfread( &b, sizeof(b), 1, file) != 1)
-               Error( "Error reading byte in cfile_read_byte()" );
-
-       return b;
-}
-
-fix cfile_read_fix(CFILE *file)
-{
-       fix f;
-
-       if (cfread( &f, sizeof(f), 1, file) != 1)
-               Error( "Error reading fix in cfile_read_fix()" );
-
-       f = (fix)INTEL_INT((int)f);
-       return f;
-}
-
-fixang cfile_read_fixang(CFILE *file)
-{
-       fixang f;
-
-       if (cfread(&f, 2, 1, file) != 1)
-               Error("Error reading fixang in cfile_read_fixang()");
-
-       f = (fixang) INTEL_SHORT((int) f);
-       return f;
-}
-
-void cfile_read_vector(vms_vector *v, CFILE *file)
-{
-       v->x = cfile_read_fix(file);
-       v->y = cfile_read_fix(file);
-       v->z = cfile_read_fix(file);
-}
-
-void cfile_read_angvec(vms_angvec *v, CFILE *file)
-{
-       v->p = cfile_read_fixang(file);
-       v->b = cfile_read_fixang(file);
-       v->h = cfile_read_fixang(file);
-}
-
-void cfile_read_matrix(vms_matrix *m,CFILE *file)
-{
-       cfile_read_vector(&m->rvec,file);
-       cfile_read_vector(&m->uvec,file);
-       cfile_read_vector(&m->fvec,file);
-}
-
-
-void cfile_read_string(char *buf, int n, CFILE *file)
-{
-       char c;
-
-       do {
-               c = (char)cfile_read_byte(file);
-               if (n > 0)
-               {
-                       *buf++ = c;
-                       n--;
-               }
-       } while (c != 0);
-}
-
-
-// equivalent write functions of above read functions follow
-
-int cfile_write_int(int i, CFILE *file)
-{
-       i = INTEL_INT(i);
-       return cfwrite(&i, sizeof(i), 1, file);
-}
-
-
-int cfile_write_short(short s, CFILE *file)
-{
-       s = INTEL_SHORT(s);
-       return cfwrite(&s, sizeof(s), 1, file);
-}
-
-
-int cfile_write_byte(sbyte b, CFILE *file)
-{
-       return cfwrite(&b, sizeof(b), 1, file);
-}
-
-
-int cfile_write_string(char *buf, CFILE *file)
-{
-       int len;
-
-       if ((!buf) || (buf && !buf[0]))
-               return cfile_write_byte(0, file);
-
-       len = strlen(buf);
-       if (!cfwrite(buf, len, 1, file))
-               return 0;
-
-       return cfile_write_byte(0, file);   // write out NULL termination
-}
index 1f82d60..27f11cd 100644 (file)
@@ -203,6 +203,9 @@ else
 #)
        AM_CONDITIONAL(USE_LIBPNG, test x$have_libpng = xyes)
 
+  # Check for PhysicsFS
+       AC_CHECK_LIB(physfs, PHYSFS_init, LIBS="-lphysfs $LIBS")
+
   # Check for OpenGL
     AC_ARG_WITH(opengl,
         [  --with-opengl           Build OpenGL support ],,)
@@ -416,7 +419,6 @@ AC_OUTPUT(
     arch/sdl/Makefile
     arch/svgalib/Makefile
     arch/win32/Makefile
-    cfile/Makefile
     console/Makefile
     iff/Makefile
     libmve/Makefile
index e223a03..1325870 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: args.h,v 1.6 2004-08-28 23:17:45 schaffner Exp $ */
+/* $Id: args.h,v 1.7 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -25,6 +25,7 @@ extern int Num_args;
 extern char *Args[];
 extern int FindArg(char *s);
 extern int FindResArg(char *prefix, int *sw, int *sh);
+extern void AppendArgs(void);
 extern void InitArgs(int argc, char **argv);
 extern int Inferno_verbose;
 
index ec28e4d..2698113 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: cfile.h,v 1.11 2004-08-28 23:17:45 schaffner Exp $ */
+/* $Id: cfile.h,v 1.12 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -14,7 +14,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 
 /*
  *
- * Prototypes for compressed file functions...
+ * Wrappers for physfs abstraction layer
  *
  */
 
@@ -22,88 +22,221 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #define _CFILE_H
 
 #include <stdio.h>
+#include <string.h>
+#include <physfs.h>
 
+#include "pstypes.h"
 #include "maths.h"
 #include "vecmat.h"
+#include "physfsx.h"
 
-typedef struct CFILE CFILE;
+#define CFILE            PHYSFS_file
+#define cfopen(n,m)      PHYSFS_openRead(n)
+#define cfread(p,s,n,fp) PHYSFS_read(fp,p,s,n)
+#define cfclose          PHYSFS_close
+#define cftell           PHYSFS_tell
+#define cfexist          PHYSFS_exists
+#define cfilelength      PHYSFS_fileLength
 
 //Specify the name of the hogfile.  Returns 1 if hogfile found & had files
-int cfile_init(char *hogname);
-
-int cfile_size(char *hogname);
-
-CFILE * cfopen(char * filename, char * mode);
-int cfilelength( CFILE *fp );                                                  // Returns actual size of file...
-size_t cfread( void * buf, size_t elsize, size_t nelem, CFILE * fp );
-int cfclose(CFILE *cfile);
-int cfgetc( CFILE * fp );
-int cfseek( CFILE *fp, long int offset, int where );
-int cftell( CFILE * fp );
-char * cfgets( char * buf, size_t n, CFILE * fp );
-
-int cfeof(CFILE *cfile);
-int cferror(CFILE *cfile);
-
-int cfexist( char * filename );        // Returns true if file exists on disk (1) or in hog (2).
-
-// Deletes a file.
-int cfile_delete(char *filename);
-
-// Rename a file.
-int cfile_rename(char *oldname, char *newname);
-
-// Make a directory
-int cfile_mkdir(char *pathname);
-
-// cfwrite() writes to the file
-int cfwrite(void *buf, int elsize, int nelem, CFILE *cfile);
-
-// cfputc() writes a character to a file
-int cfputc(int c, CFILE *cfile);
-
-// cfputs() writes a string to a file
-int cfputs(char *str, CFILE *cfile);
-
-// Allows files to be gotten from an alternate hog file.
-// Passing NULL disables this.
-// Returns 1 if hogfile found (& contains file), else 0.  
-// If NULL passed, returns 1
-int cfile_use_alternate_hogfile( char * name );
-
-// Allows files to be gotten from the Descent 1 hog file.
-// Passing NULL disables this.
-// Returns 1 if hogfile found (& contains file), else 0.
-// If NULL passed, returns 1
-int cfile_use_descent1_hogfile(char * name);
-
-// All cfile functions will check this directory if no file exists
-// in the current directory.
-void cfile_use_alternate_hogdir( char * path );
-
-//tell cfile about your critical error counter 
-void cfile_set_critical_error_counter_ptr(int *ptr);
-
-// prototypes for reading basic types from cfile
-int cfile_read_int(CFILE *file);
-short cfile_read_short(CFILE *file);
-sbyte cfile_read_byte(CFILE *file);
-fix cfile_read_fix(CFILE *file);
-fixang cfile_read_fixang(CFILE *file);
-void cfile_read_vector(vms_vector *v, CFILE *file);
-void cfile_read_angvec(vms_angvec *v, CFILE *file);
-void cfile_read_matrix(vms_matrix *v, CFILE *file);
-
-// Reads variable length, null-termined string.   Will only read up
-// to n characters.
-void cfile_read_string(char *buf, int n, CFILE *file);
-
-// functions for writing cfiles
-int cfile_write_int(int i, CFILE *file);
-int cfile_write_short(short s, CFILE *file);
-int cfile_write_byte(sbyte u, CFILE *file);
-
-// writes variable length, null-termined string.
-int cfile_write_string(char *buf, CFILE *file);
+static inline int cfile_init(char *hogname)
+{
+       char pathname[1024];
+
+       if (!PHYSFSX_getRealPath(hogname, pathname))
+               return 0;
+
+       return PHYSFS_addToSearchPath(pathname, 1);
+}
+
+static inline int cfile_close(char *hogname)
+{
+       char pathname[1024];
+
+       if (!PHYSFSX_getRealPath(hogname, pathname))
+               return 0;
+
+       return PHYSFS_removeFromSearchPath(pathname);
+}
+
+
+static inline int cfile_size(char *hogname)
+{
+       PHYSFS_file *fp;
+       int size;
+
+       fp = PHYSFS_openRead(hogname);
+       if (fp == NULL)
+               return -1;
+       size = PHYSFS_fileLength(fp);
+       cfclose(fp);
+
+       return size;
+}
+
+static inline int cfgetc(PHYSFS_file *const fp)
+{
+       unsigned char c;
+
+       if (PHYSFS_read(fp, &c, 1, 1) != 1)
+               return EOF;
+
+       return c;
+}
+
+static inline int cfseek(PHYSFS_file *fp, long int offset, int where)
+{
+       int c, goal_position;
+
+       switch(where)
+       {
+       case SEEK_SET:
+               goal_position = offset;
+               break;
+       case SEEK_CUR:
+               goal_position = PHYSFS_tell(fp) + offset;
+               break;
+       case SEEK_END:
+               goal_position = PHYSFS_fileLength(fp) + offset;
+               break;
+       default:
+               return 1;
+       }
+       c = PHYSFS_seek(fp, goal_position);
+       return !c;
+}
+
+static inline char * cfgets(char *buf, size_t n, PHYSFS_file *const fp)
+{
+       int i;
+       int c;
+
+       for (i = 0; i < n - 1; i++)
+       {
+               do
+               {
+                       c = cfgetc(fp);
+                       if (c == EOF)
+                       {
+                               *buf = 0;
+
+                               return NULL;
+                       }
+                       if (c == 0 || c == 10)  // Unix line ending
+                               break;
+                       if (c == 13)            // Mac or DOS line ending
+                       {
+                               int c1;
+
+                               c1 = cfgetc(fp);
+                               if (c1 != EOF)  // The file could end with a Mac line ending
+                                       cfseek(fp, -1, SEEK_CUR);
+                               if (c1 == 10) // DOS line ending
+                                       continue;
+                               else            // Mac line ending
+                                       break;
+                       }
+               } while (c == 13);
+               if (c == 13)    // because cr-lf is a bad thing on the mac
+                       c = '\n';   // and anyway -- 0xod is CR on mac, not 0x0a
+               if (c == '\n')
+                       break;
+               *buf++ = c;
+       }
+       *buf = 0;
+
+       return buf;
+}
+
+
+/*
+ * read some data types...
+ */
+
+static inline int cfile_read_int(PHYSFS_file *file)
+{
+       int i;
+
+       if (!PHYSFS_readSLE32(file, &i))
+       {
+               fprintf(stderr, "Error reading int in cfile_read_int()");
+               exit(1);
+       }
+
+       return i;
+}
+
+static inline short cfile_read_short(PHYSFS_file *file)
+{
+       int16_t s;
+
+       if (!PHYSFS_readSLE16(file, &s))
+       {
+               fprintf(stderr, "Error reading short in cfile_read_short()");
+               exit(1);
+       }
+
+       return s;
+}
+
+static inline sbyte cfile_read_byte(PHYSFS_file *file)
+{
+       sbyte b;
+
+       if (PHYSFS_read(file, &b, sizeof(b), 1) != 1)
+       {
+               fprintf(stderr, "Error reading byte in cfile_read_byte()");
+               exit(1);
+       }
+
+       return b;
+}
+
+static inline fix cfile_read_fix(PHYSFS_file *file)
+{
+       int f;  // a fix is defined as a long for Mac OS 9, and MPW can't convert from (long *) to (int *)
+
+       if (!PHYSFS_readSLE32(file, &f))
+       {
+               fprintf(stderr, "Error reading fix in cfile_read_fix()");
+               exit(1);
+       }
+
+       return f;
+}
+
+static inline fixang cfile_read_fixang(PHYSFS_file *file)
+{
+       fixang f;
+
+       if (!PHYSFS_readSLE16(file, &f))
+       {
+               fprintf(stderr, "Error reading fixang in cfile_read_fixang()");
+               exit(1);
+       }
+
+       return f;
+}
+
+static inline void cfile_read_vector(vms_vector *v, PHYSFS_file *file)
+{
+       v->x = cfile_read_fix(file);
+       v->y = cfile_read_fix(file);
+       v->z = cfile_read_fix(file);
+}
+
+static inline void cfile_read_angvec(vms_angvec *v, PHYSFS_file *file)
+{
+       v->p = cfile_read_fixang(file);
+       v->b = cfile_read_fixang(file);
+       v->h = cfile_read_fixang(file);
+}
+
+static inline void cfile_read_matrix(vms_matrix *m,PHYSFS_file *file)
+{
+       cfile_read_vector(&m->rvec,file);
+       cfile_read_vector(&m->uvec,file);
+       cfile_read_vector(&m->fvec,file);
+}
 
 #endif
diff --git a/include/d_io.h b/include/d_io.h
deleted file mode 100644 (file)
index d381e3d..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-// some misc. file/disk routines
-// Arne de Bruijn, 1998
-#ifndef _D_IO_H
-#define _D_IO_H
-
-#ifndef _WIN32_WCE
-#ifdef _WIN32
-#include <io.h>
-#elif !defined(macintosh)
-#include <unistd.h>
-#endif
-#endif
-
-extern long ffilelength(FILE *fh);
-#if 0
-extern long filelength(int fd);
-#endif
-unsigned long d_getdiskfree();
-// remove extension from filename, doesn't work with paths.
-void removeext(const char *filename, char *out);
-
-unsigned long GetDiskFree();
-
-#endif
diff --git a/include/findfile.h b/include/findfile.h
deleted file mode 100644 (file)
index 5fbb9f5..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-// Empty file
-typedef struct FILEFINDSTRUCT {
-               unsigned long size;
-                       char name[256];
-} FILEFINDSTRUCT;
-int FileFindFirst(char *search_str, FILEFINDSTRUCT *ffstruct);
-int FileFindNext(FILEFINDSTRUCT *ffstruct);
-int FileFindClose(void);
-
-typedef struct FILETIMESTRUCT {
-               unsigned short date,time;
-} FILETIMESTRUCT;
-
-//the both return 0 if no error
-//int GetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct);
-//int SetFileDateTime(int filehandle, FILETIMESTRUCT *ftstruct);
-//
diff --git a/include/ignorecase.h b/include/ignorecase.h
new file mode 100644 (file)
index 0000000..873202e
--- /dev/null
@@ -0,0 +1,75 @@
+/** \file ignorecase.h */
+
+/**
+ * \mainpage PhysicsFS ignorecase
+ *
+ * This is an extension to PhysicsFS to let you handle files in a
+ *  case-insensitive manner, regardless of what sort of filesystem or
+ *  archive they reside in. It does this by enumerating directories as
+ *  needed and manually locating matching entries.
+ *
+ * Please note that this brings with it some caveats:
+ *  - On filesystems that are case-insensitive to start with, such as those
+ *    used on Windows or MacOS, you are adding extra overhead.
+ *  - On filesystems that are case-sensitive, you might select the wrong dir
+ *    or file (which brings security considerations and potential bugs). This
+ *    code favours exact case matches, but you will lose access to otherwise
+ *    duplicate filenames, or you might go down a wrong directory tree, etc.
+ *    In practive, this is rarely a problem, but you need to be aware of it.
+ *  - This doesn't do _anything_ with the write directory; you're on your
+ *    own for opening the right files for writing. You can sort of get around
+ *    this by adding your write directory to the search path, but then the
+ *    interpolated directory tree can screw you up even more.
+ *
+ * This code should be considered an aid for legacy code. New development
+ *  shouldn't do dumbass things that require this aid in the first place.  :)
+ *
+ * Usage: Set up PhysicsFS as you normally would, then use
+ *  PHYSFSEXT_locateCorrectCase() to get a "correct" pathname to pass to
+ *  functions like PHYSFS_openRead(), etc.
+ *
+ * License: this code is public domain. I make no warranty that it is useful,
+ *  correct, harmless, or environmentally safe.
+ *
+ * This particular file may be used however you like, including copying it
+ *  verbatim into a closed-source project, exploiting it commercially, and
+ *  removing any trace of my name from the source (although I hope you won't
+ *  do that). I welcome enhancements and corrections to this file, but I do
+ *  not require you to send me patches if you make changes. This code has
+ *  NO WARRANTY.
+ *
+ * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
+ *  Please see LICENSE in the root of the source tree.
+ *
+ *  \author Ryan C. Gordon.
+ */
+
+
+/**
+ * \fn int PHYSFSEXT_locateCorrectCase(char *buf)
+ * \brief Find an existing filename with matching case.
+ *
+ * This function will look for a path/filename that matches the passed in
+ *  buffer. Each element of the buffer's path is checked for a
+ *  case-insensitive match. The buffer must specify a null-terminated string
+ *  in platform-independent notation.
+ *
+ * Please note results may be skewed differently depending on whether symlinks
+ *  are enabled or not.
+ *
+ * Each element of the buffer is overwritten with the actual case of an
+ *  existing match. If there is no match, the search aborts and reports an
+ *  error. Exact matches are favored over case-insensitive matches.
+ *
+ * THIS IS RISKY. Please do not use this function for anything but crappy
+ *  legacy code.
+ *
+ *   \param buf Buffer with null-terminated string of path/file to locate.
+ *               This buffer will be modified by this function.
+ *  \return zero if match was found, -1 if the final element (the file itself)
+ *               is missing, -2 if one of the parent directories is missing.
+ */
+int PHYSFSEXT_locateCorrectCase(char *buf);
+
+/* end of ignorecase.h ... */
+
diff --git a/include/physfsrwops.h b/include/physfsrwops.h
new file mode 100644 (file)
index 0000000..683954d
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * This code provides a glue layer between PhysicsFS and Simple Directmedia
+ *  Layer's (SDL) RWops i/o abstraction.
+ *
+ * License: this code is public domain. I make no warranty that it is useful,
+ *  correct, harmless, or environmentally safe.
+ *
+ * This particular file may be used however you like, including copying it
+ *  verbatim into a closed-source project, exploiting it commercially, and
+ *  removing any trace of my name from the source (although I hope you won't
+ *  do that). I welcome enhancements and corrections to this file, but I do
+ *  not require you to send me patches if you make changes. This code has
+ *  NO WARRANTY.
+ *
+ * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
+ *  Please see LICENSE in the root of the source tree.
+ *
+ * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/
+ *
+ *  This file was written by Ryan C. Gordon. (icculus@clutteredmind.org).
+ */
+
+#ifndef _INCLUDE_PHYSFSRWOPS_H_
+#define _INCLUDE_PHYSFSRWOPS_H_
+
+#include "physfs.h"
+#include "SDL.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * Open a platform-independent filename for reading, and make it accessible
+ *  via an SDL_RWops structure. The file will be closed in PhysicsFS when the
+ *  RWops is closed. PhysicsFS should be configured to your liking before
+ *  opening files through this method.
+ *
+ *   @param filename File to open in platform-independent notation.
+ *  @return A valid SDL_RWops structure on success, NULL on error. Specifics
+ *           of the error can be gleaned from PHYSFS_getLastError().
+ */
+__EXPORT__ SDL_RWops *PHYSFSRWOPS_openRead(const char *fname);
+
+/**
+ * Open a platform-independent filename for writing, and make it accessible
+ *  via an SDL_RWops structure. The file will be closed in PhysicsFS when the
+ *  RWops is closed. PhysicsFS should be configured to your liking before
+ *  opening files through this method.
+ *
+ *   @param filename File to open in platform-independent notation.
+ *  @return A valid SDL_RWops structure on success, NULL on error. Specifics
+ *           of the error can be gleaned from PHYSFS_getLastError().
+ */
+__EXPORT__ SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname);
+
+/**
+ * Open a platform-independent filename for appending, and make it accessible
+ *  via an SDL_RWops structure. The file will be closed in PhysicsFS when the
+ *  RWops is closed. PhysicsFS should be configured to your liking before
+ *  opening files through this method.
+ *
+ *   @param filename File to open in platform-independent notation.
+ *  @return A valid SDL_RWops structure on success, NULL on error. Specifics
+ *           of the error can be gleaned from PHYSFS_getLastError().
+ */
+__EXPORT__ SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname);
+
+/**
+ * Make a SDL_RWops from an existing PhysicsFS file handle. You should
+ *  dispose of any references to the handle after successful creation of
+ *  the RWops. The actual PhysicsFS handle will be destroyed when the
+ *  RWops is closed.
+ *
+ *   @param handle a valid PhysicsFS file handle.
+ *  @return A valid SDL_RWops structure on success, NULL on error. Specifics
+ *           of the error can be gleaned from PHYSFS_getLastError().
+ */
+__EXPORT__ SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* include-once blocker */
+
+/* end of physfsrwops.h ... */
+
diff --git a/include/physfsx.h b/include/physfsx.h
new file mode 100644 (file)
index 0000000..ded82a7
--- /dev/null
@@ -0,0 +1,121 @@
+/* $Id: physfsx.h,v 1.2 2004-12-01 12:48:13 btb Exp $ */
+
+/*
+ *
+ * Some simple physfs extensions
+ *
+ */
+
+#ifndef PHYSFSX_H
+#define PHYSFSX_H
+
+#ifndef macintosh
+#include <sys/param.h>
+#endif
+#if defined(__linux__)
+#include <sys/vfs.h>
+#elif defined(__MACH__) && defined(__APPLE__)
+#include <sys/mount.h>
+#endif
+#include <string.h>
+
+#include <physfs.h>
+
+static inline int PHYSFSX_readString(PHYSFS_file *file, char *s)
+{
+       char *ptr = s;
+
+       if (PHYSFS_eof(file))
+               *ptr = 0;
+       else
+               do
+                       PHYSFS_read(file, ptr, 1, 1);
+               while (!PHYSFS_eof(file) && *ptr++ != 0);
+
+       return strlen(s);
+}
+
+static inline int PHYSFSX_gets(PHYSFS_file *file, char *s)
+{
+       char *ptr = s;
+
+       if (PHYSFS_eof(file))
+               *ptr = 0;
+       else
+               do
+                       PHYSFS_read(file, ptr, 1, 1);
+               while (!PHYSFS_eof(file) && *ptr++ != '\n');
+
+       return strlen(s);
+}
+
+static inline int PHYSFSX_writeU8(PHYSFS_file *file, PHYSFS_uint8 val)
+{
+       return PHYSFS_write(file, &val, 1, 1);
+}
+
+static inline int PHYSFSX_writeString(PHYSFS_file *file, char *s)
+{
+       return PHYSFS_write(file, s, 1, strlen(s) + 1);
+}
+
+static inline int PHYSFSX_puts(PHYSFS_file *file, char *s)
+{
+       return PHYSFS_write(file, s, 1, strlen(s));
+}
+
+static inline int PHYSFSX_putc(PHYSFS_file *file, int c)
+{
+       unsigned char ch = (unsigned char)c;
+
+       if (PHYSFS_write(file, &ch, 1, 1) < 1)
+               return -1;
+       else
+               return (int)c;
+}
+
+static inline int PHYSFSX_getRealPath(char *stdPath, char *realPath)
+{
+       const char *realDir = PHYSFS_getRealDir(stdPath);
+       char *p;
+       char sep = *PHYSFS_getDirSeparator();
+
+       if (!realDir)
+               return 0;
+       
+       strncpy(realPath, realDir, PATH_MAX);   // some compilers (like MPW) don't have snprintf
+       p = realPath + strlen(realPath);
+       strncat(realPath, stdPath, PATH_MAX - strlen(realPath));
+       while ((p = strchr(p, '/')))
+               *p++ = sep;
+
+       return 1;
+}
+
+static inline int PHYSFSX_rename(char *oldpath, char *newpath)
+{
+       char old[PATH_MAX], new[PATH_MAX];
+
+       PHYSFSX_getRealPath(oldpath, old);
+       PHYSFSX_getRealPath(newpath, new);
+       return (rename(old, new) == 0);
+}
+
+
+// returns -1 if error
+// Gets bytes free in current write dir
+static inline PHYSFS_sint64 PHYSFSX_getFreeDiskSpace()
+{
+#if defined(__linux__) || (defined(__MACH__) && defined(__APPLE__))
+       struct statfs sfs;
+
+       if (!statfs(PHYSFS_getWriteDir(), &sfs))
+               return (PHYSFS_sint64)(sfs.f_bavail * sfs.f_bsize);
+
+       return -1;
+#else
+       return 0x7FFFFFFF;
+#endif
+}
+
+#endif /* PHYSFSX_H */
index 175c556..3528597 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef _STRIO_H
 #define _STRIO_H
 
-char* fgets_unlimited(CFILE *f);
+char* fgets_unlimited(PHYSFS_file *f);
 char *splitword(char *s, char splitchar);
 
 #endif
index b9a32d0..f245266 100644 (file)
--- a/main/ai.c
+++ b/main/ai.c
@@ -1,4 +1,4 @@
-/* $Id: ai.c,v 1.8 2004-08-28 23:17:45 schaffner Exp $ */
+/* $Id: ai.c,v 1.9 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -23,7 +23,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include <conf.h>
 #endif
 
-char ai_rcsid[] = "$Id: ai.c,v 1.8 2004-08-28 23:17:45 schaffner Exp $";
+char ai_rcsid[] = "$Id: ai.c,v 1.9 2004-12-01 12:48:13 btb Exp $";
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -1579,79 +1579,80 @@ void init_robots_for_level(void)
        Boss_dying_start_time = 0;
 }
 
-int ai_save_state(CFILE *fp)
+int ai_save_state(PHYSFS_file *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;
-       cfwrite(&temp, sizeof(int), 1, fp);
+       PHYSFS_write(fp, &Ai_initialized, sizeof(int), 1);
+       PHYSFS_write(fp, &Overall_agitation, sizeof(int), 1);
+       PHYSFS_write(fp, Ai_local_info, sizeof(ai_local) * MAX_OBJECTS, 1);
+       PHYSFS_write(fp, Point_segs, sizeof(point_seg) * MAX_POINT_SEGS, 1);
+       PHYSFS_write(fp, Ai_cloak_info, sizeof(ai_cloak_info) * MAX_AI_CLOAK_INFO, 1);
+       PHYSFS_write(fp, &Boss_cloak_start_time, sizeof(fix), 1);
+       PHYSFS_write(fp, &Boss_cloak_end_time, sizeof(fix), 1);
+       PHYSFS_write(fp, &Last_teleport_time, sizeof(fix), 1);
+       PHYSFS_write(fp, &Boss_teleport_interval, sizeof(fix), 1);
+       PHYSFS_write(fp, &Boss_cloak_interval, sizeof(fix), 1);
+       PHYSFS_write(fp, &Boss_cloak_duration, sizeof(fix), 1);
+       PHYSFS_write(fp, &Last_gate_time, sizeof(fix), 1);
+       PHYSFS_write(fp, &Gate_interval, sizeof(fix), 1);
+       PHYSFS_write(fp, &Boss_dying_start_time, sizeof(fix), 1);
+       PHYSFS_write(fp, &Boss_dying, sizeof(int), 1);
+       PHYSFS_write(fp, &Boss_dying_sound_playing, sizeof(int), 1);
+       PHYSFS_write(fp, &Boss_hit_time, sizeof(fix), 1);
+       // -- MK, 10/21/95, unused! -- PHYSFS_write(fp, &Boss_been_hit, sizeof(int), 1);
+
+       PHYSFS_write(fp, &Escort_kill_object, sizeof(Escort_kill_object), 1);
+       PHYSFS_write(fp, &Escort_last_path_created, sizeof(Escort_last_path_created), 1);
+       PHYSFS_write(fp, &Escort_goal_object, sizeof(Escort_goal_object), 1);
+       PHYSFS_write(fp, &Escort_special_goal, sizeof(Escort_special_goal), 1);
+       PHYSFS_write(fp, &Escort_goal_index, sizeof(Escort_goal_index), 1);
+       PHYSFS_write(fp, &Stolen_items, sizeof(Stolen_items[0])*MAX_STOLEN_ITEMS, 1);
+
+       {
+               int temp;
+               temp = Point_segs_free_ptr - Point_segs;
+               PHYSFS_write(fp, &temp, sizeof(int), 1);
        }
 
-       cfwrite(&Num_boss_teleport_segs, sizeof(Num_boss_teleport_segs), 1, fp);
-       cfwrite(&Num_boss_gate_segs, sizeof(Num_boss_gate_segs), 1, fp);
+       PHYSFS_write(fp, &Num_boss_teleport_segs, sizeof(Num_boss_teleport_segs), 1);
+       PHYSFS_write(fp, &Num_boss_gate_segs, sizeof(Num_boss_gate_segs), 1);
 
        if (Num_boss_gate_segs)
-               cfwrite(Boss_gate_segs, sizeof(Boss_gate_segs[0]), Num_boss_gate_segs, fp);
+               PHYSFS_write(fp, Boss_gate_segs, sizeof(Boss_gate_segs[0]), Num_boss_gate_segs);
 
        if (Num_boss_teleport_segs)
-               cfwrite(Boss_teleport_segs, sizeof(Boss_teleport_segs[0]), Num_boss_teleport_segs, fp);
+               PHYSFS_write(fp, Boss_teleport_segs, sizeof(Boss_teleport_segs[0]), Num_boss_teleport_segs);
 
        return 1;
 }
 
-int ai_restore_state(CFILE *fp, int version)
+int ai_restore_state(PHYSFS_file *fp, int version)
 {
-       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);
+       PHYSFS_read(fp, &Ai_initialized, sizeof(int), 1);
+       PHYSFS_read(fp, &Overall_agitation, sizeof(int), 1);
+       PHYSFS_read(fp, Ai_local_info, sizeof(ai_local) * MAX_OBJECTS, 1);
+       PHYSFS_read(fp, Point_segs, sizeof(point_seg) * MAX_POINT_SEGS, 1);
+       PHYSFS_read(fp, Ai_cloak_info, sizeof(ai_cloak_info) * MAX_AI_CLOAK_INFO, 1);
+       PHYSFS_read(fp, &Boss_cloak_start_time, sizeof(fix), 1);
+       PHYSFS_read(fp, &Boss_cloak_end_time, sizeof(fix), 1);
+       PHYSFS_read(fp, &Last_teleport_time, sizeof(fix), 1);
+       PHYSFS_read(fp, &Boss_teleport_interval, sizeof(fix), 1);
+       PHYSFS_read(fp, &Boss_cloak_interval, sizeof(fix), 1);
+       PHYSFS_read(fp, &Boss_cloak_duration, sizeof(fix), 1);
+       PHYSFS_read(fp, &Last_gate_time, sizeof(fix), 1);
+       PHYSFS_read(fp, &Gate_interval, sizeof(fix), 1);
+       PHYSFS_read(fp, &Boss_dying_start_time, sizeof(fix), 1);
+       PHYSFS_read(fp, &Boss_dying, sizeof(int), 1);
+       PHYSFS_read(fp, &Boss_dying_sound_playing, sizeof(int), 1);
+       PHYSFS_read(fp, &Boss_hit_time, sizeof(fix), 1);
+       // -- MK, 10/21/95, unused! -- PHYSFS_read(fp, &Boss_been_hit, sizeof(int), 1);
 
        if (version >= 8) {
-               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);
+               PHYSFS_read(fp, &Escort_kill_object, sizeof(Escort_kill_object), 1);
+               PHYSFS_read(fp, &Escort_last_path_created, sizeof(Escort_last_path_created), 1);
+               PHYSFS_read(fp, &Escort_goal_object, sizeof(Escort_goal_object), 1);
+               PHYSFS_read(fp, &Escort_special_goal, sizeof(Escort_special_goal), 1);
+               PHYSFS_read(fp, &Escort_goal_index, sizeof(Escort_goal_index), 1);
+               PHYSFS_read(fp, &Stolen_items, sizeof(Stolen_items[0]) * MAX_STOLEN_ITEMS, 1);
        } else {
                int i;
 
@@ -1669,20 +1670,20 @@ int ai_restore_state(CFILE *fp, int version)
 
        if (version >= 15) {
                int temp;
-               cfread(&temp, sizeof(int), 1, fp);
+               PHYSFS_read(fp, &temp, sizeof(int), 1);
                Point_segs_free_ptr = &Point_segs[temp];
        } else
                ai_reset_all_paths();
 
        if (version >= 21) {
-               cfread(&Num_boss_teleport_segs, sizeof(Num_boss_teleport_segs), 1, fp);
-               cfread(&Num_boss_gate_segs, sizeof(Num_boss_gate_segs), 1, fp);
+               PHYSFS_read(fp, &Num_boss_teleport_segs, sizeof(Num_boss_teleport_segs), 1);
+               PHYSFS_read(fp, &Num_boss_gate_segs, sizeof(Num_boss_gate_segs), 1);
 
                if (Num_boss_gate_segs)
-                       cfread(Boss_gate_segs, sizeof(Boss_gate_segs[0]), Num_boss_gate_segs, fp);
+                       PHYSFS_read(fp, Boss_gate_segs, sizeof(Boss_gate_segs[0]), Num_boss_gate_segs);
 
                if (Num_boss_teleport_segs)
-                       cfread(Boss_teleport_segs, sizeof(Boss_teleport_segs[0]), Num_boss_teleport_segs, fp);
+                       PHYSFS_read(fp, Boss_teleport_segs, sizeof(Boss_teleport_segs[0]), Num_boss_teleport_segs);
        } else {
                // -- Num_boss_teleport_segs = 1;
                // -- Num_boss_gate_segs = 1;
index abe6f03..15002c2 100644 (file)
--- a/main/ai.h
+++ b/main/ai.h
@@ -1,4 +1,4 @@
-/* $Id: ai.h,v 1.8 2004-08-28 23:17:45 schaffner Exp $ */
+/* $Id: ai.h,v 1.9 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -321,8 +321,8 @@ extern void init_thief_for_level();
 
 extern int Escort_goal_object;
 
-extern int ai_save_state(CFILE *fp);
-extern int ai_restore_state(CFILE *fp, int version);
+extern int ai_save_state(PHYSFS_file * fp);
+extern int ai_restore_state(PHYSFS_file *fp, int version);
 
 extern int Buddy_objnum, Buddy_allowed_to_talk;
 
index 81b264e..e36bdc7 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: cntrlcen.c,v 1.17 2004-10-09 15:59:28 schaffner Exp $ */
+/* $Id: cntrlcen.c,v 1.18 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -23,7 +23,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: cntrlcen.c,v 1.17 2004-10-09 15:59:28 schaffner Exp $";
+static char rcsid[] = "$Id: cntrlcen.c,v 1.18 2004-12-01 12:48:13 btb Exp $";
 #endif
 
 #ifdef WINDOWS
@@ -270,9 +270,9 @@ void do_controlcen_destroyed_stuff(object *objp)
        if (Current_level_num < 0) {
                int     rval;
                #ifndef MACINTOSH
-               rval = cfile_delete("secret.sgc");
+               rval = !PHYSFS_delete("secret.sgc");
                #else
-               rval = cfile_delete(":Players:secret.sgc");
+               rval = !PHYSFS_delete("Players/secret.sgc");
                #endif
                mprintf((0, "Deleting secret.sgc, return value = %i\n", rval));
        }
index edbe12d..f59da4d 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: config.c,v 1.13 2004-10-14 16:30:56 schaffner Exp $ */
+/* $Id: config.c,v 1.14 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -38,6 +38,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include <string.h>
 #include <ctype.h>
 
+#include <physfs.h>
+
 #include "pstypes.h"
 #include "game.h"
 #include "menu.h"
@@ -53,10 +55,11 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include "mono.h"
 #include "pa_enabl.h"
 
+#include "physfsx.h"
 
 
 #ifdef RCS
-static char rcsid[] = "$Id: config.c,v 1.13 2004-10-14 16:30:56 schaffner Exp $";
+static char rcsid[] = "$Id: config.c,v 1.14 2004-12-01 12:48:13 btb Exp $";
 #endif
 
 ubyte Config_digi_volume = 8;
@@ -193,7 +196,7 @@ void CheckMovieAttributes()
 
 int ReadConfigFile()
 {
-       CFILE *infile;
+       PHYSFS_file *infile;
        char line[80], *token, *value, *ptr;
        ubyte gamma;
        int joy_axis_min[7];
@@ -234,15 +237,15 @@ int ReadConfigFile()
        SaveMovieHires = MovieHires;
        save_redbook_enabled = Redbook_enabled;
 
-       infile = cfopen("descent.cfg", "rt");
+       infile = PHYSFS_openRead("descent.cfg");
        if (infile == NULL) {
                WIN(CheckMovieAttributes());
                return 1;
        }
-       while (!cfeof(infile))
+       while (!PHYSFS_eof(infile))
        {
                memset(line, 0, 80);
-               cfgets(line, 80, infile);
+               PHYSFSX_gets(infile, line);
                ptr = &(line[0]);
                while (isspace(*ptr))
                        ptr++;
@@ -337,7 +340,7 @@ int ReadConfigFile()
                }
        }
 
-       cfclose(infile);
+       PHYSFS_close(infile);
 
 #ifdef WINDOWS
        for (i=0;i<4;i++)
@@ -410,12 +413,12 @@ int ReadConfigFile()
        } else
                digi_driver_board               = digi_driver_board;
 #else
-       infile = cfopen("descentw.cfg", "rt");
+       infile = PHYSFS_openRead("descentw.cfg");
        if (infile) {
-               while (!cfeof(infile))
+               while (!PHYSFS_eof(infile))
                {
                        memset(line, 0, 80);
-                       cfgets(line, 80, infile);
+                       PHYSFSX_gets(infile, line);
                        ptr = &(line[0]);
                        while (isspace(*ptr))
                                ptr++;
@@ -433,7 +436,7 @@ int ReadConfigFile()
                                }
                        }
                }
-               cfclose(infile);
+               PHYSFS_close(infile);
        }
 #endif
 
@@ -442,7 +445,7 @@ int ReadConfigFile()
 
 int WriteConfigFile()
 {
-       CFILE *infile;
+       PHYSFS_file *infile;
        char str[256];
        int joy_axis_min[7];
        int joy_axis_center[7];
@@ -460,66 +463,66 @@ int WriteConfigFile()
    }
 #endif
 
-       infile = cfopen("descent.cfg", "wt");
+       infile = PHYSFS_openWrite("descent.cfg");
        if (infile == NULL) {
                return 1;
        }
        /*sprintf (str, "%s=0x%x\n", digi_dev8_str, Config_digi_type);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=0x%x\n", digi_dev16_str, digi_driver_board_16);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=0x%x\n", digi_port_str, digi_driver_port);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", digi_irq_str, digi_driver_irq);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", digi_dma8_str, Config_digi_dma);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", digi_dma16_str, digi_driver_dma_16);
-       cfputs(str, infile);*/
+       PHYSFSX_puts(infile, str);*/
        sprintf (str, "%s=%d\n", digi_volume_str, Config_digi_volume);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        /*sprintf (str, "%s=0x%x\n", midi_dev_str, Config_midi_type);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=0x%x\n", midi_port_str, digi_midi_port);
-       cfputs(str, infile);*/
+       PHYSFSX_puts(infile, str);*/
        sprintf (str, "%s=%d\n", midi_volume_str, Config_midi_volume);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", redbook_enabled_str, FindArg("-noredbook")?save_redbook_enabled:Redbook_enabled);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", redbook_volume_str, Config_redbook_volume);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", stereo_rev_str, Config_channels_reversed);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", gamma_level_str, gamma);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        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);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
 
        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] );
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        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] );
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        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] );
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
 
        sprintf (str, "%s=%s\n", last_player_str, Players[Player_num].callsign );
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%s\n", last_mission_str, config_last_mission );
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", config_vr_type_str, Config_vr_type );
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", config_vr_resolution_str, Config_vr_resolution );
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", config_vr_tracking_str, Config_vr_tracking );
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
        sprintf (str, "%s=%d\n", movie_hires_str, (FindArg("-nohires") || FindArg("-nohighres") || FindArg("-lowresmovies"))?SaveMovieHires:MovieHires);
-       cfputs(str, infile);
+       PHYSFSX_puts(infile, str);
 
-       cfclose(infile);
+       PHYSFS_close(infile);
 
 #ifdef WINDOWS
 {
@@ -586,7 +589,7 @@ int WriteConfigFile()
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: config.c,v 1.13 2004-10-14 16:30:56 schaffner Exp $";
+static char rcsid[] = "$Id: config.c,v 1.14 2004-12-01 12:48:13 btb Exp $";
 #endif
 
 #define MAX_CTB_LEN    512
index dc46f74..7fcb210 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: gameseq.c,v 1.40 2004-11-26 09:45:29 btb Exp $ */
+/* $Id: gameseq.c,v 1.41 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -24,7 +24,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-char gameseq_rcsid[] = "$Id: gameseq.c,v 1.40 2004-11-26 09:45:29 btb Exp $";
+char gameseq_rcsid[] = "$Id: gameseq.c,v 1.41 2004-12-01 12:48:13 btb Exp $";
 #endif
 
 #ifdef WINDOWS
@@ -703,9 +703,6 @@ int MakeNewPlayerFile(int allow_abort)
        char filename[14];
        newmenu_item m;
        char text[CALLSIGN_LEN+1]="";
-#if 0
-       FILE *fp;
-#endif
 
        strncpy(text, Players[Player_num].callsign,CALLSIGN_LEN);
 
@@ -725,30 +722,11 @@ try_again:
                goto try_again;
        sprintf( filename, "%s.plr", text );
 
-#if 0
-       fp = fopen( filename, "rb" );
-
-#ifndef MACINTOSH
-       //if the callsign is the name of a tty device, prepend a char
-       if (fp && isatty(fileno(fp))) {
-               fclose(fp);
-               sprintf(filename,"$%.7s.plr",text);
-               fp = fopen(filename,"rb");
-       }
-#endif
-       
-       if ( fp )       {
-               nm_messagebox(NULL, 1, TXT_OK, "%s '%s' %s", TXT_PLAYER, text, TXT_ALREADY_EXISTS );
-               fclose(fp);
-               goto try_again;
-       }
-#else
-       if (cfexist(filename))
+       if (PHYSFS_exists(filename))
        {
                nm_messagebox(NULL, 1, TXT_OK, "%s '%s' %s", TXT_PLAYER, text, TXT_ALREADY_EXISTS );
                goto try_again;
        }
-#endif
 
        if ( !new_player_config() )
                goto try_again;                 // They hit Esc during New player config
@@ -795,9 +773,8 @@ do_menu_again:
        ;
 
 #ifndef MACINTOSH
-       if (!newmenu_get_filename( TXT_SELECT_PILOT, "*.plr", filename, allow_abort_flag ))     {
+       if (!newmenu_get_filename(TXT_SELECT_PILOT, "plr", filename, allow_abort_flag))
                goto do_menu_again; //return 0;         // They hit Esc in file selector
-       }
 #else
        #ifndef APPLE_DEMO
        if (!newmenu_get_filename( TXT_SELECT_PILOT, ".\\Players\\*.plr", filename, allow_abort_flag )) {
@@ -807,7 +784,6 @@ do_menu_again:
        newmenu_get_filename( "Select Pilot", ".\\Players\\*.plr", filename, 0 );               // no abort allowed ever -- and change title of menubox
        #endif
 #endif
-
        if ( filename[0] == '<' )       {
                // They selected 'create new pilot'
                if (!MakeNewPlayerFile(allow_abort_flag))
@@ -1169,7 +1145,7 @@ int p_secret_level_destroyed(void)
        if (First_secret_visit) {
                return 0;               //      Never been there, can't have been destroyed.
        } else {
-               if (cfexist(SECRETC_FILENAME))
+               if (PHYSFS_exists(SECRETC_FILENAME))
                {
                        return 0;
                } else {
@@ -1235,7 +1211,7 @@ void StartNewLevelSecret(int level_num, int page_in_textures)
                if (First_secret_visit) {
                        do_secret_message(TXT_SECRET_EXIT);
                } else {
-                       if (cfexist(SECRETC_FILENAME))
+                       if (PHYSFS_exists(SECRETC_FILENAME))
                        {
                                do_secret_message(TXT_SECRET_EXIT);
                        } else {
@@ -1282,7 +1258,7 @@ void StartNewLevelSecret(int level_num, int page_in_textures)
                reset_special_effects();
                StartSecretLevel();
        } else {
-               if (cfexist(SECRETC_FILENAME))
+               if (PHYSFS_exists(SECRETC_FILENAME))
                {
                        int     pw_save, sw_save;
 
@@ -1336,7 +1312,7 @@ void ExitSecretLevel(void)
                state_save_all(0, 2, SECRETC_FILENAME);
        }
 
-       if (cfexist(SECRETB_FILENAME))
+       if (PHYSFS_exists(SECRETB_FILENAME))
        {
                int     pw_save, sw_save;
 
@@ -1812,7 +1788,7 @@ void DoPlayerDead()
                died_in_mine_message(); // Give them some indication of what happened
 
                if (Current_level_num < 0) {
-                       if (cfexist(SECRETB_FILENAME))
+                       if (PHYSFS_exists(SECRETB_FILENAME))
                        {
                                returning_to_level_message();
                                state_restore_all(1, 2, SECRETB_FILENAME);                      //      2 means you died
@@ -1833,7 +1809,7 @@ void DoPlayerDead()
                }
 
        } else if (Current_level_num < 0) {
-               if (cfexist(SECRETB_FILENAME))
+               if (PHYSFS_exists(SECRETB_FILENAME))
                {
                        returning_to_level_message();
                        if (!Control_center_destroyed)
@@ -2089,6 +2065,7 @@ void ShowLevelIntro(int level_num)
                                }
 #endif
 
+#if 0
                                if (robot_movies)
                                {
                                        int hires_save=MenuHiresAvailable;
@@ -2101,9 +2078,12 @@ void ShowLevelIntro(int level_num)
                                                        Screen_mode = -1;               //force reset
 
                                        }
+#endif
                                        do_briefing_screens ("robot.tex",level_num);
+#if 0
                                        MenuHiresAvailable = hires_save;
                                }
+#endif
 
                        }
                }
index f709881..48d3fa0 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: inferno.c,v 1.92 2004-11-27 11:55:10 btb Exp $ */
+/* $Id: inferno.c,v 1.93 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -41,6 +41,8 @@ char copyright[] = "DESCENT II  COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPOR
 #include <sys/types.h>
 #endif
 
+#include <physfs.h>
+
 #include "pstypes.h"
 #include "strutil.h"
 #include "console.h"
@@ -95,7 +97,6 @@ char copyright[] = "DESCENT II  COPYRIGHT (C) 1994-1996 PARALLAX SOFTWARE CORPOR
 #include "gamepal.h"
 #include "mission.h"
 #include "movie.h"
-#include "d_io.h"
 
 // #  include "3dfx_des.h"
 
@@ -148,7 +149,9 @@ int Inferno_is_800x600_available = 0;
 //--unused-- int Cyberman_installed=0;                 // SWIFT device present
 ubyte CybermouseActive=0;
 
+#ifdef __WATCOMC__
 int __far descent_critical_error_handler( unsigned deverr, unsigned errcode, unsigned __far * devhdr );
+#endif
 
 void check_joystick_calibration(void);
 
@@ -459,8 +462,6 @@ int start_net_immediately = 0;
 //char *start_with_mission_name;
 //end this section addition
 
-int open_movie_file(char *filename,int must_have);
-
 #if defined(POLY_ACC)
 #define MENU_HIRES_MODE SM_640x480x15xPA
 #else
@@ -482,34 +483,67 @@ int main(int argc, char *argv[])
        int i, t;
        ubyte title_pal[768];
 
+       PHYSFS_init(argv[0]);
+       PHYSFS_permitSymbolicLinks(1);
+
        con_init();  // Initialise the console
        mem_init();
 
        error_init(NULL, NULL);
 
+       PHYSFS_addToSearchPath(PHYSFS_getBaseDir(), 1);
        InitArgs( argc,argv );
 
+       if ((t = FindArg("-userdir"))
 #ifdef __unix__
+        || 1   // or if it's a unix platform
+#endif
+        )
        {
-               char *home = getenv("HOME");
-
-               if ((t = FindArg("-userdir")))
-                       chdir(Args[t+1]);
+               // This stuff below seems overly complicated - brad
 
-               else if (home) {
-                       char buf[PATH_MAX + 5];
+               char *path = Args[t+1];
+               char fullPath[PATH_MAX + 5];
 
-                       strcpy(buf, home);
-                       strcat(buf, "/.d2x");
-                       if (chdir(buf)) {
-                               mkdir(buf, 0755);
-                               if (chdir(buf))
-                                       fprintf(stderr, "Cannot change to $HOME/.d2x\n");
-                       }
+#ifdef __unix__
+               if (!t)
+                       path = "~/.d2x";
+#endif
+               PHYSFS_removeFromSearchPath(PHYSFS_getBaseDir());
+               
+               if (path[0] == '~') // yes, this tilde can be put before non-unix paths.
+               {
+                       const char *home = PHYSFS_getUserDir();
+                       
+                       strcpy(fullPath, home); // prepend home to the path
+                       path++;
+                       if (*path == *PHYSFS_getDirSeparator())
+                               path++;
+                       strncat(fullPath, path, PATH_MAX + 5 - strlen(home));
+               }
+               else
+                       strncpy(fullPath, path, PATH_MAX + 5);
+               
+               PHYSFS_setWriteDir(fullPath);
+               if (!PHYSFS_getWriteDir())  // need to make it
+               {
+                       PHYSFS_mkdir(fullPath);
+                       PHYSFS_setWriteDir(fullPath);
                }
+                       
+               PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 1);
+               AppendArgs();
        }
-#endif
 
+       if (!PHYSFS_getWriteDir())
+       {
+               PHYSFS_setWriteDir(PHYSFS_getBaseDir());
+               if (!PHYSFS_getWriteDir())
+                       Error("can't set write dir\n");
+               else
+                       PHYSFS_addToSearchPath(PHYSFS_getWriteDir(), 0);
+       }
+       
        if (FindArg("-debug"))
                con_threshold.value = (float)2;
        else if (FindArg("-verbose"))
@@ -517,15 +551,12 @@ int main(int argc, char *argv[])
 
        //tell cfile where hogdir is
        if ((t=FindArg("-hogdir")))
-               cfile_use_alternate_hogdir(Args[t+1]);
+               PHYSFS_addToSearchPath(Args[t + 1], 1);
 #ifdef __unix__
        else if (!FindArg("-nohogdir"))
-               cfile_use_alternate_hogdir(SHAREPATH);
+               PHYSFS_addToSearchPath(SHAREPATH, 1);
 #endif
 
-       //tell cfile about our counter
-       cfile_set_critical_error_counter_ptr(&descent_critical_error);
-
        if (! cfile_init("descent2.hog"))
                if (! cfile_init("d2demo.hog"))
                        Warning("Could not find a valid hog file (descent2.hog or d2demo.hog)\nPossible locations are:\n"
@@ -565,6 +596,23 @@ int main(int argc, char *argv[])
        con_printf(CON_NORMAL, TXT_HELP, PROGNAME);             //help message has %s for program name
        con_printf(CON_NORMAL, "\n");
 
+       {
+               char **i, **list;
+
+               for (i = PHYSFS_getSearchPath(); *i != NULL; i++)
+                       con_printf(CON_VERBOSE, "PHYSFS: [%s] is in the search path.\n", *i);
+
+               list = PHYSFS_getCdRomDirs();
+               for (i = list; *i != NULL; i++)
+                       con_printf(CON_VERBOSE, "PHYSFS: cdrom dir [%s] is available.\n", *i);
+               PHYSFS_freeList(list);
+
+               list = PHYSFS_enumerateFiles("");
+               for (i = list; *i != NULL; i++)
+                       con_printf(CON_DEBUG, "PHYSFS: * We've got [%s].\n", *i);
+               PHYSFS_freeList(list);
+       }
+
        //(re)added Mar 30, 2003 Micah Lieske - Allow use of 22K sound samples again.
        if(FindArg("-sound22k"))
        {
@@ -788,7 +836,7 @@ int main(int argc, char *argv[])
                        if (!played) {
                 strcpy(filename,MenuHires?"pre_i1b.pcx":"pre_i1.pcx");
 
-                               while (cfexist(filename))
+                               while (PHYSFS_exists(filename))
                                {
                                        show_title_screen( filename, 1, 0 );
                     filename[5]++;
@@ -844,14 +892,15 @@ int main(int argc, char *argv[])
                {       //show bundler movie or screens
 
                        char filename[FILENAME_LEN];
-                       int movie_handle;
+                       PHYSFS_file *movie_handle;
 
                        played=MOVIE_NOT_PLAYED;        //default is not played
 
                        //check if OEM movie exists, so we don't stop the music if it doesn't
-                       movie_handle = open_movie_file("oem.mve",0);
-                       if (movie_handle != -1) {
-                               close(movie_handle);
+                       movie_handle = PHYSFS_openRead("oem.mve");
+                       if (movie_handle)
+                       {
+                               PHYSFS_close(movie_handle);
                                played = PlayMovie("oem.mve",0);
                                song_playing = 0;               //movie will kill sound
                        }
@@ -859,7 +908,7 @@ int main(int argc, char *argv[])
                        if (!played) {
                                strcpy(filename,MenuHires?"oem1b.pcx":"oem1.pcx");
 
-                               while (cfexist(filename))
+                               while (PHYSFS_exists(filename))
                                {
                                        show_title_screen( filename, 1, 0 );
                                        filename[3]++;
index 56da841..f20b6d3 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: kludge.c,v 1.17 2004-11-29 05:25:58 btb Exp $ */
+/* $Id: kludge.c,v 1.18 2004-12-01 12:48:13 btb Exp $ */
 
 /*
  *
@@ -17,7 +17,6 @@
 #include "gr.h"
 #include "pstypes.h"
 #include "maths.h"
-#include "findfile.h"
 
 extern int VGA_current_mode;
 
index 9dae624..9cc6d27 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: menu.c,v 1.38 2004-10-23 18:59:02 schaffner Exp $ */
+/* $Id: menu.c,v 1.39 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -379,7 +379,7 @@ void do_option ( int select)
                case MENU_DEMO_PLAY:
                {
                        char demo_file[16];
-                       if (newmenu_get_filename( TXT_SELECT_DEMO, DEMO_DIR "*.dem", demo_file, 1 ))
+                       if (newmenu_get_filename(TXT_SELECT_DEMO, "dem", demo_file, 1))
                                newdemo_start_playback(demo_file);
                        break;
                }
index 880a673..410f654 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: mission.c,v 1.31 2004-11-27 05:10:33 btb Exp $ */
+/* $Id: mission.c,v 1.32 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -39,11 +39,11 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include "songs.h"
 #include "mono.h"
 #include "error.h"
-#include "findfile.h"
 #include "config.h"
 #include "newmenu.h"
 #include "text.h"
 #include "u_mem.h"
+#include "ignorecase.h"
 
 //values for d1 built-in mission
 #define BIM_LAST_LEVEL          27
@@ -445,22 +445,27 @@ void add_builtin_mission_to_list(int *count, char *name)
 }
 
 
-void add_missions_to_list(char *search_name, int *count, int anarchy_mode)
+void add_missions_to_list(int *count, int anarchy_mode)
 {
-       FILEFINDSTRUCT find;
-       if( !FileFindFirst( search_name, &find ) ) {
-               do      {
-                       if (read_mission_file( find.name, *count, ML_MISSIONDIR )) {
+       char **find, **i, *ext;
 
+       find = PHYSFS_enumerateFiles(MISSION_DIR);
+
+       for (i = find; *i != NULL; i++)
+       {
+               ext = strrchr(*i, '.');
+               if (ext && (!strnicmp(ext, ".msn", 4) || !strnicmp(ext, ".mn2", 4)))
+                       if (read_mission_file(*i, *count, ML_MISSIONDIR))
                                if (anarchy_mode || !Mission_list[*count].anarchy_only_flag)
                                        ++(*count);
-                       }
-
-               } while( !FileFindNext( &find ) && *count < MAX_MISSIONS);
-               FileFindClose();
                if (*count >= MAX_MISSIONS)
+               {
                        mprintf((0, "Warning: more missions than d2x can handle\n"));
+                       break;
+               }
        }
+
+       PHYSFS_freeList(find);
 }
 
 /* move <mission_name> to <place> on mission list, increment <place> */
@@ -499,8 +504,10 @@ void free_mission(void)
 //in the list.  If anarchy_mode is set, then also add anarchy-only missions.
 
 extern char CDROM_dir[];
+#if 0
 extern char AltHogDir[];
 extern char AltHogdir_initialized;
+#endif
 
 int build_mission_list(int anarchy_mode)
 {
@@ -525,19 +532,8 @@ int build_mission_list(int anarchy_mode)
 
        add_builtin_mission_to_list(&count, builtin_mission_filename);  //read built-in first
        add_d1_builtin_mission_to_list(&count);
-       add_missions_to_list(MISSION_DIR "*.mn2", &count, anarchy_mode);
-       add_missions_to_list(MISSION_DIR "*.msn", &count, anarchy_mode);
-
-       if (AltHogdir_initialized) {
-               char search_name[PATH_MAX + 5];
-               strcpy(search_name, AltHogDir);
-               strcat(search_name, "/" MISSION_DIR "*.mn2");
-               add_missions_to_list(search_name, &count, anarchy_mode);
-               strcpy(search_name, AltHogDir);
-               strcat(search_name, "/" MISSION_DIR "*.msn");
-               add_missions_to_list(search_name, &count, anarchy_mode);
-       }
-
+       add_missions_to_list(&count, anarchy_mode);
+       
        // move original missions (in story-chronological order)
        // to top of mission list
        top_place = 0;
@@ -588,7 +584,7 @@ int load_mission(int mission_num)
 
     // for Descent 1 missions, load descent.hog
     if (EMULATING_D1) {
-        if (!cfile_use_descent1_hogfile("descent.hog"))
+        if (!cfile_init("descent.hog"))
             Warning("descent.hog not available, this mission may be missing some files required for briefings and exit sequence\n");
         if (!stricmp(Current_mission_filename, D1_MISSION_FILENAME))
             return load_mission_d1();
@@ -636,6 +632,8 @@ int load_mission(int mission_num)
        else
                strcat(buf,".msn");
 
+       PHYSFSEXT_locateCorrectCase(buf);
+
        mfile = cfopen(buf,"rb");
        if (mfile == NULL) {
         free_mission();
@@ -647,7 +645,9 @@ int load_mission(int mission_num)
 
         strcpy(buf+strlen(buf)-4,".hog");              //change extension
 
-        found_hogfile = cfile_use_alternate_hogfile(buf);
+               PHYSFSEXT_locateCorrectCase(buf);
+
+               found_hogfile = cfile_init(buf);
 
 #ifdef RELEASE                         //for release, require mission to be in hogfile
         if (! found_hogfile) {
@@ -690,7 +690,7 @@ int load_mission(int mission_num)
                                while (*(++bufp) == ' ')
                                        ;
 
-                       cfile_use_alternate_hogfile(bufp);
+                       cfile_init(bufp);
                        mprintf((0, "Hog file override = [%s]\n", bufp));
                }
                else if (istok(buf,"briefing")) {
@@ -773,7 +773,6 @@ int load_mission(int mission_num)
                sprintf(t,"%s.ham",Current_mission_filename);
                bm_read_extra_robots(t, Current_mission->enhanced);
                strncpy(t,Current_mission_filename,6);
-               strcat(t,"-l.mvl");
                init_extra_robot_movie(t);
        }
 
index 0fde764..b52bce5 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: movie.c,v 1.36 2004-08-06 20:36:02 schaffner Exp $ */
+/* $Id: movie.c,v 1.37 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -23,7 +23,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: movie.c,v 1.36 2004-08-06 20:36:02 schaffner Exp $";
+static char rcsid[] = "$Id: movie.c,v 1.37 2004-12-01 12:48:13 btb Exp $";
 #endif
 
 #define DEBUG_LEVEL CON_NORMAL
@@ -60,6 +60,7 @@ static char rcsid[] = "$Id: movie.c,v 1.36 2004-08-06 20:36:02 schaffner Exp $";
 #include "libmve.h"
 #include "text.h"
 #include "screens.h"
+#include "physfsrwops.h"
 
 extern int MenuHiresAvailable;
 extern char CDROM_dir[];
@@ -82,47 +83,24 @@ subtitle Subtitles[MAX_SUBTITLES];
 int Num_subtitles;
 
 // Movielib data
-typedef struct {
-       char name[FILENAME_LEN];
-       int offset,len;
-} ml_entry;
-
-#define MLF_ON_CD    1
-#define MAX_MOVIES_PER_LIB    50    //determines size of malloc
-
-typedef struct {
-       char     name[100]; //[FILENAME_LEN];
-       int      n_movies;
-       ubyte    flags,pad[3];
-       ml_entry *movies;
-} movielib;
 
 #ifdef D2_OEM
-char movielib_files[][FILENAME_LEN] = {"intro-l.mvl","other-l.mvl","robots-l.mvl","oem-l.mvl"};
+char movielib_files[5][FILENAME_LEN] = {"intro","other","robots","oem"};
 #else
-char movielib_files[][FILENAME_LEN] = {"intro-l.mvl","other-l.mvl","robots-l.mvl"};
+char movielib_files[4][FILENAME_LEN] = {"intro","other","robots"};
 #endif
 
-#define N_BUILTIN_MOVIE_LIBS (sizeof(movielib_files)/sizeof(*movielib_files))
-#define N_MOVIE_LIBS (N_BUILTIN_MOVIE_LIBS+1)
+#define N_MOVIE_LIBS (sizeof(movielib_files) / sizeof(*movielib_files))
+#define N_BUILTIN_MOVIE_LIBS (N_MOVIE_LIBS - 1)
 #define EXTRA_ROBOT_LIB N_BUILTIN_MOVIE_LIBS
-movielib *movie_libs[N_MOVIE_LIBS];
-
-
-//do we have the robot movies available
-int robot_movies = 0; //0 means none, 1 means lowres, 2 means hires
 
 int MovieHires = 1;   //default is highres
 
-CFILE *RoboFile = NULL;
-int RoboFilePos = 0;
+SDL_RWops *RoboFile;
 
 // Function Prototypes
 int RunMovie(char *filename, int highres_flag, int allow_abort,int dx,int dy);
 
-CFILE *open_movie_file(char *filename, int must_have);
-int reset_movie_file(CFILE *handle);
-
 void change_filename_ext( char *dest, char *src, char *ext );
 void decode_text_line(char *p);
 void draw_subtitles(int frame_num);
@@ -145,7 +123,7 @@ void MPlayFree(void *p)
 unsigned int FileRead(void *handle, void *buf, unsigned int count)
 {
     unsigned numread;
-    numread = cfread(buf, 1, count, (CFILE *)handle);
+    numread = SDL_RWread((SDL_RWops *)handle, buf, 1, count);
     return (numread == count);
 }
 
@@ -160,10 +138,8 @@ int PlayMovie(const char *filename, int must_have)
        char name[FILENAME_LEN],*p;
        int c, ret;
 
-#ifndef RELEASE
        if (FindArg("-nomovies"))
                return MOVIE_NOT_PLAYED;
-#endif
 
        strcpy(name,filename);
 
@@ -312,7 +288,7 @@ void clear_pause_message()
 //returns status.  see movie.h
 int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy)
 {
-       CFILE *filehndl;
+       SDL_RWops *filehndl;
        int result=1,aborted=0;
        int track = 0;
        int frame_num;
@@ -325,12 +301,12 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy)
 
        // Open Movie file.  If it doesn't exist, no movie, just return.
 
-       filehndl = open_movie_file(filename,must_have);
+       filehndl = PHYSFSRWOPS_openRead(filename);
 
-       if (filehndl == NULL)
+       if (!filehndl)
        {
                if (must_have)
-                       con_printf(CON_NORMAL, "movie: RunMovie: Cannot open movie <%s>\n",filename);
+                       Warning("movie: RunMovie: Cannot open movie <%s>: %s\n", filename, PHYSFS_getLastError());
                return MOVIE_NOT_PLAYED;
        }
 
@@ -359,6 +335,11 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy)
                return MOVIE_NOT_PLAYED;
        }
 
+#if !defined(POLY_ACC)
+       MVE_sfCallbacks(MovieShowFrame);
+       MVE_palCallbacks(MovieSetPalette);
+#endif
+
        frame_num = 0;
 
        FontHires = FontHiresAvailable && hires_flag;
@@ -400,7 +381,7 @@ int RunMovie(char *filename, int hires_flag, int must_have,int dx,int dy)
 
     MVE_rmEndMovie();
 
-       cfclose(filehndl);                           // Close Movie File
+       SDL_FreeRW(filehndl);                           // Close Movie File
 
        // Restore old graphic state
 
@@ -441,8 +422,9 @@ int RotateRobot()
 
        if (err == MVE_ERR_EOF)     //end of movie, so reset
        {
-               reset_movie_file(RoboFile);
-               if (MVE_rmPrepMovie((void *)RoboFile, MenuHires?280:140, MenuHires?200:80, 0)) {
+               SDL_RWseek(RoboFile, 0, SEEK_SET);
+               if (MVE_rmPrepMovie(RoboFile, MenuHires?280:140, MenuHires?200:80, 0))
+               {
                        Int3();
                        return 0;
                }
@@ -459,7 +441,7 @@ int RotateRobot()
 void DeInitRobotMovie(void)
 {
        MVE_rmEndMovie();
-       cfclose(RoboFile);                           // Close Movie File
+       SDL_FreeRW(RoboFile);                           // Close Movie File
 }
 
 
@@ -472,11 +454,11 @@ int InitRobotMovie(char *filename)
 
        MVE_sndInit(-1);        //tell movies to play no sound for robots
 
-       RoboFile = open_movie_file(filename, 1);
+       RoboFile = PHYSFSRWOPS_openRead(filename);
 
-       if (RoboFile == NULL)
+       if (!RoboFile)
        {
-               Warning("movie: InitRobotMovie: Cannot open movie file <%s>",filename);
+               Warning("movie: InitRobotMovie: Cannot open movie file <%s>: %s\n", filename, PHYSFS_getLastError());
                return MOVIE_NOT_PLAYED;
        }
 
@@ -487,10 +469,6 @@ int InitRobotMovie(char *filename)
                return 0;
        }
 
-       RoboFilePos = cfseek(RoboFile, 0L, SEEK_CUR);
-
-       con_printf(DEBUG_LEVEL, "RoboFilePos=%d!\n", RoboFilePos);
-
        return 1;
 }
 
@@ -658,145 +636,44 @@ void draw_subtitles(int frame_num)
 }
 
 
-movielib *init_new_movie_lib(char *filename, CFILE *fp)
-{
-       int nfiles,offset;
-       int i,n;
-       movielib *table;
-
-       //read movie file header
-
-       nfiles = cfile_read_int(fp);        //get number of files
-
-       //table = d_malloc(sizeof(*table) + sizeof(ml_entry)*nfiles);
-       MALLOC(table, movielib, 1);
-       MALLOC(table->movies, ml_entry, nfiles);
-
-       strcpy(table->name,filename);
-       table->n_movies = nfiles;
-
-       offset = 4+4+nfiles*(13+4);     //id + nfiles + nfiles * (filename + size)
-
-       for (i=0;i<nfiles;i++) {
-               int len;
-
-               n = cfread(table->movies[i].name, 13, 1, fp);
-               if ( n != 1 )
-                       break;          //end of file (probably)
-
-               len = cfile_read_int(fp);
-
-               table->movies[i].len = len;
-               table->movies[i].offset = offset;
-
-               offset += table->movies[i].len;
-
-       }
-
-       cfclose(fp);
-
-       table->flags = 0;
-
-       return table;
-
-}
-
-
-movielib *init_old_movie_lib(char *filename, CFILE *fp)
+void close_movie(char *movielib, int is_robots)
 {
-       int nfiles,size;
-       int i;
-       movielib *table,*table2;
-
-       nfiles = 0;
-
-       //allocate big table
-       table = d_malloc(sizeof(*table) + sizeof(ml_entry)*MAX_MOVIES_PER_LIB);
+       int high_res;
+       char filename[FILENAME_LEN];
 
-       while( 1 ) {
-               int len;
-
-               i = cfread(table->movies[nfiles].name, 13, 1, fp);
-               if ( i != 1 )
-                       break;          //end of file (probably)
-
-               i = cfread(&len, 4, 1, fp);
-               if ( i != 1 )
-                       Error("error reading movie library <%s>",filename);
+       if (is_robots)
+               high_res = MenuHiresAvailable;
+       else
+               high_res = MovieHires;
 
-               table->movies[nfiles].len = INTEL_INT(len);
-               table->movies[nfiles].offset = cftell(fp);
+       sprintf(filename, "%s-%s.mvl", movielib, high_res?"h":"l");
 
-               cfseek(fp, INTEL_INT(len), SEEK_CUR);       //skip data
+       if (!cfile_close(filename))
+       {
+               Warning("Couldn't remove movielib <%s>: %s\n", filename, PHYSFS_getLastError());
+               sprintf(filename, "%s-%s.mvl", movielib, high_res?"l":"h");
 
-               nfiles++;
+               if (!cfile_close(filename))
+                       Warning("Couldn't remove movielib <%s>: %s\n", filename, PHYSFS_getLastError());
        }
-
-       //allocate correct-sized table
-       size = sizeof(*table) + sizeof(ml_entry)*nfiles;
-       table2 = d_malloc(size);
-       memcpy(table2,table,size);
-       d_free(table);
-       table = table2;
-
-       strcpy(table->name,filename);
-
-       table->n_movies = nfiles;
-
-       cfclose(fp);
-
-       table->flags = 0;
-
-       return table;
-
 }
 
-
-//find the specified movie library, and read in list of movies in it
-movielib *init_movie_lib(char *filename)
+void close_movies()
 {
-       //note: this based on cfile_init_hogfile()
-
-       char id[4];
-       CFILE *fp;
-
-       fp = cfopen(filename, "rb");
-
-       if ( fp == NULL )
-               return NULL;
-
-       cfread(id, 4, 1, fp);
-       if ( !strncmp( id, "DMVL", 4 ) )
-               return init_new_movie_lib(filename,fp);
-       else if ( !strncmp( id, "DHF", 3 ) ) {
-               cfseek(fp,-1,SEEK_CUR);         //old file had 3 char id
-               return init_old_movie_lib(filename,fp);
-       }
-       else {
-               cfclose(fp);
-               return NULL;
-       }
-}
+       int i, is_robots;
 
+       for (i = 0 ; i < N_BUILTIN_MOVIE_LIBS ; i++)
+       {
+               if (!strnicmp(movielib_files[i], "robot", 5))
+                       is_robots = 1;
+               else
+                       is_robots = 0;
 
-void close_movie(int i)
-{
-       if (movie_libs[i]) {
-               d_free(movie_libs[i]->movies);
-               d_free(movie_libs[i]);
+               close_movie(movielib_files[i], is_robots);
        }
 }
 
 
-void close_movies()
-{
-       int i;
-
-       for (i=0;i<N_MOVIE_LIBS;i++)
-               close_movie(i);
-}
-
-
 //ask user to put the D2 CD in.
 //returns -1 if ESC pressed, 0 if OK chosen
 //CD may not have been inserted
@@ -856,17 +733,10 @@ int request_cd(void)
 }
 
 
-void init_movie(char *filename, int libnum, int is_robots, int required)
+void init_movie(char *movielib, int is_robots, int required)
 {
-       int high_res, try;
-       char *res = strchr(filename, '.') - 1; // 'h' == high resolution, 'l' == low
-
-#ifndef RELEASE
-       if (FindArg("-nomovies")) {
-               movie_libs[libnum] = NULL;
-               return;
-       }
-#endif
+       int high_res;
+       char filename[FILENAME_LEN];
 
        //for robots, load highres versions if highres menus set
        if (is_robots)
@@ -874,44 +744,19 @@ void init_movie(char *filename, int libnum, int is_robots, int required)
        else
                high_res = MovieHires;
 
-       if (high_res)
-               *res = 'h';
-
-       for (try = 0; (movie_libs[libnum] = init_movie_lib(filename)) == NULL; try++) {
-               char name2[100];
-
-               strcpy(name2,CDROM_dir);
-               strcat(name2,filename);
-               movie_libs[libnum] = init_movie_lib(name2);
-
-               if (movie_libs[libnum] != NULL) {
-                       movie_libs[libnum]->flags |= MLF_ON_CD;
-                       break; // we found our movie on the CD
-               } else {
-                       if (try == 0) { // first try
-                               if (*res == 'h') { // try low res instead
-                                       *res = 'l';
-                                       high_res = 0;
-                               } else if (*res == 'l') { // try high
-                                       *res = 'h';
-                                       high_res = 1;
-                               } else {
-                                       if (required)
-                                               Warning("Cannot open movie file <%s>",filename);
-                                       break;
-                               }
-                       } else { // try == 1
-                               if (required) {
-                                       *res = '*';
-                                       Warning("Cannot open any movie file <%s>", filename);
-                               }
-                               break;
-                       }
-               }
-       }
+       sprintf(filename, "%s-%s.mvl", movielib, high_res?"h":"l");
+
+       if (!cfile_init(filename))
+       {
+               if (required)
+                       Warning("Cannot open movie file <%s>: %s\n", filename, PHYSFS_getLastError());
 
-       if (is_robots && movie_libs[libnum]!=NULL)
-               robot_movies = high_res?2:1;
+               sprintf(filename, "%s-%s.mvl", movielib, high_res?"l":"h");
+
+               if (!cfile_init(filename))
+                       if (required)
+                               Warning("Cannot open movie file <%s>: %s\n", filename, PHYSFS_getLastError());
+       }
 }
 
 
@@ -921,6 +766,9 @@ void init_movies()
        int i;
        int is_robots;
 
+       if (FindArg("-nomovies"))
+               return;
+
        for (i=0;i<N_BUILTIN_MOVIE_LIBS;i++) {
 
                if (!strnicmp(movielib_files[i],"robot",5))
@@ -928,87 +776,27 @@ void init_movies()
                else
                        is_robots = 0;
 
-               init_movie(movielib_files[i],i,is_robots,1);
+               init_movie(movielib_files[i], is_robots, 1);
        }
 
-       movie_libs[EXTRA_ROBOT_LIB] = NULL;
-
        atexit(close_movies);
 }
 
 
-void init_extra_robot_movie(char *filename)
-{
-       close_movie(EXTRA_ROBOT_LIB);
-       init_movie(filename,EXTRA_ROBOT_LIB,1,0);
-}
-
-
-CFILE *movie_handle;
-int movie_start;
-
-//looks through a movie library for a movie file
-//returns filehandle, with fileposition at movie, or -1 if can't find
-CFILE *search_movie_lib(movielib *lib, char *filename, int must_have)
-{
-       int i;
-       CFILE *filehandle;
-
-       if (lib == NULL)
-               return NULL;
-
-       for (i=0;i<lib->n_movies;i++)
-               if (!stricmp(filename,lib->movies[i].name)) {   //found the movie in a library 
-                       int from_cd;
-
-                       from_cd = (lib->flags & MLF_ON_CD);
-
-                       if (from_cd)
-                               songs_stop_redbook();           //ready to read from CD
-
-                       do {            //keep trying until we get the file handle
-
-                               movie_handle = filehandle = cfopen(lib->name, "rb");
-
-                               if (must_have && from_cd && filehandle == NULL)
-                               {   //didn't get file!
-
-                                       if (request_cd() == -1)         //ESC from requester
-                                               break;                                          //bail from here. will get error later
-                               }
-
-                       } while (must_have && from_cd && filehandle == NULL);
-
-                       if (filehandle)
-                               cfseek(filehandle, (movie_start = lib->movies[i].offset), SEEK_SET);
-
-                       return filehandle;
-               }
-
-       return NULL;
-}
-
-
-//returns file handle
-CFILE *open_movie_file(char *filename, int must_have)
+void close_extra_robot_movie(void)
 {
-       CFILE *filehandle;
-       int i;
-
-       for (i=0;i<N_MOVIE_LIBS;i++) {
-               if ((filehandle = search_movie_lib(movie_libs[i], filename, must_have)) != NULL)
-                       return filehandle;
-       }
-
-       return NULL;    //couldn't find it
+       if (strlen(movielib_files[EXTRA_ROBOT_LIB]))
+               if (!cfile_close(movielib_files[EXTRA_ROBOT_LIB]))
+                       Warning("Couldn't remove robot lib: %s\n", PHYSFS_getLastError());
 }
 
-//sets the file position to the start of this already-open file
-int reset_movie_file(CFILE *handle)
+void init_extra_robot_movie(char *movielib)
 {
-       Assert(handle == movie_handle);
-
-       cfseek(handle, movie_start, SEEK_SET);
+       if (FindArg("-nomovies"))
+               return;
 
-       return 0;       //everything is cool
+       close_extra_robot_movie();
+       init_movie(movielib, 1, 0);
+       strcpy(movielib_files[EXTRA_ROBOT_LIB], movielib);
+       atexit(close_extra_robot_movie);
 }
index 27a4742..56a6fa7 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: network.c,v 1.27 2004-10-30 10:30:57 schaffner Exp $ */
+/* $Id: network.c,v 1.28 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -23,7 +23,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: network.c,v 1.27 2004-10-30 10:30:57 schaffner Exp $";
+static char rcsid[] = "$Id: network.c,v 1.28 2004-12-01 12:48:13 btb Exp $";
 #endif
 
 #define PATCH12
@@ -2530,11 +2530,11 @@ void network_process_packet(ubyte *data, int length )
 #ifndef NDEBUG
 void dump_segments()
 {
-       FILE * fp;
+       PHYSFS_file *fp;
 
-       fp = fopen( "TEST.DMP", "wb" );
-       fwrite( Segments, sizeof(segment)*(Highest_segment_index+1),1, fp );    
-       fclose(fp);
+       fp = PHYSFS_openWrite("test.dmp");
+       PHYSFS_write(fp, Segments, sizeof(segment), Highest_segment_index + 1);
+       PHYSFS_close(fp);
        mprintf( (0, "SS=%d\n", sizeof(segment) ));
 }
 #endif
index 876cc92..dfd0799 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: newdemo.c,v 1.17 2004-08-28 23:17:45 schaffner Exp $ */
+/* $Id: newdemo.c,v 1.18 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -37,6 +37,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include <sys/types.h>
 #endif
 
+#include <physfs.h>
+
 #include "u_mem.h"
 #include "inferno.h"
 #include "game.h"
@@ -94,11 +96,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include "mission.h"
 #include "piggy.h"
 #include "controls.h"
-#include "d_io.h"
 #include "timer.h"
-
-#include "findfile.h"
-
+#include "physfsx.h"
 #ifdef EDITOR
 #include "editor/editor.h"
 #endif
@@ -209,15 +208,15 @@ sbyte First_time_playback=1;
 fix JasonPlaybackTotal=0;
 
 
-CFILE *infile;
-CFILE *outfile = NULL;
+PHYSFS_file *infile;
+PHYSFS_file *outfile = NULL;
 
 int newdemo_get_percent_done() {
        if ( Newdemo_state == ND_STATE_PLAYBACK ) {
-               return (cftell(infile) * 100) / Newdemo_size;
+               return (PHYSFS_tell(infile) * 100) / Newdemo_size;
        }
        if ( Newdemo_state == ND_STATE_RECORDING ) {
-               return cftell(outfile);
+               return PHYSFS_tell(outfile);
        }
        return 0;
 }
@@ -257,8 +256,8 @@ void my_extract_shortpos(object *objp, shortpos *spp)
 int newdemo_read( void *buffer, int elsize, int nelem )
 {
        int num_read;
-       num_read = cfread(buffer, elsize, nelem, infile);
-       if (cferror(infile) || cfeof(infile))
+       num_read = PHYSFS_read(infile, buffer, elsize, nelem);
+       if (num_read < nelem || PHYSFS_eof(infile))
                nd_bad_read = -1;
 
        return num_read;
@@ -284,7 +283,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 = cfwrite(buffer, elsize, nelem, outfile);
+       num_written = PHYSFS_write(outfile, buffer, elsize, nelem);
        //if ((Newdemo_num_written > Newdemo_size) && !Newdemo_no_space) {
        //      Newdemo_no_space=1;
        //      newdemo_stop_recording();
@@ -2446,7 +2445,7 @@ int newdemo_read_frame_information()
 
                case ND_EVENT_EOF: {
                        done=-1;
-                       cfseek(infile, -1, SEEK_CUR);        // get back to the EOF marker
+                       PHYSFS_seek(infile, PHYSFS_tell(infile) - 1);        // get back to the EOF marker
                        Newdemo_at_eof = 1;
                        NewdemoFrameCount++;
                        break;
@@ -2474,7 +2473,7 @@ void newdemo_goto_beginning()
 {
        //if (NewdemoFrameCount == 0)
        //      return;
-       cfseek(infile, 0, SEEK_SET);
+       PHYSFS_seek(infile, 0);
        Newdemo_vcr_state = ND_STATE_PLAYBACK;
        if (newdemo_read_demo_start(0))
                newdemo_stop_playback();
@@ -2493,7 +2492,7 @@ void newdemo_goto_end()
        sbyte energy, shield, c;
        int i, loc, bint;
 
-       cfseek(infile, -2, SEEK_END);
+       PHYSFS_seek(infile, PHYSFS_tell(infile) - 2);
        nd_read_byte(&level);
 
        if ((level < Last_secret_level) || (level > Last_level)) {
@@ -2509,12 +2508,12 @@ void newdemo_goto_end()
        if (level != Current_level_num)
                LoadLevel(level,1);
 
-       cfseek(infile, -4, SEEK_END);
+       PHYSFS_seek(infile, PHYSFS_tell(infile) - 4);
        nd_read_short(&byte_count);
-       cfseek(infile, -2 - byte_count, SEEK_CUR);
+       PHYSFS_seek(infile, PHYSFS_tell(infile) - 2 - byte_count);
 
        nd_read_short(&frame_length);
-       loc = cftell(infile);
+       loc = PHYSFS_tell(infile);
        if (Newdemo_game_mode & GM_MULTI)
                nd_read_byte(&Newdemo_players_cloaked);
        else
@@ -2566,11 +2565,11 @@ void newdemo_goto_end()
                nd_read_int(&(Players[Player_num].score));
        }
 
-       cfseek(infile, loc, SEEK_SET);
-       cfseek(infile, -frame_length, SEEK_CUR);
+       PHYSFS_seek(infile, loc);
+       PHYSFS_seek(infile, PHYSFS_tell(infile) - frame_length);
        nd_read_int(&NewdemoFrameCount);            // get the frame count
        NewdemoFrameCount--;
-       cfseek(infile, 4, SEEK_CUR);
+       PHYSFS_seek(infile, PHYSFS_tell(infile) + 4);
        Newdemo_vcr_state = ND_STATE_PLAYBACK;
        newdemo_read_frame_information();           // then the frame information
        Newdemo_vcr_state = ND_STATE_PAUSED;
@@ -2584,9 +2583,9 @@ void newdemo_back_frames(int frames)
 
        for (i = 0; i < frames; i++)
        {
-               cfseek(infile, -10, SEEK_CUR);
+               PHYSFS_seek(infile, PHYSFS_tell(infile) - 10);
                nd_read_short(&last_frame_length);
-               cfseek(infile, 8 - last_frame_length, SEEK_CUR);
+               PHYSFS_seek(infile, PHYSFS_tell(infile) + 8 - last_frame_length);
 
                if (!Newdemo_at_eof && newdemo_read_frame_information() == -1) {
                        newdemo_stop_playback();
@@ -2595,9 +2594,9 @@ void newdemo_back_frames(int frames)
                if (Newdemo_at_eof)
                        Newdemo_at_eof = 0;
 
-               cfseek(infile, -10, SEEK_CUR);
+               PHYSFS_seek(infile, PHYSFS_tell(infile) - 10);
                nd_read_short(&last_frame_length);
-               cfseek(infile, 8 - last_frame_length, SEEK_CUR);
+               PHYSFS_seek(infile, PHYSFS_tell(infile) + 8 - last_frame_length);
        }
 
 }
@@ -2792,7 +2791,7 @@ void newdemo_playback_one_frame()
                else
                        frames_back = 1;
                if (Newdemo_at_eof) {
-                       cfseek(infile, 11, SEEK_CUR);
+                       PHYSFS_seek(infile, PHYSFS_tell(infile) + 11);
                }
                newdemo_back_frames(frames_back);
 
@@ -2940,12 +2939,8 @@ void newdemo_playback_one_frame()
 
 void newdemo_start_recording()
 {
-#ifdef WINDOWS
-       Newdemo_size=GetFreeDiskSpace();
-       mprintf((0, "Free space = %d\n", Newdemo_size));
-#else
-       Newdemo_size = GetDiskFree();
-#endif
+       Newdemo_size = PHYSFSX_getFreeDiskSpace();
+       con_printf(CON_VERBOSE, "Free space = %d\n", Newdemo_size);
 
        Newdemo_size -= 100000;
 
@@ -2963,15 +2958,15 @@ void newdemo_start_recording()
        Newdemo_num_written = 0;
        Newdemo_no_space=0;
        Newdemo_state = ND_STATE_RECORDING;
-       outfile = cfopen(DEMO_FILENAME, "wb");
+       outfile = PHYSFS_openWrite(DEMO_FILENAME);
 
 #if !defined(MACINTOSH) && !defined(_WIN32_WCE)
        if (outfile == NULL && errno == ENOENT) {   //dir doesn't exist?
 #else
        if (outfile == NULL) {                      //dir doesn't exist and no errno on mac!
 #endif
-               cfile_mkdir(DEMO_DIR); //try making directory
-               outfile = cfopen(DEMO_FILENAME, "wb");
+               PHYSFS_mkdir(DEMO_DIR); //try making directory
+               outfile = PHYSFS_openWrite(DEMO_FILENAME);
        }
 
        if (outfile == NULL)
@@ -3056,8 +3051,8 @@ void newdemo_stop_recording()
        nd_write_byte(Current_level_num);
        nd_write_byte(ND_EVENT_EOF);
 
-       l = cftell(outfile);
-       cfclose(outfile);
+       l = PHYSFS_tell(outfile);
+       PHYSFS_close(outfile);
        outfile = NULL;
        Newdemo_state = ND_STATE_NORMAL;
        gr_palette_load( gr_palette );
@@ -3107,12 +3102,12 @@ try_again:
                        strcat(save_file, ".dem");
                } else
                        sprintf (save_file, "%stmp%d.dem", DEMO_DIR, tmpcnt++);
-               cfile_delete(save_file);
-               cfile_rename(DEMO_FILENAME, save_file);
+               remove(save_file);
+               PHYSFSX_rename(DEMO_FILENAME, save_file);
                return;
        }
        if (exit == -1) {               // pressed ESC
-               cfile_delete(DEMO_FILENAME);      // might as well remove the file
+               PHYSFS_delete(DEMO_FILENAME);   // might as well remove the file
                return;                     // return without doing anything
        }
 
@@ -3131,8 +3126,8 @@ try_again:
        else
                strcat(fullname, m[0].text);
        strcat(fullname, ".dem");
-       cfile_delete(fullname);
-       cfile_rename(DEMO_FILENAME, fullname);
+       PHYSFS_delete(fullname);
+       PHYSFSX_rename(DEMO_FILENAME, fullname);
 }
 
 
@@ -3142,34 +3137,22 @@ extern char AltHogdir_initialized;
 //returns the number of demo files on the disk
 int newdemo_count_demos()
 {
-       FILEFINDSTRUCT find;
+       char **find, **i;
        int NumFiles=0;
 
-       if( !FileFindFirst( DEMO_DIR "*.dem", &find ) ) {
-               do {
-                       NumFiles++;
-               } while( !FileFindNext( &find ) );
-               FileFindClose();
-       }
+       find = PHYSFS_enumerateFiles(DEMO_DIR);
 
-       if ( AltHogdir_initialized ) {
-               char search_name[PATH_MAX + 5];
-               strcpy(search_name, AltHogDir);
-               strcat(search_name, "/" DEMO_DIR "*.dem");
-               if( !FileFindFirst( search_name, &find ) ) {
-                       do {
-                               NumFiles++;
-                       } while( !FileFindNext( &find ) );
-                       FileFindClose();
-               }
-       }
+       for (i = find; *i != NULL; i++)
+               NumFiles++;
+
+       PHYSFS_freeList(find);
 
        return NumFiles;
 }
 
 void newdemo_start_playback(char * filename)
 {
-       FILEFINDSTRUCT find;
+       char **find = NULL, **i;
        int rnd_demo = 0;
        char filename2[PATH_MAX+FILENAME_LEN] = DEMO_DIR;
 
@@ -3179,7 +3162,10 @@ void newdemo_start_playback(char * filename)
        First_time_playback=1;
        JasonPlaybackTotal=0;
 
-       if (filename==NULL) {
+       if (filename)
+               strcat(filename2, filename);
+       else
+       {
                // Randomly pick a filename
                int NumFiles = 0, RandFileNum;
                rnd_demo = 1;
@@ -3191,42 +3177,26 @@ void newdemo_start_playback(char * filename)
                }
                RandFileNum = d_rand() % NumFiles;
                NumFiles = 0;
-               if( !FileFindFirst( DEMO_DIR "*.dem", &find ) ) {
-                       do {
-                               if ( NumFiles==RandFileNum ) {
-                                       filename = (char *)&find.name;
-                                       break;
-                               }
-                               NumFiles++;
-                       } while( !FileFindNext( &find ) );
-                       FileFindClose();
-               }
-
-               if ( filename == NULL && AltHogdir_initialized ) {
-                       char search_name[PATH_MAX + 5];
-                       strcpy(search_name, AltHogDir);
-                       strcat(search_name, "/" DEMO_DIR "*.dem");
-                       if( !FileFindFirst( search_name, &find ) ) {
-                               do {
-                                       if ( NumFiles==RandFileNum ) {
-                                               filename = (char *)&find.name;
-                                               break;
-                                       }
-                                       NumFiles++;
-                               } while( !FileFindNext( &find ) );
-                               FileFindClose();
+
+               find = PHYSFS_enumerateFiles(DEMO_DIR);
+
+               for (i = find; *i != NULL; i++)
+               {
+                       if (NumFiles == RandFileNum)
+                       {
+                               strcat(filename2, *i);
+
+                               break;
                        }
+                       NumFiles++;
                }
+               PHYSFS_freeList(find);
 
-               if ( filename==NULL) return;
+               if (NumFiles > RandFileNum)
+                       return;
        }
 
-       if (!filename)
-               return;
-
-       strcat(filename2,filename);
-
-       infile = cfopen(filename2, "rb");
+       infile = PHYSFS_openRead(filename2);
 
        if (infile==NULL) {
                mprintf( (0, "Error reading '%s'\n", filename ));
@@ -3240,7 +3210,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)) {
-               cfclose(infile);
+               PHYSFS_close(infile);
                return;
        }
 
@@ -3248,7 +3218,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 = cfilelength(infile);
+       Newdemo_size = PHYSFS_fileLength(infile);
        nd_bad_read = 0;
        Newdemo_at_eof = 0;
        NewdemoFrameCount = 0;
@@ -3263,7 +3233,7 @@ void newdemo_start_playback(char * filename)
 
 void newdemo_stop_playback()
 {
-       cfclose(infile);
+       PHYSFS_close(infile);
        Newdemo_state = ND_STATE_NORMAL;
 #ifdef NETWORK
        change_playernum_to(0);             //this is reality
@@ -3282,15 +3252,15 @@ void newdemo_stop_playback()
 
 void newdemo_strip_frames(char *outname, int bytes_to_strip)
 {
-       CFILE *outfile;
+       PHYSFS_file *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 = cfilelength(infile);
-       outfile = cfopen(outname, "wb");
+       total_size = PHYSFS_fileLength(infile);
+       outfile = PHYSFS_openWrite(outname);
        if (outfile == NULL) {
                newmenu_item m[1];
 
@@ -3305,45 +3275,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 );
-               cfclose(outfile);
+               PHYSFS_close(outfile);
                newdemo_stop_playback();
                return;
        }
        newdemo_goto_end();
-       trailer_start = cftell(infile);
-       cfseek(infile, 11, SEEK_CUR);
+       trailer_start = PHYSFS_tell(infile);
+       PHYSFS_seek(infile, PHYSFS_tell(infile) + 11);
        bytes_back = 0;
        while (bytes_back < bytes_to_strip) {
-               loc1 = cftell(infile);
-               //cfseek(infile, -10, SEEK_CUR);
+               loc1 = PHYSFS_tell(infile);
+               //PHYSFS_seek(infile, PHYSFS_tell(infile) - 10);
                //nd_read_short(&last_frame_length);
-               //cfseek(infile, 8 - last_frame_length, SEEK_CUR);
+               //PHYSFS_seek(infile, PHYSFS_tell(infile) + 8 - last_frame_length);
                newdemo_back_frames(1);
-               loc2 = cftell(infile);
+               loc2 = PHYSFS_tell(infile);
                bytes_back += (loc1 - loc2);
        }
-       cfseek(infile, -10, SEEK_CUR);
+       PHYSFS_seek(infile, PHYSFS_tell(infile) - 10);
        nd_read_short(&last_frame_length);
-       cfseek(infile, -3, SEEK_CUR);
-       stop_loc = cftell(infile);
-       cfseek(infile, 0, SEEK_SET);
+       PHYSFS_seek(infile, PHYSFS_tell(infile) - 3);
+       stop_loc = PHYSFS_tell(infile);
+       PHYSFS_seek(infile, 0);
        while (stop_loc > 0) {
                if (stop_loc < BUF_SIZE)
                        bytes_to_read = stop_loc;
                else
                        bytes_to_read = BUF_SIZE;
-               read_elems = cfread(buf, 1, bytes_to_read, infile);
-               cfwrite(buf, 1, read_elems, outfile);
+               read_elems = PHYSFS_read(infile, buf, 1, bytes_to_read);
+               PHYSFS_write(outfile, buf, 1, read_elems);
                stop_loc -= read_elems;
        }
-       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);
+       stop_loc = PHYSFS_tell(outfile);
+       PHYSFS_seek(infile, trailer_start);
+       while ((read_elems = PHYSFS_read(infile, buf, 1, BUF_SIZE)) != 0)
+               PHYSFS_write(outfile, buf, 1, read_elems);
+       PHYSFS_seek(outfile, stop_loc);
+       PHYSFS_seek(outfile, PHYSFS_tell(infile) + 1);
+       PHYSFS_write(outfile, &last_frame_length, 2, 1);
+       PHYSFS_close(outfile);
        newdemo_stop_playback();
 
 }
index a3cc6d4..2856cd7 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: newmenu.c,v 1.28 2004-08-28 23:17:45 schaffner Exp $ */
+/* $Id: newmenu.c,v 1.29 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -36,6 +36,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 #include <limits.h>
 
+#include <physfs.h>
+
 #include "pa_enabl.h"                   //$$POLY_ACC
 #include "error.h"
 #include "pstypes.h"
@@ -46,8 +48,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include "palette.h"
 #include "game.h"
 #include "text.h"
-#include "findfile.h"
-
 #include "menu.h"
 #include "newmenu.h"
 #include "gamefont.h"
@@ -2022,28 +2022,26 @@ void delete_player_saved_games(char * name)
 {
        int i;
        char filename[16];
-       
+
        for (i=0;i<10; i++)     {
 #ifndef MACINTOSH
                sprintf( filename, "%s.sg%d", name, i );
 #else
-               sprintf( filename, ":Players:%s.sg%d", name, i );
+               sprintf(filename, "Players/%s.sg%d", name, i);
 #endif
-               cfile_delete(filename);
+               PHYSFS_delete(filename);
        }
 }
 
 #define MAX_FILES 300
 
-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 )
+//FIXME: should maybe put globbing ability back?
+int newmenu_get_filename(char *title, char *type, char *filename, int allow_abort_flag)
 {
        int i;
-       FILEFINDSTRUCT find;
+       char **find;
+       char **f;
+       char *ext;
        int NumFiles=0, key,done, citem, ocitem;
        char * filenames = NULL;
        int NumFiles_displayed = 8;
@@ -2063,7 +2061,7 @@ int newmenu_get_filename( char * title, char * filespec, char * filename, int al
        int dblclick_flag=0;
 # ifdef WINDOWS
        int simukey=0;
-       int show_up_arrow=0,show_down_arrow=0;
+       int show_up_arrow=0, show_down_arrow=0;
 # endif
 #endif
 WIN(int win_redraw=0);
@@ -2079,9 +2077,9 @@ WIN(int win_redraw=0);
 
        WIN(mouse_set_mode(0));                         //disable centering mode
 
-       if (strstr( filespec, "*.plr" ))
+       if (!stricmp(type, "plr"))
                player_mode = 1;
-       else if (strstr( filespec, "*.dem" ))
+       else if (!stricmp(type, "dem"))
                demo_mode = 1;
 
 ReadFileNames:
@@ -2095,41 +2093,34 @@ ReadFileNames:
        }
 #endif
 
-       if( !FileFindFirst( filespec, &find ) ) {
-               do      {
-                       if (NumFiles<MAX_FILES) {
-                                strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
-                               if ( player_mode )      {
-                                       char * p;
-                                       p = strchr(&filenames[NumFiles*14],'.');
-                                       if (p) *p = '\0';
-                               }
-                               NumFiles++;
-                       } else {
-                               break;
-                       }
-               } while( !FileFindNext( &find ) );
-               FileFindClose();
-       }
+       find = PHYSFS_enumerateFiles(demo_mode?DEMO_DIR:"");
+       for (f = find; *f != NULL; f++)
+       {
+               if (player_mode)
+               {
+                       ext = strrchr(*f, '.');
+                       if (!ext || strnicmp(ext, ".plr", 4))
+                               continue;
+               }
+               if (NumFiles < MAX_FILES)
+               {
+                       strncpy(&filenames[NumFiles*14], *f, FILENAME_LEN);
+                       if (player_mode)
+                       {
+                               char *p;
 
-       if (demo_mode && AltHogdir_initialized) {
-               char filespec2[PATH_MAX + FILENAME_LEN];
-               strcpy(filespec2, AltHogDir);
-               strcat(filespec2, "/");
-               strcat(filespec2, filespec);
-               if ( !FileFindFirst( filespec2, &find ) ) {
-                       do {
-                               if (NumFiles<MAX_FILES) {
-                                       strncpy( &filenames[NumFiles*14], find.name, FILENAME_LEN );
-                                       NumFiles++;
-                               } else {
-                                       break;
-                               }
-                       } while( !FileFindNext( &find ) );
-                       FileFindClose();
+                               p = strchr(&filenames[NumFiles*14], '.');
+                               if (p)
+                                       *p = '\0';
+                       }
+                       NumFiles++;
                }
+               else
+                       break;
        }
 
+       PHYSFS_freeList(find);
+
        if ( (NumFiles < 1) && demos_deleted )  {
                exit_value = 0;
                goto ExitFileMenu;
@@ -2150,7 +2141,7 @@ ReadFileNames:
 
        if ( NumFiles<1 )       {
                #ifndef APPLE_DEMO
-                       nm_messagebox( NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, filespec, TXT_WERE_FOUND);
+                       nm_messagebox(NULL, 1, "Ok", "%s\n '%s' %s", TXT_NO_FILES_MATCHING, type, TXT_WERE_FOUND);
                #endif
                exit_value = 0;
                goto ExitFileMenu;
@@ -2362,14 +2353,13 @@ RePaintNewmenuFile:
                                if (x==0)       {
                                        char * p;
                                        int ret;
-                                       char name[_MAX_PATH],dir[_MAX_DIR];
+                                       char name[_MAX_PATH];
 
                                        p = &filenames[(citem*14)+strlen(&filenames[citem*14])];
                                        if (player_mode)
                                                *p = '.';
 
-                                       _splitpath(filespec,name,dir,NULL,NULL);
-                                       strcat(name,dir);
+                                       strcpy(name, demo_mode?DEMO_DIR:"");
                                        strcat(name,&filenames[citem*14]);
                                        
                                        #ifdef MACINTOSH
@@ -2385,7 +2375,7 @@ RePaintNewmenuFile:
                                        }
                                        #endif
                                
-                                       ret = cfile_delete(name);
+                                       ret = !PHYSFS_delete(name);
                                        if (player_mode)
                                                *p = 0;
 
@@ -2735,7 +2725,7 @@ ExitFileMenu:
 // 
 //     if ( *keypress = KEY_CTRLED+KEY_D )     {
 //             if ( *nitems > 1 )      {
-//                     cfile_delete(items[*citem]);    // Delete the file
+//                     PHYSFS_delete(items[*citem]);     // Delete the file
 //                     for (i=*citem; i<*nitems-1; i++ )       {
 //                             items[i] = items[i+1];
 //                     }
@@ -3230,6 +3220,7 @@ RePaintNewmenuListbox:
        return citem;
 }
 
+#if 0
 int newmenu_filelist( char * title, char * filespec, char * filename )
 {
        int i, NumFiles;
@@ -3258,6 +3249,7 @@ int newmenu_filelist( char * title, char * filespec, char * filename )
        } 
        return 0;
 }
+#endif
 
 //added on 10/14/98 by Victor Rachels to attempt a fixedwidth font messagebox
 int nm_messagebox_fixedfont( char *title, int nchoices, ... )
index 8365978..523f502 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: piggy.c,v 1.57 2004-12-01 08:24:55 btb Exp $ */
+/* $Id: piggy.c,v 1.58 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -24,7 +24,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: piggy.c,v 1.57 2004-12-01 08:24:55 btb Exp $";
+static char rcsid[] = "$Id: piggy.c,v 1.58 2004-12-01 12:48:13 btb Exp $";
 #endif
 
 
@@ -59,7 +59,6 @@ static char rcsid[] = "$Id: piggy.c,v 1.57 2004-12-01 08:24:55 btb Exp $";
 #include "cfile.h"
 #include "newmenu.h"
 #include "byteswap.h"
-#include "findfile.h"
 #include "makesig.h"
 
 #ifndef MACINTOSH
@@ -556,11 +555,11 @@ CFILE *copy_pigfile_from_cd(char *filename)               // MACINTOSH VERSION
 //retuns file handle of new pig
 CFILE *copy_pigfile_from_cd(char *filename)
 {
+#if 0
        char name[80];
        FILEFINDSTRUCT find;
        int ret;
 
-       return cfopen(filename, "rb");
        show_boxed_message("Copying bitmap data from CD...");
        gr_palette_load(gr_palette);    //I don't think this line is really needed
 
@@ -600,6 +599,7 @@ CFILE *copy_pigfile_from_cd(char *filename)
                }
 
        } while (ret != EXIT_SUCCESS);
+#endif
 
        return cfopen(filename, "rb");
 }
index 5ff3e56..a52bc9c 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: playsave.c,v 1.20 2004-10-23 19:39:35 schaffner Exp $ */
+/* $Id: playsave.c,v 1.21 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -36,6 +36,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include <errno.h>
 #endif
 
+#include <physfs.h>
+
 #include "error.h"
 
 #include "pa_enabl.h"
@@ -63,6 +65,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include "byteswap.h"
 #include "escort.h"
 
+#include "physfsx.h"
+
 #define SAVE_FILE_ID                   MAKE_SIG('D','P','L','R')
 
 #ifdef MACINTOSH
@@ -299,6 +303,7 @@ WIN(extern char win95_current_joyname[]);
 
 ubyte control_type_dos,control_type_win;
 
+
 //read in the player's saved games.  returns errno (0 == no error)
 int read_player_file()
 {
@@ -307,8 +312,7 @@ int read_player_file()
        #else
        char filename[FILENAME_LEN];
        #endif
-       CFILE *file;
-       int errno_ret = EZERO;
+       PHYSFS_file *file;
        int id, i;
        short player_file_version;
        int rewrite_it=0;
@@ -319,31 +323,36 @@ int read_player_file()
 #ifndef MACINTOSH
        sprintf(filename,"%.8s.plr",Players[Player_num].callsign);
 #else
-       sprintf(filename, ":Players:%.8s.plr",Players[Player_num].callsign);
+       sprintf(filename, "Players/%.8s.plr",Players[Player_num].callsign);
 #endif
-       file = cfopen(filename, "rb");
 
-#if 0 //ndef MACINTOSH
+       if (!PHYSFS_exists(filename))
+               return ENOENT;
+
+       file = PHYSFS_openRead(filename);
+
+#if 0
+#ifndef MACINTOSH
        //check filename
        if (file && isatty(fileno(file))) {
                //if the callsign is the name of a tty device, prepend a char
-               fclose(file);
+               PHYSFS_close(file);
                sprintf(filename,"$%.7s.plr",Players[Player_num].callsign);
-               file = fopen(filename,"rb");
+               file = PHYSFS_openRead(filename);
        }
+#endif
 #endif
 
-       if (!file) {
-               return errno;
-       }
+       if (!file)
+               goto read_player_file_failed;
 
-       id = cfile_read_int(file);
+       PHYSFS_readSLE32(file, &id);
 
         // SWAPINT added here because old versions of d2x
         // used the wrong byte order.
        if (id!=SAVE_FILE_ID && id!=SWAPINT(SAVE_FILE_ID)) {
                nm_messagebox(TXT_ERROR, 1, TXT_OK, "Invalid player file");
-               cfclose(file);
+               PHYSFS_close(file);
                return -1;
        }
 
@@ -357,7 +366,7 @@ int read_player_file()
 
        if (player_file_version<COMPATIBLE_PLAYER_FILE_VERSION) {
                nm_messagebox(TXT_ERROR, 1, TXT_OK, TXT_ERROR_PLR_VERSION);
-               cfclose(file);
+               PHYSFS_close(file);
                return -1;
        }
 
@@ -383,15 +392,15 @@ int read_player_file()
                }
         #endif
        #endif
+
        Default_display_mode     = cfile_read_byte(file);
        Missile_view_enabled     = cfile_read_byte(file);
        Headlight_active_default = cfile_read_byte(file);
        Guided_in_big_window     = cfile_read_byte(file);
-
+               
        if (player_file_version >= 19)
                Automap_always_hires = cfile_read_byte(file);
-          
+
        Auto_leveling_on = Default_leveling_on;
 
        //read new highest level info
@@ -401,23 +410,19 @@ int read_player_file()
                n_highest_levels = SWAPSHORT(n_highest_levels);
        Assert(n_highest_levels <= MAX_MISSIONS);
 
-       if (cfread(highest_levels, sizeof(hli), n_highest_levels, file) != n_highest_levels)
-       {
-               errno_ret                       = errno;
-               cfclose(file);
-               return errno_ret;
-       }
+       if (PHYSFS_read(file, highest_levels, sizeof(hli), n_highest_levels) != n_highest_levels)
+               goto read_player_file_failed;
 
        //read taunt macros
        {
 #ifdef NETWORK
                int i,len;
 
-               len                     = MAX_MESSAGE_LEN;
+               len = MAX_MESSAGE_LEN;
 
-               for (i                  = 0; i < 4; i++)
-                       if (cfread(Network_message_macro[i], len, 1, file) != 1)
-                               {errno_ret                      = errno; break;}
+               for (i = 0; i < 4; i++)
+                       if (PHYSFS_read(file, Network_message_macro[i], len, 1) != 1)
+                               goto read_player_file_failed;
 #else
                char dummy[4][MAX_MESSAGE_LEN];
 
@@ -429,14 +434,14 @@ int read_player_file()
        {
                int n_control_types = (player_file_version<20)?7:CONTROL_MAX_TYPES;
 
-               if (cfread( kconfig_settings, MAX_CONTROLS*n_control_types, 1, file ) != 1)
-                       errno_ret=errno;
-               else if (cfread((ubyte *)&control_type_dos, sizeof(ubyte), 1, file ) != 1)
-                       errno_ret=errno;
-               else if (player_file_version >= 21 && cfread((ubyte *)&control_type_win, sizeof(ubyte), 1, file ) != 1)
-                       errno_ret=errno;
-               else if (cfread(&Config_joystick_sensitivity, sizeof(ubyte), 1, file ) != 1)
-                       errno_ret=errno;
+               if (PHYSFS_read(file, kconfig_settings, MAX_CONTROLS*n_control_types, 1) != 1)
+                       goto read_player_file_failed;
+               else if (PHYSFS_read(file, (ubyte *)&control_type_dos, sizeof(ubyte), 1) != 1)
+                       goto read_player_file_failed;
+               else if (player_file_version >= 21 && PHYSFS_read(file, (ubyte *)&control_type_win, sizeof(ubyte), 1) != 1)
+                       goto read_player_file_failed;
+               else if (PHYSFS_read(file, &Config_joystick_sensitivity, sizeof(ubyte), 1) !=1 )
+                       goto read_player_file_failed;
 
                #ifdef WINDOWS
                Config_control_type = control_type_win;
@@ -450,67 +455,68 @@ int read_player_file()
 
                for (i=0;i<11;i++)
                {
-                       PrimaryOrder[i]   = cfile_read_byte(file);
+                       PrimaryOrder[i] = cfile_read_byte(file);
                        SecondaryOrder[i] = cfile_read_byte(file);
                }
 
                if (player_file_version>=16)
                {
-                       Cockpit_3d_view[0] = cfile_read_int(file);
-                       Cockpit_3d_view[1] = cfile_read_int(file);
-                       if (swap) {
+                       PHYSFS_readSLE32(file, &Cockpit_3d_view[0]);
+                       PHYSFS_readSLE32(file, &Cockpit_3d_view[1]);
+                       if (swap)
+                       {
                                Cockpit_3d_view[0] = SWAPINT(Cockpit_3d_view[0]);
                                Cockpit_3d_view[1] = SWAPINT(Cockpit_3d_view[1]);
                        }
                }
-               
-                  
-               if (errno_ret==EZERO)   {
-                       kc_set_controls();
-               }
+
+               kc_set_controls();
 
        }
 
-   if (player_file_version>=22)
-        {
+       if (player_file_version>=22)
+       {
 #ifdef NETWORK
-               Netlife_kills = cfile_read_int(file);
-               Netlife_killed = cfile_read_int(file);
+               PHYSFS_readSLE32(file, &Netlife_kills);
+               PHYSFS_readSLE32(file, &Netlife_killed);
                if (swap) {
                        Netlife_kills = SWAPINT(Netlife_kills);
                        Netlife_killed = SWAPINT(Netlife_killed);
                }
 #else
-               cfile_read_int(file);
-               cfile_read_int(file);
+               {
+                       int dummy;
+                       PHYSFS_readSLE32(file, &dummy);
+                       PHYSFS_readSLE32(file, &dummy);
+               }
 #endif
-        }
+       }
 #ifdef NETWORK
-   else
-        {
-                Netlife_kills=0; Netlife_killed=0;
-        }
+       else
+       {
+               Netlife_kills=0; Netlife_killed=0;
+       }
 #endif
 
        if (player_file_version>=23)
-        {
-         i = cfile_read_int(file);
-         if (swap)
-                 i = SWAPINT(i);
+       {
+               PHYSFS_readSLE32(file, &i);
+               if (swap)
+                       i = SWAPINT(i);
 #ifdef NETWORK
-         mprintf ((0,"Reading: lifetime checksum is %d\n",i));
-         if (i!=get_lifetime_checksum (Netlife_kills,Netlife_killed))
+               mprintf ((0,"Reading: lifetime checksum is %d\n",i));
+               if (i!=get_lifetime_checksum (Netlife_kills,Netlife_killed))
                {
-                Netlife_kills=0; Netlife_killed=0;
-                nm_messagebox(NULL, 1, "Shame on me", "Trying to cheat eh?");
-                rewrite_it=1;
+                       Netlife_kills=0; Netlife_killed=0;
+                       nm_messagebox(NULL, 1, "Shame on me", "Trying to cheat eh?");
+                       rewrite_it=1;
                }
 #endif
-        }
+       }
 
        //read guidebot name
        if (player_file_version >= 18)
-               cfile_read_string(guidebot_name, GUIDEBOT_NAME_LEN, file);
+               PHYSFSX_readString(file, guidebot_name);
        else
                strcpy(guidebot_name,"GUIDE-BOT");
 
@@ -522,7 +528,7 @@ int read_player_file()
        #ifdef WINDOWS
                joy95_get_name(JOYSTICKID1, buf, 127);
                if (player_file_version >= 24) 
-                       cfile_read_string(win95_current_joyname, file);
+                       PHYSFSX_readString(file, win95_current_joyname);
                else
                        strcpy(win95_current_joyname, "Old Player File");
                
@@ -536,24 +542,30 @@ int read_player_file()
                }        
        #else
                if (player_file_version >= 24) 
-                       cfile_read_string(buf, 127, file);      // Just read it in fpr DPS.
+                       PHYSFSX_readString(file, buf);                  // Just read it in fpr DPS.
        #endif
        }
 
        if (player_file_version >= 25)
-               cfread(kconfig_d2x_settings, MAX_D2X_CONTROLS, 1, file);
+               PHYSFS_read(file, kconfig_d2x_settings, MAX_D2X_CONTROLS, 1);
        else
                for(i=0; i < MAX_D2X_CONTROLS; i++)
                        kconfig_d2x_settings[i] = default_kconfig_d2x_settings[i];
 
-       if (cfclose(file) && errno_ret == EZERO)
-               errno_ret                       = errno;
+       if (!PHYSFS_close(file))
+               goto read_player_file_failed;
 
        if (rewrite_it)
-        write_player_file();
+               write_player_file();
+
+       return EZERO;
 
-       return errno_ret;
+ read_player_file_failed:
+       nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s", "Error reading PLR file", PHYSFS_getLastError());
+       if (file)
+               PHYSFS_close(file);
 
+       return -1;
 }
 
 
@@ -619,6 +631,7 @@ int get_highest_level(void)
 
 extern int Cockpit_mode_save;
 
+
 //write out player's saved games.  returns errno (0 == no error)
 int write_player_file()
 {
@@ -627,21 +640,21 @@ int write_player_file()
        #else
        char filename[FILENAME_LEN];            // because of ":Players:" path
        #endif
-       CFILE *file;
-       int errno_ret,i;
+       PHYSFS_file *file;
+       int i;
 
 //     #ifdef APPLE_DEMO               // no saving of player files in Apple OEM version
 //     return 0;
 //     #endif
 
-       errno_ret                       = WriteConfigFile();
+       WriteConfigFile();
 
 #ifndef MACINTOSH
        sprintf(filename,"%s.plr",Players[Player_num].callsign);
 #else
        sprintf(filename, ":Players:%.8s.plr",Players[Player_num].callsign);
 #endif
-       file = cfopen(filename, "wb");
+       file = PHYSFS_openWrite(filename);
 
 #if 0 //ndef MACINTOSH
        //check filename
@@ -649,56 +662,46 @@ int write_player_file()
 
                //if the callsign is the name of a tty device, prepend a char
 
-               fclose(file);
+               PHYSFS_close(file);
                sprintf(filename,"$%.7s.plr",Players[Player_num].callsign);
-               file                    = fopen(filename,"wb");
+               file = PHYSFS_openWrite(filename);
        }
 #endif
 
        if (!file)
-              return errno;
-
-       errno_ret                       = EZERO;
+               return -1;
 
        //Write out player's info
-       cfile_write_int(SAVE_FILE_ID, file);
-       cfile_write_short(PLAYER_FILE_VERSION, file);
-
-       cfile_write_short(Game_window_w, file);
-       cfile_write_short(Game_window_h, file);
-
-       cfile_write_byte(Player_default_difficulty, file);
-       cfile_write_byte(Auto_leveling_on, file);
-       cfile_write_byte(Reticle_on, file);
-       cfile_write_byte((Cockpit_mode_save != -1)?Cockpit_mode_save:Cockpit_mode, file);   //if have saved mode, write it instead of letterbox/rear view
-       cfile_write_byte(Default_display_mode, file);
-       cfile_write_byte(Missile_view_enabled, file);
-       cfile_write_byte(Headlight_active_default, file);
-       cfile_write_byte(Guided_in_big_window, file);
-       cfile_write_byte(Automap_always_hires, file);
+       PHYSFS_writeULE32(file, SAVE_FILE_ID);
+       PHYSFS_writeULE16(file, PLAYER_FILE_VERSION);
+
+       PHYSFS_writeULE16(file, Game_window_w);
+       PHYSFS_writeULE16(file, Game_window_h);
+
+       PHYSFSX_writeU8(file, Player_default_difficulty);
+       PHYSFSX_writeU8(file, Auto_leveling_on);
+       PHYSFSX_writeU8(file, Reticle_on);
+       PHYSFSX_writeU8(file, (Cockpit_mode_save!=-1)?Cockpit_mode_save:Cockpit_mode);  //if have saved mode, write it instead of letterbox/rear view
+       PHYSFSX_writeU8(file, Default_display_mode);
+       PHYSFSX_writeU8(file, Missile_view_enabled);
+       PHYSFSX_writeU8(file, Headlight_active_default);
+       PHYSFSX_writeU8(file, Guided_in_big_window);
+       PHYSFSX_writeU8(file, Automap_always_hires);
 
        //write higest level info
-       Assert(n_highest_levels <= MAX_MISSIONS);
-       cfile_write_short(n_highest_levels, file);
-       if ((cfwrite(highest_levels, sizeof(hli), n_highest_levels, file) != n_highest_levels))
-       {
-               errno_ret                       = errno;
-               cfclose(file);
-               return errno_ret;
-       }
+       PHYSFS_writeULE16(file, n_highest_levels);
+       if ((PHYSFS_write(file, highest_levels, sizeof(hli), n_highest_levels) != n_highest_levels))
+               goto write_player_file_failed;
 
 #ifdef NETWORK
-       if ((cfwrite(Network_message_macro, MAX_MESSAGE_LEN, 4, file) != 4))
-       {
-               errno_ret                       = errno;
-               cfclose(file);
-               return errno_ret;
-       }
+       if ((PHYSFS_write(file, Network_message_macro, MAX_MESSAGE_LEN, 4) != 4))
+               goto write_player_file_failed;
 #else
        {
                char dummy[4][MAX_MESSAGE_LEN]; // Pull the messages from a hat! ;-)
-               
-               cfwrite(dummy, MAX_MESSAGE_LEN, 4, file);
+
+               if ((PHYSFS_write(file, dummy, MAX_MESSAGE_LEN, 4) != 4))
+                       goto write_player_file_failed;
        }
 #endif
 
@@ -711,39 +714,40 @@ int write_player_file()
                control_type_dos = Config_control_type;
                #endif
 
-               if (cfwrite(kconfig_settings, MAX_CONTROLS * CONTROL_MAX_TYPES, 1, file ) != 1)
-                       errno_ret=errno;
-               else if (cfwrite(&control_type_dos, sizeof(ubyte), 1, file) != 1)
-                       errno_ret=errno;
-               else if (cfwrite(&control_type_win, sizeof(ubyte), 1, file ) != 1)
-                       errno_ret=errno;
-               else if (cfwrite(&Config_joystick_sensitivity, sizeof(ubyte), 1, file) != 1)
-                       errno_ret=errno;
+               if (PHYSFS_write(file, kconfig_settings, MAX_CONTROLS*CONTROL_MAX_TYPES, 1) != 1)
+                       goto write_player_file_failed;
+               else if (PHYSFS_write(file, &control_type_dos, sizeof(ubyte), 1) != 1)
+                       goto write_player_file_failed;
+               else if (PHYSFS_write(file, &control_type_win, sizeof(ubyte), 1) != 1)
+                       goto write_player_file_failed;
+               else if (PHYSFS_write(file, &Config_joystick_sensitivity, sizeof(ubyte), 1) != 1)
+                       goto write_player_file_failed;
 
-               for (i=0;i<11;i++)
+               for (i = 0; i < 11; i++)
                {
-                       cfwrite(&PrimaryOrder[i], sizeof(ubyte), 1, file);
-                       cfwrite(&SecondaryOrder[i], sizeof(ubyte), 1, file);
+                       PHYSFS_write(file, &PrimaryOrder[i], sizeof(ubyte), 1);
+                       PHYSFS_write(file, &SecondaryOrder[i], sizeof(ubyte), 1);
                }
 
-               cfile_write_int(Cockpit_3d_view[0], file);
-               cfile_write_int(Cockpit_3d_view[1], file);
+               PHYSFS_writeULE32(file, Cockpit_3d_view[0]);
+               PHYSFS_writeULE32(file, Cockpit_3d_view[1]);
 
 #ifdef NETWORK
-               cfile_write_int(Netlife_kills, file);
-               cfile_write_int(Netlife_killed, file);
+               PHYSFS_writeULE32(file, Netlife_kills);
+               PHYSFS_writeULE32(file, Netlife_killed);
                i=get_lifetime_checksum (Netlife_kills,Netlife_killed);
                mprintf ((0,"Writing: Lifetime checksum is %d\n",i));
 #else
-               cfile_write_int(0, file);
-               cfile_write_int(0, file);
-               i = get_lifetime_checksum(0, 0);
+               PHYSFS_writeULE32(file, 0);
+               PHYSFS_writeULE32(file, 0);
+               i = get_lifetime_checksum (0, 0);
 #endif
-               cfile_write_int(i,file);
+               PHYSFS_writeULE32(file, i);
        }
 
        //write guidebot name
-       cfile_write_string(real_guidebot_name, file);
+       PHYSFSX_writeString(file, real_guidebot_name);
+
        {
                char buf[128];
                #ifdef WINDOWS
@@ -751,18 +755,13 @@ int write_player_file()
                #else
                strcpy(buf, "DOS joystick");
                #endif
-               cfile_write_string(buf, file);  // Write out current joystick for player.
+               PHYSFSX_writeString(file, buf);         // Write out current joystick for player.
        }
 
-       cfwrite(kconfig_d2x_settings, MAX_D2X_CONTROLS, 1, file);
-
-       if (cfclose(file))
-               errno_ret                       = errno;
+       PHYSFS_write(file, kconfig_d2x_settings, MAX_D2X_CONTROLS, 1);
 
-       if (errno_ret != EZERO) {
-               cfile_delete(filename);         //delete bogus file
-               nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s",TXT_ERROR_WRITING_PLR, strerror(errno_ret));
-       }
+       if (!PHYSFS_close(file))
+               goto write_player_file_failed;
 
        #ifdef MACINTOSH                // set filetype and creator for playerfile
        {
@@ -779,8 +778,17 @@ int write_player_file()
        }
        #endif
 
-       return errno_ret;
+       return EZERO;
+
+ write_player_file_failed:
+       nm_messagebox(TXT_ERROR, 1, TXT_OK, "%s\n\n%s", TXT_ERROR_WRITING_PLR, PHYSFS_getLastError());
+       if (file)
+       {
+               PHYSFS_close(file);
+               PHYSFS_delete(filename);        //delete bogus file
+       }
 
+       return -1;
 }
 
 //update the player's highest level.  returns errno (0 == no error)
index 3784ed4..a99920a 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: scores.c,v 1.6 2004-08-28 23:17:45 schaffner Exp $ */
+/* $Id: scores.c,v 1.7 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -47,7 +47,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include "joy.h"
 #include "timer.h"
 #include "text.h"
-#include "d_io.h"
 #include "strutil.h"
 
 #define VERSION_NUMBER                 1
@@ -114,13 +113,13 @@ char * get_scores_filename()
 
 void scores_read()
 {
-       CFILE *fp;
+       PHYSFS_file *fp;
        int fsize;
 
        // clear score array...
        memset( &Scores, 0, sizeof(all_scores) );
 
-       fp = cfopen(get_scores_filename(), "rb");
+       fp = PHYSFS_openRead(get_scores_filename());
        if (fp==NULL) {
                int i;
 
@@ -141,16 +140,16 @@ void scores_read()
                        Scores.stats[i].score = (10-i)*1000;
                return;
        }
-               
-       fsize = cfilelength(fp);
+
+       fsize = PHYSFS_fileLength(fp);
 
        if ( fsize != sizeof(all_scores) )      {
-               cfclose(fp);
+               PHYSFS_close(fp);
                return;
        }
        // Read 'em in...
-       cfread(&Scores, sizeof(all_scores), 1, fp);
-       cfclose(fp);
+       PHYSFS_read(fp, &Scores, sizeof(all_scores), 1);
+       PHYSFS_close(fp);
 
        if ( (Scores.version!=VERSION_NUMBER)||(Scores.signature[0]!='D')||(Scores.signature[1]!='H')||(Scores.signature[2]!='S') )     {
                memset( &Scores, 0, sizeof(all_scores) );
@@ -160,9 +159,9 @@ void scores_read()
 
 void scores_write()
 {
-       CFILE *fp;
+       PHYSFS_file *fp;
 
-       fp = cfopen(get_scores_filename(), "wb");
+       fp = PHYSFS_openWrite(get_scores_filename());
        if (fp==NULL) {
                nm_messagebox( TXT_WARNING, 1, TXT_OK, "%s\n'%s'", TXT_UNABLE_TO_OPEN, get_scores_filename()  );
                return;
@@ -172,8 +171,8 @@ void scores_write()
        Scores.signature[1]='H';
        Scores.signature[2]='S';
        Scores.version = VERSION_NUMBER;
-       cfwrite(&Scores,sizeof(all_scores),1, fp);
-       cfclose(fp);
+       PHYSFS_write(fp, &Scores,sizeof(all_scores), 1);
+       PHYSFS_close(fp);
 }
 
 void int_to_string( int number, char *dest )
@@ -465,7 +464,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 )     {
-                                       cfile_delete(get_scores_filename());
+                                       PHYSFS_delete(get_scores_filename());
                                        gr_palette_fade_out( gr_palette, 32, 0 );
                                        goto ReshowScores;
                                }
index f24e9b8..880363b 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: state.c,v 1.16 2004-10-23 19:39:35 schaffner Exp $ */
+/* $Id: state.c,v 1.17 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -107,6 +107,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #ifdef OGL
 #include "gr.h"
 #endif
+#include "physfsx.h"
 
 #define STATE_VERSION 22
 #define STATE_COMPATIBLE_VERSION 20
@@ -232,7 +233,7 @@ void rpad_string( char * string, int max_chars )
 
 int state_get_save_file(char * fname, char * dsc, int multi )
 {
-       CFILE *fp;
+       PHYSFS_file *fp;
        int i, choice, version;
        newmenu_item m[NUM_SAVES+2];
        char filename[NUM_SAVES+1][30];
@@ -255,24 +256,25 @@ 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 = cfopen(filename[i], "rb");
+               fp = PHYSFS_openRead(filename[i]);
                if ( fp ) {
                        //Read id
-                       cfread(id, sizeof(char)*4, 1, fp);
+                       //FIXME: check for swapped file, react accordingly...
+                       PHYSFS_read(fp, id, sizeof(char) * 4, 1);
                        if ( !memcmp( id, dgss_id, 4 )) {
                                //Read version
-                               cfread(&version, sizeof(int), 1, fp);
+                               PHYSFS_read(fp, &version, sizeof(int), 1);
                                if (version >= STATE_COMPATIBLE_VERSION)        {
                                        // Read description
-                                       cfread(desc[i], sizeof(char)*DESC_LENGTH, 1, fp);
+                                       PHYSFS_read(fp, desc[i], sizeof(char) * DESC_LENGTH, 1);
                                        //rpad_string( desc[i], DESC_LENGTH-1 );
                                        // Read thumbnail
                                        //sc_bmp[i] = gr_create_bitmap(THUMBNAIL_W,THUMBNAIL_H );
-                                       //cfread(sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
+                                       //PHYSFS_read(fp, sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1);
                                        valid = 1;
                                }
-                       }
-                       cfclose(fp);
+                       } 
+                       PHYSFS_close(fp);
                }
                if (!valid) {
                        strcpy( desc[i], TXT_EMPTY );
@@ -303,7 +305,7 @@ extern int Current_display_mode;
 
 int state_get_restore_file(char * fname, int multi)
 {
-       CFILE *fp;
+       PHYSFS_file *fp;
        int i, choice, version, nsaves;
        newmenu_item m[NUM_SAVES+2];
        char filename[NUM_SAVES+1][30];
@@ -328,31 +330,32 @@ 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 = cfopen(filename[i], "rb");
+               fp = PHYSFS_openRead(filename[i]);
                if ( fp ) {
                        //Read id
-                       cfread(id, sizeof(char)*4, 1, fp);
+                       //FIXME: check for swapped file, react accordingly...
+                       PHYSFS_read(fp, id, sizeof(char) * 4, 1);
                        if ( !memcmp( id, dgss_id, 4 )) {
                                //Read version
-                               cfread(&version, sizeof(int), 1, fp);
+                               PHYSFS_read(fp, &version, sizeof(int), 1);
                                if (version >= STATE_COMPATIBLE_VERSION)        {
                                        // Read description
-                                       cfread(desc[i], sizeof(char)*DESC_LENGTH, 1, fp);
+                                       PHYSFS_read(fp, desc[i], sizeof(char) * DESC_LENGTH, 1);
                                        //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 );
-                                       cfread(sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
+                                       PHYSFS_read(fp, sc_bmp[i]->bm_data, THUMBNAIL_W * THUMBNAIL_H, 1);
                                        if (version >= 9) {
                                                ubyte pal[256*3];
-                                               cfread(pal, 3, 256, fp);
+                                               PHYSFS_read(fp, pal, 3, 256);
                                                gr_remap_bitmap_good( sc_bmp[i], pal, -1, -1 );
                                        }
                                        nsaves++;
                                        valid = 1;
                                }
                        }
-                       cfclose(fp);
+                       PHYSFS_close(fp);
                }
                if (!valid) {
                        strcpy( desc[i], TXT_EMPTY );
@@ -405,51 +408,44 @@ int state_get_restore_file(char * fname, int multi)
 
 #define        CF_BUF_SIZE     1024
 
-#ifdef _WIN32_WCE
-# define errno -1
-# define strerror(x) "Unknown Error"
-#endif
-
-
 //     -----------------------------------------------------------------------------------
 //     Imagine if C had a function to copy a file...
 int copy_file(char *old_file, char *new_file)
 {
-       sbyte   buf[CF_BUF_SIZE];
-       CFILE   *in_file, *out_file;
+       sbyte   buf[CF_BUF_SIZE];
+       PHYSFS_file *in_file, *out_file;
 
-       out_file = cfopen(new_file, "wb");
+       out_file = PHYSFS_openWrite(new_file);
 
        if (out_file == NULL)
                return -1;
 
-       in_file = cfopen(old_file, "rb");
+       in_file = PHYSFS_openRead(old_file);
 
        if (in_file == NULL)
                return -2;
 
-       while (!cfeof(in_file))
+       while (!PHYSFS_eof(in_file))
        {
                int bytes_read;
 
-               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 || cfeof(in_file));
+               bytes_read = PHYSFS_read(in_file, buf, 1, CF_BUF_SIZE);
+               if (bytes_read < 0)
+                       Error("Cannot read from file <%s>: %s", old_file, PHYSFS_getLastError());
 
-               cfwrite(buf, 1, bytes_read, out_file);
+               Assert(bytes_read == CF_BUF_SIZE || PHYSFS_eof(in_file));
 
-               if (cferror(out_file))
-                       Error("Cannot write to file <%s>: %s", new_file, strerror(errno));
+               if (PHYSFS_write(out_file, buf, 1, bytes_read) < bytes_read);
+                       Error("Cannot write to file <%s>: %s", new_file, PHYSFS_getLastError());
        }
 
-       if (cfclose(in_file)) {
-               cfclose(out_file);
+       if (!PHYSFS_close(in_file))
+       {
+               PHYSFS_close(out_file);
                return -3;
        }
 
-       if (cfclose(out_file))
+       if (!PHYSFS_close(out_file))
                return -4;
 
        return 0;
@@ -496,7 +492,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"));
-               cfile_delete(SECRETB_FILENAME);
+               PHYSFS_delete(SECRETB_FILENAME);
                return 0;
        }
 
@@ -541,14 +537,14 @@ 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 (cfexist(temp_fname))
+                       if (PHYSFS_exists(temp_fname))
                        {
                                mprintf((0, "Deleting file %s\n", temp_fname));
-                               rval = cfile_delete(temp_fname);
+                               rval = PHYSFS_delete(temp_fname);
                                Assert(rval == 0);      //      Oops, error deleting file in temp_fname.
                        }
 
-                       if (cfexist(SECRETC_FILENAME))
+                       if (PHYSFS_exists(SECRETC_FILENAME))
                        {
                                mprintf((0, "Copying secret.sgc to %s.\n", temp_fname));
                                rval = copy_file(SECRETC_FILENAME, temp_fname);
@@ -559,9 +555,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) {
-               CFILE *tfp;
-       
-               tfp = cfopen(filename, "rb");
+               PHYSFS_file *tfp;
+
+               tfp = PHYSFS_openRead(filename);
 
                if ( tfp ) {
                        char    newname[128];
@@ -569,14 +565,14 @@ int state_save_all(int between_levels, int secret_save, char *filename_override)
                        #ifndef MACINTOSH
                        sprintf( newname, "%s.sg%x", Players[Player_num].callsign, NUM_SAVES );
                        #else
-                       sprintf( newname, ":Players:%s.sg%x", Players[Player_num].callsign, NUM_SAVES );
+                       sprintf(newname, "Players/%s.sg%x", Players[Player_num].callsign, NUM_SAVES);
                        #endif
-                       
-                       cfseek(tfp, DESC_OFFSET, SEEK_SET);
-                       cfwrite("[autosave backup]", sizeof(char)*DESC_LENGTH, 1, tfp);
-                       cfclose(tfp);
-                       cfile_delete(newname);
-                       cfile_rename(filename, newname);
+
+                       PHYSFS_seek(tfp, DESC_OFFSET);
+                       PHYSFS_write(tfp, "[autosave backup]", sizeof(char) * DESC_LENGTH, 1);
+                       PHYSFS_close(tfp);
+                       PHYSFS_delete(newname);
+                       PHYSFSX_rename(filename, newname);
                }
        }
        
@@ -591,7 +587,7 @@ extern      fix     Flash_effect, Time_flash_last_played;
 int state_save_all_sub(char *filename, char *desc, int between_levels)
 {
        int i,j;
-       CFILE *fp;
+       PHYSFS_file *fp;
        grs_canvas * cnv;
        #ifdef POLY_ACC
        grs_canvas cnv2,*save_cnv2;
@@ -612,7 +608,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
                Int3();
        #endif
 
-       fp = cfopen(filename, "wb");
+       fp = PHYSFS_openWrite(filename);
        if ( !fp ) {
                if ( !(Game_mode & GM_MULTI) )
                        nm_messagebox(NULL, 1, TXT_OK, "Error writing savegame.\nPossibly out of disk\nspace.");
@@ -621,14 +617,14 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
        }
 
 //Save id
-       cfwrite(dgss_id, sizeof(char)*4, 1, fp);
+       PHYSFS_write(fp, dgss_id, sizeof(char) * 4, 1);
 
 //Save version
        i = STATE_VERSION;
-       cfwrite(&i, sizeof(int), 1, fp);
+       PHYSFS_write(fp, &i, sizeof(int), 1);
 
 //Save description
-       cfwrite(desc, sizeof(char) * DESC_LENGTH, 1, fp);
+       PHYSFS_write(fp, desc, sizeof(char) * DESC_LENGTH, 1);
        
 // Save the current screen shot...
 
@@ -699,7 +695,7 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
 
                                        pal = gr_palette;
 
-                                       cfwrite(cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
+                                       PHYSFS_write(fp, cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1);
 
                        #if defined(POLY_ACC)
                                        PA_DFX (pa_alpha_always());     
@@ -722,7 +718,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;
-                       cfwrite(cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1, fp);
+                       PHYSFS_write(fp, cnv->cv_bitmap.bm_data, THUMBNAIL_W * THUMBNAIL_H, 1);
                        
                        #if defined(POLY_ACC)
                                PAEnabled = savePAEnabled;
@@ -736,68 +732,68 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
                        gr_set_current_canvas(cnv_save)
                );
                gr_free_canvas( cnv );
-               cfwrite(pal, 3, 256, fp);
+               PHYSFS_write(fp, pal, 3, 256);
        }
        else
        {
                ubyte color = 0;
                for ( i=0; i<THUMBNAIL_W*THUMBNAIL_H; i++ )
-                       cfwrite(&color, sizeof(ubyte), 1, fp);
-       }
+                       PHYSFS_write(fp, &color, sizeof(ubyte), 1);             
+       } 
 
 // Save the Between levels flag...
-       cfwrite(&between_levels, sizeof(int), 1, fp);
+       PHYSFS_write(fp, &between_levels, sizeof(int), 1);
 
 // Save the mission info...
         mprintf ((0, "HEY! Mission name is %s\n", Current_mission_filename));
-       cfwrite(Current_mission_filename, sizeof(char), 9, fp);
+       PHYSFS_write(fp, Current_mission_filename, 9 * sizeof(char), 1);
 
 //Save level info
-       cfwrite(&Current_level_num, sizeof(int), 1, fp);
-       cfwrite(&Next_level_num, sizeof(int), 1, fp);
+       PHYSFS_write(fp, &Current_level_num, sizeof(int), 1);
+       PHYSFS_write(fp, &Next_level_num, sizeof(int), 1);
 
 //Save GameTime
-       cfwrite(&GameTime, sizeof(fix), 1, fp);
+       PHYSFS_write(fp, &GameTime, sizeof(fix), 1);
 
 // If coop save, save all
 #ifdef NETWORK
    if (Game_mode & GM_MULTI_COOP)
         {
-               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);
+               PHYSFS_write(fp, &state_game_id,sizeof(int), 1);
+               PHYSFS_write(fp, &Netgame,sizeof(netgame_info), 1);
+               PHYSFS_write(fp, &NetPlayers,sizeof(AllNetPlayers_info), 1);
+               PHYSFS_write(fp, &N_players,sizeof(int), 1);
+               PHYSFS_write(fp, &Player_num,sizeof(int), 1);
                for (i=0;i<N_players;i++)
-                       cfwrite(&Players[i], sizeof(player), 1, fp);
+                       PHYSFS_write(fp, &Players[i], sizeof(player), 1);
 
 #ifdef RISKY_PROPOSITION
-               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);
-
+               PHYSFS_write(fp, &robot_controlled[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_write(fp, &robot_agitation[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_write(fp, &robot_controlled_time[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_write(fp, &robot_last_send_time[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_write(fp, &robot_last_message_time[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_write(fp, &robot_send_pending[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_write(fp, &robot_fired[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
       for (i=0;i<MAX_ROBOTS_CONTROLLED;i++)
-                       cfwrite(robot_fire_buf[i][0], 18 + 3, 1, fp);
+                       PHYSFS_write(fp, robot_fire_buf[i][0], 18 + 3, 1);
 #endif
 
         }
 #endif
 
 //Save player info
-       cfwrite(&Players[Player_num], sizeof(player), 1, fp);
+       PHYSFS_write(fp, &Players[Player_num], sizeof(player), 1);
 
 // Save the current weapon info
-       cfwrite(&Primary_weapon, sizeof(sbyte), 1, fp);
-       cfwrite(&Secondary_weapon, sizeof(sbyte), 1, fp);
+       PHYSFS_write(fp, &Primary_weapon, sizeof(sbyte), 1);
+       PHYSFS_write(fp, &Secondary_weapon, sizeof(sbyte), 1);
 
 // Save the difficulty level
-       cfwrite(&Difficulty_level, sizeof(int), 1, fp);
+       PHYSFS_write(fp, &Difficulty_level, sizeof(int), 1);
 // Save cheats enabled
-       cfwrite(&Cheats_enabled, sizeof(int), 1, fp);
+       PHYSFS_write(fp, &Cheats_enabled,sizeof(int), 1);
 
        if ( !between_levels )  {
 
@@ -823,104 +819,104 @@ int state_save_all_sub(char *filename, char *desc, int between_levels)
        
        //Save object info
                i = Highest_object_index+1;
-               cfwrite(&i, sizeof(int), 1, fp);
-               cfwrite(Objects, sizeof(object), i, fp);
+               PHYSFS_write(fp, &i, sizeof(int), 1);
+               PHYSFS_write(fp, Objects, sizeof(object), i);
                
        //Save wall info
                i = Num_walls;
-               cfwrite(&i, sizeof(int), 1, fp);
-               cfwrite(Walls, sizeof(wall), i, fp);
+               PHYSFS_write(fp, &i, sizeof(int), 1);
+               PHYSFS_write(fp, Walls, sizeof(wall), i);
 
        //Save exploding wall info
                i = MAX_EXPLODING_WALLS;
-               cfwrite(&i, sizeof(int), 1, fp);
-               cfwrite(expl_wall_list, sizeof(*expl_wall_list), i, fp);
+               PHYSFS_write(fp, &i, sizeof(int), 1);
+               PHYSFS_write(fp, expl_wall_list, sizeof(*expl_wall_list), i);
        
        //Save door info
                i = Num_open_doors;
-               cfwrite(&i, sizeof(int), 1, fp );
-               cfwrite(ActiveDoors, sizeof(active_door), i, fp);
+               PHYSFS_write(fp, &i, sizeof(int), 1);
+               PHYSFS_write(fp, ActiveDoors, sizeof(active_door), i);
        
        //Save cloaking wall info
                i = Num_cloaking_walls;
-               cfwrite(&i, sizeof(int), 1, fp );
-               cfwrite(CloakingWalls, sizeof(cloaking_wall), i, fp);
+               PHYSFS_write(fp, &i, sizeof(int), 1);
+               PHYSFS_write(fp, CloakingWalls, sizeof(cloaking_wall), i);
        
        //Save trigger info
-               cfwrite(&Num_triggers, sizeof(int), 1, fp);
-               cfwrite(Triggers, sizeof(trigger), Num_triggers, fp);
+               PHYSFS_write(fp, &Num_triggers, sizeof(int), 1);
+               PHYSFS_write(fp, Triggers, sizeof(trigger), Num_triggers);
        
        //Save tmap info
-               for (i=0; i<=Highest_segment_index; i++ )       {
-                       for (j=0; j<6; j++ )    {
-                               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);
+               for (i = 0; i <= Highest_segment_index; i++)
+               {
+                       for (j = 0; j < 6; j++)
+                       {
+                               PHYSFS_write(fp, &Segments[i].sides[j].wall_num, sizeof(short), 1);
+                               PHYSFS_write(fp, &Segments[i].sides[j].tmap_num, sizeof(short), 1);
+                               PHYSFS_write(fp, &Segments[i].sides[j].tmap_num2, sizeof(short), 1);
                        }
                }
        
        // Save the fuelcen info
-               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);
+               PHYSFS_write(fp, &Control_center_destroyed, sizeof(int), 1);
+               PHYSFS_write(fp, &Countdown_timer, sizeof(int), 1);
+               PHYSFS_write(fp, &Num_robot_centers, sizeof(int), 1);
+               PHYSFS_write(fp, RobotCenters, sizeof(matcen_info), Num_robot_centers);
+               PHYSFS_write(fp, &ControlCenterTriggers, sizeof(control_center_triggers), 1);
+               PHYSFS_write(fp, &Num_fuelcenters, sizeof(int), 1);
+               PHYSFS_write(fp, Station, sizeof(FuelCenter), Num_fuelcenters);
        
        // Save the control cen info
-               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);
+               PHYSFS_write(fp, &Control_center_been_hit, sizeof(int), 1);
+               PHYSFS_write(fp, &Control_center_player_been_seen, sizeof(int), 1);
+               PHYSFS_write(fp, &Control_center_next_fire_time, sizeof(int), 1);
+               PHYSFS_write(fp, &Control_center_present, sizeof(int), 1);
+               PHYSFS_write(fp, &Dead_controlcen_object_num, sizeof(int), 1);
        
        // Save the AI state
                ai_save_state( fp );
        
        // Save the automap visited info
-               cfwrite(Automap_visited, sizeof(ubyte) * MAX_SEGMENTS, 1, fp);
+               PHYSFS_write(fp, Automap_visited, sizeof(ubyte), MAX_SEGMENTS);
 
        }
-       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);
+       PHYSFS_write(fp, &state_game_id, sizeof(uint), 1);
+       PHYSFS_write(fp, &Laser_rapid_fire, sizeof(int), 1);
+       PHYSFS_write(fp, &Lunacy, sizeof(int), 1);  //  Yes, writing this twice.  Removed the Ugly robot system, but didn't want to change savegame format.
+       PHYSFS_write(fp, &Lunacy, sizeof(int), 1);
 
        // Save automap marker info
 
-       cfwrite(MarkerObject, sizeof(MarkerObject), 1, fp);
-       cfwrite(MarkerOwner, sizeof(MarkerOwner), 1, fp);
-       cfwrite(MarkerMessage, sizeof(MarkerMessage), 1, fp);
+       PHYSFS_write(fp, MarkerObject, sizeof(MarkerObject) ,1);
+       PHYSFS_write(fp, MarkerOwner, sizeof(MarkerOwner), 1);
+       PHYSFS_write(fp, MarkerMessage, sizeof(MarkerMessage), 1);
 
-       cfwrite(&Afterburner_charge, sizeof(fix), 1, fp);
+       PHYSFS_write(fp, &Afterburner_charge, sizeof(fix), 1);
 
        //save last was super information
-       cfwrite(&Primary_last_was_super, sizeof(Primary_last_was_super), 1, fp);
-       cfwrite(&Secondary_last_was_super, sizeof(Secondary_last_was_super), 1, fp);
+       PHYSFS_write(fp, &Primary_last_was_super, sizeof(Primary_last_was_super), 1);
+       PHYSFS_write(fp, &Secondary_last_was_super, sizeof(Secondary_last_was_super), 1);
 
        //      Save flash effect stuff
-       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);
+       PHYSFS_write(fp, &Flash_effect, sizeof(int), 1);
+       PHYSFS_write(fp, &Time_flash_last_played, sizeof(int), 1);
+       PHYSFS_write(fp, &PaletteRedAdd, sizeof(int), 1);
+       PHYSFS_write(fp, &PaletteGreenAdd, sizeof(int), 1);
+       PHYSFS_write(fp, &PaletteBlueAdd, sizeof(int), 1);
 
-       cfwrite(Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS, fp);
+       PHYSFS_write(fp, Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS);
 
-       cfwrite(&First_secret_visit, sizeof(First_secret_visit), 1, fp);
+       PHYSFS_write(fp, &First_secret_visit, sizeof(First_secret_visit), 1);
 
-       cfwrite(&Omega_charge, sizeof(Omega_charge), 1, fp);
-       
-       if (cferror(fp))
+       if (PHYSFS_write(fp, &Omega_charge, sizeof(Omega_charge), 1) < 1)
        {
                if ( !(Game_mode & GM_MULTI) ) {
                        nm_messagebox(NULL, 1, TXT_OK, "Error writing savegame.\nPossibly out of disk\nspace.");
-                       cfclose(fp);
-                       cfile_delete(filename);
+                       PHYSFS_close(fp);
+                       PHYSFS_delete(filename);
                }
        } else  {
-               cfclose(fp);
+               PHYSFS_close(fp);
 
                #ifdef MACINTOSH                // set the type and creator of the saved game file
                {
@@ -1008,18 +1004,18 @@ int state_restore_all(int in_game, int secret_restore, char *filename_override)
                        #ifndef MACINTOSH
                        sprintf(temp_fname, "%csecret.sgc", fc);
                        #else
-                       sprintf(temp_fname, ":Players:%csecret.sgc", fc);
+                       sprintf(temp_fname, "Players/%csecret.sgc", fc);
                        #endif
 
                        mprintf((0, "Trying to copy %s to secret.sgc.\n", temp_fname));
 
-                       if (cfexist(temp_fname))
+                       if (PHYSFS_exists(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
-                               cfile_delete(SECRETC_FILENAME);
+                               PHYSFS_delete(SECRETC_FILENAME);
                }
        }
 
@@ -1030,8 +1026,8 @@ int state_restore_all(int in_game, int secret_restore, char *filename_override)
                #ifndef MACINTOSH
                sprintf( temp_filename, "%s.sg%x", Players[Player_num].callsign, NUM_SAVES );
                #else
-               sprintf( temp_filename, ":Players:%s.sg%x", Players[Player_num].callsign, NUM_SAVES );
-               #endif          
+               sprintf(temp_filename, "Players/%s.sg%x", Players[Player_num].callsign, NUM_SAVES);
+               #endif
                state_save_all(!in_game, secret_restore, temp_filename);
        }
 
@@ -1061,7 +1057,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
        int ObjectStartLocation;
        int version,i, j, segnum;
        object * obj;
-       CFILE *fp;
+       PHYSFS_file *fp;
        int current_level, next_level;
        int between_levels;
        char mission[16];
@@ -1076,57 +1072,58 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
        fix     old_gametime = GameTime;
 
        #if defined(MACINTOSH) && !defined(NDEBUG)
-       if ( strncmp(filename, ":Players:", 9) )
+       if (strncmp(filename, "Players/", 9))
                Int3();
        #endif
 
-       fp = cfopen(filename, "rb");
+       fp = PHYSFS_openRead(filename);
        if ( !fp ) return 0;
 
 //Read id
-       cfread(id, sizeof(char)*4, 1, fp);
+       //FIXME: check for swapped file, react accordingly...
+       PHYSFS_read(fp, id, sizeof(char) * 4, 1);
        if ( memcmp( id, dgss_id, 4 )) {
-               cfclose(fp);
+               PHYSFS_close(fp);
                return 0;
        }
 
 //Read version
-       cfread(&version, sizeof(int), 1, fp);
+       PHYSFS_read(fp, &version, sizeof(int), 1);
        if (version < STATE_COMPATIBLE_VERSION) {
-               cfclose(fp);
+               PHYSFS_close(fp);
                return 0;
        }
 
 // Read description
-       cfread(desc, sizeof(char) * DESC_LENGTH, 1, fp);
+       PHYSFS_read(fp, desc, sizeof(char) * DESC_LENGTH, 1);
 
 // Skip the current screen shot...
-       cfseek(fp, THUMBNAIL_W*THUMBNAIL_H, SEEK_CUR);
+       PHYSFS_seek(fp, PHYSFS_tell(fp) + THUMBNAIL_W * THUMBNAIL_H);
 
 // And now...skip the goddamn palette stuff that somebody forgot to add
-       cfseek(fp, 768, SEEK_CUR);
+       PHYSFS_seek(fp, PHYSFS_tell(fp) + 768);
 
 // Read the Between levels flag...
-       cfread(&between_levels, sizeof(int), 1, fp);
+       PHYSFS_read(fp, &between_levels, sizeof(int), 1);
 
        Assert(between_levels == 0);    //between levels save ripped out
 
 // Read the mission info...
-       cfread(mission, sizeof(char), 9, fp);
+       PHYSFS_read(fp, mission, sizeof(char) * 9, 1);
         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 );
-               cfclose(fp);
+               PHYSFS_close(fp);
                return 0;
        }
 
 //Read level info
-       cfread(&current_level, sizeof(int), 1, fp);
-       cfread(&next_level, sizeof(int), 1, fp);
+       PHYSFS_read(fp, &current_level, sizeof(int), 1);
+       PHYSFS_read(fp, &next_level, sizeof(int), 1);
 
 //Restore GameTime
-       cfread(&GameTime, sizeof(fix), 1, fp);
+       PHYSFS_read(fp, &GameTime, sizeof(fix), 1);
 
 // Start new game....
        if (!multi)     {
@@ -1148,24 +1145,24 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
 #ifdef NETWORK
    if (Game_mode & GM_MULTI)
         {
-               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);
+               PHYSFS_read(fp, &state_game_id, sizeof(int), 1);
+               PHYSFS_read(fp, &Netgame, sizeof(netgame_info), 1);
+               PHYSFS_read(fp, &NetPlayers, sizeof(AllNetPlayers_info), 1);
+               PHYSFS_read(fp, &nplayers, sizeof(N_players), 1);
+               PHYSFS_read(fp, &Player_num, sizeof(Player_num), 1);
                for (i=0;i<nplayers;i++)
-                       cfread(&restore_players[i], sizeof(player), 1, fp);
+                       PHYSFS_read(fp, &restore_players[i], sizeof(player), 1);
 #ifdef RISKY_PROPOSITION
-               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);
+               PHYSFS_read(fp, &robot_controlled[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_read(fp, &robot_agitation[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_read(fp, &robot_controlled_time[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_read(fp, &robot_last_send_time[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_read(fp, &robot_last_message_time[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_read(fp, &robot_send_pending[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
+               PHYSFS_read(fp, &robot_fired[0], 4 * MAX_ROBOTS_CONTROLLED, 1);
 
       for (i=0;i<MAX_ROBOTS_CONTROLLED;i++)
-                       cfread(&robot_fire_buf[i][0], 21, 1, fp);
+                       PHYSFS_read(fp, &robot_fire_buf[i][0],21,1);
 #endif
 
           for (i=0;i<nplayers;i++)
@@ -1204,7 +1201,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
                if (secret_restore) {
                        player  dummy_player;
 
-                       cfread(&dummy_player, sizeof(player), 1, fp);
+                       PHYSFS_read(fp, &dummy_player, sizeof(player), 1);
                        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;
@@ -1224,7 +1221,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
                                Players[Player_num] = dummy_player;
                        }
                } else {
-                       cfread(&Players[Player_num], sizeof(player), 1, fp);
+                       PHYSFS_read(fp, &Players[Player_num], sizeof(player), 1);
                }
        }
        strcpy( Players[Player_num].callsign, org_callsign );
@@ -1234,32 +1231,32 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
                Players[Player_num].level = next_level;
 
 // Restore the weapon states
-       cfread(&Primary_weapon, sizeof(sbyte), 1, fp);
-       cfread(&Secondary_weapon, sizeof(sbyte), 1, fp);
+       PHYSFS_read(fp, &Primary_weapon, sizeof(sbyte), 1);
+       PHYSFS_read(fp, &Secondary_weapon, sizeof(sbyte), 1);
 
        select_weapon(Primary_weapon, 0, 0, 0);
        select_weapon(Secondary_weapon, 1, 0, 0);
 
 // Restore the difficulty level
-       cfread(&Difficulty_level, sizeof(int), 1, fp);
+       PHYSFS_read(fp, &Difficulty_level, sizeof(int), 1);
 
 // Restore the cheats enabled flag
 
-       cfread(&Cheats_enabled, sizeof(int), 1, fp);
+       PHYSFS_read(fp, &Cheats_enabled, sizeof(int),1);
 
        if ( !between_levels )  {
                Do_appearance_effect = 0;                       // Don't do this for middle o' game stuff.
 
-               ObjectStartLocation = cftell(fp);
+               ObjectStartLocation = PHYSFS_tell(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.
-               cfread(&i, sizeof(int), 1, fp);
+               PHYSFS_read(fp, &i, sizeof(int), 1);
                Highest_object_index = i-1;
-               cfread(Objects, sizeof(object), i, fp);
+               PHYSFS_read(fp, Objects, sizeof(object) * i, 1);
        
                Object_next_signature = 0;
                for (i=0; i<=Highest_object_index; i++ )        {
@@ -1299,9 +1296,9 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
                }
 
                //Restore wall info
-               cfread(&i, sizeof(int), 1, fp);
+               PHYSFS_read(fp, &i, sizeof(int), 1);
                Num_walls = i;
-               cfread(Walls, sizeof(wall), Num_walls, fp);
+               PHYSFS_read(fp, Walls, sizeof(wall) * Num_walls, 1);
 
                //now that we have the walls, check if any sounds are linked to
                //walls that are now open
@@ -1312,55 +1309,55 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
 
                //Restore exploding wall info
                if (version >= 10) {
-                       cfread(&i, sizeof(int), 1, fp);
-                       cfread(expl_wall_list, sizeof(*expl_wall_list), i, fp);
+                       PHYSFS_read(fp, &i, sizeof(int), 1);
+                       PHYSFS_read(fp, expl_wall_list, sizeof(*expl_wall_list), i);
                }
 
                //Restore door info
-               cfread(&i, sizeof(int), 1, fp);
+               PHYSFS_read(fp, &i, sizeof(int), 1);
                Num_open_doors = i;
-               cfread(ActiveDoors, sizeof(active_door), Num_open_doors, fp);
+               PHYSFS_read(fp, ActiveDoors, sizeof(active_door), Num_open_doors);
        
                if (version >= 14) {            //Restore cloaking wall info
-                       cfread(&i, sizeof(int), 1, fp);
+                       PHYSFS_read(fp, &i, sizeof(int), 1);
                        Num_cloaking_walls = i;
-                       cfread(CloakingWalls, sizeof(cloaking_wall), Num_cloaking_walls, fp);
+                       PHYSFS_read(fp, CloakingWalls, sizeof(cloaking_wall), Num_cloaking_walls);
                }
        
                //Restore trigger info
-               cfread(&Num_triggers, sizeof(int), 1, fp);
-               cfread(Triggers, sizeof(trigger), Num_triggers, fp);
+               PHYSFS_read(fp, &Num_triggers, sizeof(int), 1);
+               PHYSFS_read(fp, Triggers, sizeof(trigger), Num_triggers);
        
                //Restore tmap info
                for (i=0; i<=Highest_segment_index; i++ )       {
                        for (j=0; j<6; j++ )    {
-                               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);
+                               PHYSFS_read(fp, &Segments[i].sides[j].wall_num, sizeof(short), 1);
+                               PHYSFS_read(fp, &Segments[i].sides[j].tmap_num, sizeof(short), 1);
+                               PHYSFS_read(fp, &Segments[i].sides[j].tmap_num2, sizeof(short), 1);
                        }
                }
        
                //Restore the fuelcen info
-               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);
+               PHYSFS_read(fp, &Control_center_destroyed, sizeof(int), 1);
+               PHYSFS_read(fp, &Countdown_timer, sizeof(int), 1);
+               PHYSFS_read(fp, &Num_robot_centers, sizeof(int), 1);
+               PHYSFS_read(fp, RobotCenters, sizeof(matcen_info), Num_robot_centers);
+               PHYSFS_read(fp, &ControlCenterTriggers, sizeof(control_center_triggers), 1);
+               PHYSFS_read(fp, &Num_fuelcenters, sizeof(int), 1);
+               PHYSFS_read(fp, Station, sizeof(FuelCenter), Num_fuelcenters);
        
                // Restore the control cen info
-               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);
+               PHYSFS_read(fp, &Control_center_been_hit, sizeof(int), 1);
+               PHYSFS_read(fp, &Control_center_player_been_seen, sizeof(int), 1);
+               PHYSFS_read(fp, &Control_center_next_fire_time, sizeof(int), 1);
+               PHYSFS_read(fp, &Control_center_present, sizeof(int), 1);
+               PHYSFS_read(fp, &Dead_controlcen_object_num, sizeof(int), 1);
        
                // Restore the AI state
                ai_restore_state( fp, version );
        
                // Restore the automap visited info
-               cfread( Automap_visited, sizeof(ubyte), MAX_SEGMENTS, fp);
+               PHYSFS_read(fp, Automap_visited, sizeof(ubyte), MAX_SEGMENTS);
 
                //      Restore hacked up weapon system stuff.
                Fusion_next_sound_time = GameTime;
@@ -1373,28 +1370,28 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
        state_game_id = 0;
 
        if ( version >= 7 )     {
-               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);
+               PHYSFS_read(fp, &state_game_id, sizeof(uint), 1);
+               PHYSFS_read(fp, &Laser_rapid_fire, sizeof(int), 1);
+               PHYSFS_read(fp, &Lunacy, sizeof(int), 1);               //      Yes, writing this twice.  Removed the Ugly robot system, but didn't want to change savegame format.
+               PHYSFS_read(fp, &Lunacy, sizeof(int), 1);
                if ( Lunacy )
                        do_lunacy_on();
        }
 
        if (version >= 17) {
-               cfread(MarkerObject, sizeof(MarkerObject), 1, fp);
-               cfread(MarkerOwner, sizeof(MarkerOwner), 1, fp);
-               cfread(MarkerMessage, sizeof(MarkerMessage), 1, fp);
+               PHYSFS_read(fp, MarkerObject, sizeof(MarkerObject), 1);
+               PHYSFS_read(fp, MarkerOwner, sizeof(MarkerOwner), 1);
+               PHYSFS_read(fp, MarkerMessage, sizeof(MarkerMessage), 1);
        }
        else {
                int num,dummy;
 
                // skip dummy info
 
-               cfread(&num, sizeof(int), 1, fp);       //was NumOfMarkers
-               cfread(&dummy, sizeof(int), 1, fp);     //was CurMarker
+               PHYSFS_read(fp, &num,sizeof(int), 1);           // was NumOfMarkers
+               PHYSFS_read(fp, &dummy,sizeof(int), 1);         // was CurMarker
 
-               cfseek(fp, num * (sizeof(vms_vector) + 40), SEEK_CUR);
+               PHYSFS_seek(fp, PHYSFS_tell(fp) + num * (sizeof(vms_vector) + 40));
 
                for (num=0;num<NUM_MARKERS;num++)
                        MarkerObject[num] = -1;
@@ -1402,24 +1399,24 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
 
        if (version>=11) {
                if (secret_restore != 1)
-                       cfread(&Afterburner_charge, sizeof(fix), 1, fp);
+                       PHYSFS_read(fp, &Afterburner_charge, sizeof(fix), 1);
                else {
                        fix     dummy_fix;
-                       cfread(&dummy_fix,sizeof(fix), 1, fp);
+                       PHYSFS_read(fp, &dummy_fix, sizeof(fix), 1);
                }
        }
        if (version>=12) {
                //read last was super information
-               cfread(&Primary_last_was_super, sizeof(Primary_last_was_super), 1, fp);
-               cfread(&Secondary_last_was_super, sizeof(Secondary_last_was_super), 1, fp);
+               PHYSFS_read(fp, &Primary_last_was_super, sizeof(Primary_last_was_super), 1);
+               PHYSFS_read(fp, &Secondary_last_was_super, sizeof(Secondary_last_was_super), 1);
        }
 
        if (version >= 12) {
-               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);
+               PHYSFS_read(fp, &Flash_effect, sizeof(int), 1);
+               PHYSFS_read(fp, &Time_flash_last_played, sizeof(int), 1);
+               PHYSFS_read(fp, &PaletteRedAdd, sizeof(int), 1);
+               PHYSFS_read(fp, &PaletteGreenAdd, sizeof(int), 1);
+               PHYSFS_read(fp, &PaletteBlueAdd, sizeof(int), 1);
        } else {
                Flash_effect = 0;
                Time_flash_last_played = 0;
@@ -1430,7 +1427,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
 
        //      Load Light_subtracted
        if (version >= 16) {
-               cfread(Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS, fp);
+               PHYSFS_read(fp, Light_subtracted, sizeof(Light_subtracted[0]), MAX_SEGMENTS);
                apply_all_changed_light();
                compute_all_static_light();     //      set static_light field in segment struct.  See note at that function.
        } else {
@@ -1441,7 +1438,7 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
 
        if (!secret_restore) {
                if (version >= 20) {
-                       cfread(&First_secret_visit, sizeof(First_secret_visit), 1, fp);
+                       PHYSFS_read(fp, &First_secret_visit, sizeof(First_secret_visit), 1);
                        mprintf((0, "File: [%s] Read First_secret_visit: New value = %i\n", filename, First_secret_visit));
                } else
                        First_secret_visit = 1;
@@ -1451,14 +1448,14 @@ int state_restore_all_sub(char *filename, int multi, int secret_restore)
        if (version >= 22)
        {
                if (secret_restore != 1)
-                       cfread(&Omega_charge,sizeof(fix), 1, fp);
+                       PHYSFS_read(fp, &Omega_charge, sizeof(fix), 1);
                else {
                        fix     dummy_fix;
-                       cfread(&dummy_fix,sizeof(fix), 1, fp);
+                       PHYSFS_read(fp, &dummy_fix, sizeof(fix), 1);
                }
        }
 
-       cfclose(fp);
+       PHYSFS_close(fp);
 
 #ifdef NETWORK
    if (Game_mode & GM_MULTI)   // Get rid of ships that aren't
@@ -1517,7 +1514,7 @@ void compute_all_static_light(void)
 int state_get_game_id(char *filename)
 {
        int version;
-       CFILE *fp;
+       PHYSFS_file *fp;
        int between_levels;
        char mission[16];
        char desc[DESC_LENGTH+1];
@@ -1526,47 +1523,48 @@ int state_get_game_id(char *filename)
 
 mprintf((0, "Restoring multigame from [%s]\n", filename));
 
-       fp = cfopen(filename, "rb");
-       if ( !fp ) return 0;
+       fp = PHYSFS_openRead(filename);
+       if (!fp) return 0;
 
 //Read id
-       cfread(id, sizeof(char)*4, 1, fp);
+       //FIXME: check for swapped file, react accordingly...
+       PHYSFS_read(fp, id, sizeof(char) * 4, 1);
        if ( memcmp( id, dgss_id, 4 )) {
-               cfclose(fp);
+               PHYSFS_close(fp);
                return 0;
        }
 
 //Read version
-       cfread(&version, sizeof(int), 1, fp);
+       PHYSFS_read(fp, &version, sizeof(int), 1);
        if (version < STATE_COMPATIBLE_VERSION) {
-               cfclose(fp);
+               PHYSFS_close(fp);
                return 0;
        }
 
 // Read description
-       cfread(desc, sizeof(char)*DESC_LENGTH, 1, fp);
+       PHYSFS_read(fp, desc, sizeof(char) * DESC_LENGTH, 1);
 
 // Skip the current screen shot...
-       cfseek(fp, THUMBNAIL_W*THUMBNAIL_H, SEEK_CUR);
+       PHYSFS_seek(fp, PHYSFS_tell(fp) + THUMBNAIL_W * THUMBNAIL_H);
 
 // And now...skip the palette stuff that somebody forgot to add
-       cfseek(fp, 768, SEEK_CUR);
+       PHYSFS_seek(fp, PHYSFS_tell(fp) + 768);
 
 // Read the Between levels flag...
-       cfread(&between_levels, sizeof(int), 1, fp);
+       PHYSFS_read(fp, &between_levels, sizeof(int), 1);
 
        Assert(between_levels == 0);    //between levels save ripped out
 
 // Read the mission info...
-       cfread(mission, sizeof(char), 9, fp);
+       PHYSFS_read(fp, mission, sizeof(char) * 9, 1);
 //Read level info
-       cfread(&dumbint, sizeof(int), 1, fp);
-       cfread(&dumbint, sizeof(int), 1, fp);
+       PHYSFS_read(fp, &dumbint, sizeof(int), 1);
+       PHYSFS_read(fp, &dumbint, sizeof(int), 1);
 
 //Restore GameTime
-       cfread(&dumbint, sizeof(fix), 1, fp);
+       PHYSFS_read(fp, &dumbint, sizeof(fix), 1);
 
-       cfread(&state_game_id, sizeof(int), 1, fp);
+       PHYSFS_read(fp, &state_game_id, sizeof(int), 1);
 
        return (state_game_id);
  }
index 05c7a56..15461bf 100644 (file)
@@ -6,8 +6,8 @@ PNG_SRCS = pngfile.c
 endif
 
 libmisc_a_SOURCES = ${PNG_SRCS} \
-args.c      error.c    strio.c \
-d_io.c      hash.c     strutil.c
+args.c      error.c    strio.c    ignorecase.c physfsrwops.c \
+hash.c     strutil.c
 
 EXTRA_libmisc_a_SOURCES = pngfile.c
 
index f85ebf4..96c90b1 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: args.c,v 1.14 2004-08-28 23:17:45 schaffner Exp $ */
+/* $Id: args.c,v 1.15 2004-12-01 12:48:13 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -23,19 +23,23 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: args.c,v 1.14 2004-08-28 23:17:45 schaffner Exp $";
+static char rcsid[] = "$Id: args.c,v 1.15 2004-12-01 12:48:13 btb Exp $";
 #endif
 
 #include <stdlib.h>
 #include <string.h>
 
-#include "cfile.h"
+#include <physfs.h>
+
+#include "args.h"
 #include "u_mem.h"
 #include "strio.h"
 #include "strutil.h"
 
+#define MAX_ARGS 100
+
 int Num_args=0;
-char * Args[100];
+char * Args[MAX_ARGS];
 
 int FindArg(char *s)
 {
@@ -85,8 +89,6 @@ void args_exit(void)
 void InitArgs( int argc,char **argv )
 {
        int i;
-       CFILE *f;
-       char *line,*word;
        
        Num_args=0;
        
@@ -98,13 +100,24 @@ void InitArgs( int argc,char **argv )
                if ( Args[i][0] == '-' )
                        strlwr( Args[i]  );  // Convert all args to lowercase
        }
+       AppendArgs();
+
+       atexit(args_exit);
+}
+
+void AppendArgs(void)
+{
+       PHYSFS_file *f;
+       char *line,*word;
+       int i;
+       
        if((i=FindArg("-ini")))
-               f = cfopen(Args[i+1], "rt");
+               f = PHYSFS_openRead(Args[i+1]);
        else
-               f = cfopen("d2x.ini", "rt");
+               f = PHYSFS_openRead("d2x.ini");
        
        if(f) {
-               while(!cfeof(f))
+               while(!PHYSFS_eof(f) && Num_args < MAX_ARGS)
                {
                        line=fgets_unlimited(f);
                        word=splitword(line,' ');
@@ -116,8 +129,6 @@ void InitArgs( int argc,char **argv )
                        
                        d_free(line); d_free(word);
                }
-               cfclose(f);
+               PHYSFS_close(f);
        }
-       
-       atexit(args_exit);
 }
diff --git a/misc/d_io.c b/misc/d_io.c
deleted file mode 100644 (file)
index bb1ca4e..0000000
+++ /dev/null
@@ -1,88 +0,0 @@
-/* $Id: d_io.c,v 1.8 2004-05-19 02:20:34 btb Exp $ */
-/*
- * some misc. file/disk routines
- * Arne de Bruijn, 1998
- */
-
-#ifdef HAVE_CONFIG_H
-#include <conf.h>
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include "d_io.h"
-#ifdef __DJGPP__
-#include "dos_disk.h"
-#endif
-//added 05/17/99 Matt Mueller
-#include "u_mem.h"
-//end addition -MM
-
-#if defined(_WIN32) && !defined(_WIN32_WCE)
-#include <windows.h>
-#define lseek(a,b,c) _lseek(a,b,c)
-#endif
-
-#if 0
-long filelength(int fd) {
-       long old_pos, size;
-
-       if ((old_pos = lseek(fd, 0, SEEK_CUR)) == -1 ||
-           (size = lseek(fd, 0, SEEK_END)) == -1 ||
-           (lseek(fd, old_pos, SEEK_SET)) == -1)
-               return -1L;
-       return size;
-}
-#endif
-
-long ffilelength(FILE *file)
-{
-       long old_pos, size;
-
-       if ((old_pos = ftell(file)) == -1 ||
-           fseek(file, 0, SEEK_END) == -1 ||
-           (size = ftell(file)) == -1 ||
-           fseek(file, old_pos, SEEK_SET) == -1)
-               return -1L;
-       return size;
-}
-
-
-unsigned long d_getdiskfree()
-{
-#ifdef __MSDOS__
-  return getdiskfree();
-#else
-#if 0//def __WINDOWS__
-       DWORD cbCluster = 0;
-       DWORD cClusters = 0;
-
-       GetDiskFreeSpace (
-               NULL,
-               &cbCluster,
-               NULL,
-               &cClusters,
-               NULL);
-       
-       return cbCluster * cClusters;
-#else
-  // FIXME:
-  return 999999999;
-#endif
-#endif
-}
-
-unsigned long GetDiskFree()
-{
- return d_getdiskfree();
-}
-
-// remove extension from filename, doesn't work with paths.
-void removeext(const char *filename, char *out) {
-       char *p;
-       if ((p = strrchr(filename, '.'))) {
-               strncpy(out, filename, p - filename);
-               out[p - filename] = 0;
-       } else
-               strcpy(out, filename);
-}
diff --git a/misc/ignorecase.c b/misc/ignorecase.c
new file mode 100644 (file)
index 0000000..5260c30
--- /dev/null
@@ -0,0 +1,218 @@
+/** \file ignorecase.c */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+
+#include "physfs.h"
+#include "ignorecase.h"
+
+/**
+ * Please see ignorecase.h for details.
+ *
+ * License: this code is public domain. I make no warranty that it is useful,
+ *  correct, harmless, or environmentally safe.
+ *
+ * This particular file may be used however you like, including copying it
+ *  verbatim into a closed-source project, exploiting it commercially, and
+ *  removing any trace of my name from the source (although I hope you won't
+ *  do that). I welcome enhancements and corrections to this file, but I do
+ *  not require you to send me patches if you make changes. This code has
+ *  NO WARRANTY.
+ *
+ * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
+ *  Please see LICENSE in the root of the source tree.
+ *
+ *  \author Ryan C. Gordon.
+ */
+
+/* I'm not screwing around with stricmp vs. strcasecmp... */
+static int caseInsensitiveStringCompare(const char *x, const char *y)
+{
+    int ux, uy;
+    do
+    {
+        ux = toupper((int) *x);
+        uy = toupper((int) *y);
+        if (ux != uy)
+            return((ux > uy) ? 1 : -1);
+        x++;
+        y++;
+    } while ((ux) && (uy));
+
+    return(0);
+} /* caseInsensitiveStringCompare */
+
+
+static int locateOneElement(char *buf)
+{
+    char *ptr;
+    char **rc;
+    char **i;
+
+    if (PHYSFS_exists(buf))
+        return(1);  /* quick rejection: exists in current case. */
+
+    ptr = strrchr(buf, '/');  /* find entry at end of path. */
+    if (ptr == NULL)
+    {
+        rc = PHYSFS_enumerateFiles("/");
+        ptr = buf;
+    } /* if */
+    else
+    {
+        *ptr = '\0';
+        rc = PHYSFS_enumerateFiles(buf);
+        *ptr = '/';
+        ptr++;  /* point past dirsep to entry itself. */
+    } /* else */
+
+    for (i = rc; *i != NULL; i++)
+    {
+        if (caseInsensitiveStringCompare(*i, ptr) == 0)
+        {
+            strcpy(ptr, *i); /* found a match. Overwrite with this case. */
+            PHYSFS_freeList(rc);
+            return(1);
+        } /* if */
+    } /* for */
+
+    /* no match at all... */
+    PHYSFS_freeList(rc);
+    return(0);
+} /* locateOneElement */
+
+
+int PHYSFSEXT_locateCorrectCase(char *buf)
+{
+    int rc;
+    char *ptr;
+    char *prevptr;
+
+    while (*buf == '/')  /* skip any '/' at start of string... */
+        buf++;
+
+    ptr = prevptr = buf;
+    if (*ptr == '\0')
+        return(0);  /* Uh...I guess that's success. */
+
+    while ((ptr = strchr(ptr + 1, '/')))
+    {
+        *ptr = '\0';  /* block this path section off */
+        rc = locateOneElement(buf);
+        *ptr = '/'; /* restore path separator */
+        if (!rc)
+            return(-2);  /* missing element in path. */
+    } /* while */
+
+    /* check final element... */
+    return(locateOneElement(buf) ? 0 : -1);
+} /* PHYSFSEXT_locateCorrectCase */
+
+
+#ifdef TEST_PHYSFSEXT_LOCATECORRECTCASE
+int main(int argc, char **argv)
+{
+    int rc;
+    char buf[128];
+    PHYSFS_file *f;
+
+    if (!PHYSFS_init(argv[0]))
+    {
+        fprintf(stderr, "PHYSFS_init(): %s\n", PHYSFS_getLastError());
+        return(1);
+    } /* if */
+
+    if (!PHYSFS_addToSearchPath(".", 1))
+    {
+        fprintf(stderr, "PHYSFS_addToSearchPath(): %s\n", PHYSFS_getLastError());
+        PHYSFS_deinit();
+        return(1);
+    } /* if */
+
+    if (!PHYSFS_setWriteDir("."))
+    {
+        fprintf(stderr, "PHYSFS_setWriteDir(): %s\n", PHYSFS_getLastError());
+        PHYSFS_deinit();
+        return(1);
+    } /* if */
+
+    if (!PHYSFS_mkdir("/a/b/c"))
+    {
+        fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
+        PHYSFS_deinit();
+        return(1);
+    } /* if */
+
+    if (!PHYSFS_mkdir("/a/b/C"))
+    {
+        fprintf(stderr, "PHYSFS_mkdir(): %s\n", PHYSFS_getLastError());
+        PHYSFS_deinit();
+        return(1);
+    } /* if */
+
+    f = PHYSFS_openWrite("/a/b/c/x.txt");
+    PHYSFS_close(f);
+    if (f == NULL)
+    {
+        fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
+        PHYSFS_deinit();
+        return(1);
+    } /* if */
+
+    f = PHYSFS_openWrite("/a/b/C/X.txt");
+    PHYSFS_close(f);
+    if (f == NULL)
+    {
+        fprintf(stderr, "PHYSFS_openWrite(): %s\n", PHYSFS_getLastError());
+        PHYSFS_deinit();
+        return(1);
+    } /* if */
+
+    strcpy(buf, "/a/b/c/x.txt");
+    rc = PHYSFSEXT_locateCorrectCase(buf);
+    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
+        printf("test 1 failed\n");
+
+    strcpy(buf, "/a/B/c/x.txt");
+    rc = PHYSFSEXT_locateCorrectCase(buf);
+    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
+        printf("test 2 failed\n");
+
+    strcpy(buf, "/a/b/C/x.txt");
+    rc = PHYSFSEXT_locateCorrectCase(buf);
+    if ((rc != 0) || (strcmp(buf, "/a/b/C/X.txt") != 0))
+        printf("test 3 failed\n");
+
+    strcpy(buf, "/a/b/c/X.txt");
+    rc = PHYSFSEXT_locateCorrectCase(buf);
+    if ((rc != 0) || (strcmp(buf, "/a/b/c/x.txt") != 0))
+        printf("test 4 failed\n");
+
+    strcpy(buf, "/a/b/c/z.txt");
+    rc = PHYSFSEXT_locateCorrectCase(buf);
+    if ((rc != -1) || (strcmp(buf, "/a/b/c/z.txt") != 0))
+        printf("test 5 failed\n");
+
+    strcpy(buf, "/A/B/Z/z.txt");
+    rc = PHYSFSEXT_locateCorrectCase(buf);
+    if ((rc != -2) || (strcmp(buf, "/a/b/Z/z.txt") != 0))
+        printf("test 6 failed\n");
+
+    printf("Testing completed.\n");
+    printf("  If no errors were reported, you're good to go.\n");
+
+    PHYSFS_delete("/a/b/c/x.txt");
+    PHYSFS_delete("/a/b/C/X.txt");
+    PHYSFS_delete("/a/b/c");
+    PHYSFS_delete("/a/b/C");
+    PHYSFS_delete("/a/b");
+    PHYSFS_delete("/a");
+    PHYSFS_deinit();
+    return(0);
+} /* main */
+#endif
+
+/* end of ignorecase.c ... */
+
diff --git a/misc/physfsrwops.c b/misc/physfsrwops.c
new file mode 100644 (file)
index 0000000..a6ab6fd
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * This code provides a glue layer between PhysicsFS and Simple Directmedia
+ *  Layer's (SDL) RWops i/o abstraction.
+ *
+ * License: this code is public domain. I make no warranty that it is useful,
+ *  correct, harmless, or environmentally safe.
+ *
+ * This particular file may be used however you like, including copying it
+ *  verbatim into a closed-source project, exploiting it commercially, and
+ *  removing any trace of my name from the source (although I hope you won't
+ *  do that). I welcome enhancements and corrections to this file, but I do
+ *  not require you to send me patches if you make changes. This code has
+ *  NO WARRANTY.
+ *
+ * Unless otherwise stated, the rest of PhysicsFS falls under the zlib license.
+ *  Please see LICENSE in the root of the source tree.
+ *
+ * SDL falls under the LGPL license. You can get SDL at http://www.libsdl.org/
+ *
+ *  This file was written by Ryan C. Gordon. (icculus@clutteredmind.org).
+ */
+
+#include <stdio.h>  /* used for SEEK_SET, SEEK_CUR, SEEK_END ... */
+#include "physfsrwops.h"
+
+static int physfsrwops_seek(SDL_RWops *rw, int offset, int whence)
+{
+    PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
+    int pos = 0;
+
+    if (whence == SEEK_SET)
+    {
+        pos = offset;
+    } /* if */
+
+    else if (whence == SEEK_CUR)
+    {
+        PHYSFS_sint64 current = PHYSFS_tell(handle);
+        if (current == -1)
+        {
+            SDL_SetError("Can't find position in file: %s",
+                          PHYSFS_getLastError());
+            return(-1);
+        } /* if */
+
+        pos = (int) current;
+        if ( ((PHYSFS_sint64) pos) != current )
+        {
+            SDL_SetError("Can't fit current file position in an int!");
+            return(-1);
+        } /* if */
+
+        if (offset == 0)  /* this is a "tell" call. We're done. */
+            return(pos);
+
+        pos += offset;
+    } /* else if */
+
+    else if (whence == SEEK_END)
+    {
+        PHYSFS_sint64 len = PHYSFS_fileLength(handle);
+        if (len == -1)
+        {
+            SDL_SetError("Can't find end of file: %s", PHYSFS_getLastError());
+            return(-1);
+        } /* if */
+
+        pos = (int) len;
+        if ( ((PHYSFS_sint64) pos) != len )
+        {
+            SDL_SetError("Can't fit end-of-file position in an int!");
+            return(-1);
+        } /* if */
+
+        pos += offset;
+    } /* else if */
+
+    else
+    {
+        SDL_SetError("Invalid 'whence' parameter.");
+        return(-1);
+    } /* else */
+
+    if ( pos < 0 )
+    {
+        SDL_SetError("Attempt to seek past start of file.");
+        return(-1);
+    } /* if */
+    
+    if (!PHYSFS_seek(handle, (PHYSFS_uint64) pos))
+    {
+        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+        return(-1);
+    } /* if */
+
+    return(pos);
+} /* physfsrwops_seek */
+
+
+static int physfsrwops_read(SDL_RWops *rw, void *ptr, int size, int maxnum)
+{
+    PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
+    PHYSFS_sint64 rc = PHYSFS_read(handle, ptr, size, maxnum);
+    if (rc != maxnum)
+    {
+        if (!PHYSFS_eof(handle)) /* not EOF? Must be an error. */
+            SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+    } /* if */
+
+    return((int) rc);
+} /* physfsrwops_read */
+
+
+static int physfsrwops_write(SDL_RWops *rw, const void *ptr, int size, int num)
+{
+    PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
+    PHYSFS_sint64 rc = PHYSFS_write(handle, ptr, size, num);
+    if (rc != num)
+        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+
+    return((int) rc);
+} /* physfsrwops_write */
+
+
+static int physfsrwops_close(SDL_RWops *rw)
+{
+    PHYSFS_file *handle = (PHYSFS_file *) rw->hidden.unknown.data1;
+    if (!PHYSFS_close(handle))
+    {
+        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+        return(-1);
+    } /* if */
+
+    SDL_FreeRW(rw);
+    return(0);
+} /* physfsrwops_close */
+
+
+static SDL_RWops *create_rwops(PHYSFS_file *handle)
+{
+    SDL_RWops *retval = NULL;
+
+    if (handle == NULL)
+        SDL_SetError("PhysicsFS error: %s", PHYSFS_getLastError());
+    else
+    {
+        retval = SDL_AllocRW();
+        if (retval != NULL)
+        {
+            retval->seek  = physfsrwops_seek;
+            retval->read  = physfsrwops_read;
+            retval->write = physfsrwops_write;
+            retval->close = physfsrwops_close;
+            retval->hidden.unknown.data1 = handle;
+        } /* if */
+    } /* else */
+
+    return(retval);
+} /* create_rwops */
+
+
+SDL_RWops *PHYSFSRWOPS_makeRWops(PHYSFS_file *handle)
+{
+    SDL_RWops *retval = NULL;
+    if (handle == NULL)
+        SDL_SetError("NULL pointer passed to PHYSFSRWOPS_makeRWops().");
+    else
+        retval = create_rwops(handle);
+
+    return(retval);
+} /* PHYSFSRWOPS_makeRWops */
+
+
+SDL_RWops *PHYSFSRWOPS_openRead(const char *fname)
+{
+    return(create_rwops(PHYSFS_openRead(fname)));
+} /* PHYSFSRWOPS_openRead */
+
+
+SDL_RWops *PHYSFSRWOPS_openWrite(const char *fname)
+{
+    return(create_rwops(PHYSFS_openWrite(fname)));
+} /* PHYSFSRWOPS_openWrite */
+
+
+SDL_RWops *PHYSFSRWOPS_openAppend(const char *fname)
+{
+    return(create_rwops(PHYSFS_openAppend(fname)));
+} /* PHYSFSRWOPS_openAppend */
+
+
+/* end of physfsrwops.c ... */
+
index d90989b..7669ee6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: strio.c,v 1.5 2004-08-06 20:28:57 schaffner Exp $ */
+/* $Id: strio.c,v 1.6 2004-12-01 12:48:13 btb Exp $ */
 /*
  * strio.c: string/file manipulation functions by Victor Rachels
  */
@@ -8,7 +8,7 @@
 #endif
 
 #include <stdlib.h>
-#include <string.h>
+#include <stdio.h>
 
 #include "cfile.h"
 #include "strio.h"
@@ -16,7 +16,7 @@
 #include "u_mem.h"
 //end additions - adb
 
-char *fgets_unlimited(CFILE *f)
+char *fgets_unlimited(PHYSFS_file *f)
 {
     int                mem = 256;
     char       *word, *buf, *p;