]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
This is a patch from Elric greatly cleaning up the filesystem portions of the engine...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 21 Mar 2003 21:47:57 +0000 (21:47 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 21 Mar 2003 21:47:57 +0000 (21:47 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2844 d7cf8633-e32d-0410-b094-e92efae38249

49 files changed:
cd_linux.c
cd_win.c
cl_demo.c
cl_particles.c
cl_screen.c
cl_video.c
client.h
cmd.c
common.c
common.h
console.c
cvar.c
cvar.h
darkplaces.dsp
dpvsimpledecode.c
fs.c [new file with mode: 0644]
fs.h [new file with mode: 0644]
gl_textures.c
glquake.h
host.c
host_cmd.c
image.c
jpeg.c
keys.c
keys.h
makefile
makefile.mingw
makefile.mingwcross
menu.c
model_brush.c
model_shared.c
net_dgrm.c
net_main.c
palette.c
pr_edict.c
progs.h
quakedef.h
quakeio.c [deleted file]
quakeio.h [deleted file]
r_shadow.c
snd_mem.c
snd_mix.c
sv_main.c
sv_user.c
sys.h
sys_shared.c
wad.c
wavefile.c
wavefile.h

index eb8ef45f0abf11570930783c31625b0f78feaf12..7623b0a32cd4565a217e0c14b48df8f22a533f7a 100644 (file)
@@ -220,13 +220,13 @@ static void CD_f (void)
 
        command = Cmd_Argv (1);
 
-       if (Q_strcasecmp(command, "on") == 0)
+       if (strcasecmp(command, "on") == 0)
        {
                enabled = true;
                return;
        }
 
-       if (Q_strcasecmp(command, "off") == 0)
+       if (strcasecmp(command, "off") == 0)
        {
                if (playing)
                        CDAudio_Stop();
@@ -234,7 +234,7 @@ static void CD_f (void)
                return;
        }
 
-       if (Q_strcasecmp(command, "reset") == 0)
+       if (strcasecmp(command, "reset") == 0)
        {
                enabled = true;
                if (playing)
@@ -245,7 +245,7 @@ static void CD_f (void)
                return;
        }
 
-       if (Q_strcasecmp(command, "remap") == 0)
+       if (strcasecmp(command, "remap") == 0)
        {
                ret = Cmd_Argc() - 2;
                if (ret <= 0)
@@ -260,7 +260,7 @@ static void CD_f (void)
                return;
        }
 
-       if (Q_strcasecmp(command, "close") == 0)
+       if (strcasecmp(command, "close") == 0)
        {
                CDAudio_CloseDoor();
                return;
@@ -276,37 +276,37 @@ static void CD_f (void)
                }
        }
 
-       if (Q_strcasecmp(command, "play") == 0)
+       if (strcasecmp(command, "play") == 0)
        {
                CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false);
                return;
        }
 
-       if (Q_strcasecmp(command, "loop") == 0)
+       if (strcasecmp(command, "loop") == 0)
        {
                CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true);
                return;
        }
 
-       if (Q_strcasecmp(command, "stop") == 0)
+       if (strcasecmp(command, "stop") == 0)
        {
                CDAudio_Stop();
                return;
        }
 
-       if (Q_strcasecmp(command, "pause") == 0)
+       if (strcasecmp(command, "pause") == 0)
        {
                CDAudio_Pause();
                return;
        }
 
-       if (Q_strcasecmp(command, "resume") == 0)
+       if (strcasecmp(command, "resume") == 0)
        {
                CDAudio_Resume();
                return;
        }
 
-       if (Q_strcasecmp(command, "eject") == 0)
+       if (strcasecmp(command, "eject") == 0)
        {
                if (playing)
                        CDAudio_Stop();
@@ -315,7 +315,7 @@ static void CD_f (void)
                return;
        }
 
-       if (Q_strcasecmp(command, "info") == 0)
+       if (strcasecmp(command, "info") == 0)
        {
                Con_Printf("%u tracks\n", maxTrack);
                if (playing)
index 8d9f56841fa1a305412fcd5fd9b7f707986eb24a..8fba829a58c6677bb99fd376284bd5ed67da3e88 100644 (file)
--- a/cd_win.c
+++ b/cd_win.c
@@ -250,13 +250,13 @@ static void CD_f (void)
 
        command = Cmd_Argv (1);
 
-       if (Q_strcasecmp(command, "on") == 0)
+       if (strcasecmp(command, "on") == 0)
        {
                enabled = true;
                return;
        }
 
-       if (Q_strcasecmp(command, "off") == 0)
+       if (strcasecmp(command, "off") == 0)
        {
                if (playing)
                        CDAudio_Stop();
@@ -264,7 +264,7 @@ static void CD_f (void)
                return;
        }
 
-       if (Q_strcasecmp(command, "reset") == 0)
+       if (strcasecmp(command, "reset") == 0)
        {
                enabled = true;
                if (playing)
@@ -275,7 +275,7 @@ static void CD_f (void)
                return;
        }
 
-       if (Q_strcasecmp(command, "remap") == 0)
+       if (strcasecmp(command, "remap") == 0)
        {
                ret = Cmd_Argc() - 2;
                if (ret <= 0)
@@ -290,7 +290,7 @@ static void CD_f (void)
                return;
        }
 
-       if (Q_strcasecmp(command, "close") == 0)
+       if (strcasecmp(command, "close") == 0)
        {
                CDAudio_CloseDoor();
                return;
@@ -306,37 +306,37 @@ static void CD_f (void)
                }
        }
 
-       if (Q_strcasecmp(command, "play") == 0)
+       if (strcasecmp(command, "play") == 0)
        {
                CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), false);
                return;
        }
 
-       if (Q_strcasecmp(command, "loop") == 0)
+       if (strcasecmp(command, "loop") == 0)
        {
                CDAudio_Play((qbyte)atoi(Cmd_Argv (2)), true);
                return;
        }
 
-       if (Q_strcasecmp(command, "stop") == 0)
+       if (strcasecmp(command, "stop") == 0)
        {
                CDAudio_Stop();
                return;
        }
 
-       if (Q_strcasecmp(command, "pause") == 0)
+       if (strcasecmp(command, "pause") == 0)
        {
                CDAudio_Pause();
                return;
        }
 
-       if (Q_strcasecmp(command, "resume") == 0)
+       if (strcasecmp(command, "resume") == 0)
        {
                CDAudio_Resume();
                return;
        }
 
-       if (Q_strcasecmp(command, "eject") == 0)
+       if (strcasecmp(command, "eject") == 0)
        {
                if (playing)
                        CDAudio_Stop();
@@ -345,7 +345,7 @@ static void CD_f (void)
                return;
        }
 
-       if (Q_strcasecmp(command, "info") == 0)
+       if (strcasecmp(command, "info") == 0)
        {
                Con_Printf("%u tracks\n", maxTrack);
                if (playing)
index 831973dc58cfde3c32486e7890cbd61c9e0f2aed..2df5b97fd50c88ce12516cea5f4103af0bb9f132 100644 (file)
--- a/cl_demo.c
+++ b/cl_demo.c
@@ -78,7 +78,7 @@ void CL_StopPlayback (void)
        if (!cls.demoplayback)
                return;
 
-       Qclose (cls.demofile);
+       FS_Close (cls.demofile);
        cls.demoplayback = false;
        cls.demofile = NULL;
 
@@ -103,14 +103,14 @@ void CL_WriteDemoMessage (void)
                return;
 
        len = LittleLong (net_message.cursize);
-       Qwrite (cls.demofile, &len, 4);
+       FS_Write (cls.demofile, &len, 4);
        for (i=0 ; i<3 ; i++)
        {
                f = LittleFloat (cl.viewangles[i]);
-               Qwrite (cls.demofile, &f, 4);
+               FS_Write (cls.demofile, &f, 4);
        }
-       Qwrite (cls.demofile, net_message.data, net_message.cursize);
-       Qflush (cls.demofile);
+       FS_Write (cls.demofile, net_message.data, net_message.cursize);
+       FS_Flush (cls.demofile);
 }
 
 /*
@@ -150,18 +150,18 @@ int CL_GetMessage (void)
                }
                
        // get the next message
-               Qread (cls.demofile, &net_message.cursize, 4);
+               FS_Read (cls.demofile, &net_message.cursize, 4);
                VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
                for (i=0 ; i<3 ; i++)
                {
-                       r = Qread (cls.demofile, &f, 4);
+                       r = FS_Read (cls.demofile, &f, 4);
                        cl.mviewangles[0][i] = LittleFloat (f);
                }
                
                net_message.cursize = LittleLong (net_message.cursize);
                if (net_message.cursize > MAX_DATAGRAM)
                        Host_Error ("Demo message > MAX_DATAGRAM");
-               r = Qread (cls.demofile, net_message.data, net_message.cursize);
+               r = FS_Read (cls.demofile, net_message.data, net_message.cursize);
                if (r != net_message.cursize)
                {
                        CL_Disconnect ();
@@ -216,7 +216,7 @@ void CL_Stop_f (void)
        CL_WriteDemoMessage ();
 
 // finish up
-       Qclose (cls.demofile);
+       FS_Close (cls.demofile);
        cls.demofile = NULL;
        cls.demorecording = false;
        Con_Printf ("Completed demo\n");
@@ -257,7 +257,7 @@ void CL_Record_f (void)
                return;
        }
 
-// write the forced cd track number, or -1
+       // write the forced cd track number, or -1
        if (c == 4)
        {
                track = atoi(Cmd_Argv(3));
@@ -265,22 +265,18 @@ void CL_Record_f (void)
        }
        else
                track = -1;     
-
-       sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
        
-//
-// start the map up
-//
+       // start the map up
        if (c > 2)
                Cmd_ExecuteString ( va("map %s", Cmd_Argv(2)), src_command);
        
-//
-// open the demo file
-//
-       COM_DefaultExtension (name, ".dem");
+       // open the demo file
+       strncpy (name, Cmd_Argv(1), sizeof (name) - 1);
+       name[sizeof (name) - 1] = '\0';
+       FS_DefaultExtension (name, ".dem");
 
        Con_Printf ("recording to %s.\n", name);
-       cls.demofile = Qopen (name, "wb");
+       cls.demofile = FS_Open (name, "wb", false);
        if (!cls.demofile)
        {
                Con_Printf ("ERROR: couldn't open.\n");
@@ -288,7 +284,7 @@ void CL_Record_f (void)
        }
 
        cls.forcetrack = track;
-       Qprintf (cls.demofile, "%i\n", cls.forcetrack);
+       FS_Printf (cls.demofile, "%i\n", cls.forcetrack);
 
        cls.demorecording = true;
 }
@@ -316,19 +312,15 @@ void CL_PlayDemo_f (void)
                return;
        }
 
-//
-// disconnect from server
-//
+       // disconnect from server
        CL_Disconnect ();
 
-//
-// open the demo file
-//
+       // open the demo file
        strcpy (name, Cmd_Argv(1));
-       COM_DefaultExtension (name, ".dem");
+       FS_DefaultExtension (name, ".dem");
 
        Con_Printf ("Playing demo from %s.\n", name);
-       COM_FOpenFile (name, &cls.demofile, false, true);
+       cls.demofile = FS_Open (name, "rb", false);
        if (!cls.demofile)
        {
                Con_Printf ("ERROR: couldn't open.\n");
@@ -342,7 +334,7 @@ void CL_PlayDemo_f (void)
        cls.state = ca_connected;
        cls.forcetrack = 0;
 
-       while ((c = Qgetc(cls.demofile)) != '\n')
+       while ((c = FS_Getc (cls.demofile)) != '\n')
                if (c == '-')
                        neg = true;
                else
index d0b5fd57133e5ec57f0468d3cc183a8f0e78ea39..2dbe39dc99ff463ffc1b68e4e748921b61d8633b 100644 (file)
@@ -473,7 +473,7 @@ void CL_ReadPointFile_f (void)
                fclose(f);
        }
 #else
-       pointfile = COM_LoadFile(va("maps/%s.pts", cl.worldmodel->name), true);
+       pointfile = FS_LoadFile(va("maps/%s.pts", cl.worldmodel->name), true);
 #endif
        if (!pointfile)
        {
index 8e23cc53dac8d8c49841067fdbf8f010587b986e..5e7ce092f83bf708a1f38e4bad0cf842d984d3a6 100644 (file)
@@ -476,7 +476,7 @@ void CL_Screen_Init(void)
 
        // HACK HACK HACK
        // load the image data for the player image in the config menu
-       dat = (qpic_t *)COM_LoadFile ("gfx/menuplyr.lmp", false);
+       dat = (qpic_t *)FS_LoadFile ("gfx/menuplyr.lmp", false);
        if (!dat)
                Sys_Error("unable to load gfx/menuplyr.lmp");
        SwapPic (dat);
@@ -821,9 +821,9 @@ void SCR_ScreenShot_f (void)
        for (; i<=9999 ; i++)
        {
                sprintf (filename, "dp%04i.tga", i);
-               sprintf (checkname, "%s/%s", com_gamedir, filename);
-               if (Sys_FileTime(checkname) == -1)
-                       break;  // file doesn't exist
+               sprintf (checkname, "%s/%s", fs_gamedir, filename);
+               if (!FS_SysFileExists(checkname))
+                       break;
        }
        if (i==10000)
        {
index fb42b6f0efe1bb9f404b70b5e2b18249780ba7a7..a309b2e49288b9e9999e847d6d4c54691cdc9536 100644 (file)
@@ -193,7 +193,7 @@ static void CL_PlayVideo_f(void)
                return;
        }
 
-       sprintf(name, "%s/video/%s.dpv", com_gamedir, Cmd_Argv(1));
+       sprintf(name, "%s/video/%s.dpv", fs_gamedir, Cmd_Argv(1));
        CL_VideoStart(name);
 }
 
index 08c98223478cba7c306f968c7665e836cfb2bb6b..ff6f7b77cd49565254735a025bfe52730b563740 100644 (file)
--- a/client.h
+++ b/client.h
@@ -291,7 +291,7 @@ typedef struct
        qboolean timedemo;
        // -1 = use normal cd track
        int forcetrack;
-       QFile *demofile;
+       qfile_t *demofile;
        // to meter out one message a frame
        int td_lastframe;
        // host_framecount at start
diff --git a/cmd.c b/cmd.c
index c8aa380399379b67734276ecefbd35e44bb8bc70..fdd51bba4a590187400c770c916fbf189cc4432d 100644 (file)
--- a/cmd.c
+++ b/cmd.c
@@ -287,7 +287,7 @@ static void Cmd_Exec_f (void)
                return;
        }
 
-       f = (char *)COM_LoadFile (Cmd_Argv(1), false);
+       f = (char *)FS_LoadFile (Cmd_Argv(1), false);
        if (!f)
        {
                Con_Printf ("couldn't exec %s\n",Cmd_Argv(1));
@@ -806,7 +806,7 @@ void Cmd_ExecuteString (const char *text, cmd_source_t src)
 // check functions
        for (cmd=cmd_functions ; cmd ; cmd=cmd->next)
        {
-               if (!Q_strcasecmp (cmd_argv[0],cmd->name))
+               if (!strcasecmp (cmd_argv[0],cmd->name))
                {
                        cmd->function ();
                        return;
@@ -816,7 +816,7 @@ void Cmd_ExecuteString (const char *text, cmd_source_t src)
 // check alias
        for (a=cmd_alias ; a ; a=a->next)
        {
-               if (!Q_strcasecmp (cmd_argv[0], a->name))
+               if (!strcasecmp (cmd_argv[0], a->name))
                {
                        Cbuf_InsertText (a->value);
                        return;
@@ -848,7 +848,7 @@ void Cmd_ForwardToServer (void)
                return;         // not really connected
 
        MSG_WriteByte (&cls.message, clc_stringcmd);
-       if (Q_strcasecmp(Cmd_Argv(0), "cmd") != 0)
+       if (strcasecmp(Cmd_Argv(0), "cmd") != 0)
        {
                SZ_Print (&cls.message, Cmd_Argv(0));
                SZ_Print (&cls.message, " ");
@@ -877,7 +877,7 @@ int Cmd_CheckParm (const char *parm)
                Sys_Error ("Cmd_CheckParm: NULL");
 
        for (i = 1; i < Cmd_Argc (); i++)
-               if (!Q_strcasecmp (parm, Cmd_Argv (i)))
+               if (!strcasecmp (parm, Cmd_Argv (i)))
                        return i;
 
        return 0;
index 9e549fe7dd8ab781a66172792d409221deba64f8..c3ae64b09e787a1d55726b1a494bfb6787885422 100644 (file)
--- a/common.c
+++ b/common.c
@@ -21,9 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include <stdlib.h>
 #include <fcntl.h>
-#ifdef WIN32
-#include <io.h>
-#else
+#ifndef WIN32
 #include <unistd.h>
 #endif
 
@@ -32,14 +30,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 cvar_t registered = {0, "registered","0"};
 cvar_t cmdline = {0, "cmdline","0"};
 
-mempool_t *pak_mempool;
-
-qboolean com_modified;   // set true if using non-id files
-
-void COM_InitFilesystem (void);
+extern qboolean fs_modified;   // set true if using non-id files
 
 char com_token[1024];
-char com_basedir[MAX_OSPATH];
 int com_argc;
 const char **com_argv;
 
@@ -52,70 +45,6 @@ char *gamename;
 char *gamedirname;
 char com_modname[MAX_OSPATH];
 
-/*
-
-
-All of Quake's data access is through a hierchal file system, but the contents of the file system can be transparently merged from several sources.
-
-The "base directory" is the path to the directory holding the quake.exe and all game directories.  The sys_* files pass this to host_init in quakeparms_t->basedir.  This can be overridden with the "-basedir" command line parm to allow code debugging in a different directory.  The base directory is
-only used during filesystem initialization.
-
-The "game directory" is the first tree on the search path and directory that all generated files (savegames, screenshots, demos, config files) will be saved to.  This can be overridden with the "-game" command line parameter.  The game directory can never be changed while quake is executing.  This is a precacution against having a malicious server instruct clients to write files over areas they shouldn't.
-
-The "cache directory" is only used during development to save network bandwidth, especially over ISDN / T1 lines.  If there is a cache directory
-specified, when a file is found by the normal search path, it will be mirrored
-into the cache directory, then opened there.
-
-
-
-FIXME:
-The file "parms.txt" will be read out of the game directory and appended to the current command line arguments to allow different games to initialize startup parms differently.  This could be used to add a "-sspeed 22050" for the high quality sound edition.  Because they are added at the end, they will not override an explicit setting on the original command line.
-
-*/
-
-//============================================================================
-
-
-/*
-============================================================================
-
-                                       LIBRARY REPLACEMENT FUNCTIONS
-
-============================================================================
-*/
-
-int Q_strncasecmp (const char *s1, const char *s2, int n)
-{
-       int             c1, c2;
-
-       while (1)
-       {
-               c1 = *s1++;
-               c2 = *s2++;
-
-               if (!n--)
-                       return 0;               // strings are equal until end point
-
-               if (c1 != c2)
-               {
-                       if (c1 >= 'a' && c1 <= 'z')
-                               c1 -= ('a' - 'A');
-                       if (c2 >= 'a' && c2 <= 'z')
-                               c2 -= ('a' - 'A');
-                       if (c1 != c2)
-                               return -1;              // strings not equal
-               }
-               if (!c1)
-                       return 0;               // strings are equal
-       }
-
-       return -1;
-}
-
-int Q_strcasecmp (const char *s1, const char *s2)
-{
-       return Q_strncasecmp (s1, s2, 99999);
-}
 
 /*
 ============================================================================
@@ -528,108 +457,6 @@ void SZ_HexDumpToConsole(const sizebuf_t *buf)
 //============================================================================
 
 
-/*
-============
-COM_StripExtension
-============
-*/
-// LordHavoc: replacement for severely broken COM_StripExtension that was used in original quake.
-void COM_StripExtension (const char *in, char *out)
-{
-       char *last = NULL;
-       while (*in)
-       {
-               if (*in == '.')
-                       last = out;
-               else if (*in == '/' || *in == '\\' || *in == ':')
-                       last = NULL;
-               *out++ = *in++;
-       }
-       if (last)
-               *last = 0;
-       else
-               *out = 0;
-}
-
-/*
-============
-COM_FileExtension
-============
-*/
-char *COM_FileExtension (const char *in)
-{
-       static char exten[8];
-       int i;
-
-       while (*in && *in != '.')
-               in++;
-       if (!*in)
-               return "";
-       in++;
-       for (i=0 ; i<7 && *in ; i++,in++)
-               exten[i] = *in;
-       exten[i] = 0;
-       return exten;
-}
-
-/*
-============
-COM_FileBase
-============
-*/
-void COM_FileBase (const char *in, char *out)
-{
-       const char *slash, *dot, *s;
-
-       slash = in;
-       dot = NULL;
-       s = in;
-       while(*s)
-       {
-               if (*s == '/')
-                       slash = s + 1;
-               if (*s == '.')
-                       dot = s;
-               s++;
-       }
-       if (dot == NULL)
-               dot = s;
-       if (dot - slash < 2)
-               strcpy (out,"?model?");
-       else
-       {
-               while (slash < dot)
-                       *out++ = *slash++;
-               *out++ = 0;
-       }
-}
-
-
-/*
-==================
-COM_DefaultExtension
-==================
-*/
-void COM_DefaultExtension (char *path, const char *extension)
-{
-       const char *src;
-//
-// if path doesn't have a .EXT, append extension
-// (extension should include the .)
-//
-       src = path + strlen(path) - 1;
-
-       while (*src != '/' && src != path)
-       {
-               if (*src == '.')
-                       return;                 // it has an extension
-               src--;
-       }
-
-       strcat (path, extension);
-}
-
-
 /*
 ==============
 COM_ParseToken
@@ -756,9 +583,9 @@ void COM_CheckRegistered (void)
 {
        Cvar_Set ("cmdline", com_cmdline);
 
-       if (!Sys_FileTime("gfx/pop.lmp"))
+       if (!FS_FileExists("gfx/pop.lmp"))
        {
-               if (com_modified)
+               if (fs_modified)
                        Con_Printf ("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n");
                else
                        Con_Printf ("Playing shareware version.\n");
@@ -770,9 +597,6 @@ void COM_CheckRegistered (void)
 }
 
 
-void COM_Path_f (void);
-
-
 /*
 ================
 COM_InitArgv
@@ -799,7 +623,7 @@ void COM_InitArgv (void)
 void COM_InitGameType (void)
 {
        char name[MAX_OSPATH];
-       COM_StripExtension(com_argv[0], name);
+       FS_StripExtension(com_argv[0], name);
        COM_ToLowerString(name, name);
 
        if (strstr(name, "transfusion"))
@@ -862,6 +686,7 @@ void COM_InitGameType (void)
 
 
 extern void Mathlib_Init(void);
+extern void FS_Init (void);
 
 /*
 ================
@@ -894,15 +719,12 @@ void COM_Init (void)
        }
 #endif
 
-       pak_mempool = Mem_AllocPool("paks");
-
        Cvar_RegisterVariable (&registered);
        Cvar_RegisterVariable (&cmdline);
-       Cmd_AddCommand ("path", COM_Path_f);
 
        Mathlib_Init();
 
-       COM_InitFilesystem ();
+       FS_Init ();
        COM_CheckRegistered ();
 
        COM_InitGameType();
@@ -935,589 +757,6 @@ char *va(const char *format, ...)
 }
 
 
-/*
-=============================================================================
-
-QUAKE FILESYSTEM
-
-=============================================================================
-*/
-
-int com_filesize;
-
-
-//
-// in memory
-//
-
-typedef struct
-{
-       char name[MAX_QPATH];
-       int filepos, filelen;
-} packfile_t;
-
-typedef struct pack_s
-{
-       char filename[MAX_OSPATH];
-       int handle;
-       int numfiles;
-       packfile_t *files;
-       mempool_t *mempool;
-       struct pack_s *next;
-} pack_t;
-
-//
-// on disk
-//
-typedef struct
-{
-       char name[56];
-       int filepos, filelen;
-} dpackfile_t;
-
-typedef struct
-{
-       char id[4];
-       int dirofs;
-       int dirlen;
-} dpackheader_t;
-
-// LordHavoc: was 2048, increased to 65536 and changed info[MAX_PACK_FILES] to a temporary alloc
-#define MAX_FILES_IN_PACK       65536
-
-pack_t *packlist = NULL;
-
-#if CACHEENABLE
-char com_cachedir[MAX_OSPATH];
-#endif
-char com_gamedir[MAX_OSPATH];
-
-typedef struct searchpath_s
-{
-       // only one of filename / pack will be used
-       char filename[MAX_OSPATH];
-       pack_t *pack;
-       struct searchpath_s *next;
-} searchpath_t;
-
-searchpath_t *com_searchpaths;
-
-/*
-============
-COM_Path_f
-
-============
-*/
-void COM_Path_f (void)
-{
-       searchpath_t *s;
-
-       Con_Printf ("Current search path:\n");
-       for (s=com_searchpaths ; s ; s=s->next)
-       {
-               if (s->pack)
-               {
-                       Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles);
-               }
-               else
-                       Con_Printf ("%s\n", s->filename);
-       }
-}
-
-/*
-============
-COM_CreatePath
-
-LordHavoc: Previously only used for CopyFile, now also used for COM_WriteFile.
-============
-*/
-void    COM_CreatePath (char *path)
-{
-       char *ofs, save;
-
-       for (ofs = path+1 ; *ofs ; ofs++)
-       {
-               if (*ofs == '/' || *ofs == '\\')
-               {
-                       // create the directory
-                       save = *ofs;
-                       *ofs = 0;
-                       Sys_mkdir (path);
-                       *ofs = save;
-               }
-       }
-}
-
-
-/*
-============
-COM_WriteFile
-
-The filename will be prefixed by the current game directory
-============
-*/
-qboolean COM_WriteFile (const char *filename, void *data, int len)
-{
-       int handle;
-       char name[MAX_OSPATH];
-
-       sprintf (name, "%s/%s", com_gamedir, filename);
-
-       // LordHavoc: added this
-       // create directories up to the file
-       COM_CreatePath (name);
-
-       handle = Sys_FileOpenWrite (name);
-       if (handle == -1)
-       {
-               Con_Printf ("COM_WriteFile: failed on %s\n", name);
-               return false;
-       }
-
-       Con_DPrintf ("COM_WriteFile: %s\n", name);
-       Sys_FileWrite (handle, data, len);
-       Sys_FileClose (handle);
-       return true;
-}
-
-
-/*
-===========
-COM_CopyFile
-
-Copies a file over from the net to the local cache, creating any directories
-needed.  This is for the convenience of developers using ISDN from home.
-===========
-*/
-void COM_CopyFile (char *netpath, char *cachepath)
-{
-       int in, out, remaining, count;
-       char buf[4096];
-
-       remaining = Sys_FileOpenRead (netpath, &in);
-       COM_CreatePath (cachepath);     // create directories up to the cache file
-       out = Sys_FileOpenWrite (cachepath);
-
-       while (remaining)
-       {
-               if (remaining < (int)sizeof(buf))
-                       count = remaining;
-               else
-                       count = sizeof(buf);
-               Sys_FileRead (in, buf, count);
-               Sys_FileWrite (out, buf, count);
-               remaining -= count;
-       }
-
-       Sys_FileClose (in);
-       Sys_FileClose (out);
-}
-
-/*
-===========
-COM_OpenRead
-===========
-*/
-QFile * COM_OpenRead (const char *path, int offs, int len, qboolean zip)
-{
-       int fd = open (path, O_RDONLY);
-       unsigned char id[2], len_bytes[4];
-
-       if (fd == -1)
-       {
-               Sys_Error ("Couldn't open %s", path);
-               return 0;
-       }
-       if (offs < 0 || len < 0)
-       {
-               // normal file
-               offs = 0;
-               len = lseek (fd, 0, SEEK_END);
-               lseek (fd, 0, SEEK_SET);
-       }
-       lseek (fd, offs, SEEK_SET);
-       if (zip)
-       {
-               read (fd, id, 2);
-               if (id[0] == 0x1f && id[1] == 0x8b)
-               {
-                       lseek (fd, offs + len - 4, SEEK_SET);
-                       read (fd, len_bytes, 4);
-                       len = ((len_bytes[3] << 24)
-                                  | (len_bytes[2] << 16)
-                                  | (len_bytes[1] << 8)
-                                  | (len_bytes[0]));
-               }
-       }
-       lseek (fd, offs, SEEK_SET);
-       com_filesize = len;
-
-#ifdef WIN32
-       setmode (fd, O_BINARY);
-#endif
-       if (zip)
-               return Qdopen (fd, "rbz");
-       else
-               return Qdopen (fd, "rb");
-}
-
-/*
-===========
-COM_FindFile
-
-Finds the file in the search path.
-Sets com_filesize and one of handle or file
-===========
-*/
-int COM_FindFile (const char *filename, QFile **file, qboolean quiet, qboolean zip)
-{
-       searchpath_t *search;
-       char netpath[MAX_OSPATH];
-#if CACHEENABLE
-       char cachepath[MAX_OSPATH];
-       int cachetime;
-#endif
-       pack_t *pak;
-       int i, findtime, filenamelen;
-       char gzfilename[MAX_OSPATH];
-
-       filenamelen = strlen (filename);
-       sprintf (gzfilename, "%s.gz", filename);
-
-       if (!file)
-               Sys_Error ("COM_FindFile: file not set");
-
-//
-// search through the path, one element at a time
-//
-       search = com_searchpaths;
-
-       for ( ; search ; search = search->next)
-       {
-       // is the element a pak file?
-               if (search->pack)
-               {
-               // look through all the pak file elements
-                       pak = search->pack;
-                       for (i=0 ; i<pak->numfiles ; i++)
-                               if (!strcmp (pak->files[i].name, filename)
-                                   || !strcmp (pak->files[i].name, gzfilename))
-                               {       // found it!
-                                       if (!quiet)
-                                               Sys_Printf ("PackFile: %s : %s\n",pak->filename, pak->files[i].name);
-                                       // open a new file on the pakfile
-                                       *file = COM_OpenRead (pak->filename, pak->files[i].filepos, pak->files[i].filelen, zip);
-                                       return com_filesize;
-                               }
-               }
-               else
-               {
-                       sprintf (netpath, "%s/%s",search->filename, filename);
-
-                       findtime = Sys_FileTime (netpath);
-                       if (findtime == -1)
-                               continue;
-
-#if CACHEENABLE
-                       // see if the file needs to be updated in the cache
-                       if (com_cachedir[0])
-                       {
-#if defined(_WIN32)
-                               if ((strlen(netpath) < 2) || (netpath[1] != ':'))
-                                       sprintf (cachepath,"%s%s", com_cachedir, netpath);
-                               else
-                                       sprintf (cachepath,"%s%s", com_cachedir, netpath+2);
-#else
-                               sprintf (cachepath,"%s%s", com_cachedir, netpath);
-#endif
-
-                               cachetime = Sys_FileTime (cachepath);
-
-                               if (cachetime < findtime)
-                                       COM_CopyFile (netpath, cachepath);
-                               strcpy (netpath, cachepath);
-                       }
-#endif
-                       if (!quiet)
-                               Sys_Printf ("FindFile: %s\n",netpath);
-                       *file = COM_OpenRead (netpath, -1, -1, zip);
-                       return com_filesize;
-               }
-       }
-
-       if (!quiet)
-               Sys_Printf ("FindFile: can't find %s\n", filename);
-
-       *file = NULL;
-       com_filesize = -1;
-       return -1;
-}
-
-
-/*
-===========
-COM_FOpenFile
-
-If the requested file is inside a packfile, a new QFile * will be opened
-into the file.
-===========
-*/
-int COM_FOpenFile (const char *filename, QFile **file, qboolean quiet, qboolean zip)
-{
-       return COM_FindFile (filename, file, quiet, zip);
-}
-
-
-/*
-============
-COM_LoadFile
-
-Filename are reletive to the quake directory.
-Always appends a 0 byte.
-============
-*/
-qbyte *loadbuf;
-int loadsize;
-qbyte *COM_LoadFile (const char *path, qboolean quiet)
-{
-       QFile *h;
-       qbyte *buf;
-       char base[1024];
-       int len;
-
-       buf = NULL;     // quiet compiler warning
-       loadsize = 0;
-
-// look for it in the filesystem or pack files
-       len = COM_FOpenFile (path, &h, quiet, true);
-       if (!h)
-               return NULL;
-
-       loadsize = len;
-
-// extract the filename base name for hunk tag
-       COM_FileBase (path, base);
-
-       buf = Mem_Alloc(tempmempool, len+1);
-       if (!buf)
-               Sys_Error ("COM_LoadFile: not enough available memory for %s (size %i)", path, len);
-
-       ((qbyte *)buf)[len] = 0;
-
-       Qread (h, buf, len);
-       Qclose (h);
-
-       return buf;
-}
-
-/*
-=================
-COM_LoadPackFile
-
-Takes an explicit (not game tree related) path to a pak file.
-
-Loads the header and directory, adding the files at the beginning
-of the list so they override previous pack files.
-=================
-*/
-pack_t *COM_LoadPackFile (const char *packfile)
-{
-       dpackheader_t header;
-       int i, numpackfiles, packhandle;
-       pack_t *pack;
-       // LordHavoc: changed from stack array to temporary alloc, allowing huge pack directories
-       dpackfile_t *info;
-
-       if (Sys_FileOpenRead (packfile, &packhandle) == -1)
-               return NULL;
-
-       Sys_FileRead (packhandle, (void *)&header, sizeof(header));
-       if (memcmp(header.id, "PACK", 4))
-               Sys_Error ("%s is not a packfile", packfile);
-       header.dirofs = LittleLong (header.dirofs);
-       header.dirlen = LittleLong (header.dirlen);
-
-       if (header.dirlen % sizeof(dpackfile_t))
-               Sys_Error ("%s has an invalid directory size", packfile);
-
-       numpackfiles = header.dirlen / sizeof(dpackfile_t);
-
-       if (numpackfiles > MAX_FILES_IN_PACK)
-               Sys_Error ("%s has %i files", packfile, numpackfiles);
-
-       pack = Mem_Alloc(pak_mempool, sizeof (pack_t));
-       strcpy (pack->filename, packfile);
-       pack->handle = packhandle;
-       pack->numfiles = numpackfiles;
-       pack->mempool = Mem_AllocPool(packfile);
-       pack->files = Mem_Alloc(pack->mempool, numpackfiles * sizeof(packfile_t));
-       pack->next = packlist;
-       packlist = pack;
-
-       info = Mem_Alloc(tempmempool, sizeof(*info) * numpackfiles);
-       Sys_FileSeek (packhandle, header.dirofs);
-       Sys_FileRead (packhandle, (void *)info, header.dirlen);
-
-// parse the directory
-       for (i = 0;i < numpackfiles;i++)
-       {
-               strcpy (pack->files[i].name, info[i].name);
-               pack->files[i].filepos = LittleLong(info[i].filepos);
-               pack->files[i].filelen = LittleLong(info[i].filelen);
-       }
-
-       Mem_Free(info);
-
-       Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles);
-       return pack;
-}
-
-
-/*
-================
-COM_AddGameDirectory
-
-Sets com_gamedir, adds the directory to the head of the path,
-then loads and adds pak1.pak pak2.pak ...
-================
-*/
-void COM_AddGameDirectory (char *dir)
-{
-       stringlist_t *list, *current;
-       searchpath_t *search;
-       pack_t *pak;
-       char pakfile[MAX_OSPATH];
-
-       strcpy (com_gamedir, dir);
-
-//
-// add the directory to the search path
-//
-       search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
-       strcpy (search->filename, dir);
-       search->next = com_searchpaths;
-       com_searchpaths = search;
-
-       // add any paks in the directory
-       list = listdirectory(dir);
-       for (current = list;current;current = current->next)
-       {
-               if (matchpattern(current->text, "*.pak", true))
-               {
-                       sprintf (pakfile, "%s/%s", dir, current->text);
-                       pak = COM_LoadPackFile (pakfile);
-                       if (pak)
-                       {
-                               search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
-                               search->pack = pak;
-                               search->next = com_searchpaths;
-                               com_searchpaths = search;
-                       }
-                       else
-                               Con_Printf("unable to load pak \"%s\"\n", pakfile);
-               }
-       }
-       freedirectory(list);
-}
-
-/*
-================
-COM_InitFilesystem
-================
-*/
-void COM_InitFilesystem (void)
-{
-       int i;
-       searchpath_t *search;
-
-       strcpy(com_basedir, ".");
-
-       // -basedir <path>
-       // Overrides the system supplied base directory (under GAMENAME)
-       i = COM_CheckParm ("-basedir");
-       if (i && i < com_argc-1)
-               strcpy (com_basedir, com_argv[i+1]);
-
-       i = strlen (com_basedir);
-       if (i > 0 && (com_basedir[i-1] == '\\' || com_basedir[i-1] == '/'))
-               com_basedir[i-1] = 0;
-
-// start up with GAMENAME by default (id1)
-       strcpy(com_modname, GAMENAME);
-       COM_AddGameDirectory (va("%s/"GAMENAME, com_basedir));
-       if (gamedirname[0])
-       {
-               com_modified = true;
-               strcpy(com_modname, gamedirname);
-               COM_AddGameDirectory (va("%s/%s", com_basedir, gamedirname));
-       }
-
-       // -game <gamedir>
-       // Adds basedir/gamedir as an override game
-       i = COM_CheckParm ("-game");
-       if (i && i < com_argc-1)
-       {
-               com_modified = true;
-               strcpy(com_modname, com_argv[i+1]);
-               COM_AddGameDirectory (va("%s/%s", com_basedir, com_argv[i+1]));
-       }
-
-       // -path <dir or packfile> [<dir or packfile>] ...
-       // Fully specifies the exact search path, overriding the generated one
-       i = COM_CheckParm ("-path");
-       if (i)
-       {
-               com_modified = true;
-               com_searchpaths = NULL;
-               while (++i < com_argc)
-               {
-                       if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-')
-                               break;
-
-                       search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
-                       if ( !strcmp(COM_FileExtension(com_argv[i]), "pak") )
-                       {
-                               search->pack = COM_LoadPackFile (com_argv[i]);
-                               if (!search->pack)
-                                       Sys_Error ("Couldn't load packfile: %s", com_argv[i]);
-                       }
-                       else
-                               strcpy (search->filename, com_argv[i]);
-                       search->next = com_searchpaths;
-                       com_searchpaths = search;
-               }
-       }
-}
-
-int COM_FileExists(const char *filename)
-{
-       searchpath_t *search;
-       char netpath[MAX_OSPATH];
-       pack_t *pak;
-       int i, findtime;
-
-       for (search = com_searchpaths;search;search = search->next)
-       {
-               if (search->pack)
-               {
-                       pak = search->pack;
-                       for (i = 0;i < pak->numfiles;i++)
-                               if (!strcmp (pak->files[i].name, filename))
-                                       return true;
-               }
-               else
-               {
-                       sprintf (netpath, "%s/%s",search->filename, filename);
-                       findtime = Sys_FileTime (netpath);
-                       if (findtime != -1)
-                               return true;
-               }
-       }
-
-       return false;
-}
-
-
 //======================================
 // LordHavoc: added these because they are useful
 
index 1a917ca500e6a1f0b1feea549d9cf77c38f0b9b3..80d80e48af8477e3712348912ac85a6db88d4207 100644 (file)
--- a/common.h
+++ b/common.h
@@ -21,11 +21,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #ifndef COMMON_H
 #define COMMON_H
 
-// LordHavoc: MSVC has a different name for snprintf
+// MSVC has a different name for several standard functions
 #ifdef WIN32
-#define snprintf _snprintf
+# define snprintf _snprintf
+# define vsnprintf _vsnprintf
+# define strcasecmp stricmp
+# define strncasecmp strnicmp
 #endif
 
+
 //============================================================================
 
 typedef struct sizebuf_s
@@ -125,17 +129,10 @@ extern int dpprotocol;
 
 //============================================================================
 
-int Q_strcasecmp (const char *s1, const char *s2);
-int Q_strncasecmp (const char *s1, const char *s2, int n);
-
-//============================================================================
-
 extern char com_token[1024];
-extern qboolean com_eof;
 
 int COM_ParseToken (const char **data);
 
-extern char com_basedir[MAX_OSPATH];
 extern int com_argc;
 extern const char **com_argv;
 
@@ -144,29 +141,12 @@ void COM_Init (void);
 void COM_InitArgv (void);
 void COM_InitGameType (void);
 
-void COM_StripExtension (const char *in, char *out);
-void COM_FileBase (const char *in, char *out);
-void COM_DefaultExtension (char *path, const char *extension);
-
 char   *va(const char *format, ...);
 // does a varargs printf into a temp buffer
 
 
 //============================================================================
 
-extern int com_filesize;
-
-extern char    com_gamedir[MAX_OSPATH];
-
-qboolean COM_WriteFile (const char *filename, void *data, int len);
-int COM_FOpenFile (const char *filename, QFile **file, qboolean quiet, qboolean zip);
-
-// set by COM_LoadFile functions
-extern int loadsize;
-qbyte *COM_LoadFile (const char *path, qboolean quiet);
-
-int COM_FileExists(const char *filename);
-
 extern struct cvar_s   registered;
 
 #define GAME_NORMAL 0
@@ -178,6 +158,7 @@ extern      struct cvar_s   registered;
 
 extern int gamemode;
 extern char *gamename;
+extern char *gamedirname;
 extern char com_modname[MAX_OSPATH];
 
 // LordHavoc: useful...
index bb971ad4d46e9062e5447d559f9d9dc2f39d3316..21148248e1ccaf21ec9cc676e164f70877ca4ff1 100644 (file)
--- a/console.c
+++ b/console.c
@@ -217,9 +217,9 @@ void Con_Init (void)
 
        if (con_debuglog)
        {
-               if (strlen (com_gamedir) < (MAXGAMEDIRLEN - strlen (t2)))
+               if (strlen (fs_gamedir) < (MAXGAMEDIRLEN - strlen (t2)))
                {
-                       sprintf (temp, "%s%s", com_gamedir, t2);
+                       sprintf (temp, "%s%s", fs_gamedir, t2);
                        unlink (temp);
                }
                logfile.integer = 1;
@@ -355,16 +355,16 @@ void Con_Print (const char *txt)
 Con_DebugLog
 ================
 */
-void Con_DebugLog(const char *file, const char *fmt, ...)
+void Con_DebugLog (const char *msg)
 {
-    va_list argptr;
-    FILE* fd;
-
-    fd = fopen(file, "at");
-    va_start(argptr, fmt);
-    vfprintf (fd, fmt, argptr);
-    va_end(argptr);
-    fclose(fd);
+    qfile_t* file;
+
+    file = FS_Open ("qconsole.log", "at", true);
+       if (file)
+       {
+               FS_Printf (file, "%s", msg);
+               FS_Close (file);
+       }
 }
 
 
@@ -387,17 +387,12 @@ void Con_Printf (const char *fmt, ...)
        vsprintf (msg,fmt,argptr);
        va_end (argptr);
 
-// also echo to debugging console
+       // also echo to debugging console
        Sys_Printf ("%s", msg);
 
-// log all messages to file
+       // log all messages to file
        if (con_debuglog)
-       {
-               // can't use va() here because it might overwrite other important things
-               char logname[MAX_OSPATH];
-               sprintf(logname, "%s/qconsole.log", com_gamedir);
-               Con_DebugLog(logname, "%s", msg);
-       }
+               Con_DebugLog (msg);
 
        if (!con_initialized)
                return;
@@ -405,7 +400,7 @@ void Con_Printf (const char *fmt, ...)
        if (cls.state == ca_dedicated)
                return;         // no graphics mode
 
-// write it to the scrollable buffer
+       // write it to the scrollable buffer
        Con_Print (msg);
 }
 
diff --git a/cvar.c b/cvar.c
index f0923b02cb9c9546f58488c208a2f5b8ab6526b3..790bdd051220133bc264c2465cec29edbd6140b2 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -323,13 +323,13 @@ Writes lines containing "set variable value" for all variables
 with the archive flag set to true.
 ============
 */
-void Cvar_WriteVariables (QFile *f)
+void Cvar_WriteVariables (qfile_t *f)
 {
        cvar_t  *var;
 
        for (var = cvar_vars ; var ; var = var->next)
                if (var->flags & CVAR_SAVE)
-                       Qprintf (f, "%s \"%s\"\n", var->name, var->string);
+                       FS_Printf (f, "%s \"%s\"\n", var->name, var->string);
 }
 
 
diff --git a/cvar.h b/cvar.h
index 8a7dbc8eaa21dc1756c287aa8679953e0ebd39e6..b623566b5a2e90a22e30b2b6920eafa29c3e6910 100644 (file)
--- a/cvar.h
+++ b/cvar.h
@@ -144,7 +144,7 @@ qboolean Cvar_Command (void);
 // command.  Returns true if the command was a variable reference that
 // was handled. (print or change)
 
-void Cvar_WriteVariables (QFile *f);
+void Cvar_WriteVariables (qfile_t *f);
 // Writes lines containing "set variable value" for all variables
 // with the archive flag set to true.
 
index 8c871dd24d35b0e37144fcfbd1d5b523a80806e2..27e0f1d68612939c10b0db6b12fc8685d1123c2d 100644 (file)
@@ -312,7 +312,7 @@ SOURCE=.\protocol.c
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=.\quakeio.c\r
+SOURCE=.\fs.c\r
 # End Source File\r
 # Begin Source File\r
 \r
@@ -628,7 +628,7 @@ SOURCE=.\quakedef.h
 # End Source File\r
 # Begin Source File\r
 \r
-SOURCE=.\quakeio.h\r
+SOURCE=.\fs.h\r
 # End Source File\r
 # Begin Source File\r
 \r
index 0d30b4f703e1a3dec7e85a82191886a9f4ff30a4..b248ea0f787549296fc9ca1ea2a17b4ab5697ee7 100644 (file)
@@ -20,7 +20,7 @@
 
 typedef struct
 {
-       FILE *file;
+       qfile_t *file;
        int endoffile;
 }
 hz_bitstream_read_t;
@@ -45,9 +45,9 @@ hz_bitstream_readblocks_t;
 
 hz_bitstream_read_t *hz_bitstream_read_open(char *filename)
 {
-       FILE *file;
+       qfile_t *file;
        hz_bitstream_read_t *stream;
-       if ((file = fopen(filename, "rb")))
+       if ((file = FS_Open (filename, "rb", false)))
        {
                stream = malloc(sizeof(hz_bitstream_read_t));
                memset(stream, 0, sizeof(*stream));
@@ -62,20 +62,20 @@ void hz_bitstream_read_close(hz_bitstream_read_t *stream)
 {
        if (stream)
        {
-               fclose(stream->file);
+               FS_Close(stream->file);
                free(stream);
        }
 }
 
 unsigned int hz_bitstream_read_currentbyte(hz_bitstream_read_t *stream)
 {
-       return ftell(stream->file);
+       return FS_Tell(stream->file);
 }
 
 int hz_bitstream_read_seek(hz_bitstream_read_t *stream, unsigned int position)
 {
        stream->endoffile = 0;
-       return fseek(stream->file, position, SEEK_SET) != 0;
+       return FS_Seek(stream->file, position, SEEK_SET) != 0;
 }
 
 hz_bitstream_readblocks_t *hz_bitstream_read_blocks_new(void)
@@ -133,7 +133,7 @@ int hz_bitstream_read_blocks_read(hz_bitstream_readblocks_t *blocks, hz_bitstrea
                else
                        b->size = s;
                s -= b->size;
-               if (fread(b->data, 1, b->size, stream->file) != b->size)
+               if (FS_Read(stream->file, b->data, b->size) != b->size)
                {
                        stream->endoffile = 1;
                        break;
diff --git a/fs.c b/fs.c
new file mode 100644 (file)
index 0000000..eeb41d9
--- /dev/null
+++ b/fs.c
@@ -0,0 +1,1025 @@
+/*
+       Quake file system
+
+       Copyright (C) 2003 Mathieu Olivier
+       Copyright (C) 1999,2000  contributors of the QuakeForge project
+
+       This program is free software; you can redistribute it and/or
+       modify it under the terms of the GNU General Public License
+       as published by the Free Software Foundation; either version 2
+       of the License, or (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+       See the GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with this program; if not, write to:
+
+               Free Software Foundation, Inc.
+               59 Temple Place - Suite 330
+               Boston, MA  02111-1307, USA
+*/
+
+#include "quakedef.h"
+
+#include <stdlib.h>
+#include <string.h>
+#include <limits.h>
+#include <fcntl.h>
+
+#ifdef WIN32
+# include <direct.h>
+# include <io.h>
+#else
+# include <pwd.h>
+# include <sys/stat.h>
+# include <unistd.h>
+#endif
+
+#ifndef PATH_MAX
+# define PATH_MAX 512
+#endif
+
+#include "fs.h"
+
+/*
+
+All of Quake's data access is through a hierchal file system, but the contents
+of the file system can be transparently merged from several sources.
+
+The "base directory" is the path to the directory holding the quake.exe and
+all game directories.  The sys_* files pass this to host_init in
+quakeparms_t->basedir.  This can be overridden with the "-basedir" command
+line parm to allow code debugging in a different directory.  The base
+directory is only used during filesystem initialization.
+
+The "game directory" is the first tree on the search path and directory that
+all generated files (savegames, screenshots, demos, config files) will be
+saved to.  This can be overridden with the "-game" command line parameter.
+The game directory can never be changed while quake is executing.  This is a
+precacution against having a malicious server instruct clients to write files
+over areas they shouldn't.
+
+*/
+
+
+/*
+=============================================================================
+
+TYPES
+
+=============================================================================
+*/
+
+// Our own file structure on top of FILE
+typedef enum
+{
+       FS_FLAG_NONE            = 0,
+       FS_FLAG_PACKED          = (1 << 0)      // inside a package (PAK or PK3)
+//     FS_FLAG_COMPRESSED      = (1 << 1)  // compressed (inside a PK3 file)
+} fs_flags_t;
+
+struct qfile_s
+{
+       fs_flags_t      flags;
+       FILE*           stream;
+       size_t          length;         // file size (PACKED only)
+       size_t          offset;         // offset into a package (PACKED only)
+       size_t          position;       // current position in the file (PACKED only)
+};
+
+
+// PAK files on disk
+typedef struct
+{
+       char name[56];
+       int filepos, filelen;
+} dpackfile_t;
+
+typedef struct
+{
+       char id[4];
+       int dirofs;
+       int dirlen;
+} dpackheader_t;
+
+
+// Packages in memory
+typedef struct
+{
+       char name[MAX_QPATH];
+       int filepos, filelen;
+} packfile_t;
+
+typedef struct pack_s
+{
+       char filename[MAX_OSPATH];
+       FILE *handle;
+       int numfiles;
+       packfile_t *files;
+       mempool_t *mempool;
+       struct pack_s *next;
+} pack_t;
+
+
+// Search paths for files (including packages)
+typedef struct searchpath_s
+{
+       // only one of filename / pack will be used
+       char filename[MAX_OSPATH];
+       pack_t *pack;
+       struct searchpath_s *next;
+} searchpath_t;
+
+
+/*
+=============================================================================
+
+VARIABLES
+
+=============================================================================
+*/
+
+mempool_t *fs_mempool;
+mempool_t *pak_mempool;
+
+int fs_filesize;
+
+pack_t *packlist = NULL;
+
+searchpath_t *fs_searchpaths;
+
+// LordHavoc: was 2048, increased to 65536 and changed info[MAX_PACK_FILES] to a temporary alloc
+#define MAX_FILES_IN_PACK       65536
+
+char fs_gamedir[MAX_OSPATH];
+char fs_basedir[MAX_OSPATH];
+
+qboolean fs_modified;   // set true if using non-id files
+
+
+/*
+=============================================================================
+
+PRIVATE FUNCTIONS
+
+=============================================================================
+*/
+
+
+/*
+============
+FS_CreatePath
+
+LordHavoc: Previously only used for CopyFile, now also used for FS_WriteFile.
+============
+*/
+void FS_CreatePath (char *path)
+{
+       char *ofs, save;
+
+       for (ofs = path+1 ; *ofs ; ofs++)
+       {
+               if (*ofs == '/' || *ofs == '\\')
+               {
+                       // create the directory
+                       save = *ofs;
+                       *ofs = 0;
+                       FS_mkdir (path);
+                       *ofs = save;
+               }
+       }
+}
+
+
+/*
+============
+FS_Path_f
+
+============
+*/
+void FS_Path_f (void)
+{
+       searchpath_t *s;
+
+       Con_Printf ("Current search path:\n");
+       for (s=fs_searchpaths ; s ; s=s->next)
+       {
+               if (s->pack)
+               {
+                       Con_Printf ("%s (%i files)\n", s->pack->filename, s->pack->numfiles);
+               }
+               else
+                       Con_Printf ("%s\n", s->filename);
+       }
+}
+
+
+/*
+=================
+FS_LoadPackFile
+
+Takes an explicit (not game tree related) path to a pak file.
+
+Loads the header and directory, adding the files at the beginning
+of the list so they override previous pack files.
+=================
+*/
+pack_t *FS_LoadPackFile (const char *packfile)
+{
+       dpackheader_t header;
+       int i, numpackfiles;
+       FILE *packhandle;
+       pack_t *pack;
+       // LordHavoc: changed from stack array to temporary alloc, allowing huge pack directories
+       dpackfile_t *info;
+
+       packhandle = fopen (packfile, "rb");
+       if (!packhandle)
+               return NULL;
+
+       fread ((void *)&header, 1, sizeof(header), packhandle);
+       if (memcmp(header.id, "PACK", 4))
+               Sys_Error ("%s is not a packfile", packfile);
+       header.dirofs = LittleLong (header.dirofs);
+       header.dirlen = LittleLong (header.dirlen);
+
+       if (header.dirlen % sizeof(dpackfile_t))
+               Sys_Error ("%s has an invalid directory size", packfile);
+
+       numpackfiles = header.dirlen / sizeof(dpackfile_t);
+
+       if (numpackfiles > MAX_FILES_IN_PACK)
+               Sys_Error ("%s has %i files", packfile, numpackfiles);
+
+       pack = Mem_Alloc(pak_mempool, sizeof (pack_t));
+       strcpy (pack->filename, packfile);
+       pack->handle = packhandle;
+       pack->numfiles = numpackfiles;
+       pack->mempool = Mem_AllocPool(packfile);
+       pack->files = Mem_Alloc(pack->mempool, numpackfiles * sizeof(packfile_t));
+       pack->next = packlist;
+       packlist = pack;
+
+       info = Mem_Alloc(tempmempool, sizeof(*info) * numpackfiles);
+       fseek (packhandle, header.dirofs, SEEK_SET);
+       fread ((void *)info, 1, header.dirlen, packhandle);
+
+// parse the directory
+       for (i = 0;i < numpackfiles;i++)
+       {
+               strcpy (pack->files[i].name, info[i].name);
+               pack->files[i].filepos = LittleLong(info[i].filepos);
+               pack->files[i].filelen = LittleLong(info[i].filelen);
+       }
+
+       Mem_Free(info);
+
+       Con_Printf ("Added packfile %s (%i files)\n", packfile, numpackfiles);
+       return pack;
+}
+
+
+/*
+================
+FS_AddGameDirectory
+
+Sets fs_gamedir, adds the directory to the head of the path,
+then loads and adds pak1.pak pak2.pak ...
+================
+*/
+void FS_AddGameDirectory (char *dir)
+{
+       stringlist_t *list, *current;
+       searchpath_t *search;
+       pack_t *pak;
+       char pakfile[MAX_OSPATH];
+
+       strcpy (fs_gamedir, dir);
+
+       // add the directory to the search path
+       search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
+       strcpy (search->filename, dir);
+       search->next = fs_searchpaths;
+       fs_searchpaths = search;
+
+       // add any paks in the directory
+       list = listdirectory(dir);
+       for (current = list;current;current = current->next)
+       {
+               if (matchpattern(current->text, "*.pak", true))
+               {
+                       sprintf (pakfile, "%s/%s", dir, current->text);
+                       pak = FS_LoadPackFile (pakfile);
+                       if (pak)
+                       {
+                               search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
+                               search->pack = pak;
+                               search->next = fs_searchpaths;
+                               fs_searchpaths = search;
+                       }
+                       else
+                               Con_Printf("unable to load pak \"%s\"\n", pakfile);
+               }
+       }
+       freedirectory(list);
+}
+
+
+/*
+============
+FS_FileExtension
+============
+*/
+char *FS_FileExtension (const char *in)
+{
+       static char exten[8];
+       int i;
+
+       while (*in && *in != '.')
+               in++;
+       if (!*in)
+               return "";
+       in++;
+       for (i=0 ; i<7 && *in ; i++,in++)
+               exten[i] = *in;
+       exten[i] = 0;
+       return exten;
+}
+
+
+/*
+================
+FS_Init
+================
+*/
+void FS_Init (void)
+{
+       int i;
+       searchpath_t *search;
+
+       fs_mempool = Mem_AllocPool("file management");
+       pak_mempool = Mem_AllocPool("paks");
+
+       Cmd_AddCommand ("path", FS_Path_f);
+
+       strcpy(fs_basedir, ".");
+
+       // -basedir <path>
+       // Overrides the system supplied base directory (under GAMENAME)
+       i = COM_CheckParm ("-basedir");
+       if (i && i < com_argc-1)
+               strcpy (fs_basedir, com_argv[i+1]);
+
+       i = strlen (fs_basedir);
+       if (i > 0 && (fs_basedir[i-1] == '\\' || fs_basedir[i-1] == '/'))
+               fs_basedir[i-1] = 0;
+
+       // start up with GAMENAME by default (id1)
+       strcpy(com_modname, GAMENAME);
+       FS_AddGameDirectory (va("%s/"GAMENAME, fs_basedir));
+       if (gamedirname[0])
+       {
+               fs_modified = true;
+               strcpy(com_modname, gamedirname);
+               FS_AddGameDirectory (va("%s/%s", fs_basedir, gamedirname));
+       }
+
+       // -game <gamedir>
+       // Adds basedir/gamedir as an override game
+       i = COM_CheckParm ("-game");
+       if (i && i < com_argc-1)
+       {
+               fs_modified = true;
+               strcpy(com_modname, com_argv[i+1]);
+               FS_AddGameDirectory (va("%s/%s", fs_basedir, com_argv[i+1]));
+       }
+
+       // -path <dir or packfile> [<dir or packfile>] ...
+       // Fully specifies the exact search path, overriding the generated one
+       i = COM_CheckParm ("-path");
+       if (i)
+       {
+               fs_modified = true;
+               fs_searchpaths = NULL;
+               while (++i < com_argc)
+               {
+                       if (!com_argv[i] || com_argv[i][0] == '+' || com_argv[i][0] == '-')
+                               break;
+
+                       search = Mem_Alloc(pak_mempool, sizeof(searchpath_t));
+                       if ( !strcmp(FS_FileExtension(com_argv[i]), "pak") )
+                       {
+                               search->pack = FS_LoadPackFile (com_argv[i]);
+                               if (!search->pack)
+                                       Sys_Error ("Couldn't load packfile: %s", com_argv[i]);
+                       }
+                       else
+                               strcpy (search->filename, com_argv[i]);
+                       search->next = fs_searchpaths;
+                       fs_searchpaths = search;
+               }
+       }
+}
+
+
+/*
+=============================================================================
+
+MAIN FUNCTIONS
+
+=============================================================================
+*/
+
+/*
+====================
+FS_Open
+
+Internal function used to create a qfile_t and open the relevant file on disk
+====================
+*/
+static qfile_t* FS_SysOpen (const char* filepath, const char* mode)
+{
+       qfile_t* file;
+
+       file = Mem_Alloc (fs_mempool, sizeof (*file));
+       memset (file, 0, sizeof (*file));
+
+       file->stream = fopen (filepath, mode);
+       if (!file->stream)
+       {
+               Mem_Free (file);
+               return NULL;
+       }
+
+       return file;
+}
+
+
+/*
+===========
+FS_OpenRead
+===========
+*/
+qfile_t *FS_OpenRead (const char *path, int offs, int len)
+{
+       qfile_t* file;
+
+       file = FS_SysOpen (path, "rb");
+       if (!file)
+       {
+               Sys_Error ("Couldn't open %s", path);
+               return NULL;
+       }
+
+       // Normal file
+       if (offs < 0 || len < 0)
+       {
+               FS_Seek (file, 0, SEEK_END);
+               len = FS_Tell (file);
+               FS_Seek (file, 0, SEEK_SET);
+       }
+       // Packed file
+       else
+       {
+               FS_Seek (file, offs, SEEK_SET);
+
+               file->flags |= FS_FLAG_PACKED;
+               file->length = len;
+               file->offset = offs;
+               file->position = 0;
+       }
+
+       fs_filesize = len;
+
+       return file;
+}
+
+/*
+===========
+FS_FOpenFile
+
+If the requested file is inside a packfile, a new qfile_t* will be opened
+into the file.
+
+Sets fs_filesize
+===========
+*/
+qfile_t *FS_FOpenFile (const char *filename, qboolean quiet)
+{
+       searchpath_t *search;
+       char netpath[MAX_OSPATH];
+       pack_t *pak;
+       int i, filenamelen;
+
+       filenamelen = strlen (filename);
+
+       // search through the path, one element at a time
+       search = fs_searchpaths;
+
+       for ( ; search ; search = search->next)
+       {
+               // is the element a pak file?
+               if (search->pack)
+               {
+                       // look through all the pak file elements
+                       pak = search->pack;
+                       for (i=0 ; i<pak->numfiles ; i++)
+                               if (!strcmp (pak->files[i].name, filename))
+                               {       // found it!
+                                       if (!quiet)
+                                               Sys_Printf ("PackFile: %s : %s\n",pak->filename, pak->files[i].name);
+                                       // open a new file in the pakfile
+                                       return FS_OpenRead (pak->filename, pak->files[i].filepos, pak->files[i].filelen);
+                               }
+               }
+               else
+               {
+                       sprintf (netpath, "%s/%s",search->filename, filename);
+
+                       if (!FS_SysFileExists (netpath))
+                               continue;
+
+                       if (!quiet)
+                               Sys_Printf ("FindFile: %s\n",netpath);
+                       return FS_OpenRead (netpath, -1, -1);
+               }
+       }
+
+       if (!quiet)
+               Sys_Printf ("FindFile: can't find %s\n", filename);
+
+       fs_filesize = -1;
+       return NULL;
+}
+
+
+/*
+====================
+FS_Open
+
+Open a file. The syntax is the same as fopen
+====================
+*/
+qfile_t* FS_Open (const char* filepath, const char* mode, qboolean quiet)
+{
+       // If the file is opened in "write" or "append" mode
+       if (strchr (mode, 'w') || strchr (mode, 'a'))
+       {
+               char real_path [MAX_OSPATH];
+
+               // Open the file on disk directly
+               snprintf (real_path, sizeof (real_path), "%s/%s", fs_gamedir, filepath);
+               return FS_SysOpen (real_path, mode);
+       }
+
+       // Else, we look at the various search paths
+       return FS_FOpenFile (filepath, quiet);
+}
+
+
+/*
+====================
+FS_Close
+
+Close a file
+====================
+*/
+int FS_Close (qfile_t* file)
+{
+       if (fclose (file->stream))
+               return EOF;
+
+       Mem_Free (file);
+       return 0;
+}
+
+
+/*
+====================
+FS_Write
+
+Write "datasize" bytes into a file
+====================
+*/
+size_t FS_Write (qfile_t* file, const void* data, size_t datasize)
+{
+       return fwrite (data, 1, datasize, file->stream);
+}
+
+
+/*
+====================
+FS_Read
+
+Read up to "buffersize" bytes from a file
+====================
+*/
+size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize)
+{
+       size_t nb;
+
+       // If the file belongs to a package, we must take care
+       // to not read after the end of the file
+       if (file->flags & FS_FLAG_PACKED)
+       {
+               size_t remain = file->length - file->position;
+               if (buffersize > remain)
+                       buffersize = remain;
+       }
+
+       nb = fread (buffer, 1, buffersize, file->stream);
+
+       // Update the position index if the file is packed
+       if ((file->flags & FS_FLAG_PACKED) && nb > 0)
+               file->position += nb;
+
+       return nb;
+}
+
+
+/*
+====================
+FS_Flush
+
+Flush the file output stream
+====================
+*/
+int FS_Flush (qfile_t* file)
+{
+       return fflush (file->stream);
+}
+
+
+/*
+====================
+FS_Printf
+
+Print a string into a file
+====================
+*/
+int FS_Printf (qfile_t* file, const char* format, ...)
+{
+       int result;
+       va_list args;
+
+       va_start (args, format);
+       result = vfprintf (file->stream, format, args);
+       va_end (args);
+
+       return result;
+}
+
+
+/*
+====================
+FS_Getc
+
+Get the next character of a file
+====================
+*/
+int FS_Getc (qfile_t* file)
+{
+       int c;
+
+       // If the file belongs to a package, we must take care
+       // to not read after the end of the file
+       if (file->flags & FS_FLAG_PACKED)
+       {
+               if (file->position >= file->length)
+                       return EOF;
+       }
+
+       c = fgetc (file->stream);
+
+       // Update the position index if the file is packed
+       if ((file->flags & FS_FLAG_PACKED) && c != EOF)
+               file->position++;
+
+       return c;
+}
+
+
+/*
+====================
+FS_Seek
+
+Move the position index in a file
+====================
+*/
+int FS_Seek (qfile_t* file, long offset, int whence)
+{
+       // Packed files receive a special treatment
+       if (file->flags & FS_FLAG_PACKED)
+       {
+               switch (whence)
+               {
+                       case SEEK_CUR:
+                               offset += file->position;
+                               // It continues on the next case (no break)
+
+                       case SEEK_SET:
+                               if (offset < 0 || offset > file->length)
+                                       return -1;
+                               if (fseek (file->stream, file->offset + offset, SEEK_SET) == -1)
+                                       return -1;
+                               file->position = offset;
+                               return 0;
+
+                       case SEEK_END:
+                               if (offset > 0 || -offset > file->length)
+                                       return -1;
+                               if (fseek (file->stream, file->offset + file->length + offset, SEEK_SET) == -1)
+                                       return -1;
+                               file->position = file->length + offset;
+                               return 0;
+
+                       default:
+                               return -1;
+               }
+       }
+
+       return fseek (file->stream, offset, whence);
+}
+
+
+/*
+====================
+FS_Tell
+
+Give the current position in a file
+====================
+*/
+long FS_Tell (qfile_t* file)
+{
+       if (file->flags & FS_FLAG_PACKED)
+               return file->position;
+
+       return ftell (file->stream);
+}
+
+
+/*
+====================
+FS_Gets
+
+Extract a line from a file
+====================
+*/
+char* FS_Gets (qfile_t* file, char* buffer, int buffersize)
+{
+       if (!fgets (buffer, buffersize, file->stream))
+               return NULL;
+
+       // Check that we didn't read after the end of a packed file, and update the position
+       if (file->flags & FS_FLAG_PACKED)
+       {
+               size_t len = strlen (buffer);
+               size_t max = file->length - file->position;
+
+               if (len > max)
+               {
+                       buffer[max] = '\0';
+                       file->position = file->length;
+               }
+               else
+                       file->position += len;
+       }
+
+       return buffer;
+}
+
+
+/*
+==========
+FS_Getline
+
+Dynamic length version of fgets. DO NOT free the buffer.
+==========
+*/
+char *FS_Getline (qfile_t *file)
+{
+       static int  size = 256;
+       static char *buf = 0;
+       char        *t;
+       int         len;
+
+       if (!buf)
+               buf = Mem_Alloc (fs_mempool, size);
+
+       if (!FS_Gets (file, buf, size))
+               return 0;
+
+       len = strlen (buf);
+       while (buf[len - 1] != '\n' && buf[len - 1] != '\r')
+       {
+               t = Mem_Alloc (fs_mempool, size + 256);
+               memcpy(t, buf, size);
+               Mem_Free(buf);
+               size += 256;
+               buf = t;
+               if (!FS_Gets (file, buf + len, size - len))
+                       break;
+               len = strlen (buf);
+       }
+       while ((len = strlen(buf)) && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
+               buf[len - 1] = 0;
+       return buf;
+}
+
+
+/*
+====================
+FS_Eof
+
+Extract a line from a file
+====================
+*/
+int FS_Eof (qfile_t* file)
+{
+       if (file->flags & FS_FLAG_PACKED)
+               return (file->position == file->length);
+       
+       return feof (file->stream);
+}
+
+
+/*
+============
+FS_LoadFile
+
+Filename are relative to the quake directory.
+Always appends a 0 byte.
+============
+*/
+qbyte *FS_LoadFile (const char *path, qboolean quiet)
+{
+       qfile_t *h;
+       qbyte *buf;
+
+       // look for it in the filesystem or pack files
+       h = FS_Open (path, "rb", quiet);
+       if (!h)
+               return NULL;
+
+       buf = Mem_Alloc(tempmempool, fs_filesize+1);
+       if (!buf)
+               Sys_Error ("FS_LoadFile: not enough available memory for %s (size %i)", path, fs_filesize);
+
+       ((qbyte *)buf)[fs_filesize] = 0;
+
+       FS_Read (h, buf, fs_filesize);
+       FS_Close (h);
+
+       return buf;
+}
+
+
+/*
+============
+FS_WriteFile
+
+The filename will be prefixed by the current game directory
+============
+*/
+qboolean FS_WriteFile (const char *filename, void *data, int len)
+{
+       FILE *handle;
+       char name[MAX_OSPATH];
+
+       sprintf (name, "%s/%s", fs_gamedir, filename);
+
+       // Create directories up to the file
+       FS_CreatePath (name);
+
+       handle = fopen (name, "wb");
+       if (!handle)
+       {
+               Con_Printf ("FS_WriteFile: failed on %s\n", name);
+               return false;
+       }
+
+       Con_DPrintf ("FS_WriteFile: %s\n", name);
+       fwrite (data, 1, len, handle);
+       fclose (handle);
+       return true;
+}
+
+
+/*
+=============================================================================
+
+OTHERS FUNCTIONS
+
+=============================================================================
+*/
+
+/*
+============
+FS_StripExtension
+============
+*/
+void FS_StripExtension (const char *in, char *out)
+{
+       char *last = NULL;
+       while (*in)
+       {
+               if (*in == '.')
+                       last = out;
+               else if (*in == '/' || *in == '\\' || *in == ':')
+                       last = NULL;
+               *out++ = *in++;
+       }
+       if (last)
+               *last = 0;
+       else
+               *out = 0;
+}
+
+
+/*
+==================
+FS_DefaultExtension
+==================
+*/
+void FS_DefaultExtension (char *path, const char *extension)
+{
+       const char *src;
+
+       // if path doesn't have a .EXT, append extension
+       // (extension should include the .)
+       src = path + strlen(path) - 1;
+
+       while (*src != '/' && src != path)
+       {
+               if (*src == '.')
+                       return;                 // it has an extension
+               src--;
+       }
+
+       strcat (path, extension);
+}
+
+
+qboolean FS_FileExists (const char *filename)
+{
+       searchpath_t *search;
+       char netpath[MAX_OSPATH];
+       pack_t *pak;
+       int i;
+
+       for (search = fs_searchpaths;search;search = search->next)
+       {
+               if (search->pack)
+               {
+                       pak = search->pack;
+                       for (i = 0;i < pak->numfiles;i++)
+                               if (!strcmp (pak->files[i].name, filename))
+                                       return true;
+               }
+               else
+               {
+                       sprintf (netpath, "%s/%s",search->filename, filename);
+                       if (FS_SysFileExists (netpath))
+                               return true;
+               }
+       }
+
+       return false;
+}
+
+
+qboolean FS_SysFileExists (const char *path)
+{
+#if WIN32
+       FILE *f;
+
+       f = fopen (path, "rb");
+       if (f)
+       {
+               fclose (f);
+               return true;
+       }
+
+       return false;
+#else
+       struct stat buf;
+
+       if (stat (path,&buf) == -1)
+               return false;
+
+       return true;
+#endif
+}
+
+void FS_mkdir (const char *path)
+{
+#if WIN32
+       _mkdir (path);
+#else
+       mkdir (path, 0777);
+#endif
+}
diff --git a/fs.h b/fs.h
new file mode 100644 (file)
index 0000000..7a409e5
--- /dev/null
+++ b/fs.h
@@ -0,0 +1,75 @@
+/*
+       Quake file system
+
+       Copyright (C) 2003 Mathieu Olivier
+
+       This program is free software; you can redistribute it and/or
+       modify it under the terms of the GNU General Public License
+       as published by the Free Software Foundation; either version 2
+       of the License, or (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+
+       See the GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with this program; if not, write to:
+
+               Free Software Foundation, Inc.
+               59 Temple Place - Suite 330
+               Boston, MA  02111-1307, USA
+*/
+
+#ifndef QUAKEIO_H
+#define QUAKEIO_H
+
+
+// ------ Types ------ //
+
+typedef struct qfile_s qfile_t;
+
+
+// ------ Variables ------ //
+
+extern char fs_gamedir [MAX_OSPATH];
+extern char fs_basedir [MAX_OSPATH];
+
+extern int fs_filesize;  // set by FS_Open and FS_LoadFile
+
+
+// ------ Main functions ------ //
+
+// NOTE: the file path is automatically prefixed by the current game directory for each
+// file created by FS_WriteFile, or opened in "write" or "append" mode by FS_Open
+
+qfile_t *FS_Open (const char* filepath, const char* mode, qboolean quiet);
+int FS_Close (qfile_t* file);
+size_t FS_Write (qfile_t* file, const void* data, size_t datasize);
+size_t FS_Read (qfile_t* file, void* buffer, size_t buffersize);
+int FS_Flush (qfile_t* file);
+int FS_Printf (qfile_t* file, const char* format, ...);
+int FS_Getc (qfile_t* file);
+int FS_Seek (qfile_t* file, long offset, int whence);
+long FS_Tell (qfile_t* file);
+char *FS_Gets (qfile_t* file, char* buffer, int buffersize);
+char *FS_Getline (qfile_t *file);  // DO NOT FREE the returned buffer
+int FS_Eof (qfile_t* file);
+
+qbyte *FS_LoadFile (const char *path, qboolean quiet);
+qboolean FS_WriteFile (const char *filename, void *data, int len);
+
+
+// ------ Other functions ------ //
+
+void FS_StripExtension (const char *in, char *out);
+void FS_DefaultExtension (char *path, const char *extension);
+
+qboolean FS_FileExists (const char *filename);         // the file can be into a package
+qboolean FS_SysFileExists (const char *filename);      // only look for files outside of packages
+
+void FS_mkdir (const char *path);
+
+
+#endif
index 65794a0f067d41250390cc75f82ff3e9083e9fd3..cab9f636b450bd135bb4be3df5b18eda327d8ffb 100644 (file)
@@ -343,7 +343,7 @@ static void GL_TextureMode_f (void)
        }
 
        for (i = 0;i < 6;i++)
-               if (!Q_strcasecmp (modes[i].name, Cmd_Argv(1) ) )
+               if (!strcasecmp (modes[i].name, Cmd_Argv(1) ) )
                        break;
        if (i == 6)
        {
index 58068e6b750dd5896000154a11d6f4da0c71c996..4e9e3a24547f44747fee93250b94d2bbb9c7d7b7 100644 (file)
--- a/glquake.h
+++ b/glquake.h
@@ -29,13 +29,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #pragma warning(disable : 4018)                // LordHavoc: MSVC++ 4 x86, signed/unsigned mismatch
 #endif
 
-#ifdef _WIN32
-#include <windows.h>
-#define strcasecmp stricmp
-#define strncasecmp strnicmp
-#endif
-
-//#include <GL/gl.h>
 
 //====================================================
 
diff --git a/host.c b/host.c
index 3ac0f7e03f84eee8eda861ab3901540e40c94f5e..465545ad74c7f7ac088537e0d80f5c2ae1c1e202 100644 (file)
--- a/host.c
+++ b/host.c
@@ -321,13 +321,13 @@ Writes key bindings and archived cvars to config.cfg
 */
 void Host_WriteConfiguration (void)
 {
-       QFile *f;
+       qfile_t *f;
 
 // dedicated servers initialize the host but don't parse and set the
 // config.cfg cvars
        if (host_initialized && cls.state != ca_dedicated)
        {
-               f = Qopen (va("%s/config.cfg",com_gamedir), "w");
+               f = FS_Open ("config.cfg", "w", false);
                if (!f)
                {
                        Con_Printf ("Couldn't write config.cfg.\n");
@@ -337,7 +337,7 @@ void Host_WriteConfiguration (void)
                Key_WriteBindings (f);
                Cvar_WriteVariables (f);
 
-               Qclose (f);
+               FS_Close (f);
        }
 }
 
@@ -856,7 +856,6 @@ void Host_Frame (float time)
 //============================================================================
 
 void Render_Init(void);
-void QuakeIO_Init(void);
 
 /*
 ====================
@@ -880,7 +879,6 @@ void Host_Init (void)
        Memory_Init_Commands();
        R_Modules_Init();
        Cbuf_Init ();
-       QuakeIO_Init ();
        V_Init ();
        COM_Init ();
        Host_InitLocal ();
index 3179cee269a144714d038f6c1d323e2cb736c8b8..fc78cee4becd7f515c6352296312da31b086847d 100644 (file)
@@ -379,7 +379,7 @@ Host_Savegame_f
 void Host_Savegame_f (void)
 {
        char    name[256];
-       QFile   *f;
+       qfile_t *f;
        int             i;
        char    comment[SAVEGAME_COMMENT_LENGTH+1];
 
@@ -425,34 +425,35 @@ void Host_Savegame_f (void)
                }
        }
 
-       sprintf (name, "%s/%s", com_gamedir, Cmd_Argv(1));
-       COM_DefaultExtension (name, ".sav");
+       strncpy (name, Cmd_Argv(1), sizeof (name) - 1);
+       name[sizeof (name) - 1] = '\0';
+       FS_DefaultExtension (name, ".sav");
 
        Con_Printf ("Saving game to %s...\n", name);
-       f = Qopen (name, "w");
+       f = FS_Open (name, "w", false);
        if (!f)
        {
                Con_Printf ("ERROR: couldn't open.\n");
                return;
        }
 
-       Qprintf (f, "%i\n", SAVEGAME_VERSION);
+       FS_Printf (f, "%i\n", SAVEGAME_VERSION);
        Host_SavegameComment (comment);
-       Qprintf (f, "%s\n", comment);
+       FS_Printf (f, "%s\n", comment);
        for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
-               Qprintf (f, "%f\n", svs.clients->spawn_parms[i]);
-       Qprintf (f, "%d\n", current_skill);
-       Qprintf (f, "%s\n", sv.name);
-       Qprintf (f, "%f\n",sv.time);
+               FS_Printf (f, "%f\n", svs.clients->spawn_parms[i]);
+       FS_Printf (f, "%d\n", current_skill);
+       FS_Printf (f, "%s\n", sv.name);
+       FS_Printf (f, "%f\n",sv.time);
 
 // write the light styles
 
        for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
        {
                if (sv.lightstyles[i])
-                       Qprintf (f, "%s\n", sv.lightstyles[i]);
+                       FS_Printf (f, "%s\n", sv.lightstyles[i]);
                else
-                       Qprintf (f,"m\n");
+                       FS_Printf (f,"m\n");
        }
 
 
@@ -460,9 +461,9 @@ void Host_Savegame_f (void)
        for (i=0 ; i<sv.num_edicts ; i++)
        {
                ED_Write (f, EDICT_NUM(i));
-               Qflush (f);
+               FS_Flush (f);
        }
-       Qclose (f);
+       FS_Close (f);
        Con_Printf ("done.\n");
 }
 
@@ -485,15 +486,15 @@ void Host_Loadgame_f (void)
                return;
        }
 
-       sprintf (sv_loadgame, "%s/%s", com_gamedir, Cmd_Argv(1));
-       COM_DefaultExtension (sv_loadgame, ".sav");
+       sprintf (sv_loadgame, "%s/%s", fs_gamedir, Cmd_Argv(1));
+       FS_DefaultExtension (sv_loadgame, ".sav");
 
        Con_Printf ("Loading game from %s...\n", sv_loadgame);
 }
 
 void Host_PerformLoadGame(char *name)
 {
-       QFile *f;
+       qfile_t *f;
        char mapname[MAX_QPATH];
        float time, tfloat;
        char buf[32768];
@@ -507,39 +508,39 @@ void Host_PerformLoadGame(char *name)
 
        cls.demonum = -1;               // stop demo loop in case this fails
 
-       f = Qopen (name, "rz");
+       f = FS_Open (name, "r", false);
        if (!f)
        {
                Con_Printf ("ERROR: couldn't open.\n");
                return;
        }
 
-       str = Qgetline (f);
+       str = FS_Getline (f);
        sscanf (str, "%i\n", &version);
        if (version != SAVEGAME_VERSION)
        {
-               Qclose (f);
+               FS_Close (f);
                Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
                return;
        }
 
        SCR_BeginLoadingPlaque ();
 
-       str = Qgetline (f);
+       str = FS_Getline (f);
        for (i = 0;i < NUM_SPAWN_PARMS;i++)
        {
-               str = Qgetline (f);
+               str = FS_Getline (f);
                sscanf (str, "%f\n", &spawn_parms[i]);
        }
 // this silliness is so we can load 1.06 save files, which have float skill values
-       str = Qgetline (f);
+       str = FS_Getline (f);
        sscanf (str, "%f\n", &tfloat);
        current_skill = (int)(tfloat + 0.1);
        Cvar_SetValue ("skill", (float)current_skill);
 
-       strcpy (mapname, Qgetline (f));
+       strcpy (mapname, FS_Getline (f));
 
-       str = Qgetline (f);
+       str = FS_Getline (f);
        sscanf (str, "%f\n",&time);
 
        CL_Disconnect_f ();
@@ -557,7 +558,7 @@ void Host_PerformLoadGame(char *name)
 
        for (i = 0;i < MAX_LIGHTSTYLES;i++)
        {
-               str = Qgetline (f);
+               str = FS_Getline (f);
                sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
                strcpy (sv.lightstyles[i], str);
        }
@@ -565,11 +566,11 @@ void Host_PerformLoadGame(char *name)
 // load the edicts out of the savegame file
        // -1 is the globals
        entnum = -1;
-       while (!Qeof(f))
+       while (!FS_Eof (f))
        {
                for (i = 0;i < (int)sizeof(buf) - 1;i++)
                {
-                       r = Qgetc (f);
+                       r = FS_Getc (f);
                        if (r == EOF || !r)
                                break;
                        buf[i] = r;
@@ -615,7 +616,7 @@ void Host_PerformLoadGame(char *name)
        sv.num_edicts = entnum;
        sv.time = time;
 
-       Qclose (f);
+       FS_Close (f);
 
        for (i = 0;i < NUM_SPAWN_PARMS;i++)
                svs.clients->spawn_parms[i] = spawn_parms[i];
@@ -821,7 +822,7 @@ void Host_Tell_f(void)
        {
                if (!client->active || !client->spawned)
                        continue;
-               if (Q_strcasecmp(client->name, Cmd_Argv(1)))
+               if (strcasecmp(client->name, Cmd_Argv(1)))
                        continue;
                host_client = client;
                SV_ClientPrintf("%s", text);
@@ -1185,7 +1186,7 @@ void Host_Kick_f (void)
                {
                        if (!host_client->active)
                                continue;
-                       if (Q_strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
+                       if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
                                break;
                }
        }
diff --git a/image.c b/image.c
index 53ddafb1214400fe769b8355330b8e9bf6741ba4..51cde77117bbfc9eb5a53fc1c6c548d1ba72e83c 100644 (file)
--- a/image.c
+++ b/image.c
@@ -93,7 +93,7 @@ qbyte* LoadPCX (const qbyte *f, int matchwidth, int matchheight)
        const qbyte *palette, *fin, *enddata;
        int x, y, x2, dataByte;
 
-       if (loadsize < (int)sizeof(pcx) + 768)
+       if (fs_filesize < (int)sizeof(pcx) + 768)
        {
                Con_Printf ("Bad pcx file\n");
                return NULL;
@@ -132,7 +132,7 @@ qbyte* LoadPCX (const qbyte *f, int matchwidth, int matchheight)
        image_width = pcx.xmax+1;
        image_height = pcx.ymax+1;
 
-       palette = f + loadsize - 768;
+       palette = f + fs_filesize - 768;
 
        image_rgba = Mem_Alloc(tempmempool, image_width*image_height*4);
        if (!image_rgba)
@@ -231,10 +231,10 @@ qbyte *LoadTGA (const qbyte *f, int matchwidth, int matchheight)
        TargaHeader targa_header;
        unsigned char palette[256*4], *p;
 
-       if (loadsize < 19)
+       if (fs_filesize < 19)
                return NULL;
 
-       enddata = f + loadsize;
+       enddata = f + fs_filesize;
 
        targa_header.id_length = f[0];
        targa_header.colormap_type = f[1];
@@ -441,7 +441,7 @@ qbyte *LoadLMP (const qbyte *f, int matchwidth, int matchheight)
        qbyte *image_rgba;
        int width, height;
 
-       if (loadsize < 9)
+       if (fs_filesize < 9)
        {
                Con_Printf("LoadLMP: invalid LMP file\n");
                return NULL;
@@ -458,7 +458,7 @@ qbyte *LoadLMP (const qbyte *f, int matchwidth, int matchheight)
        if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight))
                return NULL;
 
-       if (loadsize < 8 + width * height)
+       if (fs_filesize < 8 + width * height)
        {
                Con_Printf("LoadLMP: invalid LMP file\n");
                return NULL;
@@ -487,7 +487,7 @@ qbyte *LoadLMPAs8Bit (const qbyte *f, int matchwidth, int matchheight)
        qbyte *image_8bit;
        int width, height;
 
-       if (loadsize < 9)
+       if (fs_filesize < 9)
        {
                Con_Printf("LoadLMPAs8Bit: invalid LMP file\n");
                return NULL;
@@ -504,7 +504,7 @@ qbyte *LoadLMPAs8Bit (const qbyte *f, int matchwidth, int matchheight)
        if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight))
                return NULL;
 
-       if (loadsize < 8 + width * height)
+       if (fs_filesize < 8 + width * height)
        {
                Con_Printf("LoadLMPAs8Bit: invalid LMP file\n");
                return NULL;
@@ -550,63 +550,63 @@ qbyte *loadimagepixels (const char *filename, qboolean complain, int matchwidth,
                if (*c == '*')
                        *c = '#';
        sprintf (name, "override/%s.tga", basename);
-       f = COM_LoadFile(name, true);
+       f = FS_LoadFile(name, true);
        if (f)
        {
                data = LoadTGA (f, matchwidth, matchheight);
                goto loaded;
        }
        sprintf (name, "override/%s.jpg", basename);
-       f = COM_LoadFile(name, true);
+       f = FS_LoadFile(name, true);
        if (f)
        {
                data = JPEG_LoadImage (f, matchwidth, matchheight);
                goto loaded;
        }
        sprintf (name, "textures/%s.tga", basename);
-       f = COM_LoadFile(name, true);
+       f = FS_LoadFile(name, true);
        if (f)
        {
                data = LoadTGA (f, matchwidth, matchheight);
                goto loaded;
        }
        sprintf (name, "textures/%s.jpg", basename);
-       f = COM_LoadFile(name, true);
+       f = FS_LoadFile(name, true);
        if (f)
        {
                data = JPEG_LoadImage (f, matchwidth, matchheight);
                goto loaded;
        }
        sprintf (name, "textures/%s.pcx", basename);
-       f = COM_LoadFile(name, true);
+       f = FS_LoadFile(name, true);
        if (f)
        {
                data = LoadPCX (f, matchwidth, matchheight);
                goto loaded;
        }
        sprintf (name, "%s.tga", basename);
-       f = COM_LoadFile(name, true);
+       f = FS_LoadFile(name, true);
        if (f)
        {
                data = LoadTGA (f, matchwidth, matchheight);
                goto loaded;
        }
        sprintf (name, "%s.jpg", basename);
-       f = COM_LoadFile(name, true);
+       f = FS_LoadFile(name, true);
        if (f)
        {
                data = JPEG_LoadImage (f, matchwidth, matchheight);
                goto loaded;
        }
        sprintf (name, "%s.pcx", basename);
-       f = COM_LoadFile(name, true);
+       f = FS_LoadFile(name, true);
        if (f)
        {
                data = LoadPCX (f, matchwidth, matchheight);
                goto loaded;
        }
        sprintf (name, "%s.lmp", basename);
-       f = COM_LoadFile(name, true);
+       f = FS_LoadFile(name, true);
        if (f)
        {
                data = LoadLMP (f, matchwidth, matchheight);
@@ -768,7 +768,7 @@ qboolean Image_WriteTGARGB_preflipped (const char *filename, int width, int heig
                *out++ = in[1];
                *out++ = in[0];
        }
-       ret = COM_WriteFile (filename, buffer, width*height*3 + 18 );
+       ret = FS_WriteFile (filename, buffer, width*height*3 + 18 );
 
        Mem_Free(buffer);
        return ret;
@@ -803,7 +803,7 @@ void Image_WriteTGARGB (const char *filename, int width, int height, const qbyte
                        *out++ = in[0];
                }
        }
-       COM_WriteFile (filename, buffer, width*height*3 + 18 );
+       FS_WriteFile (filename, buffer, width*height*3 + 18 );
 
        Mem_Free(buffer);
 }
@@ -838,7 +838,7 @@ void Image_WriteTGARGBA (const char *filename, int width, int height, const qbyt
                        *out++ = in[3];
                }
        }
-       COM_WriteFile (filename, buffer, width*height*4 + 18 );
+       FS_WriteFile (filename, buffer, width*height*4 + 18 );
 
        Mem_Free(buffer);
 }
diff --git a/jpeg.c b/jpeg.c
index 85e0a71993e60179c7c36a3141b95cad41db5766..3519ab19d28cdecf3074b314bc4337326c9f2e6e 100644 (file)
--- a/jpeg.c
+++ b/jpeg.c
@@ -359,7 +359,7 @@ static void JPEG_MemSrc (j_decompress_ptr cinfo, qbyte *buffer)
        cinfo->src = (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT, sizeof (struct jpeg_source_mgr));
 
        cinfo->src->next_input_byte = buffer;
-       cinfo->src->bytes_in_buffer = com_filesize;
+       cinfo->src->bytes_in_buffer = fs_filesize;
 
        cinfo->src->init_source = JPEG_Noop;
        cinfo->src->fill_input_buffer = JPEG_FillInputBuffer;
diff --git a/keys.c b/keys.c
index 9b018bde264c4df41b8c317c9075ef748116ca8d..b49e2ac1e64737c144d75bc70e2cba6bea440705 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -509,7 +509,7 @@ int Key_StringToKeynum (const char *str)
                return str[0];
 
        for (kn=keynames ; kn->name ; kn++)
-               if (!Q_strcasecmp(str,kn->name))
+               if (!strcasecmp(str,kn->name))
                        return kn->keynum;
        return -1;
 }
@@ -661,13 +661,13 @@ Key_WriteBindings
 Writes lines containing "bind key value"
 ============
 */
-void Key_WriteBindings (QFile *f)
+void Key_WriteBindings (qfile_t *f)
 {
        int i;
 
        for (i = 0;i < 256;i++)
                if (keybindings[i] && *keybindings[i])
-                       Qprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
+                       FS_Printf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
 }
 
 
diff --git a/keys.h b/keys.h
index fcd39ce41ede714d8bcaf322da30d95b9364d7b9..37141c0b3e1255f1e162981fb4cdc8068d48a303 100644 (file)
--- a/keys.h
+++ b/keys.h
@@ -151,7 +151,7 @@ extern keydest_t key_dest;
 
 void Key_Event (int key, qboolean down);
 void Key_Init (void);
-void Key_WriteBindings (QFile *f);
+void Key_WriteBindings (qfile_t *f);
 void Key_SetBinding (int keynum, char *binding);
 void Key_ClearStates (void);
 
index 507f6233cdb806b1fa7bc8fffe04def469186c65..9da3b6b6d38be5313f61c0d687bb9b2f4a1ff336 100644 (file)
--- a/makefile
+++ b/makefile
@@ -50,7 +50,7 @@ SHAREDOBJECTS=        builddate.o cmd.o collision.o common.o crc.o cvar.o \
                filematch.o host.o host_cmd.o image.o mathlib.o matrixlib.o \
                model_alias.o model_brush.o model_shared.o model_sprite.o \
                net_bsd.o net_dgrm.o net_loop.o net_main.o net_master.o \
-               net_udp.o palette.o portals.o protocol.o quakeio.o sys_linux.o \
+               net_udp.o palette.o portals.o protocol.o fs.o sys_linux.o \
                sys_shared.o world.o wad.o zone.o
 
 OBJ_COMMON= $(CLIENTOBJECTS) $(SERVEROBJECTS) $(SHAREDOBJECTS)
index 0c08811f9852334e1cada8f5e1ab1d2f04862ced..c895758579b873c5ddca5664cb852a31f1d5316b 100644 (file)
@@ -7,7 +7,7 @@ OBJECTS= builddate.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cmd.o \
        sbar.o snd_dma.o snd_mem.o snd_mix.o sv_main.o sv_move.o \
        sv_phys.o sv_user.o sv_light.o view.o wad.o world.o zone.o vid_shared.o \
        palette.o r_crosshairs.o gl_textures.o gl_models.o r_sprites.o \
-       r_modules.o r_explosion.o r_lerpanim.o protocol.o quakeio.o ui.o \
+       r_modules.o r_explosion.o r_lerpanim.o protocol.o fs.o ui.o \
        portals.o sys_shared.o gl_backend.o cl_particles.o cl_screen.o cgamevm.o \
        cgame.o filematch.o collision.o cl_collision.o matrixlib.o cl_video.o \
        dpvsimpledecode.o wavefile.o meshqueue.o net_master.o r_shadow.o jpeg.o
index 16642b4ab05a29e16b2ac1a56074c68eaa90dcc0..ce0d610591156a6adb9e5346ea005aa9cb716e01 100644 (file)
@@ -37,7 +37,7 @@ SHAREDOBJECTS=        builddate.o cmd.o collision.o common.o crc.o cvar.o \
                filematch.o host.o host_cmd.o image.o mathlib.o matrixlib.o \
                model_alias.o model_brush.o model_shared.o model_sprite.o \
                net_dgrm.o net_loop.o net_main.o net_master.o \
-               palette.o portals.o protocol.o quakeio.o \
+               palette.o portals.o protocol.o fs.o \
                sys_shared.o world.o wad.o zone.o
 
 
diff --git a/menu.c b/menu.c
index f940766941007b16d90e5174d27489727974eb51..f4bda352360446dcd1cb324d011f7304ea861e8c 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -676,20 +676,20 @@ void M_ScanSaves (void)
        int             i, j;
        char    name[MAX_OSPATH];
        char    *str;
-       QFile   *f;
+       qfile_t *f;
        int             version;
 
        for (i=0 ; i<MAX_SAVEGAMES ; i++)
        {
                strcpy (m_filenames[i], "--- UNUSED SLOT ---");
                loadable[i] = false;
-               sprintf (name, "%s/s%i.sav", com_gamedir, i);
-               f = Qopen (name, "rz");
+               sprintf (name, "%s/s%i.sav", fs_gamedir, i);
+               f = FS_Open (name, "r", false);
                if (!f)
                        continue;
-               str = Qgetline (f);
+               str = FS_Getline (f);
                sscanf (str, "%i\n", &version);
-               str = Qgetline (f);
+               str = FS_Getline (f);
                strncpy (m_filenames[i], str, sizeof(m_filenames[i])-1);
 
        // change _ back to space
@@ -697,7 +697,7 @@ void M_ScanSaves (void)
                        if (m_filenames[i][j] == '_')
                                m_filenames[i][j] = ' ';
                loadable[i] = true;
-               Qclose (f);
+               FS_Close (f);
        }
 }
 
@@ -949,7 +949,7 @@ void M_MenuPlayerTranslate (qbyte *translation, int top, int bottom)
        if (menuplyr_load)
        {
                menuplyr_load = false;
-               f = COM_LoadFile("gfx/menuplyr.lmp", true);
+               f = FS_LoadFile("gfx/menuplyr.lmp", true);
                if (!f)
                {
                        menuplyr_failed = true;
@@ -3572,9 +3572,9 @@ void M_Init (void)
 
        if (gamemode == GAME_NEHAHRA)
        {
-               if (COM_FileExists("maps/neh1m4.bsp"))
+               if (FS_FileExists("maps/neh1m4.bsp"))
                {
-                       if (COM_FileExists("hearing.dem"))
+                       if (FS_FileExists("hearing.dem"))
                        {
                                Con_Printf("Nehahra movie and game detected.\n");
                                NehGameType = TYPE_BOTH;
@@ -3587,7 +3587,7 @@ void M_Init (void)
                }
                else
                {
-                       if (COM_FileExists("hearing.dem"))
+                       if (FS_FileExists("hearing.dem"))
                        {
                                Con_Printf("Nehahra movie detected.\n");
                                NehGameType = TYPE_DEMO;
index ac88de7f529c9e8cb7711f8d25aa45b448a066ac..5347384db691953d7fcd74c25b8fc60a1c89abbc 100644 (file)
@@ -617,19 +617,19 @@ static void Mod_LoadLighting (lump_t *l)
        {
                // LordHavoc: hope is not lost yet, check for a .lit file to load
                strcpy(litfilename, loadmodel->name);
-               COM_StripExtension(litfilename, litfilename);
+               FS_StripExtension(litfilename, litfilename);
                strcat(litfilename, ".lit");
-               data = (qbyte*) COM_LoadFile (litfilename, false);
+               data = (qbyte*) FS_LoadFile (litfilename, false);
                if (data)
                {
-                       if (loadsize > 8 && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
+                       if (fs_filesize > 8 && data[0] == 'Q' && data[1] == 'L' && data[2] == 'I' && data[3] == 'T')
                        {
                                i = LittleLong(((int *)data)[1]);
                                if (i == 1)
                                {
                                        Con_DPrintf("loaded %s\n", litfilename);
-                                       loadmodel->lightdata = Mem_Alloc(loadmodel->mempool, loadsize - 8);
-                                       memcpy(loadmodel->lightdata, data + 8, loadsize - 8);
+                                       loadmodel->lightdata = Mem_Alloc(loadmodel->mempool, fs_filesize - 8);
+                                       memcpy(loadmodel->lightdata, data + 8, fs_filesize - 8);
                                        Mem_Free(data);
                                        return;
                                }
@@ -641,7 +641,7 @@ static void Mod_LoadLighting (lump_t *l)
                        }
                        else
                        {
-                               if (loadsize == 8)
+                               if (fs_filesize == 8)
                                        Con_Printf("Empty .lit file, ignoring\n");
                                else
                                        Con_Printf("Corrupt .lit file (old version?), ignoring\n");
@@ -672,9 +672,9 @@ void Mod_LoadLightList(void)
        mlight_t *e;
 
        strcpy(lightsfilename, loadmodel->name);
-       COM_StripExtension(lightsfilename, lightsfilename);
+       FS_StripExtension(lightsfilename, lightsfilename);
        strcat(lightsfilename, ".lights");
-       s = lightsstring = (char *) COM_LoadFile (lightsfilename, false);
+       s = lightsstring = (char *) FS_LoadFile (lightsfilename, false);
        if (s)
        {
                numlights = 0;
index 97efa1f5d3f8a65eecd9d92f23b36075a756db83..05e7edd3adf7f14c495ad50a93c122d0fff0937b 100644 (file)
@@ -199,7 +199,7 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk,
        {
                if (checkdisk)
                {
-                       buf = COM_LoadFile (mod->name, false);
+                       buf = FS_LoadFile (mod->name, false);
                        if (!buf)
                        {
                                if (crash)
@@ -207,7 +207,7 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk,
                                return NULL;
                        }
 
-                       crc = CRC_Block(buf, com_filesize);
+                       crc = CRC_Block(buf, fs_filesize);
                }
                else
                        crc = mod->crc;
@@ -224,14 +224,14 @@ static model_t *Mod_LoadModel (model_t *mod, qboolean crash, qboolean checkdisk,
 
        if (!buf)
        {
-               buf = COM_LoadFile (mod->name, false);
+               buf = FS_LoadFile (mod->name, false);
                if (!buf)
                {
                        if (crash)
                                Host_Error ("Mod_LoadModel: %s not found", mod->name);
                        return NULL;
                }
-               crc = CRC_Block(buf, com_filesize);
+               crc = CRC_Block(buf, fs_filesize);
        }
 
        // allocate a new model
index cf72d84dbd0ffd8907ae2398127894cfd125eae9..31b654a83f5aaa714f26625b9e32c629a653c47e 100644 (file)
@@ -136,7 +136,7 @@ void NET_Ban_f (void)
                        break;
 
                case 2:
-                       if (Q_strcasecmp(Cmd_Argv(1), "off") == 0)
+                       if (strcasecmp(Cmd_Argv(1), "off") == 0)
                                banAddr = 0x00000000;
                        else
                                banAddr = inet_addr(Cmd_Argv(1));
@@ -491,7 +491,7 @@ void NET_Stats_f (void)
        else
        {
                for (s = net_activeSockets; s; s = s->next)
-                       if (Q_strcasecmp(Cmd_Argv(1), s->address) == 0)
+                       if (strcasecmp(Cmd_Argv(1), s->address) == 0)
                                break;
                if (s == NULL)
                        return;
@@ -581,7 +581,7 @@ static void Test_f (void)
        if (host && hostCacheCount)
        {
                for (n = 0; n < hostCacheCount; n++)
-                       if (Q_strcasecmp (host, hostcache[n].name) == 0)
+                       if (strcasecmp (host, hostcache[n].name) == 0)
                        {
                                if (hostcache[n].driver != myDriverLevel)
                                        continue;
@@ -711,7 +711,7 @@ static void Test2_f (void)
        if (host && hostCacheCount)
        {
                for (n = 0; n < hostCacheCount; n++)
-                       if (Q_strcasecmp (host, hostcache[n].name) == 0)
+                       if (strcasecmp (host, hostcache[n].name) == 0)
                        {
                                if (hostcache[n].driver != myDriverLevel)
                                        continue;
@@ -1156,7 +1156,7 @@ static qboolean Datagram_HandleServerInfo (struct qsockaddr *readaddr)
        {
                if (i == n)
                        continue;
-               if (Q_strcasecmp (hostcache[n].name, hostcache[i].name) == 0)
+               if (strcasecmp (hostcache[n].name, hostcache[i].name) == 0)
                {
                        i = strlen(hostcache[n].name);
                        if (i < 15 && hostcache[n].name[i-1] > '8')
index 836d2d043331e75e97e21b6c7e9348bbd7895cdc..e29480a309fd629d4d4926521ffb2c4dd2ae7b51 100644 (file)
@@ -525,7 +525,7 @@ qsocket_t *NET_Connect (char *host)
 
        if (host)
        {
-               if (Q_strcasecmp (host, "local") == 0)
+               if (strcasecmp (host, "local") == 0)
                {
                        net_driverlevel = 0;
                        return dfunc.Connect (host);
@@ -534,7 +534,7 @@ qsocket_t *NET_Connect (char *host)
                if (hostCacheCount)
                {
                        for (n = 0; n < hostCacheCount; n++)
-                               if (Q_strcasecmp (host, hostcache[n].name) == 0)
+                               if (strcasecmp (host, hostcache[n].name) == 0)
                                {
                                        host = hostcache[n].cname;
                                        break;
@@ -560,7 +560,7 @@ qsocket_t *NET_Connect (char *host)
 
        if (hostCacheCount)
                for (n = 0; n < hostCacheCount; n++)
-                       if (Q_strcasecmp (host, hostcache[n].name) == 0)
+                       if (strcasecmp (host, hostcache[n].name) == 0)
                        {
                                host = hostcache[n].cname;
                                break;
index b08118b8afa2f4fdbe3da97f8b5ec0d0f13fc13d..1a481e3ffac671c45413a2683775200c6662d1d3 100644 (file)
--- a/palette.c
+++ b/palette.c
@@ -35,8 +35,8 @@ void Palette_Setup8to24(void)
        palette_complete[255] = 0; // completely transparent black
 
        // FIXME: fullbright_start should be read from colormap.lmp
-       colormap = COM_LoadFile("gfx/colormap.lmp", true);
-       if (colormap && com_filesize >= 16385)
+       colormap = FS_LoadFile("gfx/colormap.lmp", true);
+       if (colormap && fs_filesize >= 16385)
                fullbright_start = 256 - colormap[16384];
        else
                fullbright_start = 256;
@@ -171,7 +171,7 @@ void Palette_Init(void)
        float gamma, scale, base;
        qbyte *pal;
        qbyte temp[256];
-       pal = (qbyte *)COM_LoadFile ("gfx/palette.lmp", false);
+       pal = (qbyte *)FS_LoadFile ("gfx/palette.lmp", false);
        if (!pal)
                Sys_Error ("Couldn't load gfx/palette.lmp");
        memcpy(host_basepal, pal, 765);
index 374a9648ec541cf80e0bce1652aa7c04669e9eef..db12799b4d7e5d8df22354c22ce31d90b3690f1d 100644 (file)
@@ -622,7 +622,7 @@ ED_Write
 For savegames
 =============
 */
-void ED_Write (QFile *f, edict_t *ed)
+void ED_Write (qfile_t *f, edict_t *ed)
 {
        ddef_t  *d;
        int             *v;
@@ -630,11 +630,11 @@ void ED_Write (QFile *f, edict_t *ed)
        char    *name;
        int             type;
 
-       Qprintf (f, "{\n");
+       FS_Printf (f, "{\n");
 
        if (ed->free)
        {
-               Qprintf (f, "}\n");
+               FS_Printf (f, "}\n");
                return;
        }
 
@@ -655,11 +655,11 @@ void ED_Write (QFile *f, edict_t *ed)
                if (j == type_size[type])
                        continue;
 
-               Qprintf (f,"\"%s\" ",name);
-               Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
+               FS_Printf (f,"\"%s\" ",name);
+               FS_Printf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
        }
 
-       Qprintf (f, "}\n");
+       FS_Printf (f, "}\n");
 }
 
 void ED_PrintNum (int ent)
@@ -753,14 +753,14 @@ FIXME: need to tag constants, doesn't really work
 ED_WriteGlobals
 =============
 */
-void ED_WriteGlobals (QFile *f)
+void ED_WriteGlobals (qfile_t *f)
 {
        ddef_t          *def;
        int                     i;
        char            *name;
        int                     type;
 
-       Qprintf (f,"{\n");
+       FS_Printf (f,"{\n");
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
@@ -773,10 +773,10 @@ void ED_WriteGlobals (QFile *f)
                        continue;
 
                name = PR_GetString(def->s_name);
-               Qprintf (f,"\"%s\" ", name);
-               Qprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));              
+               FS_Printf (f,"\"%s\" ", name);
+               FS_Printf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));            
        }
-       Qprintf (f,"}\n");
+       FS_Printf (f,"}\n");
 }
 
 /*
@@ -1181,18 +1181,18 @@ void PR_LoadProgs (void)
        Mem_EmptyPool(progs_mempool);
        Mem_EmptyPool(edictstring_mempool);
 
-       temp = COM_LoadFile ("progs.dat", false);
+       temp = FS_LoadFile ("progs.dat", false);
        if (!temp)
                Host_Error ("PR_LoadProgs: couldn't load progs.dat");
 
-       progs = (dprograms_t *)Mem_Alloc(progs_mempool, com_filesize);
+       progs = (dprograms_t *)Mem_Alloc(progs_mempool, fs_filesize);
 
-       memcpy(progs, temp, com_filesize);
+       memcpy(progs, temp, fs_filesize);
        Mem_Free(temp);
 
-       Con_DPrintf ("Programs occupy %iK.\n", com_filesize/1024);
+       Con_DPrintf ("Programs occupy %iK.\n", fs_filesize/1024);
 
-       pr_crc = CRC_Block((qbyte *)progs, com_filesize);
+       pr_crc = CRC_Block((qbyte *)progs, fs_filesize);
 
 // byte swap the header
        for (i = 0;i < (int) sizeof(*progs) / 4;i++)
diff --git a/progs.h b/progs.h
index f9d1bde401a5f27bab9d9c5f012380b171f6d793..702c44594baa4ac3b8ed4c54685aa6eb60a85b59 100644 (file)
--- a/progs.h
+++ b/progs.h
@@ -149,10 +149,10 @@ char      *ED_NewString (const char *string);
 // returns a copy of the string allocated from the server's string heap
 
 void ED_Print (edict_t *ed);
-void ED_Write (QFile *f, edict_t *ed);
+void ED_Write (qfile_t *f, edict_t *ed);
 const char *ED_ParseEdict (const char *data, edict_t *ent);
 
-void ED_WriteGlobals (QFile *f);
+void ED_WriteGlobals (qfile_t *f);
 void ED_ParseGlobals (const char *data);
 
 void ED_LoadFromFile (const char *data);
index f1d6d5ed7c5931d759e0145e06f3227966695733..4ebc22f24e1cafad081fb5bcb61e0d2743101076 100644 (file)
@@ -156,7 +156,7 @@ extern char *buildstring;
 #define        SOUND_CHANNELS          8
 
 #include "zone.h"
-#include "quakeio.h"
+#include "fs.h"
 #include "common.h"
 #include "cvar.h"
 #include "bspfile.h"
diff --git a/quakeio.c b/quakeio.c
deleted file mode 100644 (file)
index d3dd6cf..0000000
--- a/quakeio.c
+++ /dev/null
@@ -1,401 +0,0 @@
-/*
-       quakeio.c
-
-       (description)
-
-       Copyright (C) 1996-1997  Id Software, Inc.
-       Copyright (C) 1999,2000  contributors of the QuakeForge project
-       Please see the file "AUTHORS" for a list of contributors
-
-       This program is free software; you can redistribute it and/or
-       modify it under the terms of the GNU General Public License
-       as published by the Free Software Foundation; either version 2
-       of the License, or (at your option) any later version.
-
-       This program is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-       See the GNU General Public License for more details.
-
-       You should have received a copy of the GNU General Public License
-       along with this program; if not, write to:
-
-               Free Software Foundation, Inc.
-               59 Temple Place - Suite 330
-               Boston, MA  02111-1307, USA
-
-       $Id$
-*/
-
-#include "quakedef.h"
-#include <stdlib.h>
-#include <string.h>
-#ifdef WIN32
-# include <io.h>
-# include <fcntl.h>
-#else
-# include <pwd.h>
-# include <unistd.h>
-#endif
-
-#include <stdarg.h>
-#include <stdlib.h>
-#include <limits.h>
-
-#ifndef PATH_MAX
-# define PATH_MAX 512
-#endif
-
-#include "quakeio.h"
-
-#ifdef WIN32
-# ifndef __BORLANDC__
-#  define setmode _setmode
-#  define O_BINARY _O_BINARY
-# endif
-#endif
-
-mempool_t *quakeio_mempool;
-
-void
-Qexpand_squiggle (const char *path, char *dest)
-{
-       char       *home;
-
-#ifndef _WIN32
-       struct passwd *pwd_ent;
-#endif
-
-       if (strncmp (path, "~/", 2) != 0) {
-               strcpy (dest, path);
-               return;
-       }
-
-#ifdef _WIN32
-       // LordHavoc: first check HOME to duplicate previous version behavior
-       // (also handy if someone wants it somewhere other than their
-       //  windows directory)
-       home = getenv ("HOME");
-       if (!home || !home[0])
-               home = getenv ("WINDIR");
-#else
-       if ((pwd_ent = getpwuid (getuid ()))) {
-               home = pwd_ent->pw_dir;
-       } else
-               home = getenv ("HOME");
-#endif
-
-       if (home) {
-               strcpy (dest, home);
-               strncat (dest, path + 1, MAX_OSPATH - strlen (dest));   // skip
-                                                                                                                               // leading ~
-       } else
-               strcpy (dest, path);
-}
-
-int
-Qrename (const char *old, const char *new)
-{
-       char        e_old[PATH_MAX];
-       char        e_new[PATH_MAX];
-
-       Qexpand_squiggle (old, e_old);
-       Qexpand_squiggle (new, e_new);
-       return rename (e_old, e_new);
-}
-
-QFile *
-Qopen (const char *path, const char *mode)
-{
-       QFile      *file;
-       char        m[80], *p;
-       int         zip = 0;
-       char        e_path[PATH_MAX];
-
-       Qexpand_squiggle (path, e_path);
-       path = e_path;
-
-       for (p = m; *mode && p - m < (int)(sizeof (m) - 1); mode++) {
-               if (*mode == 'z') {
-                       zip = 1;
-                       continue;
-               }
-#ifndef HAVE_ZLIB
-               if (strchr ("0123456789fh", *mode)) {
-                       continue;
-               }
-#endif
-               *p++ = *mode;
-       }
-       *p = 0;
-
-       file = Mem_Alloc(quakeio_mempool, sizeof (*file));
-       memset(file, 0, sizeof(*file));
-       if (!file)
-               return 0;
-#ifdef HAVE_ZLIB
-       if (zip) {
-               file->gzfile = gzopen (path, m);
-               if (!file->gzfile) {
-                       Mem_Free(file);
-                       return 0;
-               }
-       } else
-#endif
-       {
-               file->file = fopen (path, m);
-               if (!file->file) {
-                       Mem_Free(file);
-                       return 0;
-               }
-       }
-       return file;
-}
-
-QFile *
-Qdopen (int fd, const char *mode)
-{
-       QFile      *file;
-       char        m[80], *p;
-       int         zip = 0;
-
-       for (p = m; *mode && p - m < (int)(sizeof (m) - 1); mode++) {
-               if (*mode == 'z') {
-                       zip = 1;
-                       continue;
-               }
-               *p++ = *mode;
-       }
-
-       *p = 0;
-
-       file = Mem_Alloc(quakeio_mempool, sizeof (*file));
-       memset(file, 0, sizeof(*file));
-       if (!file)
-               return 0;
-#ifdef HAVE_ZLIB
-       if (zip) {
-               file->gzfile = gzdopen (fd, m);
-               if (!file->gzfile) {
-                       Mem_Free(file);
-                       return 0;
-               }
-       } else
-#endif
-       {
-               file->file = fdopen (fd, m);
-               if (!file->file) {
-                       Mem_Free(file);
-                       return 0;
-               }
-       }
-#ifdef WIN32
-       if (file->file)
-               setmode (_fileno (file->file), O_BINARY);
-#endif
-       return file;
-}
-
-void
-Qclose (QFile *file)
-{
-       if (file->file)
-               fclose (file->file);
-#ifdef HAVE_ZLIB
-       else
-               gzclose (file->gzfile);
-#endif
-       Mem_Free(file);
-}
-
-int
-Qread (QFile *file, void *buf, int count)
-{
-       if (file->file)
-               return fread (buf, 1, count, file->file);
-#ifdef HAVE_ZLIB
-       else
-               return gzread (file->gzfile, buf, count);
-#else
-       return -1;
-#endif
-}
-
-int
-Qwrite (QFile *file, void *buf, int count)
-{
-       if (file->file)
-               return fwrite (buf, 1, count, file->file);
-#ifdef HAVE_ZLIB
-       else
-               return gzwrite (file->gzfile, buf, count);
-#else
-       return -1;
-#endif
-}
-
-int
-Qprintf (QFile *file, const char *fmt, ...)
-{
-       va_list     args;
-       int         ret = -1;
-
-       va_start (args, fmt);
-       if (file->file)
-               ret = vfprintf (file->file, fmt, args);
-#ifdef HAVE_ZLIB
-       else {
-               char        buf[4096];
-
-               va_start (args, fmt);
-#ifdef HAVE_VSNPRINTF
-               (void) vsnprintf (buf, sizeof (buf), fmt, args);
-#else
-               (void) vsprintf (buf, fmt, args);
-#endif
-               va_end (args);
-               ret = strlen (buf);                             /* some *snprintf don't return the nb 
-                                                                                  of bytes written */
-               if (ret > 0)
-                       ret = gzwrite (file->gzfile, buf, (unsigned) ret);
-       }
-#endif
-       va_end (args);
-       return ret;
-}
-
-char *
-Qgets (QFile *file, char *buf, int count)
-{
-       if (file->file)
-               return fgets (buf, count, file->file);
-#ifdef HAVE_ZLIB
-       else
-               return gzgets (file->gzfile, buf, count);
-#else
-       return 0;
-#endif
-}
-
-int
-Qgetc (QFile *file)
-{
-       if (file->file)
-               return fgetc (file->file);
-#ifdef HAVE_ZLIB
-       else
-               return gzgetc (file->gzfile);
-#else
-       return -1;
-#endif
-}
-
-int
-Qputc (QFile *file, int c)
-{
-       if (file->file)
-               return fputc (c, file->file);
-#ifdef HAVE_ZLIB
-       else
-               return gzputc (file->gzfile, c);
-#else
-       return -1;
-#endif
-}
-
-int
-Qseek (QFile *file, long offset, int whence)
-{
-       if (file->file)
-               return fseek (file->file, offset, whence);
-#ifdef HAVE_ZLIB
-       else
-               return gzseek (file->gzfile, offset, whence);
-#else
-       return -1;
-#endif
-}
-
-long
-Qtell (QFile *file)
-{
-       if (file->file)
-               return ftell (file->file);
-#ifdef HAVE_ZLIB
-       else
-               return gztell (file->gzfile);
-#else
-       return -1;
-#endif
-}
-
-int
-Qflush (QFile *file)
-{
-       if (file->file)
-               return fflush (file->file);
-#ifdef HAVE_ZLIB
-       else
-               return gzflush (file->gzfile, Z_SYNC_FLUSH);
-#else
-       return -1;
-#endif
-}
-
-int
-Qeof (QFile *file)
-{
-       if (file->file)
-               return feof (file->file);
-#ifdef HAVE_ZLIB
-       else
-               return gzeof (file->gzfile);
-#else
-       return -1;
-#endif
-}
-
-/*
-
-       Qgetline
-
-       Dynamic length version of Qgets. DO NOT free the buffer.
-
-*/
-char *
-Qgetline (QFile *file)
-{
-       static int  size = 256;
-       static char *buf = 0;
-       char        *t;
-       int         len;
-
-       if (!buf)
-               buf = Mem_Alloc(quakeio_mempool, size);
-
-       if (!Qgets (file, buf, size))
-               return 0;
-
-       len = strlen (buf);
-       while (buf[len - 1] != '\n' && buf[len - 1] != '\r')
-       {
-               t = Mem_Alloc(quakeio_mempool, size + 256);
-               memcpy(t, buf, size);
-               Mem_Free(buf);
-               size += 256;
-               buf = t;
-               if (!Qgets (file, buf + len, size - len))
-                       break;
-               len = strlen (buf);
-       }
-       while ((len = strlen(buf)) && (buf[len - 1] == '\n' || buf[len - 1] == '\r'))
-               buf[len - 1] = 0;
-       return buf;
-}
-
-void QuakeIO_Init(void)
-{
-       quakeio_mempool = Mem_AllocPool("file management");
-}
-
diff --git a/quakeio.h b/quakeio.h
deleted file mode 100644 (file)
index cf8a9b5..0000000
--- a/quakeio.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
-       quakeio.h
-
-       (description)
-
-       Copyright (C) 1996-1997  Id Software, Inc.
-       Copyright (C) 1999,2000  contributors of the QuakeForge project
-       Please see the file "AUTHORS" for a list of contributors
-
-       This program is free software; you can redistribute it and/or
-       modify it under the terms of the GNU General Public License
-       as published by the Free Software Foundation; either version 2
-       of the License, or (at your option) any later version.
-
-       This program is distributed in the hope that it will be useful,
-       but WITHOUT ANY WARRANTY; without even the implied warranty of
-       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-
-       See the GNU General Public License for more details.
-
-       You should have received a copy of the GNU General Public License
-       along with this program; if not, write to:
-
-               Free Software Foundation, Inc.
-               59 Temple Place - Suite 330
-               Boston, MA  02111-1307, USA
-
-       $Id$
-*/
-#ifndef __quakeio_h
-#define __quakeio_h
-
-//#define HAVE_ZLIB
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <stdio.h>
-
-#ifdef HAVE_ZLIB
-# include <zlib.h>
-# ifdef WIN32
-#  undef FAR
-# endif
-#endif
-
-//#include "QF/gcc_attr.h"
-
-typedef struct {
-       FILE *file;
-#ifdef HAVE_ZLIB
-       gzFile *gzfile;
-#endif
-} QFile;
-
-void Qexpand_squiggle(const char *path, char *dest);
-int Qrename(const char *old, const char *new);
-QFile *Qopen(const char *path, const char *mode);
-QFile *Qdopen(int fd, const char *mode);
-void Qclose(QFile *file);
-int Qread(QFile *file, void *buf, int count);
-int Qwrite(QFile *file, void *buf, int count);
-//int Qprintf(QFile *file, const char *fmt, ...) __attribute__((format(printf,2,3)));
-int Qprintf(QFile *file, const char *fmt, ...);
-char *Qgets(QFile *file, char *buf, int count);
-int Qgetc(QFile *file);
-int Qputc(QFile *file, int c);
-int Qseek(QFile *file, long offset, int whence);
-long Qtell(QFile *file);
-int Qflush(QFile *file);
-int Qeof(QFile *file);
-char *Qgetline(QFile *file);
-
-#endif /*__quakeio_h*/
index 2036a8b5593556d1a7dbeb9e1241e504224dcb42..de429d0b49711a8318b307d6a81de1a990529ef7 100644 (file)
@@ -1963,9 +1963,9 @@ void R_Shadow_LoadWorldLights(void)
                Con_Printf("No map loaded.\n");
                return;
        }
-       COM_StripExtension(cl.worldmodel->name, name);
+       FS_StripExtension(cl.worldmodel->name, name);
        strcat(name, ".rtlights");
-       lightsstring = COM_LoadFile(name, false);
+       lightsstring = FS_LoadFile(name, false);
        if (lightsstring)
        {
                s = lightsstring;
@@ -2020,7 +2020,7 @@ void R_Shadow_SaveWorldLights(void)
                Con_Printf("No map loaded.\n");
                return;
        }
-       COM_StripExtension(cl.worldmodel->name, name);
+       FS_StripExtension(cl.worldmodel->name, name);
        strcat(name, ".rtlights");
        bufchars = bufmaxchars = 0;
        buf = NULL;
@@ -2046,7 +2046,7 @@ void R_Shadow_SaveWorldLights(void)
                }
        }
        if (bufchars)
-               COM_WriteFile(name, buf, bufchars);
+               FS_WriteFile(name, buf, bufchars);
        if (buf)
                Mem_Free(buf);
 }
@@ -2061,9 +2061,9 @@ void R_Shadow_LoadLightsFile(void)
                Con_Printf("No map loaded.\n");
                return;
        }
-       COM_StripExtension(cl.worldmodel->name, name);
+       FS_StripExtension(cl.worldmodel->name, name);
        strcat(name, ".lights");
-       lightsstring = COM_LoadFile(name, false);
+       lightsstring = FS_LoadFile(name, false);
        if (lightsstring)
        {
                s = lightsstring;
index c8c0bdaa25a810d170b13a13f5fb8f7479618a35..47398c6e0bde95f92279ed238d5c60dd82543410 100644 (file)
--- a/snd_mem.c
+++ b/snd_mem.c
@@ -228,7 +228,7 @@ sfxcache_t *S_LoadSound (sfx_t *s, int complain)
        strcpy(namebuffer, "sound/");
        strcat(namebuffer, s->name);
 
-       data = COM_LoadFile(namebuffer, false);
+       data = FS_LoadFile(namebuffer, false);
 
        if (!data)
        {
@@ -237,7 +237,7 @@ sfxcache_t *S_LoadSound (sfx_t *s, int complain)
                return NULL;
        }
 
-       info = GetWavinfo (s->name, data, com_filesize);
+       info = GetWavinfo (s->name, data, fs_filesize);
        // LordHavoc: stereo sounds are now allowed (intended for music)
        if (info.channels < 1 || info.channels > 2)
        {
index a006f68f7fac6ed1dceeb284b8eeb9b3402321eb..790642cc8f418206b9d12cac3068fb514ee2b023 100644 (file)
--- a/snd_mix.c
+++ b/snd_mix.c
@@ -41,7 +41,7 @@ void S_CaptureAVISound(portable_samplepair_t *buf, int length)
                if (cl_avidemo_soundfile == NULL)
                {
                        sprintf (filename, "%s/dpavi.wav", com_gamedir);
-                       cl_avidemo_soundfile = fopen(filename, "wb");
+                       cl_avidemo_soundfile = FS_Open (filename, "wb", false);
                        memset(out, 0, 44);
                        fwrite(out, 1, 44, cl_avidemo_soundfile);
                        // header will be filled out when file is closed
index 502a630e90290c9fc15fb9cd3674832e9cb7bd71..5941b55e7ac76c83412ed492bda0b2d2e647bde3 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -1868,7 +1868,7 @@ void SV_SpawnServer (const char *server)
        // load replacement entity file if found
        entities = NULL;
        if (sv_entpatch.integer)
-               entities = COM_LoadFile(va("maps/%s.ent", sv.name), true);
+               entities = FS_LoadFile(va("maps/%s.ent", sv.name), true);
        if (entities)
        {
                Con_Printf("Loaded maps/%s.ent\n", sv.name);
index 135a6d50abfb370bf1e7bd6ad3f8792d285b4546..06ef02ead23551ec2911446549cb3ca1189c06b2 100644 (file)
--- a/sv_user.c
+++ b/sv_user.c
@@ -580,23 +580,23 @@ nextmsg:
                        case clc_stringcmd:
                                s = MSG_ReadString ();
                                ret = 0;
-                               if (Q_strncasecmp(s, "status", 6) == 0
-                                || Q_strncasecmp(s, "name", 4) == 0
-                                || Q_strncasecmp(s, "say", 3) == 0
-                                || Q_strncasecmp(s, "say_team", 8) == 0
-                                || Q_strncasecmp(s, "tell", 4) == 0
-                                || Q_strncasecmp(s, "color", 5) == 0
-                                || Q_strncasecmp(s, "kill", 4) == 0
-                                || Q_strncasecmp(s, "pause", 5) == 0
-                                || Q_strncasecmp(s, "spawn", 5) == 0
-                                || Q_strncasecmp(s, "begin", 5) == 0
-                                || Q_strncasecmp(s, "prespawn", 8) == 0
-                                || Q_strncasecmp(s, "kick", 4) == 0
-                                || Q_strncasecmp(s, "ping", 4) == 0
-                                || Q_strncasecmp(s, "ban", 3) == 0
-                                || Q_strncasecmp(s, "pmodel", 6) == 0
-                                || (gamemode == GAME_NEHAHRA && (Q_strncasecmp(s, "max", 3) == 0 || Q_strncasecmp(s, "monster", 7) == 0 || Q_strncasecmp(s, "scrag", 5) == 0 || Q_strncasecmp(s, "gimme", 5) == 0 || Q_strncasecmp(s, "wraith", 6) == 0))
-                                || (gamemode != GAME_NEHAHRA && (Q_strncasecmp(s, "god", 3) == 0 || Q_strncasecmp(s, "notarget", 8) == 0 || Q_strncasecmp(s, "fly", 3) == 0 || Q_strncasecmp(s, "give", 4) == 0 || Q_strncasecmp(s, "noclip", 6) == 0)))
+                               if (strncasecmp(s, "status", 6) == 0
+                                || strncasecmp(s, "name", 4) == 0
+                                || strncasecmp(s, "say", 3) == 0
+                                || strncasecmp(s, "say_team", 8) == 0
+                                || strncasecmp(s, "tell", 4) == 0
+                                || strncasecmp(s, "color", 5) == 0
+                                || strncasecmp(s, "kill", 4) == 0
+                                || strncasecmp(s, "pause", 5) == 0
+                                || strncasecmp(s, "spawn", 5) == 0
+                                || strncasecmp(s, "begin", 5) == 0
+                                || strncasecmp(s, "prespawn", 8) == 0
+                                || strncasecmp(s, "kick", 4) == 0
+                                || strncasecmp(s, "ping", 4) == 0
+                                || strncasecmp(s, "ban", 3) == 0
+                                || strncasecmp(s, "pmodel", 6) == 0
+                                || (gamemode == GAME_NEHAHRA && (strncasecmp(s, "max", 3) == 0 || strncasecmp(s, "monster", 7) == 0 || strncasecmp(s, "scrag", 5) == 0 || strncasecmp(s, "gimme", 5) == 0 || strncasecmp(s, "wraith", 6) == 0))
+                                || (gamemode != GAME_NEHAHRA && (strncasecmp(s, "god", 3) == 0 || strncasecmp(s, "notarget", 8) == 0 || strncasecmp(s, "fly", 3) == 0 || strncasecmp(s, "give", 4) == 0 || strncasecmp(s, "noclip", 6) == 0)))
                                {
                                        ret = 1;
                                        Cmd_ExecuteString (s, src_client);
diff --git a/sys.h b/sys.h
index cc0ced45acaa268ac3da034c04b537a68d06620a..91eeb2c03fb6c830ebe27e750cb2a850a3a872e5 100644 (file)
--- a/sys.h
+++ b/sys.h
@@ -49,23 +49,6 @@ void Sys_UnloadLibrary (dllhandle_t handle);
 void* Sys_GetProcAddress (dllhandle_t handle, const char* name);
 
 
-//
-// file IO
-//
-
-// returns the file size
-// return -1 if file is not present
-// the file should be in BINARY mode for stupid OSs that care
-int Sys_FileOpenRead (const char *path, int *hndl);
-
-int Sys_FileOpenWrite (const char *path);
-void Sys_FileClose (int handle);
-void Sys_FileSeek (int handle, int position);
-int Sys_FileRead (int handle, void *dest, int count);
-int Sys_FileWrite (int handle, void *data, int count);
-int    Sys_FileTime (const char *path);
-void Sys_mkdir (const char *path);
-
 //
 // system IO
 //
index 76c32fa751b5b7fdf5071e26b5f7ab085f8e144d..f6f6804f6a158f624902f6ab34fdcf9bd13f4a98 100644 (file)
@@ -1,14 +1,10 @@
 
 #include "quakedef.h"
 #include <time.h>
-#ifdef WIN32
-#include <direct.h>
-#else
-#include <sys/stat.h>
+#ifndef WIN32
 #include <unistd.h>
 #include <fcntl.h>
 #endif
-#include <errno.h>
 
 extern cvar_t  timestamps;
 extern cvar_t  timeformat;
@@ -73,11 +69,7 @@ void Sys_Printf (const char *fmt, ...)
 #endif
 
        va_start (argptr, fmt);
-#ifdef HAVE_VSNPRINTF
        vsnprintf (start, sizeof(start), fmt, argptr);
-#else
-       vsprintf (start, fmt, argptr);
-#endif
        va_end (argptr);
 
        if (sys_nostdout)
@@ -106,149 +98,26 @@ void Sys_Printf (const char *fmt, ...)
 #endif
 }
 
-// LordHavoc: 256 pak files (was 10)
-#define MAX_HANDLES 256
-QFile *sys_handles[MAX_HANDLES];
-
-int findhandle (void)
-{
-       int i;
-
-       for (i = 1;i < MAX_HANDLES;i++)
-               if (!sys_handles[i])
-                       return i;
-       Sys_Error ("out of handles");
-       return -1;
-}
-
-/*
-================
-Sys_FileLength
-================
-*/
-int Sys_FileLength (QFile *f)
-{
-       int pos, end;
-
-       pos = Qtell (f);
-       Qseek (f, 0, SEEK_END);
-       end = Qtell (f);
-       Qseek (f, pos, SEEK_SET);
-
-       return end;
-}
-
-int Sys_FileOpenRead (const char *path, int *handle)
-{
-       QFile *f;
-       int i, retval;
-
-       i = findhandle ();
-
-       f = Qopen(path, "rbz");
-
-       if (!f)
-       {
-               *handle = -1;
-               retval = -1;
-       }
-       else
-       {
-               sys_handles[i] = f;
-               *handle = i;
-               retval = Sys_FileLength(f);
-       }
-
-       return retval;
-}
-
-int Sys_FileOpenWrite (const char *path)
-{
-       QFile   *f;
-       int             i;
-
-       i = findhandle ();
-
-       f = Qopen(path, "wb");
-       if (!f)
-       {
-               Con_Printf("Sys_FileOpenWrite: Error opening %s: %s", path, strerror(errno));
-               return 0;
-       }
-       sys_handles[i] = f;
-
-       return i;
-}
-
-void Sys_FileClose (int handle)
-{
-       Qclose (sys_handles[handle]);
-       sys_handles[handle] = NULL;
-}
-
-void Sys_FileSeek (int handle, int position)
-{
-       Qseek (sys_handles[handle], position, SEEK_SET);
-}
-
-int Sys_FileRead (int handle, void *dest, int count)
-{
-       return Qread (sys_handles[handle], dest, count);
-}
-
-int Sys_FileWrite (int handle, void *data, int count)
-{
-       return Qwrite (sys_handles[handle], data, count);
-}
-
-int Sys_FileTime (const char *path)
-{
-#if WIN32
-       QFile *f;
-
-       f = Qopen(path, "rb");
-       if (f)
-       {
-               Qclose(f);
-               return 1;
-       }
-
-       return -1;
-#else
-       struct stat buf;
-
-       if (stat (path,&buf) == -1)
-               return -1;
-
-       return buf.st_mtime;
-#endif
-}
-
-void Sys_mkdir (const char *path)
-{
-#if WIN32
-       _mkdir (path);
-#else
-       mkdir (path, 0777);
-#endif
-}
 
 char engineversion[128];
 
 void Sys_Shared_EarlyInit(void)
 {
+       const char* os;
+
        Memory_Init ();
 
        COM_InitArgv();
        COM_InitGameType();
 
 #if defined(__linux__)
-       sprintf (engineversion, "%s Linux %s", gamename, buildstring);
+       os = "Linux";
 #elif defined(WIN32)
-       sprintf (engineversion, "%s Windows %s", gamename, buildstring);
+       os = "Windows";
 #else
-       sprintf (engineversion, "%s Unknown %s", gamename, buildstring);
+       os = "Unknown";
 #endif
+       snprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
 
        if (COM_CheckParm("-nostdout"))
                sys_nostdout = 1;
diff --git a/wad.c b/wad.c
index 755ae5e6662319245c3c805fb9f33007eecbcabe..e5b53c353b39341b0e725f37316d016754b62052 100644 (file)
--- a/wad.c
+++ b/wad.c
@@ -74,16 +74,16 @@ void W_LoadWadFile (char *filename)
        int                             infotableofs;
        void                    *temp;
 
-       temp = COM_LoadFile (filename, false);
+       temp = FS_LoadFile (filename, false);
        if (!temp)
                Sys_Error ("W_LoadWadFile: couldn't load %s", filename);
 
        if (wad_mempool)
                Mem_FreePool(&wad_mempool);
        wad_mempool = Mem_AllocPool(filename);
-       wad_base = Mem_Alloc(wad_mempool, loadsize);
+       wad_base = Mem_Alloc(wad_mempool, fs_filesize);
 
-       memcpy(wad_base, temp, loadsize);
+       memcpy(wad_base, temp, fs_filesize);
        Mem_Free(temp);
 
        header = (wadinfo_t *)wad_base;
@@ -139,7 +139,7 @@ void SwapPic (qpic_t *pic)
 typedef struct
 {
        char name[16];
-       QFile *file;
+       qfile_t *file;
        int position;
        int size;
 } texwadlump_t;
@@ -157,10 +157,10 @@ void W_LoadTextureWadFile (char *filename, int complain)
        wadinfo_t               header;
        int                             i, j;
        int                             infotableofs;
-       QFile                   *file;
+       qfile_t                 *file;
        int                             numlumps;
 
-       COM_FOpenFile (filename, &file, false, false);
+       file = FS_Open (filename, "rb", false);
        if (!file)
        {
                if (complain)
@@ -168,7 +168,7 @@ void W_LoadTextureWadFile (char *filename, int complain)
                return;
        }
 
-       if (Qread(file, &header, sizeof(wadinfo_t)) != sizeof(wadinfo_t))
+       if (FS_Read(file, &header, sizeof(wadinfo_t)) != sizeof(wadinfo_t))
        {Con_Printf ("W_LoadTextureWadFile: unable to read wad header");return;}
 
        if(memcmp(header.identification, "WAD3", 4))
@@ -178,12 +178,12 @@ void W_LoadTextureWadFile (char *filename, int complain)
        if (numlumps < 1 || numlumps > TEXWAD_MAXIMAGES)
        {Con_Printf ("W_LoadTextureWadFile: invalid number of lumps (%i)\n", numlumps);return;}
        infotableofs = LittleLong(header.infotableofs);
-       if (Qseek(file, infotableofs, SEEK_SET))
+       if (FS_Seek (file, infotableofs, SEEK_SET))
        {Con_Printf ("W_LoadTextureWadFile: unable to seek to lump table");return;}
        if (!(lumps = Mem_Alloc(tempmempool, sizeof(lumpinfo_t)*numlumps)))
        {Con_Printf ("W_LoadTextureWadFile: unable to allocate temporary memory for lump table");return;}
 
-       if (Qread(file, lumps, sizeof(lumpinfo_t) * numlumps) != (int)sizeof(lumpinfo_t) * numlumps)
+       if (FS_Read(file, lumps, sizeof(lumpinfo_t) * numlumps) != (int)sizeof(lumpinfo_t) * numlumps)
        {Con_Printf ("W_LoadTextureWadFile: unable to read lump table");return;}
 
        for (i=0, lump_p = lumps ; i<numlumps ; i++,lump_p++)
@@ -246,7 +246,7 @@ qbyte *W_GetTexture(char *name)
 {
        char texname[17];
        int i, j;
-       QFile *file;
+       qfile_t *file;
        miptex_t *tex;
        qbyte *data;
 
@@ -259,13 +259,13 @@ qbyte *W_GetTexture(char *name)
                        if (!strcmp(texname, texwadlump[i].name)) // found it
                        {
                                file = texwadlump[i].file;
-                               if (Qseek(file, texwadlump[i].position, SEEK_SET))
+                               if (FS_Seek(file, texwadlump[i].position, SEEK_SET))
                                {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
 
                                tex = Mem_Alloc(tempmempool, texwadlump[i].size);
                                if (!tex)
                                        return NULL;
-                               if (Qread(file, tex, texwadlump[i].size) < texwadlump[i].size)
+                               if (FS_Read(file, tex, texwadlump[i].size) < texwadlump[i].size)
                                {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
 
                                tex->width = LittleLong(tex->width);
index 67a4575cf71f593da824319ac9dd16a8035df723..37db56f29b31e2820f651cf4662c15fd5322f724 100644 (file)
@@ -1,4 +1,5 @@
 
+#include "quakedef.h"
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
@@ -9,10 +10,10 @@ wavefile_t *waveopen(char *filename, char **errorstring)
        int validfmt, position, length, l;
        char *error;
        wavefile_t *w;
-       FILE *file;
+       qfile_t *file;
        unsigned char buffer[1024];
        error = NULL;
-       file = fopen(filename, "rb");
+       file = FS_Open (filename, "rb", true);
        if (file)
        {
                w = malloc(sizeof(*w));
@@ -20,7 +21,7 @@ wavefile_t *waveopen(char *filename, char **errorstring)
                if (w)
                {
                        w->file = file;
-                       if (fread(buffer, 12, 1, w->file))
+                       if (FS_Read (w->file, buffer, 12))
                        {
                                if (!memcmp(buffer, "RIFF", 4))
                                {
@@ -29,12 +30,12 @@ wavefile_t *waveopen(char *filename, char **errorstring)
                                                validfmt = 0;
                                                for(;;)
                                                {
-                                                       if (!fread(buffer, 8, 1, w->file))
+                                                       if (!FS_Read(w->file, buffer, 8))
                                                        {
                                                                //error = "error reading chunk\n");
                                                                break;
                                                        }
-                                                       position = ftell(w->file);
+                                                       position = FS_Tell(w->file);
                                                        length = buffer[4] | (buffer[5] << 8) | (buffer[6] << 16) | (buffer[7] << 24);
                                                        if (!memcmp(buffer, "fmt ", 4))
                                                        {
@@ -42,7 +43,7 @@ wavefile_t *waveopen(char *filename, char **errorstring)
                                                                l = length;
                                                                if (l > 16)
                                                                        l = 16;
-                                                               if (!fread(buffer, l, 1, w->file))
+                                                               if (!FS_Read(w->file, buffer, l))
                                                                {
                                                                        error = "error reading \"fmt \" chunk\n";
                                                                        break;
@@ -83,7 +84,7 @@ wavefile_t *waveopen(char *filename, char **errorstring)
                                                        }
                                                        // other chunks that might be of interest:
                                                        // "cue " (for looping)
-                                                       if (fseek(w->file, position + length, SEEK_SET))
+                                                       if (FS_Seek(w->file, position + length, SEEK_SET))
                                                        {
                                                                error = "error seeking to next chunk\n";
                                                                break;
@@ -95,7 +96,7 @@ wavefile_t *waveopen(char *filename, char **errorstring)
                                                        w->info_bytespersample = w->info_channels * w->info_bytesperchannel;
                                                        w->length = w->datalength / w->info_bytespersample;
                                                        w->position = 0;
-                                                       fseek(w->file, w->dataposition, SEEK_SET);
+                                                       FS_Seek(w->file, w->dataposition, SEEK_SET);
                                                        return w;
                                                }
                                        }
@@ -111,7 +112,7 @@ wavefile_t *waveopen(char *filename, char **errorstring)
                }
                else
                        error = "unable to allocate memory\n";
-               fclose(file);
+               FS_Close(file);
        }
        else
                error = "unable to open file\n";
@@ -124,7 +125,7 @@ void waveclose(wavefile_t *f)
 {
        if (f)
        {
-               fclose(f->file);
+               FS_Close(f->file);
                free(f);
        }
 }
@@ -145,7 +146,7 @@ unsigned int waveread16stereo(wavefile_t *w, short *soundbuffer, unsigned int sa
                w->bufferlength = length + 100;
                w->buffer = malloc(w->bufferlength * w->info_bytespersample);
        }
-       length = fread(w->buffer, w->info_bytespersample, length, w->file);
+       length = FS_Read(w->file, w->buffer, w->info_bytespersample * length);
        w->position += length;
        if (length > 0)
        {
@@ -188,7 +189,7 @@ unsigned int waveseek(wavefile_t *w, unsigned int samples)
        else
        {
                w->position = samples;
-               fseek(w->file, w->dataposition + w->position * w->info_bytespersample, SEEK_SET);
+               FS_Seek(w->file, w->dataposition + w->position * w->info_bytespersample, SEEK_SET);
                return 0;
        }
 }
index de8b33aa9548efd4a49673a3e4971b10cf3c6979..f0037ca6a2629fb4f26d180204d6a0379deaafe1 100644 (file)
@@ -2,10 +2,12 @@
 #ifndef WAVEFILE_H
 #define WAVEFILE_H
 
+#include "quakedef.h"
+
 typedef struct wavefile_s
 {
        // file this is reading from
-       FILE *file;
+       qfile_t *file;
 
        // these settings are read directly from the wave format
        // 1 is uncompressed PCM