Before I can fix the (MANY!) problems with newtree, I have to fix the

little problem of mixed QFile and FILE.  Since we're not using ZLib in
this tree, QFile makes no real sense.  That didn't fix the real problem
I am having though.
This commit is contained in:
Joseph Carter 2000-05-22 21:16:22 +00:00
parent 08b551f7ae
commit 3d59dfed98
24 changed files with 127 additions and 280 deletions

View File

@ -49,8 +49,8 @@ void Server_List_Swap(server_entry_t *swap1, server_entry_t *swap2);
server_entry_t *Server_List_Get_By_Num(server_entry_t *start, int n);
int Server_List_Len(server_entry_t *start);
server_entry_t *Server_List_LoadF(QFile *f, server_entry_t *start);
void Server_List_SaveF(QFile *f, server_entry_t *start);
server_entry_t *Server_List_LoadF(FILE *f, server_entry_t *start);
void Server_List_SaveF(FILE *f, server_entry_t *start);
void Server_List_Del_All(server_entry_t *start);
void Server_List_Shutdown(server_entry_t *start);

View File

@ -199,7 +199,7 @@ typedef struct
int qport;
QFile *download; // file transfer from server
FILE *download; // file transfer from server
char downloadtempname[MAX_OSPATH];
char downloadname[MAX_OSPATH];
int downloadnumber;
@ -215,7 +215,7 @@ typedef struct
qboolean demorecording;
qboolean demoplayback;
qboolean timedemo;
QFile *demofile;
FILE *demofile;
float td_lastframe; // to meter out one message a frame
int td_startframe; // host_framecount at start
float td_starttime; // realtime at second frame of timedemo

View File

@ -100,7 +100,7 @@ qboolean Cvar_Command (void);
// command. Returns true if the command was a variable reference that
// was handled. (print or change)
void Cvar_WriteVariables (QFile *f);
void Cvar_WriteVariables (FILE *f);
// Writes lines containing "set variable value" for all variables
// with the archive flag set to true.

View File

@ -175,7 +175,7 @@ extern qboolean chat_team;
void Key_Event (int key, qboolean down);
void Key_Init (void);
void Key_WriteBindings (QFile *f);
void Key_WriteBindings (FILE *f);
void Key_SetBinding (int keynum, char *binding);
void Key_ClearStates (void);

View File

@ -49,9 +49,9 @@ extern char com_gamedir[MAX_OSPATH];
extern char gamedirfile[MAX_OSPATH];
void COM_WriteFile (char *filename, void *data, int len);
int COM_FOpenFile (char *filename, QFile **gzfile);
void COM_CloseFile (QFile *h);
int COM_filelength (QFile *f);
int COM_FOpenFile (char *filename, FILE **gzfile);
void COM_CloseFile (FILE *h);
int COM_filelength (FILE *f);
void COM_FileBase (char *in, char *out);
void COM_DefaultExtension (char *path, char *extension);
char *COM_SkipPath (char *pathname);

View File

@ -33,32 +33,22 @@
#include <stdio.h>
#include <config.h>
#ifdef HAS_ZLIB
#include <zlib.h>
#endif
typedef struct {
FILE *file;
#ifdef HAS_ZLIB
gzFile *gzfile;
#endif
} QFile;
void Qexpand_squiggle(const char *path, char *dest);
int Qrename(const char *old, const char *new);
QFile *Qopen(const char *path, const char *mode);
QFile *Qdopen(int fd, const char *mode);
void Qclose(QFile *file);
int Qread(QFile *file, void *buf, int count);
int Qwrite(QFile *file, void *buf, int count);
int Qprintf(QFile *file, const char *fmt, ...);
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);
FILE *Qopen(const char *path, const char *mode);
FILE *Qdopen(int fd, const char *mode);
void Qclose(FILE *file);
int Qread(FILE *file, void *buf, int count);
int Qwrite(FILE *file, void *buf, int count);
int Qprintf(FILE *file, const char *fmt, ...);
char *Qgets(FILE *file, char *buf, int count);
int Qgetc(FILE *file);
int Qputc(FILE *file, int c);
int Qseek(FILE *file, long offset, int whence);
long Qtell(FILE *file);
int Qflush(FILE *file);
int Qeof(FILE *file);
#endif /*_QUAKEIO_H*/

View File

@ -187,7 +187,7 @@ typedef struct client_s
client_frame_t frames[UPDATE_BACKUP]; // updates can be deltad from here
QFile *download; // file being downloaded
FILE *download; // file being downloaded
int downloadsize; // total bytes
int downloadcount; // bytes sent
@ -199,7 +199,7 @@ typedef struct client_s
qboolean upgradewarn; // did we warn him?
QFile *upload;
FILE *upload;
char uploadfn[MAX_QPATH];
netadr_t snap_from;
qboolean remote_snap;
@ -363,8 +363,8 @@ extern char localmodels[MAX_MODELS][5]; // inline model names for precache
extern char localinfo[MAX_LOCALINFO_STRING+1];
extern int host_hunklevel;
extern QFile *sv_logfile;
extern QFile *sv_fraglogfile;
extern FILE *sv_logfile;
extern FILE *sv_fraglogfile;
//===========================================================
// FIXME: declare exported functions in their own relevant .h

View File

@ -1186,8 +1186,8 @@ CL_Init
*/
void CL_Init (void)
{
QFile *servlist;
char st[80];
FILE *servlist;
char st[80];
cls.state = ca_disconnected;
@ -1484,7 +1484,7 @@ Writes key bindings and archived cvars to config.cfg
*/
void Host_WriteConfiguration (void)
{
QFile *f;
FILE *f;
if (host_initialized)
{

View File

@ -178,7 +178,7 @@ to start a download from the server.
*/
qboolean CL_CheckOrDownloadFile (char *filename)
{
QFile *f;
FILE *f;
if (strstr (filename, ".."))
{
@ -548,7 +548,7 @@ CL_ParseServerData
void CL_ParseServerData (void)
{
char *str;
QFile *f;
FILE *f;
char fn[MAX_OSPATH];
qboolean cflag = false;
extern char gamedirfile[MAX_OSPATH];

View File

@ -138,7 +138,7 @@ int Server_List_Len (server_entry_t *start) {
return i;
}
server_entry_t *Server_List_LoadF (QFile *f,server_entry_t *start) { // This could get messy
server_entry_t *Server_List_LoadF (FILE *f,server_entry_t *start) { // This could get messy
char line[256]; /* Long lines get truncated. */
int c = ' '; /* int so it can be compared to EOF properly*/
int len;
@ -175,7 +175,7 @@ server_entry_t *Server_List_LoadF (QFile *f,server_entry_t *start) { // This cou
}
}
void Server_List_SaveF (QFile *f,server_entry_t *start) {
void Server_List_SaveF (FILE *f,server_entry_t *start) {
do {
Qprintf(f,"%s %s\n",start->server,start->desc);
start = start->next;
@ -184,7 +184,7 @@ server_entry_t *Server_List_LoadF (QFile *f,server_entry_t *start) { // This cou
}
void Server_List_Shutdown (server_entry_t *start) {
QFile *f;
FILE *f;
if (start) {
if ((f = Qopen(va("%s/servers.txt",fs_userpath->string),"w"))) {
Server_List_SaveF(f,start);

View File

@ -305,7 +305,7 @@ Cmd_Exec_File (char *path)
int mark;
int len;
char base[32];
QFile *file;
FILE *file;
if ((file = Qopen (path, "r")) != NULL) {
// extract the filename base name for hunk tag

View File

@ -62,7 +62,7 @@ being registered.
*/
void COM_CheckRegistered (void)
{
QFile *h;
FILE *h;
unsigned short check[128];
COM_FOpenFile("gfx/pop.lmp", &h);

View File

@ -247,7 +247,7 @@ Writes lines containing "set variable value" for all variables
with the archive flag set to true.
============
*/
void Cvar_WriteVariables (QFile *f)
void Cvar_WriteVariables (FILE *f)
{
cvar_t *var;

View File

@ -320,7 +320,7 @@ void GL_MakeAliasModelDisplayLists (model_t *m, aliashdr_t *hdr)
int *cmds;
trivertx_t *verts;
char cache[MAX_QPATH], fullpath[MAX_OSPATH];
QFile *f;
FILE *f;
aliasmodel = m;
paliashdr = hdr; // (aliashdr_t *)Mod_Extradata (m);

View File

@ -120,7 +120,7 @@ void R_ClearParticles (void)
void R_ReadPointFile_f (void)
{
QFile *f;
FILE *f;
vec3_t org;
int r;
int c;

View File

@ -357,7 +357,7 @@ byte *pcx_rgb;
LoadPCX
============
*/
void LoadPCX (QFile *f)
void LoadPCX (FILE *f)
{
pcx_t *pcx, pcxbuf;
byte palette[768];
@ -441,7 +441,7 @@ typedef struct _TargaHeader {
TargaHeader targa_header;
byte *targa_rgba;
int fgetLittleShort (QFile *f)
int fgetLittleShort (FILE *f)
{
byte b1, b2;
@ -451,7 +451,7 @@ int fgetLittleShort (QFile *f)
return (short)(b1 + b2*256);
}
int fgetLittleLong (QFile *f)
int fgetLittleLong (FILE *f)
{
byte b1, b2, b3, b4;
@ -469,7 +469,7 @@ int fgetLittleLong (QFile *f)
LoadTGA
=============
*/
void LoadTGA (QFile *fin)
void LoadTGA (FILE *fin)
{
int columns, rows, numPixels;
byte *pixbuf;
@ -626,7 +626,7 @@ char *suf[6] = {"rt", "bk", "lf", "ft", "up", "dn"};
void R_LoadSkys (char * skyname)
{
int i;
QFile *f;
FILE *f;
char name[64];
if (stricmp (skyname, "none") == 0)

View File

@ -667,7 +667,7 @@ Key_WriteBindings
Writes lines containing "bind key value"
============
*/
void Key_WriteBindings (QFile *f)
void Key_WriteBindings (FILE *f)
{
int i;

View File

@ -1317,33 +1317,33 @@ void M_Quit_Draw (void)
{
#define VSTR(x) #x
#define VSTR2(x) VSTR(x)
char *cmsg[] = {
// char *cmsg[] = {
// 0123456789012345678901234567890123456789
"0 QuakeWorld",
"1 version " VSTR2(VERSION) " by id Software",
"0Programming",
"1 John Carmack Michael Abrash",
"1 John Cash Christian Antkow",
"0Additional Programming",
"1 Dave 'Zoid' Kirsch",
"1 Jack 'morbid' Mathews",
"0Id Software is not responsible for",
"0providing technical support for",
"0QUAKEWORLD(tm). (c)1996 Id Software,",
"0Inc. All Rights Reserved.",
"0QUAKEWORLD(tm) is a trademark of Id",
"0Software, Inc.",
"1NOTICE: THE COPYRIGHT AND TRADEMARK",
"1NOTICES APPEARING IN YOUR COPY OF",
"1QUAKE(r) ARE NOT MODIFIED BY THE USE",
"1OF QUAKEWORLD(tm) AND REMAIN IN FULL",
"1FORCE.",
"0NIN(r) is a registered trademark",
"0licensed to Nothing Interactive, Inc.",
"0All rights reserved. Press y to exit",
NULL };
char **p;
int y;
// "0 QuakeWorld",
// "1 version " VSTR2(VERSION) " by id Software",
// "0Programming",
// "1 John Carmack Michael Abrash",
// "1 John Cash Christian Antkow",
// "0Additional Programming",
// "1 Dave 'Zoid' Kirsch",
// "1 Jack 'morbid' Mathews",
// "0Id Software is not responsible for",
// "0providing technical support for",
// "0QUAKEWORLD(tm). (c)1996 Id Software,",
// "0Inc. All Rights Reserved.",
// "0QUAKEWORLD(tm) is a trademark of Id",
// "0Software, Inc.",
// "1NOTICE: THE COPYRIGHT AND TRADEMARK",
// "1NOTICES APPEARING IN YOUR COPY OF",
// "1QUAKE(r) ARE NOT MODIFIED BY THE USE",
// "1OF QUAKEWORLD(tm) AND REMAIN IN FULL",
// "1FORCE.",
// "0NIN(r) is a registered trademark",
// "0licensed to Nothing Interactive, Inc.",
// "0All rights reserved. Press y to exit",
// NULL };
// char **p;
// int y;
if (wasInMenus)
{
@ -1352,7 +1352,7 @@ void M_Quit_Draw (void)
M_Draw ();
m_state = m_quit;
}
#if 1
#if 0
M_DrawTextBox (0, 0, 38, 23);
y = 12;
for (p = cmsg; *p; p++, y += 8) {

View File

@ -121,7 +121,7 @@ typedef struct
typedef struct pack_s
{
char filename[MAX_OSPATH];
QFile *handle;
FILE *handle;
int numfiles;
packfile_t *files;
} pack_t;
@ -186,7 +186,7 @@ COM_FileBase (char *in, char *out)
COM_filelength
*/
int
COM_filelength (QFile *f)
COM_filelength (FILE *f)
{
int pos;
int end;
@ -203,9 +203,9 @@ COM_filelength (QFile *f)
COM_FileOpenRead
*/
int
COM_FileOpenRead (char *path, QFile **hndl)
COM_FileOpenRead (char *path, FILE **hndl)
{
QFile *f;
FILE *f;
f = Qopen(path, "rbz");
if (!f)
@ -285,7 +285,7 @@ COM_Maplist_f ( void )
void
COM_WriteFile ( char *filename, void *data, int len )
{
QFile *f;
FILE *f;
char name[MAX_OSPATH];
snprintf(name, sizeof(name), "%s/%s", com_gamedir, filename);
@ -338,7 +338,7 @@ COM_CreatePath ( char *path )
void
COM_CopyFile (char *netpath, char *cachepath)
{
QFile *in, *out;
FILE *in, *out;
int remaining, count;
char buf[4096];
@ -366,7 +366,7 @@ COM_CopyFile (char *netpath, char *cachepath)
/*
COM_OpenRead
*/
QFile *
FILE *
COM_OpenRead (const char *path, int offs, int len)
{
int fd=open(path,O_RDONLY);
@ -406,7 +406,7 @@ int file_from_pak; // global indicating file came from pack file ZOID
Sets com_filesize and one of handle or file
*/
int
COM_FOpenFile (char *filename, QFile **gzfile)
COM_FOpenFile (char *filename, FILE **gzfile)
{
searchpath_t *search;
char netpath[MAX_OSPATH];
@ -482,7 +482,7 @@ int loadsize;
byte *
COM_LoadFile (char *path, int usehunk)
{
QFile *h;
FILE *h;
byte *buf;
char base[32];
int len;
@ -579,7 +579,7 @@ COM_LoadPackFile (char *packfile)
packfile_t *newfiles;
int numpackfiles;
pack_t *pack;
QFile *packhandle;
FILE *packhandle;
dpackfile_t info[MAX_FILES_IN_PACK];
if (COM_FileOpenRead (packfile, &packhandle) == -1)

View File

@ -32,24 +32,24 @@
# include <config.h>
#endif
#ifdef HAVE_MALLOC_H
#include <malloc.h>
# include <malloc.h>
#endif
#include <stdarg.h>
#include <stdlib.h>
#include <quakeio.h>
#include <string.h>
#ifdef WIN32
#include <io.h>
#include <fcntl.h>
# include <io.h>
# include <fcntl.h>
#else
#include <pwd.h>
# include <pwd.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
# include <unistd.h>
#endif
#ifdef _MSC_VER
#define _POSIX_
# define _POSIX_
#endif
#include <limits.h>
@ -91,247 +91,104 @@ Qrename(const char *old, const char *new)
return rename (e_old, e_new);
}
QFile *
FILE *
Qopen(const char *path, const char *mode)
{
QFile *file;
char m[80],*p;
int zip=0;
FILE *file;
char e_path[PATH_MAX];
Qexpand_squiggle (path, e_path);
path = e_path;
for (p=m; *mode && p-m<(sizeof(m)-1); mode++) {
if (*mode=='z') {
zip=1;
continue;
}
*p++=*mode;
}
*p=0;
file=calloc(sizeof(*file),1);
if (!file)
return 0;
#ifdef HAS_ZLIB
if (zip) {
file->gzfile=gzopen(path,m);
if (!file->gzfile) {
free(file);
return 0;
}
} else
#endif
{
file->file=fopen(path,m);
if (!file->file) {
free(file);
return 0;
}
}
file=fopen(path,mode);
return file;
}
QFile *
FILE *
Qdopen(int fd, const char *mode)
{
QFile *file;
char m[80],*p;
int zip=0;
FILE *file;
for (p=m; *mode && p-m<(sizeof(m)-1); mode++) {
if (*mode=='z') {
zip=1;
continue;
}
*p++=*mode;
}
*p=0;
file=calloc(sizeof(*file),1);
if (!file)
return 0;
#ifdef HAS_ZLIB
if (zip) {
file->gzfile=gzdopen(fd,m);
if (!file->gzfile) {
free(file);
return 0;
}
} else
#endif
{
file->file=fdopen(fd,m);
if (!file->file) {
free(file);
return 0;
}
}
file=fdopen(fd,mode);
#ifdef WIN32
#ifdef __BORLANDC__
setmode(_fileno(file->file),O_BINARY);
#else
_setmode(_fileno(file->file),_O_BINARY);
#endif
# ifdef __BORLANDC__
setmode(_fileno(file),O_BINARY);
# else
_setmode(_fileno(file),_O_BINARY);
# endif
#endif
return file;
}
void
Qclose(QFile *file)
Qclose(FILE *file)
{
if (file->file)
fclose(file->file);
#ifdef HAS_ZLIB
else
gzclose(file->gzfile);
#endif
fclose(file);
free(file);
}
int
Qread(QFile *file, void *buf, int count)
Qread(FILE *file, void *buf, int count)
{
if (file->file)
return fread(buf, 1, count, file->file);
#ifdef HAS_ZLIB
else
return gzread(file->gzfile,buf,count);
#else
return -1;
#endif
return fread(buf, 1, count, file);
}
int
Qwrite(QFile *file, void *buf, int count)
Qwrite(FILE *file, void *buf, int count)
{
if (file->file)
return fwrite(buf, 1, count, file->file);
#ifdef HAS_ZLIB
else
return gzwrite(file->gzfile,buf,count);
#else
return -1;
#endif
return fwrite(buf, 1, count, file);
}
int
Qprintf(QFile *file, const char *fmt, ...)
Qprintf(FILE *file, const char *fmt, ...)
{
va_list args;
int ret=-1;
va_start(args,fmt);
if (file->file)
ret=vfprintf(file->file, fmt, args);
#ifdef HAS_ZLIB
else {
char buf[4096];
va_start(args, fmt);
#ifdef HAVE_VSNPRINTF
(void)vsnprintf(buf, sizeof(buf), fmt, args);
#else
(void)vsprintf(buf, fmt, args);
#endif
va_end(args);
ret = strlen(buf); /* some *sprintf don't return the nb of bytes written */
if (ret>0)
ret=gzwrite(file, buf, (unsigned)ret);
}
#endif
ret=vfprintf(file, fmt, args);
va_end(args);
return ret;
}
char *
Qgets(QFile *file, char *buf, int count)
Qgets(FILE *file, char *buf, int count)
{
if (file->file)
return fgets(buf, count, file->file);
#ifdef HAS_ZLIB
else
return gzgets(file->gzfile,buf,count);
#else
return 0;
#endif
return fgets(buf, count, file);
}
int
Qgetc(QFile *file)
Qgetc(FILE *file)
{
if (file->file)
return fgetc(file->file);
#ifdef HAS_ZLIB
else
return gzgetc(file->gzfile);
#else
return -1;
#endif
return fgetc(file);
}
int
Qputc(QFile *file, int c)
Qputc(FILE *file, int c)
{
if (file->file)
return fputc(c, file->file);
#ifdef HAS_ZLIB
else
return gzputc(file->gzfile,c);
#else
return -1;
#endif
return fputc(c, file);
}
int
Qseek(QFile *file, long offset, int whence)
Qseek(FILE *file, long offset, int whence)
{
if (file->file)
return fseek(file->file, offset, whence);
#ifdef HAS_ZLIB
else
return gzseek(file->gzfile,offset,whence);
#else
return -1;
#endif
return fseek(file, offset, whence);
}
long
Qtell(QFile *file)
Qtell(FILE *file)
{
if (file->file)
return ftell(file->file);
#ifdef HAS_ZLIB
else
return gztell(file->gzfile);
#else
return -1;
#endif
return ftell(file);
}
int
Qflush(QFile *file)
Qflush(FILE *file)
{
if (file->file)
return fflush(file->file);
#ifdef HAS_ZLIB
else
return gzflush(file->gzfile,Z_SYNC_FLUSH);
#else
return -1;
#endif
return fflush(file);
}
int
Qeof(QFile *file)
Qeof(FILE *file)
{
if (file->file)
return feof(file->file);
#ifdef HAS_ZLIB
else
return gzeof(file->gzfile);
#else
return -1;
#endif
return feof(file);
}

View File

@ -101,7 +101,7 @@ void R_ClearParticles (void)
void R_ReadPointFile_f (void)
{
QFile *f;
FILE *f;
vec3_t org;
int r;
int c;

View File

@ -332,7 +332,7 @@ void SV_Map_f (void)
{
char level[MAX_QPATH];
char expanded[MAX_QPATH];
QFile *f;
FILE *f;
if (Cmd_Argc() != 2)
{

View File

@ -163,8 +163,8 @@ cvar_t *watervis;
CVAR_FIXME */
cvar_t *hostname;
QFile *sv_logfile;
QFile *sv_fraglogfile;
FILE *sv_logfile;
FILE *sv_fraglogfile;
void SV_AcceptClient (netadr_t adr, int userid, char *userinfo);
void Master_Shutdown (void);
@ -1110,7 +1110,7 @@ SV_WriteIP_f
*/
void SV_WriteIP_f (void)
{
QFile *f;
FILE *f;
char name[MAX_OSPATH];
byte b[4];
int i;

View File

@ -480,7 +480,7 @@ void VID_SetPalette (unsigned char *palette)
int k;
unsigned short i;
unsigned *table;
QFile *f;
FILE *f;
char s[255];
float dist, bestdist;
static qboolean palflag = false;