Replaced every single fscking FILE and gzFile (except in quakeio.*) with QFile

and fixed up as many f* and gz* calls as gcc found (and, where sensible, grep)

Unfortuanatly, demos are broken again.
This commit is contained in:
Bill Currie 2000-02-08 07:23:09 +00:00
parent e67f3dc07a
commit a078544d38
28 changed files with 299 additions and 233 deletions

View file

@ -296,7 +296,7 @@ void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
int *cmds;
trivertx_t *verts;
char cache[MAX_QPATH], fullpath[MAX_OSPATH];
gzFile *f;
QFile *f;
aliasmodel = m;
paliashdr = hdr; // (aliashdr_t *)Mod_Extradata (m);
@ -311,11 +311,11 @@ void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
COM_FOpenFile (cache, &f);
if (f)
{
gzread (f, &numcommands, 4);
gzread (f, &numorder, 4);
gzread (f, commands, numcommands * sizeof(commands[0]));
gzread (f, vertexorder, numorder * sizeof(vertexorder[0]));
gzclose (f);
Qread (f, &numcommands, 4);
Qread (f, &numorder, 4);
Qread (f, commands, numcommands * sizeof(commands[0]));
Qread (f, vertexorder, numorder * sizeof(vertexorder[0]));
Qclose (f);
}
else
{
@ -330,24 +330,24 @@ void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
// save out the cached version
//
snprintf(fullpath, sizeof(fullpath), "%s/%s", com_gamedir, cache);
f = gzopen (fullpath, "wb");
f = Qopen (fullpath, "wb");
#ifdef QUAKEWORLD
if (!f) {
char gldir[MAX_OSPATH];
snprintf(gldir, sizeof(gldir), "%s/glquake", com_gamedir);
Sys_mkdir (gldir);
f = gzopen (fullpath, "wb");
f = Qopen (fullpath, "wb");
}
#endif
if (f)
{
gzwrite(f, &numcommands, 4);
gzwrite(f, &numorder, 4);
gzwrite(f, commands, numcommands * sizeof(commands[0]));
gzwrite(f, vertexorder, numorder * sizeof(vertexorder[0]));
gzclose (f);
Qwrite(f, &numcommands, 4);
Qwrite(f, &numorder, 4);
Qwrite(f, commands, numcommands * sizeof(commands[0]));
Qwrite(f, vertexorder, numorder * sizeof(vertexorder[0]));
Qclose (f);
}
}

View file

@ -376,7 +376,7 @@ void VID_SetPalette (unsigned char *palette)
int k;
unsigned short i;
unsigned *table;
gzFile *f;
QFile *f;
char s[255];
float dist, bestdist;
static qboolean palflag = false;
@ -410,8 +410,8 @@ void VID_SetPalette (unsigned char *palette)
COM_FOpenFile("glquake/15to8.pal", &f);
if (f) {
gzread(f, d_15to8table, 1<<15);
gzclose(f);
Qread(f, d_15to8table, 1<<15);
Qclose(f);
} else {
for (i=0; i < (1<<15); i++) {
/* Maps
@ -439,9 +439,9 @@ void VID_SetPalette (unsigned char *palette)
snprintf(s, sizeof(s), "%s/glquake", com_gamedir);
Sys_mkdir (s);
snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir);
if ((f = gzopen(s, "wb")) != NULL) {
gzwrite(f, d_15to8table, 1<<15);
gzclose(f);
if ((f = Qopen(s, "wb")) != NULL) {
Qwrite(f, d_15to8table, 1<<15);
Qclose(f);
}
}
}

View file

@ -131,7 +131,7 @@ void VID_SetPalette (unsigned char *palette)
unsigned short i;
unsigned *table;
//#ifdef QUAKEWORLD
gzFile *f;
QFile *f;
char s[255];
//#endif
float dist, bestdist;
@ -169,8 +169,8 @@ void VID_SetPalette (unsigned char *palette)
COM_FOpenFile("glquake/15to8.pal", &f);
if (f) {
gzread(f, d_15to8table, 1<<15);
gzclose(f);
Qread(f, d_15to8table, 1<<15);
Qclose(f);
} else
//#endif // QUAKEWORLD
{
@ -201,9 +201,9 @@ void VID_SetPalette (unsigned char *palette)
snprintf(s, sizeof(s), "%s/glquake", com_gamedir);
Sys_mkdir (s);
snprintf(s, sizeof(s), "%s/glquake/15to8.pal", com_gamedir);
if ((f = gzopen(s, "wb")) != NULL) {
gzwrite(f, d_15to8table, 1<<15);
gzclose(f);
if ((f = Qopen(s, "wb")) != NULL) {
Qwrite(f, d_15to8table, 1<<15);
Qclose(f);
}
//#endif // QUAKEWORLD
}

View file

@ -706,7 +706,7 @@ void VID_SetPalette (unsigned char *palette)
int j,k,l,m;
unsigned short i;
unsigned *table;
FILE *f;
QFile *f;
char s[255];
HWND hDlg, hProgress;
float gamma;

View file

@ -358,7 +358,7 @@ byte *pcx_rgb;
LoadPCX
*/
void
LoadPCX (gzFile *f) {
LoadPCX (QFile *f) {
pcx_t *pcx, pcxbuf;
byte palette[768];
@ -370,7 +370,7 @@ LoadPCX (gzFile *f) {
/*
Parse PCX file
*/
gzread (f, &pcxbuf, sizeof(pcxbuf));
Qread (f, &pcxbuf, sizeof(pcxbuf));
pcx = &pcxbuf;
@ -382,10 +382,10 @@ LoadPCX (gzFile *f) {
}
// seek to palette
gzseek (f, -768, SEEK_END);
gzread (f, palette, 768);
Qseek (f, -768, SEEK_END);
Qread (f, palette, 768);
gzseek (f, sizeof(pcxbuf) - 4, SEEK_SET);
Qseek (f, sizeof(pcxbuf) - 4, SEEK_SET);
count = (pcx->xmax+1) * (pcx->ymax+1);
pcx_rgb = malloc( count * 4);
@ -393,11 +393,11 @@ LoadPCX (gzFile *f) {
for (y=0 ; y<=pcx->ymax ; y++) {
pix = pcx_rgb + 4*y*(pcx->xmax+1);
for (x=0 ; x<=pcx->ymax ; ) {
dataByte = gzgetc(f);
dataByte = Qgetc(f);
if((dataByte & 0xC0) == 0xC0) {
runLength = dataByte & 0x3F;
dataByte = gzgetc(f);
dataByte = Qgetc(f);
}
else
runLength = 1;
@ -430,25 +430,25 @@ TargaHeader targa_header;
byte *targa_rgba;
int
gzgetLittleShort ( gzFile *f ) {
QgetLittleShort ( QFile *f ) {
byte b1, b2;
b1 = gzgetc(f);
b2 = gzgetc(f);
b1 = Qgetc(f);
b2 = Qgetc(f);
return (short)(b1 + b2*256);
}
int
gzgetLittleLong (gzFile *f) {
QgetLittleLong (QFile *f) {
byte b1, b2, b3, b4;
b1 = gzgetc(f);
b2 = gzgetc(f);
b3 = gzgetc(f);
b4 = gzgetc(f);
b1 = Qgetc(f);
b2 = Qgetc(f);
b3 = Qgetc(f);
b4 = Qgetc(f);
return b1 + (b2<<8) + (b3<<16) + (b4<<24);
}
@ -457,25 +457,25 @@ gzgetLittleLong (gzFile *f) {
LoadTGA
*/
void
LoadTGA (gzFile *fin) {
LoadTGA (QFile *fin) {
int columns, rows, numPixels;
byte *pixbuf;
int row, column;
targa_header.id_length = gzgetc(fin);
targa_header.colormap_type = gzgetc(fin);
targa_header.image_type = gzgetc(fin);
targa_header.id_length = Qgetc(fin);
targa_header.colormap_type = Qgetc(fin);
targa_header.image_type = Qgetc(fin);
targa_header.colormap_index = gzgetLittleShort(fin);
targa_header.colormap_length = gzgetLittleShort(fin);
targa_header.colormap_size = gzgetc(fin);
targa_header.x_origin = gzgetLittleShort(fin);
targa_header.y_origin = gzgetLittleShort(fin);
targa_header.width = gzgetLittleShort(fin);
targa_header.height = gzgetLittleShort(fin);
targa_header.pixel_size = gzgetc(fin);
targa_header.attributes = gzgetc(fin);
targa_header.colormap_index = QgetLittleShort(fin);
targa_header.colormap_length = QgetLittleShort(fin);
targa_header.colormap_size = Qgetc(fin);
targa_header.x_origin = QgetLittleShort(fin);
targa_header.y_origin = QgetLittleShort(fin);
targa_header.width = QgetLittleShort(fin);
targa_header.height = QgetLittleShort(fin);
targa_header.pixel_size = Qgetc(fin);
targa_header.attributes = Qgetc(fin);
if (targa_header.image_type!=2 && targa_header.image_type!=10)
Sys_Error ("LoadTGA: Only type 2 and 10 targa RGB images supported\n");
@ -492,7 +492,7 @@ LoadTGA (gzFile *fin) {
targa_rgba = malloc (numPixels*4);
if (targa_header.id_length != 0)
gzseek(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--) {
@ -502,19 +502,19 @@ LoadTGA (gzFile *fin) {
switch (targa_header.pixel_size) {
case 24:
blue = gzgetc(fin);
green = gzgetc(fin);
red = gzgetc(fin);
blue = Qgetc(fin);
green = Qgetc(fin);
red = Qgetc(fin);
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = 255;
break;
case 32:
blue = gzgetc(fin);
green = gzgetc(fin);
red = gzgetc(fin);
alphabyte = gzgetc(fin);
blue = Qgetc(fin);
green = Qgetc(fin);
red = Qgetc(fin);
alphabyte = Qgetc(fin);
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
@ -529,21 +529,21 @@ LoadTGA (gzFile *fin) {
for(row=rows-1; row>=0; row--) {
pixbuf = targa_rgba + row*columns*4;
for(column=0; column<columns; ) {
packetHeader=gzgetc(fin);
packetHeader=Qgetc(fin);
packetSize = 1 + (packetHeader & 0x7f);
if (packetHeader & 0x80) { // run-length packet
switch (targa_header.pixel_size) {
case 24:
blue = gzgetc(fin);
green = gzgetc(fin);
red = gzgetc(fin);
blue = Qgetc(fin);
green = Qgetc(fin);
red = Qgetc(fin);
alphabyte = 255;
break;
case 32:
blue = gzgetc(fin);
green = gzgetc(fin);
red = gzgetc(fin);
alphabyte = gzgetc(fin);
blue = Qgetc(fin);
green = Qgetc(fin);
red = Qgetc(fin);
alphabyte = Qgetc(fin);
break;
}
@ -567,19 +567,19 @@ LoadTGA (gzFile *fin) {
for(j=0;j<packetSize;j++) {
switch (targa_header.pixel_size) {
case 24:
blue = gzgetc(fin);
green = gzgetc(fin);
red = gzgetc(fin);
blue = Qgetc(fin);
green = Qgetc(fin);
red = Qgetc(fin);
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
*pixbuf++ = 255;
break;
case 32:
blue = gzgetc(fin);
green = gzgetc(fin);
red = gzgetc(fin);
alphabyte = gzgetc(fin);
blue = Qgetc(fin);
green = Qgetc(fin);
red = Qgetc(fin);
alphabyte = Qgetc(fin);
*pixbuf++ = red;
*pixbuf++ = green;
*pixbuf++ = blue;
@ -601,7 +601,7 @@ LoadTGA (gzFile *fin) {
breakOut:;
}
}
gzclose(fin);
Qclose(fin);
// fclose(fin);
}
@ -614,7 +614,7 @@ void
R_LoadSkys ( void ) {
int i;
gzFile *f;
QFile *f;
char name[64];
for (i=0 ; i<6 ; i++) {

View file

@ -1805,8 +1805,8 @@ void PF_logfrag (void)
SZ_Print (&svs.log[svs.logsequence&1], s);
if (sv_fraglogfile) {
fprintf (sv_fraglogfile, s);
fflush (sv_fraglogfile);
Qprintf (sv_fraglogfile, s);
Qflush (sv_fraglogfile);
}
}

View file

@ -86,7 +86,7 @@ typedef struct
typedef struct pack_s
{
char filename[MAX_OSPATH];
FILE *handle;
QFile *handle;
int numfiles;
packfile_t *files;
} pack_t;
@ -127,24 +127,24 @@ searchpath_t *com_base_searchpaths; // without gamedirs
COM_filelength
================
*/
int COM_filelength (FILE *f)
int COM_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 COM_FileOpenRead (char *path, FILE **hndl)
int COM_FileOpenRead (char *path, QFile **hndl)
{
FILE *f;
QFile *f;
f = fopen(path, "rb");
f = Qopen(path, "rb");
if (!f)
{
*hndl = NULL;
@ -186,22 +186,22 @@ The filename will be prefixed by the current game directory
*/
void COM_WriteFile (char *filename, void *data, int len)
{
FILE *f;
QFile *f;
char name[MAX_OSPATH];
snprintf(name, sizeof(name), "%s/%s", com_gamedir, filename);
f = fopen (name, "wb");
f = Qopen (name, "wb");
if (!f) {
Sys_mkdir(com_gamedir);
f = fopen (name, "wb");
f = Qopen (name, "wb");
if (!f)
Sys_Error ("Error opening %s", filename);
}
Sys_Printf ("COM_WriteFile: %s\n", name);
fwrite (data, 1, len, f);
fclose (f);
Qwrite (f, data, len);
Qclose (f);
}
@ -238,13 +238,13 @@ needed. This is for the convenience of developers using ISDN from home.
*/
void COM_CopyFile (char *netpath, char *cachepath)
{
FILE *in, *out;
QFile *in, *out;
int remaining, count;
char buf[4096];
remaining = COM_FileOpenRead (netpath, &in);
COM_CreatePath (cachepath); // create directories up to the cache file
out = fopen(cachepath, "wb");
out = Qopen(cachepath, "wb");
if (!out)
Sys_Error ("Error opening %s", cachepath);
@ -254,19 +254,19 @@ void COM_CopyFile (char *netpath, char *cachepath)
count = remaining;
else
count = sizeof(buf);
fread (buf, 1, count, in);
fwrite (buf, 1, count, out);
Qread (in, buf, count);
Qwrite (out, buf, count);
remaining -= count;
}
fclose (in);
fclose (out);
Qclose (in);
Qclose (out);
}
QFile *COM_gzOpenRead(const char *path, int offs, int len)
QFile *COM_OpenRead(const char *path, int offs, int len)
{
/* int fd=open(path,O_RDONLY);
int fd=open(path,O_RDONLY);
unsigned char id[2];
unsigned char len_bytes[4];
if (fd==-1) {
@ -290,7 +290,7 @@ QFile *COM_gzOpenRead(const char *path, int offs, int len)
}
lseek(fd,offs,SEEK_SET);
com_filesize=len;
return gzdopen(fd,"rb");*/
return Qdopen(fd,"rb");
return 0;
}
@ -348,8 +348,8 @@ int COM_FOpenFile (char *filename, QFile **gzfile)
// Sys_Error ("Couldn't reopen %s", pak->filename);
//fseek (*file, pak->files[i].filepos, SEEK_SET);
//com_filesize = pak->files[i].filelen;
*gzfile=COM_gzOpenRead(pak->filename,pak->files[i].filepos,
pak->files[i].filelen);
*gzfile=COM_OpenRead(pak->filename,pak->files[i].filepos,
pak->files[i].filelen);
file_from_pak = 1;
return com_filesize;
}
@ -377,7 +377,7 @@ int COM_FOpenFile (char *filename, QFile **gzfile)
//*file = fopen (netpath, "rb");
//return COM_filelength (*file);
*gzfile=COM_gzOpenRead(netpath,-1,-1);
*gzfile=COM_OpenRead(netpath,-1,-1);
return com_filesize;
}
@ -497,13 +497,13 @@ pack_t *COM_LoadPackFile (char *packfile)
packfile_t *newfiles;
int numpackfiles;
pack_t *pack;
FILE *packhandle;
QFile *packhandle;
dpackfile_t info[MAX_FILES_IN_PACK];
if (COM_FileOpenRead (packfile, &packhandle) == -1)
return NULL;
fread (&header, 1, sizeof(header), packhandle);
Qread (packhandle, &header, sizeof(header));
if (header.id[0] != 'P' || header.id[1] != 'A'
|| header.id[2] != 'C' || header.id[3] != 'K')
Sys_Error ("%s is not a packfile", packfile);
@ -517,8 +517,8 @@ pack_t *COM_LoadPackFile (char *packfile)
newfiles = Z_Malloc (numpackfiles * sizeof(packfile_t));
fseek (packhandle, header.dirofs, SEEK_SET);
fread (info, 1, header.dirlen, packhandle);
Qseek (packhandle, header.dirofs, SEEK_SET);
Qread (packhandle, info, header.dirlen);
// parse the directory
@ -778,7 +778,7 @@ void COM_Gamedir (char *dir)
{
if (com_searchpaths->pack)
{
fclose (com_searchpaths->pack->handle);
Qclose (com_searchpaths->pack->handle);
Z_Free (com_searchpaths->pack->files);
Z_Free (com_searchpaths->pack);
}

View file

@ -6,7 +6,23 @@ QFile *Qopen(const char *path, const char *mode)
{
QFile *file;
file=calloc(sizeof(*file),1);
if (!file)
return 0;
file->file=fopen(path,mode);
if (!file->file)
return 0;
return file;
}
QFile *Qdopen(int fd, const char *mode)
{
QFile *file;
file=calloc(sizeof(*file),1);
if (!file)
return 0;
file->file=fdopen(fd,mode);
if (!file->file)
return 0;
return file;
}
@ -68,6 +84,22 @@ char *Qgets(QFile *file, char *buf, int count)
return gzgets(file->gzfile,buf,count);
}
int Qgetc(QFile *file)
{
if (file->file)
return fgetc(file->file);
else
return gzgetc(file->gzfile);
}
int Qputc(QFile *file, int c)
{
if (file->file)
return fputc(c, file->file);
else
return gzputc(file->gzfile,c);
}
int Qseek(QFile *file, long offset, int whence)
{
if (file->file)
@ -91,3 +123,11 @@ int Qflush(QFile *file)
else
return gzflush(file->gzfile,Z_SYNC_FLUSH);
}
int Qeof(QFile *file)
{
if (file->file)
return feof(file->file);
else
return gzeof(file->gzfile);
}

View file

@ -14,13 +14,18 @@ typedef struct {
} QFile;
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, ...);
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);
#endif /*__quake_io_h*/

View file

@ -33,9 +33,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define INI_STRING_SIZE 0x100
FILE *ini_fopen(const char *filename, const char *modes);
int ini_fclose(FILE *f);
void ini_fgets(FILE *f, const char *section, const char *field, char *s);
QFile *ini_fopen(const char *filename, const char *modes);
int ini_fclose(QFile *f);
void ini_fgets(QFile *f, const char *section, const char *field, char *s);
// Routines for reading from .INI files
// The read routines are fairly efficient.
@ -61,7 +61,7 @@ struct field_buffer
char name[MAX_FIELD_WIDTH+1];
};
static FILE *current_file=NULL;
static QFile *current_file=NULL;
static int current_section;
static int current_section_buffer=0;
@ -79,7 +79,7 @@ static char toupper(char c)
return(c);
}
static void reset_buffer(FILE *f)
static void reset_buffer(QFile *f)
{
int i;
@ -318,7 +318,7 @@ static void add_field(char *instring, int section, long offset)
// Identical to fgets except the string is trucated at the first ';',
// carriage return or line feed.
static char *stripped_fgets(char *s, int n, FILE *f)
static char *stripped_fgets(char *s, int n, QFile *f)
{
int i=0;
@ -336,13 +336,13 @@ static char *stripped_fgets(char *s, int n, FILE *f)
// Externally accessable routines
//***************************************************************************
// Opens an .INI file. Works like fopen
FILE *ini_fopen(const char *filename, const char *modes)
QFile *ini_fopen(const char *filename, const char *modes)
{
return(fopen(filename,modes));
}
// Closes a .INI file. Works like fclose
int ini_fclose(FILE *f)
int ini_fclose(QFile *f)
{
if (f==current_file)
reset_buffer(NULL);
@ -352,7 +352,7 @@ int ini_fclose(FILE *f)
// Puts "field" from "section" from .ini file "f" into "s".
// If "section" does not exist or "field" does not exist in
// section then s="";
void ini_fgets(FILE *f, const char *section, const char *field, char *s)
void ini_fgets(QFile *f, const char *section, const char *field, char *s)
{
int i;
long start_pos,string_start_pos;
@ -662,7 +662,7 @@ void ClearGf1Ints(void)
static qboolean GUS_GetIWData(void)
{
char *Interwave,s[INI_STRING_SIZE];
FILE *IwFile;
QFile *IwFile;
int CodecBase,CodecDma,i;
Interwave=getenv("INTERWAVE");

View file

@ -131,7 +131,7 @@ int Sys_FileTime (char *path)
if (stat(path, &buf) == 0) ret = buf.st_mtime;
#else /* HAVE_STAT */
FILE *f;
QFile *f;
#if defined(_WIN32) && !defined(SERVERONLY)
int t = VID_ForceUnlockedAndReturnState();
#endif

View file

@ -171,7 +171,7 @@ void Sys_DebugLog(char *file, char *fmt, ...) {
va_list argptr;
static char data[1024];
FILE *stream;
QFile *stream;
unsigned char *p;
//int fd;
@ -179,11 +179,11 @@ void Sys_DebugLog(char *file, char *fmt, ...) {
vsnprintf(data, sizeof(data), fmt, argptr);
va_end(argptr);
// fd = open(file, O_WRONLY | O_BINARY | O_CREAT | O_APPEND, 0666);
stream = fopen(file, "a");
stream = Qopen(file, "a");
for (p = (unsigned char *) data; *p; p++) {
putc(trans_table[*p], stream);
Qputc(stream, trans_table[*p]);
}
fclose(stream);
Qclose(stream);
/*
fd = open(file, O_WRONLY | O_CREAT | O_APPEND, 0666);
write(fd, data, strlen(data));

View file

@ -29,7 +29,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#define MAX_HANDLES 10
FILE *sys_handles[MAX_HANDLES];
QFile *sys_handles[MAX_HANDLES];
int findhandle (void)
{
@ -47,7 +47,7 @@ int findhandle (void)
filelength
================
*/
int filelength (FILE *f)
int filelength (QFile *f)
{
int pos;
int end;
@ -62,7 +62,7 @@ int filelength (FILE *f)
int Sys_FileOpenRead (char *path, int *hndl)
{
FILE *f;
QFile *f;
int i;
i = findhandle ();
@ -81,7 +81,7 @@ int Sys_FileOpenRead (char *path, int *hndl)
int Sys_FileOpenWrite (char *path)
{
FILE *f;
QFile *f;
int i;
i = findhandle ();

View file

@ -88,7 +88,7 @@ typedef struct
uLong crc32_wait; /* crc32 we must obtain after decompress all */
uLong rest_read_compressed; /* number of byte to be decompressed */
uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
FILE* file; /* io structore of the zipfile */
QFile* file; /* io structore of the zipfile */
uLong compression_method; /* compression method (0==store) */
uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
} file_in_zip_read_info_s;
@ -98,7 +98,7 @@ typedef struct
*/
typedef struct
{
FILE* file; /* io structore of the zipfile */
QFile* file; /* io structore of the zipfile */
unz_global_info gi; /* public global information */
uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
uLong num_file; /* number of the current file in the zipfile*/
@ -125,7 +125,7 @@ typedef struct
local int unzlocal_getByte(fin,pi)
FILE *fin;
QFile *fin;
int *pi;
{
unsigned char c;
@ -149,7 +149,7 @@ local int unzlocal_getByte(fin,pi)
Reads a long in LSB order from the given gz_stream. Sets
*/
local int unzlocal_getShort (fin,pX)
FILE* fin;
QFile* fin;
uLong *pX;
{
uLong x ;
@ -171,7 +171,7 @@ local int unzlocal_getShort (fin,pX)
}
local int unzlocal_getLong (fin,pX)
FILE* fin;
QFile* fin;
uLong *pX;
{
uLong x ;
@ -266,7 +266,7 @@ extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivit
the global comment)
*/
local uLong unzlocal_SearchCentralDir(fin)
FILE *fin;
QFile *fin;
{
unsigned char* buf;
uLong uSizeFile;
@ -336,7 +336,7 @@ extern unzFile ZEXPORT unzOpen (path)
unz_s us;
unz_s *s;
uLong central_pos,uL;
FILE * fin ;
QFile * fin ;
uLong number_disk; /* number of the current dist, used for
spaning ZIP, unsupported, always 0*/

View file

@ -538,7 +538,7 @@ CL_ParseServerData
void CL_ParseServerData (void)
{
char *str;
FILE *f;
QFile *f;
char fn[MAX_OSPATH];
qboolean cflag = false;
extern char gamedirfile[MAX_OSPATH];
@ -580,8 +580,8 @@ void CL_ParseServerData (void)
//if it exists
if (cflag) {
snprintf(fn, sizeof(fn), "%s/%s", com_gamedir, "config.cfg");
if ((f = fopen(fn, "r")) != NULL) {
fclose(f);
if ((f = Qopen(fn, "r")) != NULL) {
Qclose(f);
Cbuf_AddText ("cl_warncmd 0\n");
Cbuf_AddText("exec config.cfg\n");
Cbuf_AddText("exec frontend.cfg\n");

View file

@ -84,7 +84,7 @@ FILE IO
filelength
================
*/
int filelength (FILE *f)
int filelength (QFile *f)
{
int pos;
int end;

View file

@ -189,7 +189,7 @@ typedef struct client_s
qboolean upgradewarn; // did we warn him?
FILE *upload;
QFile *upload;
char uploadfn[MAX_QPATH];
netadr_t snap_from;
qboolean remote_snap;
@ -355,8 +355,8 @@ extern char localmodels[MAX_MODELS][5]; // inline model names for precache
extern char localinfo[MAX_LOCALINFO_STRING+1];
extern int host_hunklevel;
extern FILE *sv_logfile;
extern FILE *sv_fraglogfile;
extern QFile *sv_logfile;
extern QFile *sv_fraglogfile;
//===========================================================

View file

@ -102,14 +102,14 @@ void SV_Logfile_f (void)
if (sv_logfile)
{
Con_Printf ("File logging off.\n");
fclose (sv_logfile);
Qclose (sv_logfile);
sv_logfile = NULL;
return;
}
snprintf(name, sizeof(name), "%s/qconsole.log", com_gamedir);
Con_Printf ("Logging text to %s.\n", name);
sv_logfile = fopen (name, "w");
sv_logfile = Qopen (name, "w");
if (!sv_logfile)
Con_Printf ("failed.\n");
}
@ -128,7 +128,7 @@ void SV_Fraglogfile_f (void)
if (sv_fraglogfile)
{
Con_Printf ("Frag file logging off.\n");
fclose (sv_fraglogfile);
Qclose (sv_fraglogfile);
sv_fraglogfile = NULL;
return;
}
@ -137,15 +137,15 @@ void SV_Fraglogfile_f (void)
for (i=0 ; i<1000 ; i++)
{
snprintf(name, sizeof(name), "%s/frag_%i.log", com_gamedir, i);
sv_fraglogfile = fopen (name, "r");
sv_fraglogfile = Qopen (name, "r");
if (!sv_fraglogfile)
{ // can't read it, so create this one
sv_fraglogfile = fopen (name, "w");
sv_fraglogfile = Qopen (name, "w");
if (!sv_fraglogfile)
i=1000; // give error
break;
}
fclose (sv_fraglogfile);
Qclose (sv_fraglogfile);
}
if (i==1000)
{
@ -331,7 +331,7 @@ void SV_Map_f (void)
Con_Printf ("Can't find %s\n", expanded);
return;
}
gzclose (f);
Qclose (f);
SV_BroadcastCommand ("changing\n");
SV_SendMessagesToAll ();

View file

@ -83,8 +83,8 @@ cvar_t watervis = {"watervis", "0", false, true};
cvar_t hostname = {"hostname","unnamed", false, true};
FILE *sv_logfile;
FILE *sv_fraglogfile;
QFile *sv_logfile;
QFile *sv_fraglogfile;
void SV_AcceptClient (netadr_t adr, int userid, char *userinfo);
@ -108,12 +108,12 @@ void SV_Shutdown (void)
Shutdown_Master ();
if (sv_logfile)
{
fclose (sv_logfile);
Qclose (sv_logfile);
sv_logfile = NULL;
}
if (sv_fraglogfile)
{
fclose (sv_fraglogfile);
Qclose (sv_fraglogfile);
sv_logfile = NULL;
}
NET_Shutdown ();
@ -218,12 +218,12 @@ void SV_DropClient (client_t *drop)
if (drop->download)
{
gzclose (drop->download);
Qclose (drop->download);
drop->download = NULL;
}
if (drop->upload)
{
fclose (drop->upload);
Qclose (drop->upload);
drop->upload = NULL;
}
*drop->uploadfn = 0;
@ -1010,7 +1010,7 @@ SV_WriteIP_f
*/
void SV_WriteIP_f (void)
{
FILE *f;
QFile *f;
char name[MAX_OSPATH];
byte b[4];
int i;
@ -1019,7 +1019,7 @@ void SV_WriteIP_f (void)
Con_Printf ("Writing %s.\n", name);
f = fopen (name, "wb");
f = Qopen (name, "wb");
if (!f)
{
Con_Printf ("Couldn't open %s\n", name);
@ -1029,10 +1029,10 @@ void SV_WriteIP_f (void)
for (i=0 ; i<numipfilters ; i++)
{
*(unsigned *)b = ipfilters[i].compare;
fprintf (f, "addip %i.%i.%i.%i\n", b[0], b[1], b[2], b[3]);
Qprintf (f, "addip %i.%i.%i.%i\n", b[0], b[1], b[2], b[3]);
}
fclose (f);
Qclose (f);
}
/*

View file

@ -125,7 +125,7 @@ void Con_Printf (char *fmt, ...)
Sys_Printf ("%s", msg); // also echo to debugging console
if (sv_logfile)
fprintf (sv_logfile, "%s", msg);
Qprintf (sv_logfile, "%s", msg);
}
/*

View file

@ -533,7 +533,7 @@ void SV_NextDownload_f (void)
r = host_client->downloadsize - host_client->downloadcount;
if (r > 768)
r = 768;
r = gzread (host_client->download, buffer, r);
r = Qread (host_client->download, buffer, r);
ClientReliableWrite_Begin (host_client, svc_download, 6+r);
ClientReliableWrite_Short (host_client, r);
@ -548,7 +548,7 @@ void SV_NextDownload_f (void)
if (host_client->downloadcount != host_client->downloadsize)
return;
gzclose (host_client->download);
Qclose (host_client->download);
host_client->download = NULL;
}
@ -596,7 +596,7 @@ void SV_NextUpload (void)
if (!host_client->upload)
{
host_client->upload = fopen(host_client->uploadfn, "wb");
host_client->upload = Qopen(host_client->uploadfn, "wb");
if (!host_client->upload) {
Sys_Printf("Can't create %s\n", host_client->uploadfn);
ClientReliableWrite_Begin (host_client, svc_stufftext, 8);
@ -609,7 +609,7 @@ void SV_NextUpload (void)
OutofBandPrintf(host_client->snap_from, "Server receiving %s from %d...\n", host_client->uploadfn, host_client->userid);
}
fwrite (net_message.data + msg_readcount, 1, size, host_client->upload);
Qwrite (host_client->upload, net_message.data + msg_readcount, size);
msg_readcount += size;
Con_DPrintf ("UPLOAD: %d received\n", size);
@ -618,7 +618,7 @@ Con_DPrintf ("UPLOAD: %d received\n", size);
ClientReliableWrite_Begin (host_client, svc_stufftext, 8);
ClientReliableWrite_String (host_client, "nextul\n");
} else {
fclose (host_client->upload);
Qclose (host_client->upload);
host_client->upload = NULL;
Sys_Printf("%s upload completed.\n", host_client->uploadfn);
@ -678,7 +678,7 @@ void SV_BeginDownload_f(void)
}
if (host_client->download) {
gzclose (host_client->download);
Qclose (host_client->download);
host_client->download = NULL;
}
@ -700,7 +700,7 @@ void SV_BeginDownload_f(void)
|| (strncmp(name, "maps/", 5) == 0 && file_from_pak))
{
if (host_client->download) {
gzclose(host_client->download);
Qclose(host_client->download);
host_client->download = NULL;
}

View file

@ -57,7 +57,7 @@ void CL_StopPlayback (void)
if (!cls.demoplayback)
return;
gzclose (cls.demofile);
Qclose (cls.demofile);
cls.demoplayback = false;
cls.demofile = NULL;
cls.state = ca_disconnected;
@ -80,14 +80,14 @@ void CL_WriteDemoMessage (void)
float f;
len = LittleLong (net_message.cursize);
gzwrite (cls.demofile, &len, 4);
Qwrite (cls.demofile, &len, 4);
for (i=0 ; i<3 ; i++)
{
f = LittleFloat (cl.viewangles[i]);
gzwrite (cls.demofile, &f, 4);
Qwrite (cls.demofile, &f, 4);
}
gzwrite (cls.demofile, net_message.data, net_message.cursize);
gzflush (cls.demofile, Z_SYNC_FLUSH);
Qwrite (cls.demofile, net_message.data, net_message.cursize);
Qflush (cls.demofile);
}
/*
@ -124,18 +124,18 @@ int CL_GetMessage (void)
}
// get the next message
gzread (cls.demofile, &net_message.cursize, 4);
Qread (cls.demofile, &net_message.cursize, 4);
VectorCopy (cl.mviewangles[0], cl.mviewangles[1]);
for (i=0 ; i<3 ; i++)
{
r = gzread (cls.demofile, &f, 4);
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)
Sys_Error ("Demo message > MAX_MSGLEN");
r = gzread (cls.demofile, net_message.data, net_message.cursize);
r = Qread (cls.demofile, net_message.data, net_message.cursize);
if (r != net_message.cursize)
{
CL_StopPlayback ();
@ -190,7 +190,7 @@ void CL_Stop_f (void)
CL_WriteDemoMessage ();
// finish up
gzclose (cls.demofile);
Qclose (cls.demofile);
cls.demofile = NULL;
cls.demorecording = false;
Con_Printf ("Completed demo\n");
@ -254,7 +254,7 @@ void CL_Record_f (void)
COM_DefaultExtension (name, ".dem");
Con_Printf ("recording to %s.\n", name);
cls.demofile = gzopen (name, "wb");
cls.demofile = Qopen (name, "wb");
if (!cls.demofile)
{
Con_Printf ("ERROR: couldn't open.\n");
@ -262,7 +262,7 @@ void CL_Record_f (void)
}
cls.forcetrack = track;
gzprintf (cls.demofile, "%i\n", cls.forcetrack);
Qprintf (cls.demofile, "%i\n", cls.forcetrack);
cls.demorecording = true;
}
@ -314,7 +314,7 @@ void CL_PlayDemo_f (void)
cls.state = ca_connected;
cls.forcetrack = 0;
while ((c = gzgetc(cls.demofile)) != '\n')
while ((c = Qgetc(cls.demofile)) != '\n')
if (c == '-')
neg = true;
else

View file

@ -579,7 +579,7 @@ 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;
@ -588,6 +588,7 @@ void Host_Loadgame_f (void)
int entnum;
int version;
float spawn_parms[NUM_SPAWN_PARMS];
char buf[100];
if (cmd_source != src_command)
return;
@ -608,25 +609,30 @@ void Host_Loadgame_f (void)
// SCR_BeginLoadingPlaque ();
Con_Printf ("Loading game from %s...\n", name);
f = fopen (name, "r");
f = Qopen (name, "r");
if (!f)
{
Con_Printf ("ERROR: couldn't open.\n");
return;
}
fscanf (f, "%i\n", &version);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%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]);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%s\n", str);
for (i=0 ; i<NUM_SPAWN_PARMS ; i++) {
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%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);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%f\n", &tfloat);
current_skill = (int)(tfloat + 0.1);
Cvar_SetValue ("skill", (float)current_skill);
@ -636,8 +642,10 @@ void Host_Loadgame_f (void)
Cvar_SetValue ("teamplay", 0);
#endif
fscanf (f, "%s\n",mapname);
fscanf (f, "%f\n",&time);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%s\n",mapname);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%f\n",&time);
CL_Disconnect_f ();
@ -658,18 +666,19 @@ void Host_Loadgame_f (void)
for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
{
fscanf (f, "%s\n", str);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%s\n", str);
sv.lightstyles[i] = Hunk_Alloc (strlen(str)+1);
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++)
{
r = fgetc (f);
r = Qgetc (f);
if (r == EOF || !r)
break;
str[i] = r;
@ -712,7 +721,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];
@ -728,7 +737,7 @@ void Host_Loadgame_f (void)
void SaveGamestate()
{
char name[256];
FILE *f;
QFile *f;
int i;
char comment[SAVEGAME_COMMENT_LENGTH+1];
edict_t *ent;
@ -772,14 +781,14 @@ void SaveGamestate()
ED_Write (f, ent);
fflush (f);
}
fclose (f);
Qclose (f);
Con_Printf ("done.\n");
}
int LoadGamestate(char *level, char *startspot)
{
char name[MAX_OSPATH];
FILE *f;
QFile *f;
char mapname[MAX_QPATH];
float time, sk;
char str[32768], *start;
@ -799,21 +808,28 @@ int LoadGamestate(char *level, char *startspot)
return -1;
}
fscanf (f, "%i\n", &version);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%i\n", &version);
if (version != SAVEGAME_VERSION)
{
fclose (f);
Qclose (f);
Con_Printf ("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
return -1;
}
fscanf (f, "%s\n", str);
// for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
// fscanf (f, "%f\n", &spawn_parms[i]);
fscanf (f, "%f\n", &sk);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%s\n", str);
// for (i=0 ; i<NUM_SPAWN_PARMS ; i++) {
// Qgets(f,buf,sizeof(buf));
// sscanf (buf, "%f\n", &spawn_parms[i]);
// }
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%f\n", &sk);
Cvar_SetValue ("skill", sk);
fscanf (f, "%s\n",mapname);
fscanf (f, "%f\n",&time);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%s\n",mapname);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%f\n",&time);
SV_SpawnServer (mapname, startspot);
@ -826,7 +842,8 @@ int LoadGamestate(char *level, char *startspot)
// load the light styles
for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
{
fscanf (f, "%s\n", str);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%s\n", str);
sv.lightstyles[i] = Hunk_Alloc (strlen(str)+1);
strcpy (sv.lightstyles[i], str);
}
@ -834,10 +851,11 @@ int LoadGamestate(char *level, char *startspot)
// load the edicts out of the savegame file
while (!feof(f))
{
fscanf (f, "%i\n",&entnum);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%i\n",&entnum);
for (i=0 ; i<sizeof(str)-1 ; i++)
{
r = fgetc (f);
r = Qgetc (f);
if (r == EOF || !r)
break;
str[i] = r;
@ -871,7 +889,7 @@ int LoadGamestate(char *level, char *startspot)
// 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];

View file

@ -473,19 +473,22 @@ void M_ScanSaves (void)
{
int i, j;
char name[MAX_OSPATH];
FILE *f;
QFile *f;
int version;
char buf[100];
for (i=0 ; i<MAX_SAVEGAMES ; i++)
{
strcpy (m_filenames[i], "--- UNUSED SLOT ---");
loadable[i] = false;
snprintf(name, sizeof(name), "%s/s%i.sav", com_gamedir, i);
f = fopen (name, "r");
f = Qopen (name, "r");
if (!f)
continue;
fscanf (f, "%i\n", &version);
fscanf (f, "%79s\n", name);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%i\n", &version);
Qgets(f,buf,sizeof(buf));
sscanf (buf, "%79s\n", name);
strncpy (m_filenames[i], name, sizeof(m_filenames[i])-1);
// change _ back to space
@ -493,7 +496,7 @@ void M_ScanSaves (void)
if (m_filenames[i][j] == '_')
m_filenames[i][j] = ' ';
loadable[i] = true;
fclose (f);
Qclose (f);
}
}

View file

@ -60,7 +60,7 @@ FILE IO
typedef struct
{
FILE *hFile;
QFile *hFile;
char *pMap;
int nLen;
int nPos;
@ -84,7 +84,7 @@ int findhandle (void)
filelength
================
*/
int filelength (FILE *f)
int filelength (QFile *f)
{
int pos;
int end;
@ -99,7 +99,7 @@ int filelength (FILE *f)
int Sys_FileOpenRead (char *path, int *hndl)
{
FILE *f;
QFile *f;
int i;
i = findhandle ();
@ -127,7 +127,7 @@ int Sys_FileOpenRead (char *path, int *hndl)
int Sys_FileOpenWrite (char *path)
{
FILE *f;
QFile *f;
int i;
i = findhandle ();
@ -188,7 +188,7 @@ void Sys_DebugLog(char *file, char *fmt, ...) {
va_list argptr;
static char data[1024];
FILE *stream;
QFile *stream;
unsigned char *p;
//int fd;

View file

@ -97,7 +97,7 @@ FILE IO
*/
#define MAX_HANDLES 10
FILE *sys_handles[MAX_HANDLES];
QFile *sys_handles[MAX_HANDLES];
int findhandle (void)
{
@ -116,7 +116,7 @@ int findhandle (void)
filelength
================
*/
int filelength (FILE *f)
int filelength (QFile *f)
{
int pos;
int end;
@ -137,7 +137,7 @@ int filelength (FILE *f)
int Sys_FileOpenRead (char *path, int *hndl)
{
FILE *f;
QFile *f;
int i, retval;
int t;
@ -166,7 +166,7 @@ int Sys_FileOpenRead (char *path, int *hndl)
int Sys_FileOpenWrite (char *path)
{
FILE *f;
QFile *f;
int i;
int t;

View file

@ -35,7 +35,7 @@ FILE IO
*/
#define MAX_HANDLES 10
FILE *sys_handles[MAX_HANDLES];
QFile *sys_handles[MAX_HANDLES];
int findhandle (void)
{
@ -53,7 +53,7 @@ int findhandle (void)
filelength
================
*/
int filelength (FILE *f)
int filelength (QFile *f)
{
int pos;
int end;
@ -68,7 +68,7 @@ int filelength (FILE *f)
int Sys_FileOpenRead (char *path, int *hndl)
{
FILE *f;
QFile *f;
int i;
i = findhandle ();
@ -87,7 +87,7 @@ int Sys_FileOpenRead (char *path, int *hndl)
int Sys_FileOpenWrite (char *path)
{
FILE *f;
QFile *f;
int i;
i = findhandle ();

View file

@ -97,7 +97,7 @@ FILE IO
*/
#define MAX_HANDLES 10
FILE *sys_handles[MAX_HANDLES];
QFile *sys_handles[MAX_HANDLES];
int findhandle (void)
{
@ -115,7 +115,7 @@ int findhandle (void)
filelength
================
*/
int wfilelength (FILE *f)
int wfilelength (QFile *f)
{
int pos;
int end;
@ -135,7 +135,7 @@ int wfilelength (FILE *f)
int Sys_FileOpenRead (char *path, int *hndl)
{
FILE *f;
QFile *f;
int i, retval;
int t;
@ -164,7 +164,7 @@ int Sys_FileOpenRead (char *path, int *hndl)
int Sys_FileOpenWrite (char *path)
{
FILE *f;
QFile *f;
int i;
int t;