gzip support from quakeforge (QFile and friends). also includes a couple of
authortaniwha <taniwha@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 30 May 2001 02:36:15 +0000 (02:36 +0000)
committertaniwha <taniwha@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 30 May 2001 02:36:15 +0000 (02:36 +0000)
compile fixes

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@210 d7cf8633-e32d-0410-b094-e92efae38249

25 files changed:
cl_demo.c
client.h
common.c
common.h
cvar.c
cvar.h
host.c
host_cmd.c
image.c
keys.c
keys.h
makefile
menu.c
menu.h
model_brush.h
pr_edict.c
progs.h
quakeio.c
quakeio.h
r_part.c
snd_alsa_0_5.c
snd_oss.c
sys_linux.c
sys_win.c
wad.c

index 56b6dd7..34c875e 100644 (file)
--- a/cl_demo.c
+++ b/cl_demo.c
@@ -47,7 +47,7 @@ void CL_StopPlayback (void)
        if (!cls.demoplayback)
                return;
 
-       fclose (cls.demofile);
+       Qclose (cls.demofile);
        cls.demoplayback = false;
        cls.demofile = NULL;
        cls.state = ca_disconnected;
@@ -73,14 +73,14 @@ void CL_WriteDemoMessage (void)
                return;
 
        len = LittleLong (net_message.cursize);
-       fwrite (&len, 4, 1, cls.demofile);
+       Qwrite (cls.demofile, &len, 4);
        for (i=0 ; i<3 ; i++)
        {
                f = LittleFloat (cl.viewangles[i]);
-               fwrite (&f, 4, 1, cls.demofile);
+               Qwrite (cls.demofile, &f, 4);
        }
-       fwrite (net_message.data, net_message.cursize, 1, cls.demofile);
-       fflush (cls.demofile);
+       Qwrite (cls.demofile, net_message.data, net_message.cursize);
+       Qflush (cls.demofile);
 }
 
 /*
@@ -120,19 +120,19 @@ int CL_GetMessage (void)
                }
                
        // get the next message
-               fread (&net_message.cursize, 4, 1, cls.demofile);
+               Qread (cls.demofile, &net_message.cursize, 4);
                VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
                for (i=0 ; i<3 ; i++)
                {
-                       r = fread (&f, 4, 1, cls.demofile);
+                       r = Qread (cls.demofile, &f, 4);
                        cl.mviewangles[0][i] = LittleFloat (f);
                }
                
                net_message.cursize = LittleLong (net_message.cursize);
                if (net_message.cursize > MAX_MSGLEN)
                        Host_Error ("Demo message > MAX_MSGLEN");
-               r = fread (net_message.data, net_message.cursize, 1, cls.demofile);
-               if (r != 1)
+               r = Qread (cls.demofile, net_message.data, net_message.cursize);
+               if (r != net_message.cursize)
                {
                        CL_StopPlayback ();
                        return 0;
@@ -186,7 +186,7 @@ void CL_Stop_f (void)
        CL_WriteDemoMessage ();
 
 // finish up
-       fclose (cls.demofile);
+       Qclose (cls.demofile);
        cls.demofile = NULL;
        cls.demorecording = false;
        Con_Printf ("Completed demo\n");
@@ -250,7 +250,7 @@ void CL_Record_f (void)
        COM_DefaultExtension (name, ".dem");
 
        Con_Printf ("recording to %s.\n", name);
-       cls.demofile = fopen (name, "wb");
+       cls.demofile = Qopen (name, "wb");
        if (!cls.demofile)
        {
                Con_Printf ("ERROR: couldn't open.\n");
@@ -258,7 +258,7 @@ void CL_Record_f (void)
        }
 
        cls.forcetrack = track;
-       fprintf (cls.demofile, "%i\n", cls.forcetrack);
+       Qprintf (cls.demofile, "%i\n", cls.forcetrack);
        
        cls.demorecording = true;
 }
@@ -300,7 +300,7 @@ void CL_PlayDemo_f (void)
        COM_DefaultExtension (name, ".dem");
 
        Con_Printf ("Playing demo from %s.\n", name);
-       COM_FOpenFile (name, &cls.demofile, false);
+       COM_FOpenFile (name, &cls.demofile, false, true);
        if (!cls.demofile)
        {
                Con_Printf ("ERROR: couldn't open.\n");
@@ -312,7 +312,7 @@ void CL_PlayDemo_f (void)
        cls.state = ca_connected;
        cls.forcetrack = 0;
 
-       while ((c = getc(cls.demofile)) != '\n')
+       while ((c = Qgetc(cls.demofile)) != '\n')
                if (c == '-')
                        neg = true;
                else
index 0ff6de0..a690fdc 100644 (file)
--- a/client.h
+++ b/client.h
@@ -110,7 +110,7 @@ typedef struct
        qboolean        demoplayback;
        qboolean        timedemo;
        int                     forcetrack;                     // -1 = use normal cd track
-       FILE            *demofile;
+       QFile           *demofile;
        int                     td_lastframe;           // to meter out one message a frame
        int                     td_startframe;          // host_framecount at start
        double          td_starttime;           // realtime at second frame of timedemo (LordHavoc: changed to double)
index d5eed88..43f5c6a 100644 (file)
--- a/common.c
+++ b/common.c
@@ -19,6 +19,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
 // common.c -- misc functions used in client and server
 
+#include <fcntl.h>
+#ifndef WIN32
+#include <unistd.h>
+#endif
+#include <stdlib.h>
+
 #include "quakedef.h"
 
 #define NUM_SAFE_ARGVS  7
@@ -1071,16 +1077,16 @@ being registered.
 */
 void COM_CheckRegistered (void)
 {
-       int             h;
+       QFile           *h;
        unsigned short  check[128];
        int                     i;
 
        Cvar_Set ("cmdline", com_cmdline);
 
-       COM_OpenFile("gfx/pop.lmp", &h, false);
+       COM_FOpenFile("gfx/pop.lmp", &h, false, true);
        static_registered = 0;
 
-       if (h == -1)
+       if (!h)
        {
                if (com_modified)
                        Con_Printf ("Playing shareware version, with modification.\nwarning: most mods require full quake data.\n");
@@ -1095,8 +1101,8 @@ void COM_CheckRegistered (void)
                return;
        }
 
-       Sys_FileRead (h, check, sizeof(check));
-       COM_CloseFile (h);
+       Qread (h, check, sizeof(check));
+       Qclose (h);
        
        for (i=0 ; i<128 ; i++)
                if (pop[i] != (unsigned short)BigShort (check[i]))
@@ -1472,6 +1478,55 @@ void COM_CopyFile (char *netpath, char *cachepath)
        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];
+       unsigned char   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
@@ -1480,7 +1535,7 @@ Finds the file in the search path.
 Sets com_filesize and one of handle or file
 ===========
 */
-int COM_FindFile (char *filename, int *handle, FILE **file, qboolean quiet)
+int COM_FindFile (char *filename, QFile **file, qboolean quiet, qboolean zip)
 {
        searchpath_t    *search;
        char                    netpath[MAX_OSPATH];
@@ -1491,11 +1546,14 @@ int COM_FindFile (char *filename, int *handle, FILE **file, qboolean quiet)
        pack_t                  *pak;
        int                             i;
        int                             findtime;
+       char                    gzfilename[MAX_OSPATH];
+       int                             filenamelen;
+
+       filenamelen = strlen (filename);
+       snprintf (gzfilename, sizeof (gzfilename), "%s.gz", filename);
 
-       if (file && handle)
-               Sys_Error ("COM_FindFile: both handle and file set");
-       if (!file && !handle)
-               Sys_Error ("COM_FindFile: neither handle or file set");
+       if (!file)
+               Sys_Error ("COM_FindFile: file not set");
                
 //
 // search through the path, one element at a time
@@ -1515,22 +1573,13 @@ int COM_FindFile (char *filename, int *handle, FILE **file, qboolean quiet)
                // look through all the pak file elements
                        pak = search->pack;
                        for (i=0 ; i<pak->numfiles ; i++)
-                               if (!strcmp (pak->files[i].name, filename))
+                               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, filename);
-                                       if (handle)
-                                       {
-                                               *handle = pak->handle;
-                                               Sys_FileSeek (pak->handle, pak->files[i].filepos);
-                                       }
-                                       else
-                                       {       // open a new file on the pakfile
-                                               *file = fopen (pak->filename, "rb");
-                                               if (*file)
-                                                       fseek (*file, pak->files[i].filepos, SEEK_SET);
-                                       }
-                                       com_filesize = pak->files[i].filelen;
+                                               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;
                                }
                }
@@ -1572,14 +1621,7 @@ int COM_FindFile (char *filename, int *handle, FILE **file, qboolean quiet)
 
                        if (!quiet)
                                Sys_Printf ("FindFile: %s\n",netpath);
-                       com_filesize = Sys_FileOpenRead (netpath, &i);
-                       if (handle)
-                               *handle = i;
-                       else
-                       {
-                               Sys_FileClose (i);
-                               *file = fopen (netpath, "rb");
-                       }
+                       *file = COM_OpenRead (netpath, -1, -1, zip);
                        return com_filesize;
                }
                
@@ -1588,58 +1630,23 @@ int COM_FindFile (char *filename, int *handle, FILE **file, qboolean quiet)
        if (!quiet)
                Sys_Printf ("FindFile: can't find %s\n", filename);
        
-       if (handle)
-               *handle = -1;
-       else
-               *file = NULL;
+       *file = NULL;
        com_filesize = -1;
        return -1;
 }
 
 
-/*
-===========
-COM_OpenFile
-
-filename never has a leading slash, but may contain directory walks
-returns a handle and a length
-it may actually be inside a pak file
-===========
-*/
-int COM_OpenFile (char *filename, int *handle, qboolean quiet)
-{
-       return COM_FindFile (filename, handle, NULL, quiet);
-}
-
 /*
 ===========
 COM_FOpenFile
 
-If the requested file is inside a packfile, a new FILE * will be opened
+If the requested file is inside a packfile, a new QFile * will be opened
 into the file.
 ===========
 */
-int COM_FOpenFile (char *filename, FILE **file, qboolean quiet)
+int COM_FOpenFile (char *filename, QFile **file, qboolean quiet, qboolean zip)
 {
-       return COM_FindFile (filename, NULL, file, quiet);
-}
-
-/*
-============
-COM_CloseFile
-
-If it is a pak file handle, don't really close it
-============
-*/
-void COM_CloseFile (int h)
-{
-       searchpath_t    *s;
-       
-       for (s = com_searchpaths ; s ; s=s->next)
-               if (s->pack && s->pack->handle == h)
-                       return;
-                       
-       Sys_FileClose (h);
+       return COM_FindFile (filename, file, quiet, zip);
 }
 
 
@@ -1656,7 +1663,7 @@ byte    *loadbuf;
 int             loadsize;
 byte *COM_LoadFile (char *path, int usehunk, qboolean quiet)
 {
-       int             h;
+       QFile             *h;
        byte    *buf;
        char    base[1024];
        int             len;
@@ -1664,8 +1671,8 @@ byte *COM_LoadFile (char *path, int usehunk, qboolean quiet)
        buf = NULL;     // quiet compiler warning
 
 // look for it in the filesystem or pack files
-       len = COM_OpenFile (path, &h, quiet);
-       if (h == -1)
+       len = COM_FOpenFile (path, &h, quiet, true);
+       if (!h)
                return NULL;
        
 // extract the filename base name for hunk tag
@@ -1700,8 +1707,8 @@ byte *COM_LoadFile (char *path, int usehunk, qboolean quiet)
 
        ((byte *)buf)[len] = 0;
 
-       Sys_FileRead (h, buf, len);                     
-       COM_CloseFile (h);
+       Qread (h, buf, len);                     
+       Qclose (h);
 
        return buf;
 }
index 502f4cd..17c2790 100644 (file)
--- a/common.h
+++ b/common.h
@@ -29,6 +29,8 @@ typedef unsigned char                 byte;
 
 typedef enum {false, true}     qboolean;
 
+#include "quakeio.h"
+
 //============================================================================
 
 extern void *qmalloc(unsigned int size);
@@ -203,9 +205,7 @@ struct cache_user_s;
 extern char    com_gamedir[MAX_OSPATH];
 
 void COM_WriteFile (char *filename, void *data, int len);
-int COM_OpenFile (char *filename, int *hndl, qboolean quiet);
-int COM_FOpenFile (char *filename, FILE **file, qboolean quiet);
-void COM_CloseFile (int h);
+int COM_FOpenFile (char *filename, QFile **file, qboolean quiet, qboolean zip);
 
 byte *COM_LoadHunkFile (char *path, qboolean quiet);
 byte *COM_LoadMallocFile (char *path, qboolean quiet);
diff --git a/cvar.c b/cvar.c
index bb68015..0f8ccd4 100644 (file)
--- a/cvar.c
+++ b/cvar.c
@@ -214,12 +214,12 @@ Writes lines containing "set variable value" for all variables
 with the archive flag set to true.
 ============
 */
-void Cvar_WriteVariables (FILE *f)
+void Cvar_WriteVariables (QFile *f)
 {
        cvar_t  *var;
        
        for (var = cvar_vars ; var ; var = var->next)
                if (var->archive)
-                       fprintf (f, "%s \"%s\"\n", var->name, var->string);
+                       Qprintf (f, "%s \"%s\"\n", var->name, var->string);
 }
 
diff --git a/cvar.h b/cvar.h
index 4a961b2..6aa1ad1 100644 (file)
--- a/cvar.h
+++ b/cvar.h
@@ -88,7 +88,7 @@ qboolean Cvar_Command (void);
 // command.  Returns true if the command was a variable reference that
 // was handled. (print or change)
 
-void   Cvar_WriteVariables (FILE *f);
+void   Cvar_WriteVariables (QFile *f);
 // Writes lines containing "set variable value" for all variables
 // with the archive flag set to true.
 
diff --git a/host.c b/host.c
index 675e30e..b419f8a 100644 (file)
--- a/host.c
+++ b/host.c
@@ -265,13 +265,13 @@ Writes key bindings and archived cvars to config.cfg
 */
 void Host_WriteConfiguration (void)
 {
-       FILE    *f;
+       QFile   *f;
 
 // dedicated servers initialize the host but don't parse and set the
 // config.cfg cvars
        if (host_initialized & !isDedicated)
        {
-               f = fopen (va("%s/config.cfg",com_gamedir), "w");
+               f = Qopen (va("%s/config.cfg",com_gamedir), "w");
                if (!f)
                {
                        Con_Printf ("Couldn't write config.cfg.\n");
@@ -281,7 +281,7 @@ void Host_WriteConfiguration (void)
                Key_WriteBindings (f);
                Cvar_WriteVariables (f);
 
-               fclose (f);
+               Qclose (f);
        }
 }
 
index 5e0a66f..c949589 100644 (file)
@@ -428,7 +428,7 @@ Host_Savegame_f
 void Host_Savegame_f (void)
 {
        char    name[256];
-       FILE    *f;
+       QFile   *f;
        int             i;
        char    comment[SAVEGAME_COMMENT_LENGTH+1];
 
@@ -478,30 +478,30 @@ void Host_Savegame_f (void)
        COM_DefaultExtension (name, ".sav");
        
        Con_Printf ("Saving game to %s...\n", name);
-       f = fopen (name, "w");
+       f = Qopen (name, "w");
        if (!f)
        {
                Con_Printf ("ERROR: couldn't open.\n");
                return;
        }
        
-       fprintf (f, "%i\n", SAVEGAME_VERSION);
+       Qprintf (f, "%i\n", SAVEGAME_VERSION);
        Host_SavegameComment (comment);
-       fprintf (f, "%s\n", comment);
+       Qprintf (f, "%s\n", comment);
        for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
-               fprintf (f, "%f\n", svs.clients->spawn_parms[i]);
-       fprintf (f, "%d\n", current_skill);
-       fprintf (f, "%s\n", sv.name);
-       fprintf (f, "%f\n",sv.time);
+               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);
 
 // write the light styles
 
        for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
        {
                if (sv.lightstyles[i])
-                       fprintf (f, "%s\n", sv.lightstyles[i]);
+                       Qprintf (f, "%s\n", sv.lightstyles[i]);
                else
-                       fprintf (f,"m\n");
+                       Qprintf (f,"m\n");
        }
 
 
@@ -509,9 +509,9 @@ void Host_Savegame_f (void)
        for (i=0 ; i<sv.num_edicts ; i++)
        {
                ED_Write (f, EDICT_NUM(i));
-               fflush (f);
+               Qflush (f);
        }
-       fclose (f);
+       Qclose (f);
        Con_Printf ("done.\n");
 }
 
@@ -524,10 +524,11 @@ Host_Loadgame_f
 void Host_Loadgame_f (void)
 {
        char    name[MAX_OSPATH];
-       FILE    *f;
+       QFile   *f;
        char    mapname[MAX_QPATH];
        float   time, tfloat;
-       char    str[32768], *start;
+       char    buf[32768], *start;
+       char    *str;
        int             i, r;
        edict_t *ent;
        int             entnum;
@@ -554,30 +555,35 @@ void Host_Loadgame_f (void)
 //     SCR_BeginLoadingPlaque ();
 
        Con_Printf ("Loading game from %s...\n", name);
-       f = fopen (name, "r");
+       f = Qopen (name, "rz");
        if (!f)
        {
                Con_Printf ("ERROR: couldn't open.\n");
                return;
        }
 
-       fscanf (f, "%i\n", &version);
+       str = Qgetline (f);
+       sscanf (str, "%i\n", &version);
        if (version != SAVEGAME_VERSION)
        {
-               fclose (f);
+               Qclose (f);
                Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
                return;
        }
-       fscanf (f, "%s\n", str);
-       for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
-               fscanf (f, "%f\n", &spawn_parms[i]);
+       str = Qgetline (f);
+       for (i=0 ; i<NUM_SPAWN_PARMS ; i++) {
+               str = Qgetline (f);
+               sscanf (str, "%f\n", &spawn_parms[i]);
+       }
 // this silliness is so we can load 1.06 save files, which have float skill values
-       fscanf (f, "%f\n", &tfloat);
+       str = Qgetline (f);
+       sscanf (str, "%f\n", &tfloat);
        current_skill = (int)(tfloat + 0.1);
        Cvar_SetValue ("skill", (float)current_skill);
 
-       fscanf (f, "%s\n",mapname);
-       fscanf (f, "%f\n",&time);
+       strcpy (mapname, Qgetline (f));
+       str = Qgetline (f);
+       sscanf (str, "%f\n",&time);
 
        CL_Disconnect_f ();
        
@@ -594,32 +600,32 @@ void Host_Loadgame_f (void)
 
        for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
        {
-               fscanf (f, "%s\n", str);
+               str = Qgetline (f);
                sv.lightstyles[i] = Hunk_AllocName (strlen(str)+1, "lightstyles");
                strcpy (sv.lightstyles[i], str);
        }
 
 // load the edicts out of the savegame file
        entnum = -1;            // -1 is the globals
-       while (!feof(f))
+       while (!Qeof(f))
        {
-               for (i=0 ; i<sizeof(str)-1 ; i++)
+               for (i=0 ; i<sizeof(buf)-1 ; i++)
                {
-                       r = fgetc (f);
+                       r = Qgetc (f);
                        if (r == EOF || !r)
                                break;
-                       str[i] = r;
+                       buf[i] = r;
                        if (r == '}')
                        {
                                i++;
                                break;
                        }
                }
-               if (i == sizeof(str)-1)
+               if (i == sizeof(buf)-1)
                        Sys_Error ("Loadgame buffer overflow");
-               str[i] = 0;
-               start = str;
-               start = COM_Parse(str);
+               buf[i] = 0;
+               start = buf;
+               start = COM_Parse(buf);
                if (!com_token[0])
                        break;          // end of file
                if (strcmp(com_token,"{"))
@@ -648,7 +654,7 @@ void Host_Loadgame_f (void)
        sv.num_edicts = entnum;
        sv.time = time;
 
-       fclose (f);
+       Qclose (f);
 
        for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
                svs.clients->spawn_parms[i] = spawn_parms[i];
diff --git a/image.c b/image.c
index db7570f..23b69ba 100644 (file)
--- a/image.c
+++ b/image.c
@@ -86,7 +86,7 @@ typedef struct
 LoadPCX
 ============
 */
-byte* LoadPCX (FILE *f, int matchwidth, int matchheight)
+byte* LoadPCX (QFile *f, int matchwidth, int matchheight)
 {
        pcx_t   *pcx, pcxbuf;
        byte    palette[768];
@@ -98,7 +98,7 @@ byte* LoadPCX (FILE *f, int matchwidth, int matchheight)
 //
 // parse the PCX file
 //
-       fread (&pcxbuf, 1, sizeof(pcxbuf), f);
+       Qread (f, &pcxbuf, sizeof(pcxbuf));
 
        pcx = &pcxbuf;
 
@@ -124,10 +124,10 @@ byte* LoadPCX (FILE *f, int matchwidth, int matchheight)
                return NULL;
 
        // seek to palette
-       fseek (f, -768, SEEK_END);
-       fread (palette, 1, 768, f);
+       Qseek (f, -768, SEEK_END);
+       Qread (f, palette, 768);
 
-       fseek (f, sizeof(pcxbuf) - 4, SEEK_SET);
+       Qseek (f, sizeof(pcxbuf) - 4, SEEK_SET);
 
        count = (pcx->xmax+1) * (pcx->ymax+1);
        image_rgba = qmalloc( count * 4);
@@ -137,12 +137,12 @@ byte* LoadPCX (FILE *f, int matchwidth, int matchheight)
                pix = image_rgba + 4*y*(pcx->xmax+1);
                for (x=0 ; x<=pcx->xmax ; )
                {
-                       dataByte = fgetc(f);
+                       dataByte = Qgetc(f);
 
                        if((dataByte & 0xC0) == 0xC0)
                        {
                                runLength = dataByte & 0x3F;
-                               dataByte = fgetc(f);
+                               dataByte = Qgetc(f);
                                if (runLength)
                                {
                                        x += runLength;
@@ -168,7 +168,7 @@ byte* LoadPCX (FILE *f, int matchwidth, int matchheight)
 
                }
        }
-       fclose(f);
+       Qclose(f);
        image_width = pcx->xmax+1;
        image_height = pcx->ymax+1;
        return image_rgba;
@@ -193,24 +193,24 @@ typedef struct _TargaHeader {
 
 TargaHeader            targa_header;
 
-int fgetLittleShort (FILE *f)
+int fgetLittleShort (QFile *f)
 {
        byte    b1, b2;
 
-       b1 = fgetc(f);
-       b2 = fgetc(f);
+       b1 = Qgetc(f);
+       b2 = Qgetc(f);
 
        return (short)(b1 + b2*256);
 }
 
-int fgetLittleLong (FILE *f)
+int fgetLittleLong (QFile *f)
 {
        byte    b1, b2, b3, b4;
 
-       b1 = fgetc(f);
-       b2 = fgetc(f);
-       b3 = fgetc(f);
-       b4 = fgetc(f);
+       b1 = Qgetc(f);
+       b2 = Qgetc(f);
+       b3 = Qgetc(f);
+       b4 = Qgetc(f);
 
        return b1 + (b2<<8) + (b3<<16) + (b4<<24);
 }
@@ -221,20 +221,20 @@ int fgetLittleLong (FILE *f)
 LoadTGA
 =============
 */
-byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
+byte* LoadTGA (QFile *fin, int matchwidth, int matchheight)
 {
        int                             columns, rows, numPixels;
        byte                    *pixbuf;
        int                             row, column;
        byte                    *image_rgba;
 
-       targa_header.id_length = fgetc(fin);
-       targa_header.colormap_type = fgetc(fin);
-       targa_header.image_type = fgetc(fin);
+       targa_header.id_length = Qgetc(fin);
+       targa_header.colormap_type = Qgetc(fin);
+       targa_header.image_type = Qgetc(fin);
        
        targa_header.colormap_index = fgetLittleShort(fin);
        targa_header.colormap_length = fgetLittleShort(fin);
-       targa_header.colormap_size = fgetc(fin);
+       targa_header.colormap_size = Qgetc(fin);
        targa_header.x_origin = fgetLittleShort(fin);
        targa_header.y_origin = fgetLittleShort(fin);
        targa_header.width = fgetLittleShort(fin);
@@ -243,8 +243,8 @@ byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
                return NULL;
        if (matchheight && targa_header.height != matchheight)
                return NULL;
-       targa_header.pixel_size = fgetc(fin);
-       targa_header.attributes = fgetc(fin);
+       targa_header.pixel_size = Qgetc(fin);
+       targa_header.attributes = Qgetc(fin);
 
        if (targa_header.image_type!=2 
                && targa_header.image_type!=10) 
@@ -261,7 +261,7 @@ byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
        image_rgba = qmalloc(numPixels*4);
        
        if (targa_header.id_length != 0)
-               fseek(fin, targa_header.id_length, SEEK_CUR);  // skip TARGA image comment
+               Qseek(fin, targa_header.id_length, SEEK_CUR);  // skip TARGA image comment
        
        if (targa_header.image_type==2) {  // Uncompressed, RGB images
                for(row=rows-1; row>=0; row--) {
@@ -271,19 +271,19 @@ byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
                                switch (targa_header.pixel_size) {
                                        case 24:
                                                        
-                                                       blue = getc(fin);
-                                                       green = getc(fin);
-                                                       red = getc(fin);
+                                                       blue = Qgetc(fin);
+                                                       green = Qgetc(fin);
+                                                       red = Qgetc(fin);
                                                        *pixbuf++ = red;
                                                        *pixbuf++ = green;
                                                        *pixbuf++ = blue;
                                                        *pixbuf++ = 255;
                                                        break;
                                        case 32:
-                                                       blue = getc(fin);
-                                                       green = getc(fin);
-                                                       red = getc(fin);
-                                                       alphabyte = getc(fin);
+                                                       blue = Qgetc(fin);
+                                                       green = Qgetc(fin);
+                                                       red = Qgetc(fin);
+                                                       alphabyte = Qgetc(fin);
                                                        *pixbuf++ = red;
                                                        *pixbuf++ = green;
                                                        *pixbuf++ = blue;
@@ -298,21 +298,21 @@ byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
                for(row=rows-1; row>=0; row--) {
                        pixbuf = image_rgba + row*columns*4;
                        for(column=0; column<columns; ) {
-                               packetHeader=getc(fin);
+                               packetHeader=Qgetc(fin);
                                packetSize = 1 + (packetHeader & 0x7f);
                                if (packetHeader & 0x80) {        // run-length packet
                                        switch (targa_header.pixel_size) {
                                                case 24:
-                                                               blue = getc(fin);
-                                                               green = getc(fin);
-                                                               red = getc(fin);
+                                                               blue = Qgetc(fin);
+                                                               green = Qgetc(fin);
+                                                               red = Qgetc(fin);
                                                                alphabyte = 255;
                                                                break;
                                                case 32:
-                                                               blue = getc(fin);
-                                                               green = getc(fin);
-                                                               red = getc(fin);
-                                                               alphabyte = getc(fin);
+                                                               blue = Qgetc(fin);
+                                                               green = Qgetc(fin);
+                                                               red = Qgetc(fin);
+                                                               alphabyte = Qgetc(fin);
                                                                break;
                                        }
        
@@ -336,19 +336,19 @@ byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
                                        for(j=0;j<packetSize;j++) {
                                                switch (targa_header.pixel_size) {
                                                        case 24:
-                                                                       blue = getc(fin);
-                                                                       green = getc(fin);
-                                                                       red = getc(fin);
+                                                                       blue = Qgetc(fin);
+                                                                       green = Qgetc(fin);
+                                                                       red = Qgetc(fin);
                                                                        *pixbuf++ = red;
                                                                        *pixbuf++ = green;
                                                                        *pixbuf++ = blue;
                                                                        *pixbuf++ = 255;
                                                                        break;
                                                        case 32:
-                                                                       blue = getc(fin);
-                                                                       green = getc(fin);
-                                                                       red = getc(fin);
-                                                                       alphabyte = getc(fin);
+                                                                       blue = Qgetc(fin);
+                                                                       green = Qgetc(fin);
+                                                                       red = Qgetc(fin);
+                                                                       alphabyte = Qgetc(fin);
                                                                        *pixbuf++ = red;
                                                                        *pixbuf++ = green;
                                                                        *pixbuf++ = blue;
@@ -371,7 +371,7 @@ byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
                }
        }
        
-       fclose(fin);
+       Qclose(fin);
        image_width = columns;
        image_height = rows;
        return image_rgba;
@@ -382,7 +382,7 @@ byte* LoadTGA (FILE *fin, int matchwidth, int matchheight)
 LoadLMP
 ============
 */
-byte* LoadLMP (FILE *f, int matchwidth, int matchheight)
+byte* LoadLMP (QFile *f, int matchwidth, int matchheight)
 {
        byte    *image_rgba;
        int             width, height;
@@ -398,8 +398,8 @@ byte* LoadLMP (FILE *f, int matchwidth, int matchheight)
                return NULL;
 
        image_rgba = qmalloc(width*height*4);
-       fread(image_rgba + width*height*3, 1, width*height, f);
-       fclose(f);
+       Qread(f, image_rgba + width*height*3, width*height);
+       Qclose(f);
 
        Image_Copy8bitRGBA(image_rgba + width*height*3, image_rgba, width*height, d_8to24table);
        image_width = width;
@@ -426,7 +426,7 @@ void Image_StripImageExtension (char *in, char *out)
 
 byte* loadimagepixels (char* filename, qboolean complain, int matchwidth, int matchheight)
 {
-       FILE    *f;
+       QFile   *f;
        char    basename[256], name[256];
        byte    *c;
        Image_StripImageExtension(filename, basename); // strip .tga, .pcx and .lmp extensions to allow replacement by other types
@@ -435,23 +435,23 @@ byte* loadimagepixels (char* filename, qboolean complain, int matchwidth, int ma
                if (*c == '*')
                        *c = '#';
        sprintf (name, "textures/%s.tga", basename);
-       COM_FOpenFile (name, &f, true);
+       COM_FOpenFile (name, &f, true, true);
        if (f)
                return LoadTGA (f, matchwidth, matchheight);
        sprintf (name, "textures/%s.pcx", basename);
-       COM_FOpenFile (name, &f, true);
+       COM_FOpenFile (name, &f, true, true);
        if (f)
                return LoadPCX (f, matchwidth, matchheight);
        sprintf (name, "%s.tga", basename);
-       COM_FOpenFile (name, &f, true);
+       COM_FOpenFile (name, &f, true, true);
        if (f)
                return LoadTGA (f, matchwidth, matchheight);
        sprintf (name, "%s.pcx", basename);
-       COM_FOpenFile (name, &f, true);
+       COM_FOpenFile (name, &f, true, true);
        if (f)
                return LoadPCX (f, matchwidth, matchheight);
        sprintf (name, "%s.lmp", basename);
-       COM_FOpenFile (name, &f, true);
+       COM_FOpenFile (name, &f, true, true);
        if (f)
                return LoadLMP (f, matchwidth, matchheight);
        if (complain)
diff --git a/keys.c b/keys.c
index c3a8a75..1929b68 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -503,14 +503,14 @@ Key_WriteBindings
 Writes lines containing "bind key value"
 ============
 */
-void Key_WriteBindings (FILE *f)
+void Key_WriteBindings (QFile *f)
 {
        int             i;
 
        for (i=0 ; i<256 ; i++)
                if (keybindings[i])
                        if (*keybindings[i])
-                               fprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
+                               Qprintf (f, "bind \"%s\" \"%s\"\n", Key_KeynumToString(i), keybindings[i]);
 }
 
 
diff --git a/keys.h b/keys.h
index b874934..d49d5e3 100644 (file)
--- a/keys.h
+++ b/keys.h
@@ -154,7 +154,7 @@ extern      int             key_lastpress;
 
 void Key_Event (int key, qboolean down);
 void Key_Init (void);
-void Key_WriteBindings (FILE *f);
+void Key_WriteBindings (QFile *f);
 void Key_SetBinding (int keynum, char *binding);
 void Key_ClearStates (void);
 
index 0a0202f..43931b1 100644 (file)
--- a/makefile
+++ b/makefile
@@ -6,7 +6,7 @@
 #if you use the kernel sound driver or OSS
 SND=snd_oss.o
 
-OBJECTS= buildnumber.o cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o gl_poly.o gl_rmain.o gl_rmisc.o gl_rsurf.o gl_screen.o gl_warp.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_part.o r_explosion.o sbar.o snd_dma.o snd_mem.o snd_mix.o $(SND) sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o sys_linux.o transform.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 cl_effects.o r_decals.o protocol.o
+OBJECTS= buildnumber.o cd_linux.o chase.o cl_demo.o cl_input.o cl_main.o cl_parse.o cl_tent.o cmd.o common.o console.o crc.o cvar.o fractalnoise.o gl_draw.o gl_poly.o gl_rmain.o gl_rmisc.o gl_rsurf.o gl_screen.o gl_warp.o host.o host_cmd.o image.o keys.o mathlib.o menu.o model_alias.o model_brush.o model_shared.o model_sprite.o net_bsd.o net_udp.o net_dgrm.o net_loop.o net_main.o pr_cmds.o pr_edict.o pr_exec.o r_light.o r_part.o r_explosion.o sbar.o snd_dma.o snd_mem.o snd_mix.o $(SND) sv_main.o sv_move.o sv_phys.o sv_user.o sv_light.o sys_linux.o transform.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 cl_effects.o r_decals.o protocol.o quakeio.o
 
 OPTIMIZATIONS= -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimizations
 #OPTIMIZATIONS= -O -g
@@ -14,7 +14,7 @@ OPTIMIZATIONS= -O6 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-o
 CFLAGS= -Wall -Werror -I/usr/X11R6/include -I/usr/include/glide $(OPTIMIZATIONS)
 #CFLAGS= -Wall -Werror -I/usr/X11R6/include -ggdb $(OPTIMIZATIONS)
 #LDFLAGS= -L/usr/X11R6/lib -lm -lX11 -lXext -lXIE -lXxf86dga -lXxf86vm -lGL -ldl
-LDFLAGS= -L/usr/X11R6/lib -lm -lX11 -lXext -lXIE -lXxf86dga -lXxf86vm -lGL -ldl -lasound
+LDFLAGS= -L/usr/X11R6/lib -lm -lX11 -lXext -lXIE -lXxf86dga -lXxf86vm -lGL -ldl -lasound -lz
 
 #most people can't build the -3dfx version (-3dfx version needs some updates for new mesa)
 all: darkplaces-glx
diff --git a/menu.c b/menu.c
index 7092080..4cf1b58 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -32,7 +32,7 @@ void (*vid_menukeyfn)(int key);
 
 int NehGameType;
 
-enum {m_none, m_main, m_demo, m_singleplayer, m_load, m_save, m_multiplayer, m_setup, m_net, m_options, m_video, m_keys, m_help, m_quit, m_lanconfig, m_gameoptions, m_search, m_slist} m_state;
+enum m_state_e m_state;
 
 void M_Menu_Main_f (void);
        void M_Menu_SinglePlayer_f (void);
@@ -703,7 +703,8 @@ void M_ScanSaves (void)
 {
        int             i, j;
        char    name[MAX_OSPATH];
-       FILE    *f;
+       char    *str;
+       QFile   *f;
        int             version;
 
        for (i=0 ; i<MAX_SAVEGAMES ; i++)
@@ -711,19 +712,20 @@ void M_ScanSaves (void)
                strcpy (m_filenames[i], "--- UNUSED SLOT ---");
                loadable[i] = false;
                sprintf (name, "%s/s%i.sav", com_gamedir, i);
-               f = fopen (name, "r");
+               f = Qopen (name, "rz");
                if (!f)
                        continue;
-               fscanf (f, "%i\n", &version);
-               fscanf (f, "%79s\n", name);
-               strncpy (m_filenames[i], name, sizeof(m_filenames[i])-1);
+               str = Qgetline (f);
+               sscanf (str, "%i\n", &version);
+               str = Qgetline (f);
+               strncpy (m_filenames[i], str, sizeof(m_filenames[i])-1);
 
        // change _ back to space
                for (j=0 ; j<SAVEGAME_COMMENT_LENGTH ; j++)
                        if (m_filenames[i][j] == '_')
                                m_filenames[i][j] = ' ';
                loadable[i] = true;
-               fclose (f);
+               Qclose (f);
        }
 }
 
diff --git a/menu.h b/menu.h
index 8b5a34e..4e3d334 100644 (file)
--- a/menu.h
+++ b/menu.h
@@ -25,9 +25,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define        MNET_IPX                1
 #define        MNET_TCP                2
 
+enum m_state_e {
+       m_none,
+       m_main,
+       m_demo,
+       m_singleplayer,
+       m_load,
+       m_save,
+       m_multiplayer,
+       m_setup,
+       m_net,
+       m_options,
+       m_video,
+       m_keys,
+       m_help,
+       m_quit,
+       m_lanconfig,
+       m_gameoptions,
+       m_search,
+       m_slist
+};
+
 extern int m_activenet;
 extern int m_return_state;
-extern int m_state;
+extern enum m_state_e m_state;
 extern qboolean m_return_onerror;
 extern char m_return_reason[32];
 
index 61dbc1e..cfb371e 100644 (file)
@@ -206,5 +206,6 @@ extern void CL_ParseEntityLump(char *entdata);
 extern rtexture_t *r_notexture;
 extern texture_t r_notexture_mip;
 
+struct model_s;
 extern void Mod_LoadBrushModel (struct model_s *mod, void *buffer);
 extern void Mod_BrushInit(void);
index cec47e8..49253e1 100644 (file)
@@ -599,7 +599,7 @@ ED_Write
 For savegames
 =============
 */
-void ED_Write (FILE *f, edict_t *ed)
+void ED_Write (QFile *f, edict_t *ed)
 {
        ddef_t  *d;
        int             *v;
@@ -607,11 +607,11 @@ void ED_Write (FILE *f, edict_t *ed)
        char    *name;
        int             type;
 
-       fprintf (f, "{\n");
+       Qprintf (f, "{\n");
 
        if (ed->free)
        {
-               fprintf (f, "}\n");
+               Qprintf (f, "}\n");
                return;
        }
        
@@ -632,11 +632,11 @@ void ED_Write (FILE *f, edict_t *ed)
                if (j == type_size[type])
                        continue;
        
-               fprintf (f,"\"%s\" ",name);
-               fprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));               
+               Qprintf (f,"\"%s\" ",name);
+               Qprintf (f,"\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));               
        }
 
-       fprintf (f, "}\n");
+       Qprintf (f, "}\n");
 }
 
 void ED_PrintNum (int ent)
@@ -730,14 +730,14 @@ FIXME: need to tag constants, doesn't really work
 ED_WriteGlobals
 =============
 */
-void ED_WriteGlobals (FILE *f)
+void ED_WriteGlobals (QFile *f)
 {
        ddef_t          *def;
        int                     i;
        char            *name;
        int                     type;
 
-       fprintf (f,"{\n");
+       Qprintf (f,"{\n");
        for (i=0 ; i<progs->numglobaldefs ; i++)
        {
                def = &pr_globaldefs[i];
@@ -750,10 +750,10 @@ void ED_WriteGlobals (FILE *f)
                        continue;
 
                name = pr_strings + def->s_name;                
-               fprintf (f,"\"%s\" ", name);
-               fprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));              
+               Qprintf (f,"\"%s\" ", name);
+               Qprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs]));              
        }
-       fprintf (f,"}\n");
+       Qprintf (f,"}\n");
 }
 
 /*
diff --git a/progs.h b/progs.h
index 2264ac1..a6603d5 100644 (file)
--- a/progs.h
+++ b/progs.h
@@ -128,10 +128,10 @@ char      *ED_NewString (char *string);
 // returns a copy of the string allocated from the server's string heap
 
 void ED_Print (edict_t *ed);
-void ED_Write (FILE *f, edict_t *ed);
+void ED_Write (QFile *f, edict_t *ed);
 char *ED_ParseEdict (char *data, edict_t *ent);
 
-void ED_WriteGlobals (FILE *f);
+void ED_WriteGlobals (QFile *f);
 void ED_ParseGlobals (char *data);
 
 void ED_LoadFromFile (char *data);
index 547dbb9..710e856 100644 (file)
--- a/quakeio.c
+++ b/quakeio.c
@@ -388,25 +388,3 @@ Qgetline (QFile *file)
        }
        return buf;
 }
-
-int
-Qgetpos (QFile *file, fpos_t * pos)
-{
-#ifdef HAVE_FPOS_T_STRUCT
-       pos->__pos = Qtell (file);
-       return pos->__pos == -1 ? -1 : 0;
-#else
-       *pos = Qtell (file);
-       return *pos == -1 ? -1 : 0;
-#endif
-}
-
-int
-Qsetpos (QFile *file, fpos_t * pos)
-{
-#ifdef HAVE_FPOS_T_STRUCT
-       return Qseek (file, pos->__pos, 0);
-#else
-       return Qseek (file, *pos, 0);
-#endif
-}
index d8bd040..acb9a91 100644 (file)
--- a/quakeio.h
+++ b/quakeio.h
@@ -64,7 +64,5 @@ long Qtell(QFile *file);
 int Qflush(QFile *file);
 int Qeof(QFile *file);
 char *Qgetline(QFile *file);
-int Qgetpos(QFile *file, fpos_t *pos);
-int Qsetpos(QFile *file, fpos_t *pos);
 
 #endif /*__quakeio_h*/
index fa9ec93..b5624af 100644 (file)
--- a/r_part.c
+++ b/r_part.c
@@ -466,7 +466,7 @@ void R_EntityParticles (entity_t *ent)
 
 void R_ReadPointFile_f (void)
 {
-       FILE    *f;
+       QFile   *f;
        vec3_t  org;
        int             r;
        int             c;
@@ -474,7 +474,7 @@ void R_ReadPointFile_f (void)
        
        sprintf (name,"maps/%s.pts", sv.name);
 
-       COM_FOpenFile (name, &f, false);
+       COM_FOpenFile (name, &f, false, true);
        if (!f)
        {
                Con_Printf ("couldn't open %s\n", name);
@@ -485,7 +485,8 @@ void R_ReadPointFile_f (void)
        c = 0;
        for (;;)
        {
-               r = fscanf (f,"%f %f %f\n", &org[0], &org[1], &org[2]);
+               char *str = Qgetline (f);
+               r = sscanf (str,"%f %f %f\n", &org[0], &org[1], &org[2]);
                if (r != 3)
                        break;
                c++;
@@ -498,7 +499,7 @@ void R_ReadPointFile_f (void)
                particle(pt_static, (-c)&15, particletexture, TPOLYTYPE_ALPHA, false, 2, 255, 99999, 0, org[0], org[1], org[2], 0, 0, 0);
        }
 
-       fclose (f);
+       Qclose (f);
        Con_Printf ("%i points read\n", c);
 }
 
index ba04b5b..d3551e0 100644 (file)
@@ -320,7 +320,7 @@ void SNDDMA_Submit(void)
        switch (mmap_control->status.status) {
        case SND_PCM_STATUS_PREPARED:
                if ((rc=snd_pcm_channel_go(pcm_handle, SND_PCM_CHANNEL_PLAYBACK))<0) {
-                       fprintf(stderr, "unable to start playback. %s\n",
+                       Qprintf(stderr, "unable to start playback. %s\n",
                                        snd_strerror(rc));
                        exit(1);
                }
@@ -329,7 +329,7 @@ void SNDDMA_Submit(void)
                break;
        case SND_PCM_STATUS_UNDERRUN:
                if ((rc=snd_pcm_plugin_prepare(pcm_handle, SND_PCM_CHANNEL_PLAYBACK))<0) {
-                       fprintf(stderr, "underrun: playback channel prepare error. %s\n",
+                       Qprintf(stderr, "underrun: playback channel prepare error. %s\n",
                                        snd_strerror(rc));
                        exit(1);
                }
index 4579e40..a0afe75 100644 (file)
--- a/snd_oss.c
+++ b/snd_oss.c
@@ -240,7 +240,7 @@ int SNDDMA_GetDMAPos(void)
                return 0;
        }
 //     shm->samplepos = (count.bytes / (shm->samplebits / 8)) & (shm->samples-1);
-//     fprintf(stderr, "%d    \r", count.ptr);
+//     Qprintf(stderr, "%d    \r", count.ptr);
        shm->samplepos = count.ptr / (shm->samplebits / 8);
 
        return shm->samplepos;
index c1d1494..e886874 100644 (file)
@@ -87,7 +87,7 @@ void Sys_Printf (char *fmt, ...)
        va_start (argptr,fmt);
        vsprintf (text,fmt,argptr);
        va_end (argptr);
-       fprintf(stderr, "%s", text);
+       Qprintf(stderr, "%s", text);
        
        Con_Print (text);
 }
index e4e6cfd..8353408 100644 (file)
--- a/sys_win.c
+++ b/sys_win.c
@@ -81,14 +81,14 @@ void Sys_PageIn (void *ptr, int size)
 /*
 ===============================================================================
 
-FILE IO
+QFile IO
 
 ===============================================================================
 */
 
 // LordHavoc: 256 pak files (was 10)
 #define        MAX_HANDLES             256
-FILE   *sys_handles[MAX_HANDLES];
+QFile  *sys_handles[MAX_HANDLES];
 
 int            findhandle (void)
 {
@@ -106,27 +106,27 @@ int               findhandle (void)
 filelength
 ================
 */
-int filelength (FILE *f)
+int filelength (QFile *f)
 {
        int             pos;
        int             end;
 
-       pos = ftell (f);
-       fseek (f, 0, SEEK_END);
-       end = ftell (f);
-       fseek (f, pos, SEEK_SET);
+       pos = Qtell (f);
+       Qseek (f, 0, SEEK_END);
+       end = Qtell (f);
+       Qseek (f, pos, SEEK_SET);
 
        return end;
 }
 
 int Sys_FileOpenRead (char *path, int *hndl)
 {
-       FILE    *f;
+       QFile   *f;
        int             i, retval;
 
        i = findhandle ();
 
-       f = fopen(path, "rb");
+       f = Qopen(path, "rbz");
 
        if (!f)
        {
@@ -145,12 +145,12 @@ int Sys_FileOpenRead (char *path, int *hndl)
 
 int Sys_FileOpenWrite (char *path)
 {
-       FILE    *f;
+       QFile   *f;
        int             i;
 
        i = findhandle ();
 
-       f = fopen(path, "wb");
+       f = Qopen(path, "wb");
        if (!f)
                Host_Error ("Error opening %s: %s", path,strerror(errno));
        sys_handles[i] = f;
@@ -160,33 +160,33 @@ int Sys_FileOpenWrite (char *path)
 
 void Sys_FileClose (int handle)
 {
-       fclose (sys_handles[handle]);
+       Qclose (sys_handles[handle]);
        sys_handles[handle] = NULL;
 }
 
 void Sys_FileSeek (int handle, int position)
 {
-       fseek (sys_handles[handle], position, SEEK_SET);
+       Qseek (sys_handles[handle], position, SEEK_SET);
 }
 
 int Sys_FileRead (int handle, void *dest, int count)
 {
-       return fread (dest, 1, count, sys_handles[handle]);
+       return Qread (dest, 1, count, sys_handles[handle]);
 }
 
 int Sys_FileWrite (int handle, void *data, int count)
 {
-       return fwrite (data, 1, count, sys_handles[handle]);
+       return Qwrite (data, 1, count, sys_handles[handle]);
 }
 
 int    Sys_FileTime (char *path)
 {
-       FILE    *f;
+       QFile   *f;
        
-       f = fopen(path, "rb");
+       f = Qopen(path, "rb");
        if (f)
        {
-               fclose(f);
+               Qclose(f);
                return 1;
        }
        
diff --git a/wad.c b/wad.c
index 177c7a7..1a5ab0a 100644 (file)
--- a/wad.c
+++ b/wad.c
@@ -162,7 +162,7 @@ void SwapPic (qpic_t *pic)
 typedef struct
 {
        char name[16];
-       FILE *file;
+       QFile *file;
        int position;
        int size;
 } texwadlump_t;
@@ -180,10 +180,10 @@ void W_LoadTextureWadFile (char *filename, int complain)
        wadinfo_t               header;
        unsigned                i, j;
        int                             infotableofs;
-       FILE                    *file;
+       QFile                   *file;
        int                             numlumps;
        
-       COM_FOpenFile (filename, &file, false);
+       COM_FOpenFile (filename, &file, false, true);
        if (!file)
        {
                if (complain)
@@ -191,7 +191,7 @@ void W_LoadTextureWadFile (char *filename, int complain)
                return;
        }
 
-       if (fread(&header, sizeof(wadinfo_t), 1, file) != 1)
+       if (Qread(file, &header, sizeof(wadinfo_t)) != sizeof(wadinfo_t))
        {Con_Printf ("W_LoadTextureWadFile: unable to read wad header");return;}
        
        if(header.identification[0] != 'W'
@@ -204,12 +204,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 (fseek(file, infotableofs, SEEK_SET))
+       if (Qseek(file, infotableofs, SEEK_SET))
        {Con_Printf ("W_LoadTextureWadFile: unable to seek to lump table");return;}
        if (!(lumps = qmalloc(sizeof(lumpinfo_t)*numlumps)))
        {Con_Printf ("W_LoadTextureWadFile: unable to allocate temporary memory for lump table");return;}
 
-       if (fread(lumps, sizeof(lumpinfo_t), numlumps, file) != numlumps)
+       if (Qread(file, lumps, sizeof(lumpinfo_t) * numlumps) != 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++)
@@ -331,7 +331,7 @@ byte *W_GetTexture(char *name)
 //     byte pal[256][3], *indata, *outdata, *data;
        char texname[17];
        int i, j;
-       FILE *file;
+       QFile *file;
        miptex_t *tex;
        byte *data;
        texname[16] = 0;
@@ -343,13 +343,13 @@ byte *W_GetTexture(char *name)
                        if (!strcmp(texname, texwadlump[i].name)) // found it
                        {
                                file = texwadlump[i].file;
-                               if (fseek(file, texwadlump[i].position, SEEK_SET))
+                               if (Qseek(file, texwadlump[i].position, SEEK_SET))
                                {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
 
                                tex = qmalloc(texwadlump[i].size);
                                if (!tex)
                                        return NULL;
-                               if (fread(tex, 1, texwadlump[i].size, file) < texwadlump[i].size)
+                               if (Qread(file, tex, texwadlump[i].size) < texwadlump[i].size)
                                {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
 
                                tex->width = LittleLong(tex->width);
@@ -375,14 +375,14 @@ byte *W_GetTexture(char *name)
                                indata = outdata + image_width*image_height*3;
                                datasize = image_width*image_height*85/64;
                                // read the image data
-                               if (fseek(file, texwadlump[i].position + sizeof(t), SEEK_SET))
+                               if (Qseek(file, texwadlump[i].position + sizeof(t), SEEK_SET))
                                {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
-                               if (fread(indata, 1, image_width*image_height, file) != image_width*image_height)
+                               if (Qread(file, indata, image_width*image_height) != image_width*image_height)
                                {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
                                // read the number of colors used (always 256)
-                               if (fseek(file, texwadlump[i].position + sizeof(t) + datasize, SEEK_SET))
+                               if (Qseek(file, texwadlump[i].position + sizeof(t) + datasize, SEEK_SET))
                                {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
-                               if (fread(&colorcount, 2, 1, file) != 1)
+                               if (Qread(file, &colorcount, 2) != 2)
                                {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
                                if (texwadlump[i].size > (datasize + sizeof(t)))
                                {
@@ -391,8 +391,8 @@ byte *W_GetTexture(char *name)
                                        if (colorcount < 0) colorcount = 0;
                                        if (colorcount > 256) colorcount = 256;
                                        // read the palette
-       //                              fseek(file, texwadlump[i].position + sizeof(t) + datasize + 2, SEEK_SET);
-                                       if (fread(&pal, 3, colorcount, file) != colorcount)
+       //                              Qseek(file, texwadlump[i].position + sizeof(t) + datasize + 2, SEEK_SET);
+                                       if (Qread(file, &pal, 3 * colorcount) != 3 * colorcount)
                                        {Con_Printf("W_GetTexture: corrupt WAD3 file");return NULL;}
                                }
                                else