From 7305ab0695a23466c3554c8670c3b8a38bbc54a9 Mon Sep 17 00:00:00 2001 From: taniwha Date: Wed, 30 May 2001 02:36:15 +0000 Subject: [PATCH] gzip support from quakeforge (QFile and friends). also includes a couple of compile fixes git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@210 d7cf8633-e32d-0410-b094-e92efae38249 --- cl_demo.c | 28 ++++----- client.h | 2 +- common.c | 159 ++++++++++++++++++++++++++----------------------- common.h | 6 +- cvar.c | 4 +- cvar.h | 2 +- host.c | 6 +- host_cmd.c | 72 ++++++++++++---------- image.c | 112 +++++++++++++++++----------------- keys.c | 4 +- keys.h | 2 +- makefile | 4 +- menu.c | 16 ++--- menu.h | 23 ++++++- model_brush.h | 1 + pr_edict.c | 22 +++---- progs.h | 4 +- quakeio.c | 22 ------- quakeio.h | 2 - r_part.c | 9 +-- snd_alsa_0_5.c | 4 +- snd_oss.c | 2 +- sys_linux.c | 2 +- sys_win.c | 36 +++++------ wad.c | 30 +++++----- 25 files changed, 294 insertions(+), 280 deletions(-) diff --git a/cl_demo.c b/cl_demo.c index 56b6dd76..34c875ea 100644 --- 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 diff --git a/client.h b/client.h index 0ff6de07..a690fdc5 100644 --- 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) diff --git a/common.c b/common.c index d5eed882..43f5c6a9 100644 --- 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 +#ifndef WIN32 +#include +#endif +#include + #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 ; inumfiles ; 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; } diff --git a/common.h b/common.h index 502f4cdb..17c2790e 100644 --- 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 bb680158..0f8ccd4d 100644 --- 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 4a961b20..6aa1ad14 100644 --- 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 675e30ea..b419f8a9 100644 --- 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); } } diff --git a/host_cmd.c b/host_cmd.c index 5e0a66f6..c949589c 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -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 ; ispawn_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 ; ispawn_parms[i] = spawn_parms[i]; diff --git a/image.c b/image.c index db7570f0..23b69ba7 100644 --- 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; columnfree) { - 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 ; inumglobaldefs ; 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 2264ac11..a6603d5d 100644 --- 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); diff --git a/quakeio.c b/quakeio.c index 547dbb9f..710e8560 100644 --- 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 -} diff --git a/quakeio.h b/quakeio.h index d8bd0402..acb9a915 100644 --- 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*/ diff --git a/r_part.c b/r_part.c index fa9ec93c..b5624af0 100644 --- 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); } diff --git a/snd_alsa_0_5.c b/snd_alsa_0_5.c index ba04b5b1..d3551e04 100644 --- a/snd_alsa_0_5.c +++ b/snd_alsa_0_5.c @@ -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); } diff --git a/snd_oss.c b/snd_oss.c index 4579e40d..a0afe75d 100644 --- 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; diff --git a/sys_linux.c b/sys_linux.c index c1d14940..e886874f 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -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); } diff --git a/sys_win.c b/sys_win.c index e4e6cfd6..8353408b 100644 --- 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 177c7a70..1a5ab0a1 100644 --- 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 ; iwidth = 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 -- 2.39.2