char com_token[1024];
char com_basedir[MAX_OSPATH];
int com_argc;
-char **com_argv;
+const char **com_argv;
// LordHavoc: made commandline 1024 characters instead of 256
#define CMDLINE_LENGTH 1024
============================================================================
*/
-int Q_strncasecmp (char *s1, char *s2, int n)
+int Q_strncasecmp (const char *s1, const char *s2, int n)
{
int c1, c2;
return -1;
}
-int Q_strcasecmp (char *s1, char *s2)
+int Q_strcasecmp (const char *s1, const char *s2)
{
return Q_strncasecmp (s1, s2, 99999);
}
SZ_Write (sb, &dat.l, 4);
}
-void MSG_WriteString (sizebuf_t *sb, char *s)
+void MSG_WriteString (sizebuf_t *sb, const char *s)
{
if (!s)
SZ_Write (sb, "", 1);
//
// reading functions
//
-int msg_readcount;
-qboolean msg_badread;
+int msg_readcount;
+qboolean msg_badread;
void MSG_BeginReading (void)
{
int MSG_ReadShort (void)
{
- int c;
+ int c;
if (msg_readcount+2 > net_message.cursize)
{
int MSG_ReadLong (void)
{
- int c;
+ int c;
if (msg_readcount+4 > net_message.cursize)
{
{
union
{
- qbyte b[4];
- float f;
- int l;
+ qbyte b[4];
+ float f;
+ int l;
} dat;
dat.b[0] = net_message.data[msg_readcount];
char *MSG_ReadString (void)
{
- static char string[2048];
- int l,c;
+ static char string[2048];
+ int l,c;
l = 0;
do
//===========================================================================
-void SZ_Alloc (sizebuf_t *buf, int startsize, char *name)
+void SZ_Alloc (sizebuf_t *buf, int startsize, const char *name)
{
if (startsize < 256)
startsize = 256;
void *SZ_GetSpace (sizebuf_t *buf, int length)
{
- void *data;
+ void *data;
if (buf->cursize + length > buf->maxsize)
{
if (!buf->allowoverflow)
- Host_Error ("SZ_GetSpace: overflow without allowoverflow set");
+ Host_Error ("SZ_GetSpace: overflow without allowoverflow set\n");
if (length > buf->maxsize)
- Host_Error ("SZ_GetSpace: %i is > full buffer size", length);
+ Host_Error ("SZ_GetSpace: %i is > full buffer size\n", length);
buf->overflowed = true;
- Con_Printf ("SZ_GetSpace: overflow");
+ Con_Printf ("SZ_GetSpace: overflow\n");
SZ_Clear (buf);
}
data = buf->data + buf->cursize;
buf->cursize += length;
-
+
return data;
}
-void SZ_Write (sizebuf_t *buf, void *data, int length)
+void SZ_Write (sizebuf_t *buf, const void *data, int length)
{
- memcpy (SZ_GetSpace(buf,length),data,length);
+ memcpy (SZ_GetSpace(buf,length),data,length);
}
-void SZ_Print (sizebuf_t *buf, char *data)
+void SZ_Print (sizebuf_t *buf, const char *data)
{
- int len;
-
+ int len;
len = strlen(data)+1;
// byte * cast to keep VC++ happy
memcpy ((qbyte *)SZ_GetSpace(buf, len-1)-1,data,len); // write over trailing 0
}
-
-//============================================================================
-
-
-/*
-============
-COM_SkipPath
-============
-*/
-char *COM_SkipPath (char *pathname)
+static char *hexchar = "0123456789ABCDEF";
+void SZ_HexDumpToConsole(const sizebuf_t *buf)
{
- char *last;
-
- last = pathname;
- while (*pathname)
+ int i;
+ char text[1024];
+ char *cur, *flushpointer;
+ cur = text;
+ flushpointer = text + 512;
+ for (i = 0;i < buf->cursize;i++)
+ {
+ if ((i & 15) == 0)
+ {
+ *cur++ = hexchar[(i >> 12) & 15];
+ *cur++ = hexchar[(i >> 8) & 15];
+ *cur++ = hexchar[(i >> 4) & 15];
+ *cur++ = hexchar[(i >> 0) & 15];
+ *cur++ = ':';
+ *cur++ = ' ';
+ }
+ else if ((i & 15) == 15)
+ *cur++ = '\n';
+ else
+ *cur++ = ' ';
+ if (i & 1)
+ {
+ *cur++ = hexchar[(buf->data[i] >> 4) & 15] | 0x80;
+ *cur++ = hexchar[(buf->data[i] >> 0) & 15] | 0x80;
+ }
+ else
+ {
+ *cur++ = hexchar[(buf->data[i] >> 4) & 15];
+ *cur++ = hexchar[(buf->data[i] >> 0) & 15];
+ }
+ if (cur >= flushpointer)
+ {
+ *cur++ = 0;
+ Con_Printf("%s", text);
+ cur = text;
+ }
+ }
+ if ((i & 15) != 0)
+ *cur++ = '\n';
+ if (cur > text)
{
- if (*pathname=='/')
- last = pathname+1;
- pathname++;
+ *cur++ = 0;
+ Con_Printf("%s", text);
}
- return last;
}
+
+//============================================================================
+
+
/*
============
COM_StripExtension
============
*/
// LordHavoc: replacement for severely broken COM_StripExtension that was used in original quake.
-void COM_StripExtension (char *in, char *out)
+void COM_StripExtension (const char *in, char *out)
{
char *last = NULL;
while (*in)
COM_FileExtension
============
*/
-char *COM_FileExtension (char *in)
+char *COM_FileExtension (const char *in)
{
static char exten[8];
- int i;
+ int i;
while (*in && *in != '.')
in++;
COM_FileBase
============
*/
-void COM_FileBase (char *in, char *out)
+void COM_FileBase (const char *in, char *out)
{
- char *slash, *dot;
- char *s;
+ const char *slash, *dot, *s;
slash = in;
dot = NULL;
COM_DefaultExtension
==================
*/
-void COM_DefaultExtension (char *path, char *extension)
+void COM_DefaultExtension (char *path, const char *extension)
{
- char *src;
+ const char *src;
//
// if path doesn't have a .EXT, append extension
// (extension should include the .)
/*
==============
-COM_Parse
+COM_ParseToken
Parse a token out of a string
==============
*/
-char *COM_Parse (char *data)
+int COM_ParseToken (const char **datapointer)
{
- int c;
- int len;
-
+ int c;
+ int len;
+ const char *data = *datapointer;
+
len = 0;
com_token[0] = 0;
-
+
if (!data)
- return NULL;
-
+ {
+ *datapointer = NULL;
+ return false;
+ }
+
// skip whitespace
skipwhite:
- while ( (c = *data) <= ' ')
+ while ((c = *data) <= ' ')
{
if (c == 0)
- return NULL; // end of file;
+ {
+ // end of file
+ *datapointer = NULL;
+ return false;
+ }
data++;
}
data++;
goto skipwhite;
}
-
+
// handle quoted strings specially
if (c == '\"')
if (c=='\"' || !c)
{
com_token[len] = 0;
- return data;
+ *datapointer = data;
+ return true;
}
com_token[len] = c;
len++;
com_token[len] = c;
len++;
com_token[len] = 0;
- return data+1;
+ *datapointer = data+1;
+ return true;
}
// parse a regular word
data++;
len++;
c = *data;
- if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
+ if (c=='{' || c=='}'|| c==')'|| c=='(' || c=='\'' || c==':')
break;
} while (c>32);
-
+
com_token[len] = 0;
- return data;
+ *datapointer = data;
+ return true;
}
where the given parameter apears, or 0 if not present
================
*/
-int COM_CheckParm (char *parm)
+int COM_CheckParm (const char *parm)
{
- int i;
-
+ int i;
+
for (i=1 ; i<com_argc ; i++)
{
if (!com_argv[i])
if (!strcmp (parm,com_argv[i]))
return i;
}
-
+
return 0;
}
void COM_InitGameType (void)
{
- char name[128];
+ char name[MAX_OSPATH];
COM_StripExtension(com_argv[0], name);
COM_ToLowerString(name, name);
if (strstr(name, "transfusion"))
gamemode = GAME_TRANSFUSION;
- else if (strstr(name, "zymotic"))
- gamemode = GAME_ZYMOTIC;
- else if (strstr(name, "fiendarena"))
- gamemode = GAME_FIENDARENA;
else if (strstr(name, "nehahra"))
gamemode = GAME_NEHAHRA;
else if (strstr(name, "hipnotic"))
if (COM_CheckParm ("-transfusion"))
gamemode = GAME_TRANSFUSION;
- else if (COM_CheckParm ("-zymotic"))
- gamemode = GAME_ZYMOTIC;
- else if (COM_CheckParm ("-fiendarena"))
- gamemode = GAME_FIENDARENA;
else if (COM_CheckParm ("-nehahra"))
gamemode = GAME_NEHAHRA;
else if (COM_CheckParm ("-hipnotic"))
switch(gamemode)
{
case GAME_NORMAL:
- if (registered.integer)
- gamename = "DarkPlaces-Quake";
- else
- gamename = "DarkPlaces-SharewareQuake";
+ gamename = "DarkPlaces-Quake";
gamedirname = "";
break;
case GAME_HIPNOTIC:
gamename = "DarkPlaces-Nehahra";
gamedirname = "nehahra";
break;
- case GAME_FIENDARENA:
- gamename = "FiendArena";
- gamedirname = "fiendarena";
- break;
- case GAME_ZYMOTIC:
- gamename = "Zymotic";
- gamedirname = "zymotic";
- break;
case GAME_TRANSFUSION:
gamename = "Transfusion";
gamedirname = "transfusion";
void COM_Init (void)
{
#if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
- qbyte swaptest[2] = {1,0};
+ qbyte swaptest[2] = {1,0};
// set the byte swapping variables in a portable manner
if ( *(short *)swaptest == 1)
COM_InitFilesystem ();
COM_CheckRegistered ();
+
+ COM_InitGameType();
}
FIXME: make this buffer size safe someday
============
*/
-char *va(char *format, ...)
+char *va(const char *format, ...)
{
va_list argptr;
// LordHavoc: now cycles through 8 buffers to avoid problems in most cases
=============================================================================
*/
-int com_filesize;
+int com_filesize;
//
// LordHavoc: was 2048, increased to 65536 and changed info[MAX_PACK_FILES] to a temporary alloc
#define MAX_FILES_IN_PACK 65536
-pack_t *packlist = NULL;
+pack_t *packlist = NULL;
#if CACHEENABLE
-char com_cachedir[MAX_OSPATH];
+char com_cachedir[MAX_OSPATH];
#endif
-char com_gamedir[MAX_OSPATH];
+char com_gamedir[MAX_OSPATH];
typedef struct searchpath_s
{
+ // only one of filename / pack will be used
char filename[MAX_OSPATH];
- pack_t *pack; // only one of filename / pack will be used
+ pack_t *pack;
struct searchpath_s *next;
} searchpath_t;
-searchpath_t *com_searchpaths;
+searchpath_t *com_searchpaths;
/*
============
*/
void COM_Path_f (void)
{
- searchpath_t *s;
+ searchpath_t *s;
Con_Printf ("Current search path:\n");
for (s=com_searchpaths ; s ; s=s->next)
*/
void COM_CreatePath (char *path)
{
- char *ofs, save;
+ char *ofs, save;
for (ofs = path+1 ; *ofs ; ofs++)
{
The filename will be prefixed by the current game directory
============
*/
-qboolean COM_WriteFile (char *filename, void *data, int len)
+qboolean COM_WriteFile (const char *filename, void *data, int len)
{
- int handle;
- char name[MAX_OSPATH];
+ int handle;
+ char name[MAX_OSPATH];
sprintf (name, "%s/%s", com_gamedir, filename);
// LordHavoc: added this
- COM_CreatePath (name); // create directories up to the file
+ // create directories up to the file
+ COM_CreatePath (name);
handle = Sys_FileOpenWrite (name);
if (handle == -1)
*/
void COM_CopyFile (char *netpath, char *cachepath)
{
- int in, out;
- int remaining, count;
- char buf[4096];
+ int in, out, remaining, count;
+ char buf[4096];
- remaining = Sys_FileOpenRead (netpath, &in);
+ remaining = Sys_FileOpenRead (netpath, &in);
COM_CreatePath (cachepath); // create directories up to the cache file
out = Sys_FileOpenWrite (cachepath);
-
+
while (remaining)
{
if (remaining < sizeof(buf))
}
Sys_FileClose (in);
- Sys_FileClose (out);
+ Sys_FileClose (out);
}
/*
*/
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];
+ int fd = open (path, O_RDONLY);
+ unsigned char id[2], len_bytes[4];
if (fd == -1)
{
Sets com_filesize and one of handle or file
===========
*/
-int COM_FindFile (char *filename, QFile **file, qboolean quiet, qboolean zip)
+int COM_FindFile (const char *filename, QFile **file, qboolean quiet, qboolean zip)
{
- searchpath_t *search;
- char netpath[MAX_OSPATH];
+ searchpath_t *search;
+ char netpath[MAX_OSPATH];
#if CACHEENABLE
- char cachepath[MAX_OSPATH];
- int cachetime;
+ char cachepath[MAX_OSPATH];
+ int cachetime;
#endif
- pack_t *pak;
- int i;
- int findtime;
- char gzfilename[MAX_OSPATH];
- int filenamelen;
+ pack_t *pak;
+ int i, findtime, filenamelen;
+ char gzfilename[MAX_OSPATH];
filenamelen = strlen (filename);
sprintf (gzfilename, "%s.gz", filename);
if (!file)
Sys_Error ("COM_FindFile: file not set");
-
+
//
// search through the path, one element at a time
//
}
}
else
- {
+ {
sprintf (netpath, "%s/%s",search->filename, filename);
-
+
findtime = Sys_FileTime (netpath);
if (findtime == -1)
continue;
-
+
#if CACHEENABLE
// see if the file needs to be updated in the cache
if (com_cachedir[0])
- {
+ {
#if defined(_WIN32)
if ((strlen(netpath) < 2) || (netpath[1] != ':'))
sprintf (cachepath,"%s%s", com_cachedir, netpath);
if (cachetime < findtime)
COM_CopyFile (netpath, cachepath);
strcpy (netpath, cachepath);
- }
+ }
#endif
-
if (!quiet)
Sys_Printf ("FindFile: %s\n",netpath);
*file = COM_OpenRead (netpath, -1, -1, zip);
return com_filesize;
}
-
}
-
+
if (!quiet)
Sys_Printf ("FindFile: can't find %s\n", filename);
-
+
*file = NULL;
com_filesize = -1;
return -1;
into the file.
===========
*/
-int COM_FOpenFile (char *filename, QFile **file, qboolean quiet, qboolean zip)
+int COM_FOpenFile (const char *filename, QFile **file, qboolean quiet, qboolean zip)
{
return COM_FindFile (filename, file, quiet, zip);
}
*/
qbyte *loadbuf;
int loadsize;
-qbyte *COM_LoadFile (char *path, qboolean quiet)
+qbyte *COM_LoadFile (const char *path, qboolean quiet)
{
QFile *h;
qbyte *buf;
of the list so they override previous pack files.
=================
*/
-pack_t *COM_LoadPackFile (char *packfile)
+pack_t *COM_LoadPackFile (const char *packfile)
{
- dpackheader_t header;
- int i;
- int numpackfiles;
- pack_t *pack;
- int packhandle;
+ dpackheader_t header;
+ int i, numpackfiles, packhandle;
+ pack_t *pack;
// LordHavoc: changed from stack array to temporary alloc, allowing huge pack directories
- dpackfile_t *info;
+ dpackfile_t *info;
if (Sys_FileOpenRead (packfile, &packhandle) == -1)
return NULL;
list = listdirectory(dir);
for (current = list;current;current = current->next)
{
- if (matchpattern(current->text, "*.pak"))
+ if (matchpattern(current->text, "*.pak", true))
{
sprintf (pakfile, "%s/%s", dir, current->text);
pak = COM_LoadPackFile (pakfile);
}
}
-int COM_FileExists(char *filename)
+int COM_FileExists(const char *filename)
{
- searchpath_t *search;
- char netpath[MAX_OSPATH];
- pack_t *pak;
- int i;
- int findtime;
+ searchpath_t *search;
+ char netpath[MAX_OSPATH];
+ pack_t *pak;
+ int i, findtime;
for (search = com_searchpaths;search;search = search->next)
{
findtime = Sys_FileTime (netpath);
if (findtime != -1)
return true;
- }
+ }
}
return false;
//======================================
// LordHavoc: added these because they are useful
-void COM_ToLowerString(char *in, char *out)
+void COM_ToLowerString(const char *in, char *out)
{
while (*in)
{
}
}
-void COM_ToUpperString(char *in, char *out)
+void COM_ToUpperString(const char *in, char *out)
{
while (*in)
{
return false;
return true;
}
-