From: havoc Date: Wed, 11 Sep 2002 14:55:46 +0000 (+0000) Subject: whitespace X-Git-Tag: RELEASE_0_2_0_RC1~244 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=43ee5e136a693ac9cfb40cb03fceea7d3149104f;p=xonotic%2Fdarkplaces.git whitespace lots of things are now const pointers git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2362 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_input.c b/cl_input.c index 21d79bec..018eb2c1 100644 --- a/cl_input.c +++ b/cl_input.c @@ -59,8 +59,8 @@ int in_impulse; void KeyDown (kbutton_t *b) { - int k; - char *c; + int k; + const char *c; c = Cmd_Argv(1); if (c[0]) @@ -80,7 +80,7 @@ void KeyDown (kbutton_t *b) Con_Printf ("Three keys down for a button!\n"); return; } - + if (b->state & 1) return; // still down b->state |= 1 + 2; // down + impulse down @@ -88,9 +88,9 @@ void KeyDown (kbutton_t *b) void KeyUp (kbutton_t *b) { - int k; - char *c; - + int k; + const char *c; + c = Cmd_Argv(1); if (c[0]) k = atoi(c); diff --git a/cl_parse.c b/cl_parse.c index 0bb92223..9d74bae2 100644 --- a/cl_parse.c +++ b/cl_parse.c @@ -220,22 +220,20 @@ void CL_KeepaliveMessage (void) void CL_ParseEntityLump(char *entdata) { - char *data; + const char *data; char key[128], value[4096]; FOG_clear(); // LordHavoc: no fog until set R_SetSkyBox(""); // LordHavoc: no environment mapped sky until set data = entdata; if (!data) return; - data = COM_Parse(data); - if (!data) + if (!COM_ParseToken(&data)) return; // error if (com_token[0] != '{') return; // error while (1) { - data = COM_Parse(data); - if (!data) + if (!COM_ParseToken(&data)) return; // error if (com_token[0] == '}') break; // end of worldspawn @@ -245,8 +243,7 @@ void CL_ParseEntityLump(char *entdata) strcpy(key, com_token); while (key[strlen(key)-1] == ' ') // remove trailing spaces key[strlen(key)-1] = 0; - data = COM_Parse(data); - if (!data) + if (!COM_ParseToken(&data)) return; // error strcpy(value, com_token); if (!strcmp("sky", key)) diff --git a/cmd.c b/cmd.c index d46db844..c8aa3803 100644 --- a/cmd.c +++ b/cmd.c @@ -25,9 +25,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. typedef struct cmdalias_s { - struct cmdalias_s *next; - char name[MAX_ALIAS_NAME]; - char *value; + struct cmdalias_s *next; + char name[MAX_ALIAS_NAME]; + char *value; } cmdalias_t; static cmdalias_t *cmd_alias; @@ -81,7 +81,7 @@ Cbuf_AddText Adds command text at the end of the buffer ============ */ -void Cbuf_AddText (char *text) +void Cbuf_AddText (const char *text) { int l; @@ -106,7 +106,7 @@ Adds a \n to the text FIXME: actually change the command buffer to do less copying ============ */ -void Cbuf_InsertText (char *text) +void Cbuf_InsertText (const char *text) { char *temp; int templen; @@ -140,10 +140,10 @@ Cbuf_Execute */ void Cbuf_Execute (void) { - int i; - char *text; - char line[1024]; - int quotes; + int i; + char *text; + char line[1024]; + int quotes; while (cmd_text.cursize) { @@ -279,7 +279,7 @@ Cmd_Exec_f */ static void Cmd_Exec_f (void) { - char *f; + char *f; if (Cmd_Argc () != 2) { @@ -323,10 +323,9 @@ Cmd_Alias_f Creates a new command that executes a command string (possibly ; seperated) =============== */ - static char *CopyString (char *in) { - char *out; + char *out; out = Z_Malloc (strlen(in)+1); strcpy (out, in); @@ -338,7 +337,7 @@ static void Cmd_Alias_f (void) cmdalias_t *a; char cmd[1024]; int i, c; - char *s; + const char *s; if (Cmd_Argc() == 1) { @@ -397,18 +396,18 @@ static void Cmd_Alias_f (void) typedef struct cmd_function_s { - struct cmd_function_s *next; - char *name; - xcommand_t function; + struct cmd_function_s *next; + const char *name; + xcommand_t function; } cmd_function_t; #define MAX_ARGS 80 static int cmd_argc; -static char *cmd_argv[MAX_ARGS]; -static char *cmd_null_string = ""; -static char *cmd_args = NULL; +static const char *cmd_argv[MAX_ARGS]; +static const char *cmd_null_string = ""; +static const char *cmd_args = NULL; cmd_source_t cmd_source; @@ -426,21 +425,24 @@ Cmd_List */ static void Cmd_List_f (void) { - cmd_function_t *cmd; - char *partial; - int len; - int count; + cmd_function_t *cmd; + const char *partial; + int len, count; - if (Cmd_Argc() > 1) { + if (Cmd_Argc() > 1) + { partial = Cmd_Argv (1); len = strlen(partial); - } else { + } + else + { partial = NULL; len = 0; } count = 0; - for (cmd = cmd_functions; cmd; cmd = cmd->next) { + for (cmd = cmd_functions; cmd; cmd = cmd->next) + { if (partial && strncmp(partial, cmd->name, len)) continue; Con_Printf ("%s\n", cmd->name); @@ -492,7 +494,7 @@ int Cmd_Argc (void) Cmd_Argv ============ */ -char *Cmd_Argv (int arg) +const char *Cmd_Argv (int arg) { if (arg >= cmd_argc ) return cmd_null_string; @@ -504,7 +506,7 @@ char *Cmd_Argv (int arg) Cmd_Args ============ */ -char *Cmd_Args (void) +const char *Cmd_Args (void) { return cmd_args; } @@ -520,7 +522,7 @@ Cmd_TokenizeString Parses the given string into command line tokens. ============ */ -static void Cmd_TokenizeString (char *text) +static void Cmd_TokenizeString (const char *text) { int l; int pos; @@ -549,8 +551,7 @@ static void Cmd_TokenizeString (char *text) if (cmd_argc == 1) cmd_args = text; - text = COM_Parse (text); - if (!text) + if (!COM_ParseToken (&text)) return; if (cmd_argc < MAX_ARGS) @@ -558,9 +559,9 @@ static void Cmd_TokenizeString (char *text) l = strlen(com_token) + 1; if (pos + l > CMD_TOKENIZELENGTH) Sys_Error("Cmd_TokenizeString: ran out of %i character buffer space for command arguements\n", CMD_TOKENIZELENGTH); + strcpy (cmd_tokenizebuffer + pos, com_token); cmd_argv[cmd_argc] = cmd_tokenizebuffer + pos; pos += l; - strcpy (cmd_argv[cmd_argc], com_token); cmd_argc++; } } @@ -573,9 +574,9 @@ static void Cmd_TokenizeString (char *text) Cmd_AddCommand ============ */ -void Cmd_AddCommand (char *cmd_name, xcommand_t function) +void Cmd_AddCommand (const char *cmd_name, xcommand_t function) { - cmd_function_t *cmd; + cmd_function_t *cmd; // fail if the command is a variable name if (Cvar_VariableString(cmd_name)[0]) @@ -606,7 +607,7 @@ void Cmd_AddCommand (char *cmd_name, xcommand_t function) Cmd_Exists ============ */ -qboolean Cmd_Exists (char *cmd_name) +qboolean Cmd_Exists (const char *cmd_name) { cmd_function_t *cmd; @@ -623,10 +624,10 @@ qboolean Cmd_Exists (char *cmd_name) Cmd_CompleteCommand ============ */ -char *Cmd_CompleteCommand (char *partial) +const char *Cmd_CompleteCommand (const char *partial) { - cmd_function_t *cmd; - int len; + cmd_function_t *cmd; + int len; len = strlen(partial); @@ -650,11 +651,10 @@ char *Cmd_CompleteCommand (char *partial) Thanks to taniwha */ -int Cmd_CompleteCountPossible (char *partial) +int Cmd_CompleteCountPossible (const char *partial) { - cmd_function_t *cmd; - int len; - int h; + cmd_function_t *cmd; + int len, h; h = 0; len = strlen(partial); @@ -679,16 +679,16 @@ int Cmd_CompleteCountPossible (char *partial) Thanks to taniwha */ -char **Cmd_CompleteBuildList (char *partial) +const char **Cmd_CompleteBuildList (const char *partial) { - cmd_function_t *cmd; - int len = 0; - int bpos = 0; - int sizeofbuf = (Cmd_CompleteCountPossible (partial) + 1) * sizeof (char *); - char **buf; + cmd_function_t *cmd; + int len = 0; + int bpos = 0; + int sizeofbuf = (Cmd_CompleteCountPossible (partial) + 1) * sizeof (const char *); + const char **buf; len = strlen(partial); - buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (char *)); + buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (const char *)); // Loop through the alias list and print all matches for (cmd = cmd_functions; cmd; cmd = cmd->next) if (!strncasecmp(partial, cmd->name, len)) @@ -707,10 +707,10 @@ char **Cmd_CompleteBuildList (char *partial) Thanks to taniwha */ -char *Cmd_CompleteAlias (char * partial) +const char *Cmd_CompleteAlias (const char *partial) { - cmdalias_t *alias; - int len; + cmdalias_t *alias; + int len; len = strlen(partial); @@ -734,7 +734,7 @@ char *Cmd_CompleteAlias (char * partial) Thanks to taniwha */ -int Cmd_CompleteAliasCountPossible (char *partial) +int Cmd_CompleteAliasCountPossible (const char *partial) { cmdalias_t *alias; int len; @@ -764,16 +764,16 @@ int Cmd_CompleteAliasCountPossible (char *partial) Thanks to taniwha */ -char **Cmd_CompleteAliasBuildList (char *partial) +const char **Cmd_CompleteAliasBuildList (const char *partial) { - cmdalias_t *alias; - int len = 0; - int bpos = 0; - int sizeofbuf = (Cmd_CompleteAliasCountPossible (partial) + 1) * sizeof (char *); - char **buf; + cmdalias_t *alias; + int len = 0; + int bpos = 0; + int sizeofbuf = (Cmd_CompleteAliasCountPossible (partial) + 1) * sizeof (const char *); + const char **buf; len = strlen(partial); - buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (char *)); + buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (const char *)); // Loop through the alias list and print all matches for (alias = cmd_alias; alias; alias = alias->next) if (!strncasecmp(partial, alias->name, len)) @@ -791,10 +791,10 @@ A complete command line has been parsed, so try to execute it FIXME: lookupnoadd the token to speed search? ============ */ -void Cmd_ExecuteString (char *text, cmd_source_t src) +void Cmd_ExecuteString (const char *text, cmd_source_t src) { - cmd_function_t *cmd; - cmdalias_t *a; + cmd_function_t *cmd; + cmdalias_t *a; cmd_source = src; Cmd_TokenizeString (text); @@ -869,7 +869,7 @@ where the given parameter apears, or 0 if not present ================ */ -int Cmd_CheckParm (char *parm) +int Cmd_CheckParm (const char *parm) { int i; diff --git a/cmd.h b/cmd.h index f4965187..bc74058f 100644 --- a/cmd.h +++ b/cmd.h @@ -40,11 +40,11 @@ The game starts with a Cbuf_AddText ("exec quake.rc\n"); Cbuf_Execute (); void Cbuf_Init (void); // allocates an initial text buffer that will grow as needed -void Cbuf_AddText (char *text); +void Cbuf_AddText (const char *text); // as new commands are generated from the console or keybindings, // the text is added to the end of the command buffer. -void Cbuf_InsertText (char *text); +void Cbuf_InsertText (const char *text); // when a command wants to issue other commands immediately, the text is // inserted at the beginning of the buffer, before any remaining unexecuted // commands. @@ -81,40 +81,40 @@ extern cmd_source_t cmd_source; void Cmd_Init (void); -void Cmd_AddCommand (char *cmd_name, xcommand_t function); +void Cmd_AddCommand (const char *cmd_name, xcommand_t function); // called by the init functions of other parts of the program to // register commands and functions to call for them. // The cmd_name is referenced later, so it should not be in temp memory -qboolean Cmd_Exists (char *cmd_name); +qboolean Cmd_Exists (const char *cmd_name); // used by the cvar code to check for cvar / command name overlap -char *Cmd_CompleteCommand (char *partial); +const char *Cmd_CompleteCommand (const char *partial); // attempts to match a partial command for automatic command line completion // returns NULL if nothing fits -int Cmd_CompleteAliasCountPossible (char *partial); +int Cmd_CompleteAliasCountPossible (const char *partial); -char **Cmd_CompleteAliasBuildList (char *partial); +const char **Cmd_CompleteAliasBuildList (const char *partial); -int Cmd_CompleteCountPossible (char *partial); +int Cmd_CompleteCountPossible (const char *partial); -char **Cmd_CompleteBuildList (char *partial); +const char **Cmd_CompleteBuildList (const char *partial); -char *Cmd_CompleteAlias (char *partial); +const char *Cmd_CompleteAlias (const char *partial); // Enhanced console completion by Fett erich@heintz.com // Added by EvilTypeGuy eviltypeguy@qeradiant.com int Cmd_Argc (void); -char *Cmd_Argv (int arg); -char *Cmd_Args (void); +const char *Cmd_Argv (int arg); +const char *Cmd_Args (void); // The functions that execute commands get their parameters with these // functions. Cmd_Argv () will return an empty string, not a NULL // if arg > argc, so string operations are always safe. -int Cmd_CheckParm (char *parm); +int Cmd_CheckParm (const char *parm); // Returns the position (1 to argc-1) in the command's argument list // where the given parameter apears, or 0 if not present @@ -122,7 +122,7 @@ int Cmd_CheckParm (char *parm); // Takes a null terminated string. Does not need to be /n terminated. // breaks the string up into arg tokens. -void Cmd_ExecuteString (char *text, cmd_source_t src); +void Cmd_ExecuteString (const char *text, cmd_source_t src); // Parses a single line of text into arguments and tries to execute it. // The text can come from the command buffer, a remote client, or stdin. @@ -131,7 +131,7 @@ void Cmd_ForwardToServer (void); // things like godmode, noclip, etc, are commands directed to the server, // so when they are typed in at the console, they will need to be forwarded. -void Cmd_Print (char *text); +void Cmd_Print (const char *text); // used by command functions to send output to either the graphics console or // passed as a print message to the client diff --git a/common.c b/common.c index 3dfcf6d5..7ce4b548 100644 --- a/common.c +++ b/common.c @@ -43,7 +43,7 @@ void COM_InitFilesystem (void); 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 @@ -85,7 +85,7 @@ The file "parms.txt" will be read out of the game directory and appended to the ============================================================================ */ -int Q_strncasecmp (char *s1, char *s2, int n) +int Q_strncasecmp (const char *s1, const char *s2, int n) { int c1, c2; @@ -113,7 +113,7 @@ int Q_strncasecmp (char *s1, char *s2, int n) return -1; } -int Q_strcasecmp (char *s1, char *s2) +int Q_strcasecmp (const char *s1, const char *s2) { return Q_strncasecmp (s1, s2, 99999); } @@ -259,7 +259,7 @@ void MSG_WriteFloat (sizebuf_t *sb, float f) 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); @@ -296,8 +296,8 @@ void MSG_WriteAngle (sizebuf_t *sb, float f) // // reading functions // -int msg_readcount; -qboolean msg_badread; +int msg_readcount; +qboolean msg_badread; void MSG_BeginReading (void) { @@ -307,7 +307,7 @@ void MSG_BeginReading (void) int MSG_ReadShort (void) { - int c; + int c; if (msg_readcount+2 > net_message.cursize) { @@ -325,7 +325,7 @@ int MSG_ReadShort (void) int MSG_ReadLong (void) { - int c; + int c; if (msg_readcount+4 > net_message.cursize) { @@ -347,9 +347,9 @@ float MSG_ReadFloat (void) { union { - qbyte b[4]; - float f; - int l; + qbyte b[4]; + float f; + int l; } dat; dat.b[0] = net_message.data[msg_readcount]; @@ -365,8 +365,8 @@ float MSG_ReadFloat (void) char *MSG_ReadString (void) { - static char string[2048]; - int l,c; + static char string[2048]; + int l,c; l = 0; do @@ -403,7 +403,7 @@ float MSG_ReadCoord (void) //=========================================================================== -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; @@ -429,7 +429,7 @@ void SZ_Clear (sizebuf_t *buf) void *SZ_GetSpace (sizebuf_t *buf, int length) { - void *data; + void *data; if (buf->cursize + length > buf->maxsize) { @@ -446,19 +446,18 @@ void *SZ_GetSpace (sizebuf_t *buf, int length) 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 @@ -469,7 +468,7 @@ void SZ_Print (sizebuf_t *buf, char *data) } static char *hexchar = "0123456789ABCDEF"; -void SZ_HexDumpToConsole(sizebuf_t *buf) +void SZ_HexDumpToConsole(const sizebuf_t *buf) { int i; char text[1024]; @@ -521,32 +520,13 @@ void SZ_HexDumpToConsole(sizebuf_t *buf) //============================================================================ -/* -============ -COM_SkipPath -============ -*/ -char *COM_SkipPath (char *pathname) -{ - char *last; - - last = pathname; - while (*pathname) - { - if (*pathname=='/') - last = pathname+1; - pathname++; - } - 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) @@ -568,10 +548,10 @@ void COM_StripExtension (char *in, char *out) 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++; @@ -589,10 +569,9 @@ char *COM_FileExtension (char *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; @@ -623,9 +602,9 @@ void COM_FileBase (char *in, char *out) 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 .) @@ -645,28 +624,36 @@ void COM_DefaultExtension (char *path, char *extension) /* ============== -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++; } @@ -677,7 +664,7 @@ skipwhite: data++; goto skipwhite; } - + // handle quoted strings specially if (c == '\"') @@ -689,7 +676,8 @@ skipwhite: if (c=='\"' || !c) { com_token[len] = 0; - return data; + *datapointer = data; + return true; } com_token[len] = c; len++; @@ -702,7 +690,8 @@ skipwhite: com_token[len] = c; len++; com_token[len] = 0; - return data+1; + *datapointer = data+1; + return true; } // parse a regular word @@ -712,12 +701,13 @@ skipwhite: 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; } @@ -729,10 +719,10 @@ Returns the position (1 to argc-1) in the program's argument list 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 ; inext) @@ -1024,7 +1017,7 @@ LordHavoc: Previously only used for CopyFile, now also used for COM_WriteFile. */ void COM_CreatePath (char *path) { - char *ofs, save; + char *ofs, save; for (ofs = path+1 ; *ofs ; ofs++) { @@ -1047,15 +1040,16 @@ COM_WriteFile 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) @@ -1081,14 +1075,13 @@ needed. This is for the convenience of developers using ISDN from home. */ 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)) @@ -1101,7 +1094,7 @@ void COM_CopyFile (char *netpath, char *cachepath) } Sys_FileClose (in); - Sys_FileClose (out); + Sys_FileClose (out); } /* @@ -1111,9 +1104,8 @@ 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]; + int fd = open (path, O_RDONLY); + unsigned char id[2], len_bytes[4]; if (fd == -1) { @@ -1161,26 +1153,24 @@ Finds the file in the search path. 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 // @@ -1205,17 +1195,17 @@ int COM_FindFile (char *filename, QFile **file, qboolean quiet, qboolean zip) } } 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); @@ -1230,20 +1220,18 @@ int COM_FindFile (char *filename, QFile **file, qboolean quiet, qboolean zip) 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; @@ -1258,7 +1246,7 @@ If the requested file is inside a packfile, a new QFile * will be opened 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); } @@ -1274,7 +1262,7 @@ Always appends a 0 byte. */ qbyte *loadbuf; int loadsize; -qbyte *COM_LoadFile (char *path, qboolean quiet) +qbyte *COM_LoadFile (const char *path, qboolean quiet) { QFile *h; qbyte *buf; @@ -1316,15 +1304,13 @@ Loads the header and directory, adding the files at the beginning 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; @@ -1484,13 +1470,12 @@ void COM_InitFilesystem (void) } } -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) { @@ -1507,7 +1492,7 @@ int COM_FileExists(char *filename) findtime = Sys_FileTime (netpath); if (findtime != -1) return true; - } + } } return false; @@ -1517,7 +1502,7 @@ int COM_FileExists(char *filename) //====================================== // LordHavoc: added these because they are useful -void COM_ToLowerString(char *in, char *out) +void COM_ToLowerString(const char *in, char *out) { while (*in) { @@ -1528,7 +1513,7 @@ void COM_ToLowerString(char *in, char *out) } } -void COM_ToUpperString(char *in, char *out) +void COM_ToUpperString(const char *in, char *out) { while (*in) { @@ -1546,4 +1531,3 @@ int COM_StringBeginsWith(const char *s, const char *match) return false; return true; } - diff --git a/common.h b/common.h index 7ad25529..84bfaaaa 100644 --- a/common.h +++ b/common.h @@ -38,13 +38,13 @@ typedef struct sizebuf_s int cursize; } sizebuf_t; -void SZ_Alloc (sizebuf_t *buf, int startsize, char *name); +void SZ_Alloc (sizebuf_t *buf, int startsize, const char *name); void SZ_Free (sizebuf_t *buf); void SZ_Clear (sizebuf_t *buf); void *SZ_GetSpace (sizebuf_t *buf, int length); -void SZ_Write (sizebuf_t *buf, void *data, int length); -void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf -void SZ_HexDumpToConsole(sizebuf_t *buf); +void SZ_Write (sizebuf_t *buf, const void *data, int length); +void SZ_Print (sizebuf_t *buf, const char *data); // strcats onto the sizebuf +void SZ_HexDumpToConsole(const sizebuf_t *buf); //============================================================================ #if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG) @@ -92,7 +92,7 @@ void MSG_WriteByte (sizebuf_t *sb, int c); void MSG_WriteShort (sizebuf_t *sb, int c); void MSG_WriteLong (sizebuf_t *sb, int c); void MSG_WriteFloat (sizebuf_t *sb, float f); -void MSG_WriteString (sizebuf_t *sb, char *s); +void MSG_WriteString (sizebuf_t *sb, const char *s); void MSG_WriteCoord (sizebuf_t *sb, float f); void MSG_WriteAngle (sizebuf_t *sb, float f); void MSG_WritePreciseAngle (sizebuf_t *sb, float f); @@ -123,31 +123,30 @@ extern int dpprotocol; //============================================================================ -int Q_strcasecmp (char *s1, char *s2); -int Q_strncasecmp (char *s1, char *s2, int n); +int Q_strcasecmp (const char *s1, const char *s2); +int Q_strncasecmp (const char *s1, const char *s2, int n); //============================================================================ -extern char com_token[1024]; -extern qboolean com_eof; +extern char com_token[1024]; +extern qboolean com_eof; -char *COM_Parse (char *data); +int COM_ParseToken (const char **data); extern char com_basedir[MAX_OSPATH]; extern int com_argc; -extern char **com_argv; +extern const char **com_argv; -int COM_CheckParm (char *parm); +int COM_CheckParm (const char *parm); void COM_Init (void); void COM_InitArgv (void); void COM_InitGameType (void); -char *COM_SkipPath (char *pathname); -void COM_StripExtension (char *in, char *out); -void COM_FileBase (char *in, char *out); -void COM_DefaultExtension (char *path, char *extension); +void COM_StripExtension (const char *in, char *out); +void COM_FileBase (const char *in, char *out); +void COM_DefaultExtension (char *path, const char *extension); -char *va(char *format, ...); +char *va(const char *format, ...); // does a varargs printf into a temp buffer @@ -157,14 +156,14 @@ extern int com_filesize; extern char com_gamedir[MAX_OSPATH]; -qboolean COM_WriteFile (char *filename, void *data, int len); -int COM_FOpenFile (char *filename, QFile **file, qboolean quiet, qboolean zip); +qboolean COM_WriteFile (const char *filename, void *data, int len); +int COM_FOpenFile (const char *filename, QFile **file, qboolean quiet, qboolean zip); // set by COM_LoadFile functions extern int loadsize; -qbyte *COM_LoadFile (char *path, qboolean quiet); +qbyte *COM_LoadFile (const char *path, qboolean quiet); -int COM_FileExists(char *filename); +int COM_FileExists(const char *filename); extern struct cvar_s registered; @@ -178,8 +177,8 @@ extern int gamemode; extern char *gamename; // LordHavoc: useful... -void COM_ToLowerString(char *in, char *out); -void COM_ToUpperString(char *in, char *out); +void COM_ToLowerString(const char *in, char *out); +void COM_ToUpperString(const char *in, char *out); int COM_StringBeginsWith(const char *s, const char *match); typedef struct stringlist_s diff --git a/console.c b/console.c index 31c19cc5..c337e514 100644 --- a/console.c +++ b/console.c @@ -33,41 +33,47 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "quakedef.h" -int con_linewidth; +int con_linewidth; -float con_cursorspeed = 4; +float con_cursorspeed = 4; #define CON_TEXTSIZE 131072 -int con_totallines; // total lines in console scrollback -int con_backscroll; // lines up from bottom to display -int con_current; // where next message will be printed -int con_x; // offset in current line for next print -char *con_text = 0; +// total lines in console scrollback +int con_totallines; +// lines up from bottom to display +int con_backscroll; +// where next message will be printed +int con_current; +// offset in current line for next print +int con_x; +char *con_text = 0; -cvar_t con_notifytime = {CVAR_SAVE, "con_notifytime","3"}; //seconds -cvar_t logfile = {0, "logfile","0"}; +//seconds +cvar_t con_notifytime = {CVAR_SAVE, "con_notifytime","3"}; +cvar_t logfile = {0, "logfile","0"}; #define NUM_CON_TIMES 4 -float con_times[NUM_CON_TIMES]; // realtime time the line was generated - // for transparent notify lines +// realtime time the line was generated for transparent notify lines +float con_times[NUM_CON_TIMES]; -int con_vislines; +int con_vislines; -qboolean con_debuglog; +qboolean con_debuglog; -#define MAXCMDLINE 256 -extern char key_lines[32][MAXCMDLINE]; -extern int edit_line; -extern int key_linepos; -extern int key_insert; +#define MAXCMDLINE 256 +extern char key_lines[32][MAXCMDLINE]; +extern int edit_line; +extern int key_linepos; +extern int key_insert; -qboolean con_initialized; +qboolean con_initialized; -mempool_t *console_mempool; +mempool_t *console_mempool; -int con_notifylines; // scan lines to clear for notify lines +// scan lines to clear for notify lines +int con_notifylines; extern void M_Menu_Main_f (void); @@ -102,7 +108,7 @@ Con_ClearNotify */ void Con_ClearNotify (void) { - int i; + int i; for (i=0 ; i> 3); @@ -203,9 +209,9 @@ Con_Init */ void Con_Init (void) { -#define MAXGAMEDIRLEN 1000 - char temp[MAXGAMEDIRLEN+1]; - char *t2 = "/qconsole.log"; +#define MAXGAMEDIRLEN 1000 + char temp[MAXGAMEDIRLEN+1]; + char *t2 = "/qconsole.log"; Cvar_RegisterVariable(&logfile); con_debuglog = COM_CheckParm("-condebug"); @@ -262,12 +268,10 @@ All console printing must go through this in order to be logged to disk If no console is visible, the notify window will pop up. ================ */ -void Con_Print (char *txt) +void Con_Print (const char *txt) { - int y; - int c, l; - static int cr; - int mask; + int y, c, l, mask; + static int cr; con_backscroll = 0; @@ -344,7 +348,7 @@ void Con_Print (char *txt) Con_DebugLog ================ */ -void Con_DebugLog(char *file, char *fmt, ...) +void Con_DebugLog(const char *file, const char *fmt, ...) { va_list argptr; FILE* fd; @@ -367,10 +371,10 @@ Handles cursor positioning, line wrapping, etc // LordHavoc: increased from 4096 to 16384 #define MAXPRINTMSG 16384 // FIXME: make a buffer size safe vsprintf? -void Con_Printf (char *fmt, ...) +void Con_Printf (const char *fmt, ...) { - va_list argptr; - char msg[MAXPRINTMSG]; + va_list argptr; + char msg[MAXPRINTMSG]; va_start (argptr,fmt); vsprintf (msg,fmt,argptr); @@ -405,10 +409,10 @@ Con_DPrintf A Con_Printf that only shows up if the "developer" cvar is set ================ */ -void Con_DPrintf (char *fmt, ...) +void Con_DPrintf (const char *fmt, ...) { - va_list argptr; - char msg[MAXPRINTMSG]; + va_list argptr; + char msg[MAXPRINTMSG]; if (!developer.integer) return; // don't confuse non-developers with techie stuff... @@ -428,7 +432,7 @@ Con_SafePrintf Okay to call even when the screen can't be updated ================== */ -void Con_SafePrintf (char *fmt, ...) +void Con_SafePrintf (const char *fmt, ...) { va_list argptr; char msg[1024]; @@ -568,10 +572,8 @@ extern cvar_t scr_conalpha; extern char engineversion[40]; void Con_DrawConsole (int lines) { - int i, y; - int rows; - char *text; - int j; + int i, y, rows, j; + char *text; if (lines <= 0) return; @@ -606,15 +608,10 @@ void Con_DrawConsole (int lines) MEGA Thanks to Taniwha */ -void -Con_DisplayList(char **list) +void Con_DisplayList(const char **list) { - int i = 0; - int pos = 0; - int len = 0; - int maxlen = 0; - int width = (con_linewidth - 4); - char **walk = list; + int i = 0, pos = 0, len = 0, maxlen = 0, width = (con_linewidth - 4); + const char **walk = list; while (*walk) { len = strlen(*walk); @@ -652,14 +649,11 @@ Con_DisplayList(char **list) Thanks to taniwha */ -void -Con_CompleteCommandLine (void) +void Con_CompleteCommandLine (void) { - char *cmd = ""; - char *s; - int c, v, a, i; - int cmd_len; - char **list[3] = {0, 0, 0}; + const char *cmd = "", *s; + const char **list[3] = {0, 0, 0}; + int c, v, a, i, cmd_len; s = key_lines[edit_line] + 1; // Count number of possible matches @@ -691,7 +685,7 @@ Con_CompleteCommandLine (void) do { for (i = 0; i < 3; i++) { char ch = cmd[cmd_len]; - char **l = list[i]; + const char **l = list[i]; if (l) { while (*l && (*l)[cmd_len] == ch) l++; diff --git a/console.h b/console.h index 6f3a9f3a..9042ac06 100644 --- a/console.h +++ b/console.h @@ -30,15 +30,13 @@ extern qboolean con_initialized; extern qbyte *con_chars; extern int con_notifylines; // scan lines to clear for notify lines -void Con_DrawCharacter (int cx, int line, int num); - void Con_CheckResize (void); void Con_Init (void); void Con_DrawConsole (int lines); -void Con_Print (char *txt); -void Con_Printf (char *fmt, ...); -void Con_DPrintf (char *fmt, ...); -void Con_SafePrintf (char *fmt, ...); +void Con_Print (const char *txt); +void Con_Printf (const char *fmt, ...); +void Con_DPrintf (const char *fmt, ...); +void Con_SafePrintf (const char *fmt, ...); void Con_Clear_f (void); void Con_DrawNotify (void); void Con_ClearNotify (void); @@ -52,7 +50,7 @@ void Con_CompleteCommandLine(void); // Generic libs/util/console.c function to display a list // formatted in columns on the console -void Con_DisplayList(char **list); +void Con_DisplayList(const char **list); #endif diff --git a/cvar.c b/cvar.c index 3349986b..f0923b02 100644 --- a/cvar.c +++ b/cvar.c @@ -21,15 +21,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" -cvar_t *cvar_vars = NULL; -char *cvar_null_string = ""; +cvar_t *cvar_vars = NULL; +char *cvar_null_string = ""; /* ============ Cvar_FindVar ============ */ -cvar_t *Cvar_FindVar (char *var_name) +cvar_t *Cvar_FindVar (const char *var_name) { cvar_t *var; @@ -40,7 +40,7 @@ cvar_t *Cvar_FindVar (char *var_name) return NULL; } -cvar_t *Cvar_FindVarAfter (char *prev_var_name, int neededflags) +cvar_t *Cvar_FindVarAfter (const char *prev_var_name, int neededflags) { cvar_t *var; @@ -69,9 +69,9 @@ cvar_t *Cvar_FindVarAfter (char *prev_var_name, int neededflags) Cvar_VariableValue ============ */ -float Cvar_VariableValue (char *var_name) +float Cvar_VariableValue (const char *var_name) { - cvar_t *var; + cvar_t *var; var = Cvar_FindVar (var_name); if (!var) @@ -85,7 +85,7 @@ float Cvar_VariableValue (char *var_name) Cvar_VariableString ============ */ -char *Cvar_VariableString (char *var_name) +const char *Cvar_VariableString (const char *var_name) { cvar_t *var; @@ -101,7 +101,7 @@ char *Cvar_VariableString (char *var_name) Cvar_CompleteVariable ============ */ -char *Cvar_CompleteVariable (char *partial) +const char *Cvar_CompleteVariable (const char *partial) { cvar_t *cvar; int len; @@ -128,8 +128,7 @@ char *Cvar_CompleteVariable (char *partial) Thanks to Fett erich@heintz.com */ -int -Cvar_CompleteCountPossible (char *partial) +int Cvar_CompleteCountPossible (const char *partial) { cvar_t *cvar; int len; @@ -158,17 +157,16 @@ Cvar_CompleteCountPossible (char *partial) Thanks to taniwha */ -char ** -Cvar_CompleteBuildList (char *partial) +const char **Cvar_CompleteBuildList (const char *partial) { - cvar_t *cvar; - int len = 0; - int bpos = 0; - int sizeofbuf = (Cvar_CompleteCountPossible (partial) + 1) * sizeof (char *); - char **buf; + const cvar_t *cvar; + int len = 0; + int bpos = 0; + int sizeofbuf = (Cvar_CompleteCountPossible (partial) + 1) * sizeof (const char *); + const char **buf; len = strlen(partial); - buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (char *)); + buf = Mem_Alloc(tempmempool, sizeofbuf + sizeof (const char *)); // Loop through the alias list and print all matches for (cvar = cvar_vars; cvar; cvar = cvar->next) if (!strncasecmp(partial, cvar->name, len)) @@ -183,7 +181,7 @@ Cvar_CompleteBuildList (char *partial) Cvar_Set ============ */ -void Cvar_SetQuick (cvar_t *var, char *value) +void Cvar_SetQuick (cvar_t *var, const char *value) { qboolean changed; @@ -215,7 +213,7 @@ void Cvar_SetQuick (cvar_t *var, char *value) } } -void Cvar_Set (char *var_name, char *value) +void Cvar_Set (const char *var_name, const char *value) { cvar_t *var; var = Cvar_FindVar (var_name); @@ -243,7 +241,7 @@ void Cvar_SetValueQuick (cvar_t *var, float value) Cvar_SetQuick (var, val); } -void Cvar_SetValue (char *var_name, float value) +void Cvar_SetValue (const char *var_name, float value) { char val[32]; @@ -344,21 +342,24 @@ Cvar_List */ void Cvar_List_f (void) { - cvar_t *cvar; - char *partial; - int len; - int count; + cvar_t *cvar; + const char *partial; + int len, count; - if (Cmd_Argc() > 1) { + if (Cmd_Argc() > 1) + { partial = Cmd_Argv (1); len = strlen(partial); - } else { + } + else + { partial = NULL; len = 0; } count = 0; - for (cvar = cvar_vars; cvar; cvar = cvar->next) { + for (cvar = cvar_vars; cvar; cvar = cvar->next) + { if (partial && strncmp (partial,cvar->name,len)) continue; diff --git a/cvar.h b/cvar.h index 89ad8fc9..8a7dbc8e 100644 --- a/cvar.h +++ b/cvar.h @@ -60,6 +60,7 @@ interface from being ambiguous. #define CVAR_SAVE 1 #define CVAR_NOTIFY 2 +/* // type of a cvar for menu purposes #define CVARMENUTYPE_FLOAT 1 #define CVARMENUTYPE_INTEGER 2 @@ -80,58 +81,61 @@ interface from being ambiguous. typedef struct { int value; - char *name; + const char *name; } cvaroption_t; typedef struct { - int type; - float valuemin, valuemax, valuestep; - int numoptions; - cvaroption_t optionlist[MAX_CVAROPTIONS]; + int type; + float valuemin, valuemax, valuestep; + int numoptions; + cvaroption_t optionlist[MAX_CVAROPTIONS]; } menucvar_t; +*/ typedef struct cvar_s { - int flags; - char *name; - char *string; - int integer; - float value; - float vector[3]; - menucvar_t menuinfo; - struct cvar_s *next; + int flags; + char *name; + char *string; + int integer; + float value; + float vector[3]; + //menucvar_t menuinfo; + struct cvar_s *next; } cvar_t; -void Cvar_MenuSlider(cvar_t *variable, int menu, float slider_min, float slider_max, float slider_step); -void Cvar_MenuBool(cvar_t *variable, int menu, char *name_false, char *name_true); -void Cvar_MenuFloat(cvar_t *variable, int menu, float range_min, float range_max); -void Cvar_MenuInteger(cvar_t *variable, int menu, int range_min, int range_max); -void Cvar_MenuString(cvar_t *variable, int menu); -void Cvar_MenuOption(cvar_t *variable, int menu, int value[16], char *name[16]); +/* +void Cvar_MenuSlider(cvar_t *variable, int menu, float slider_min, float slider_max, float slider_step); +void Cvar_MenuBool(cvar_t *variable, int menu, const char *name_false, const char *name_true); +void Cvar_MenuFloat(cvar_t *variable, int menu, float range_min, float range_max); +void Cvar_MenuInteger(cvar_t *variable, int menu, int range_min, int range_max); +void Cvar_MenuString(cvar_t *variable, int menu); +void Cvar_MenuOption(cvar_t *variable, int menu, int value[16], const char *name[16]); +*/ -void Cvar_RegisterVariable (cvar_t *variable); +void Cvar_RegisterVariable (cvar_t *variable); // registers a cvar that already has the name, string, and optionally the // archive elements set. -void Cvar_Set (char *var_name, char *value); +void Cvar_Set (const char *var_name, const char *value); // equivelant to " " typed at the console -void Cvar_SetValue (char *var_name, float value); +void Cvar_SetValue (const char *var_name, float value); // expands value to a string and calls Cvar_Set -void Cvar_SetQuick (cvar_t *var, char *value); -void Cvar_SetValueQuick (cvar_t *var, float value); +void Cvar_SetQuick (cvar_t *var, const char *value); +void Cvar_SetValueQuick (cvar_t *var, float value); -float Cvar_VariableValue (char *var_name); +float Cvar_VariableValue (const char *var_name); // returns 0 if not defined or non numeric -char *Cvar_VariableString (char *var_name); +const char *Cvar_VariableString (const char *var_name); // returns an empty string if not defined -char *Cvar_CompleteVariable (char *partial); +const char *Cvar_CompleteVariable (const char *partial); // attempts to match a partial variable name for command line completion // returns NULL if nothing fits @@ -140,20 +144,20 @@ 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 (QFile *f); // Writes lines containing "set variable value" for all variables // with the archive flag set to true. -cvar_t *Cvar_FindVar (char *var_name); -cvar_t *Cvar_FindVarAfter (char *prev_var_name, int neededflags); +cvar_t *Cvar_FindVar (const char *var_name); +cvar_t *Cvar_FindVarAfter (const char *prev_var_name, int neededflags); -int Cvar_CompleteCountPossible (char *partial); -char **Cvar_CompleteBuildList (char *partial); +int Cvar_CompleteCountPossible (const char *partial); +const char **Cvar_CompleteBuildList (const char *partial); // Added by EvilTypeGuy - functions for tab completion system // Thanks to Fett erich@heintz.com // Thanks to taniwha -void Cvar_List_f (void); +void Cvar_List_f (void); // Prints a list of Cvars including a count of them to the user console // Referenced in cmd.c in Cmd_Init hence it's inclusion here // Added by EvilTypeGuy eviltypeguy@qeradiant.com diff --git a/host.c b/host.c index 7b6cd76e..305fe588 100644 --- a/host.c +++ b/host.c @@ -34,65 +34,80 @@ Memory is cleared / released when a server or client begins, not when they end. */ -qboolean host_initialized; // true if into command execution -qboolean host_loopactive = false; // LordHavoc: used to turn Host_Error into Sys_Error if starting up or shutting down -qboolean host_shuttingdown = false; // LordHavoc: set when quit is executed +// true if into command execution +qboolean host_initialized; +// LordHavoc: used to turn Host_Error into Sys_Error if starting up or shutting down +qboolean host_loopactive = false; +// LordHavoc: set when quit is executed +qboolean host_shuttingdown = false; -double host_frametime; -double host_realframetime; // LordHavoc: the real frametime, before slowmo and clamping are applied (used for console scrolling) -double realtime; // without any filtering or bounding -double oldrealtime; // last frame run -int host_framecount; +double host_frametime; +// LordHavoc: the real frametime, before slowmo and clamping are applied (used for console scrolling) +double host_realframetime; +// the real time, without any slowmo or clamping +double realtime; +// realtime from previous frame +double oldrealtime; +// how many frames have occurred +int host_framecount; -int forcedeveloper; // used for -developer commandline parameter, hacky hacky +// used for -developer commandline parameter, hacky hacky +int forcedeveloper; -client_t *host_client; // current client +// current client +client_t *host_client; -jmp_buf host_abortserver; +jmp_buf host_abortserver; -cvar_t host_framerate = {0, "host_framerate","0"}; // set for slow motion -cvar_t host_speeds = {0, "host_speeds","0"}; // set for running times -cvar_t slowmo = {0, "slowmo", "1.0"}; // LordHavoc: framerate independent slowmo -cvar_t host_minfps = {CVAR_SAVE, "host_minfps", "10"}; // LordHavoc: game logic lower cap on framerate (if framerate is below this is, it pretends it is this, so game logic will run normally) -cvar_t host_maxfps = {CVAR_SAVE, "host_maxfps", "1000"}; // LordHavoc: framerate upper cap +// pretend frames take this amount of time (in seconds), 0 = realtime +cvar_t host_framerate = {0, "host_framerate","0"}; +// shows time used by certain subsystems +cvar_t host_speeds = {0, "host_speeds","0"}; +// LordHavoc: framerate independent slowmo +cvar_t slowmo = {0, "slowmo", "1.0"}; +// LordHavoc: game logic lower cap on framerate (if framerate is below this is, it pretends it is this, so game logic will run normally) +cvar_t host_minfps = {CVAR_SAVE, "host_minfps", "10"}; +// LordHavoc: framerate upper cap +cvar_t host_maxfps = {CVAR_SAVE, "host_maxfps", "1000"}; -cvar_t sv_echobprint = {CVAR_SAVE, "sv_echobprint", "1"}; // print broadcast messages in dedicated mode +// print broadcast messages in dedicated mode +cvar_t sv_echobprint = {CVAR_SAVE, "sv_echobprint", "1"}; -cvar_t sys_ticrate = {CVAR_SAVE, "sys_ticrate","0.05"}; -cvar_t serverprofile = {0, "serverprofile","0"}; +cvar_t sys_ticrate = {CVAR_SAVE, "sys_ticrate","0.05"}; +cvar_t serverprofile = {0, "serverprofile","0"}; -cvar_t fraglimit = {CVAR_NOTIFY, "fraglimit","0"}; -cvar_t timelimit = {CVAR_NOTIFY, "timelimit","0"}; -cvar_t teamplay = {CVAR_NOTIFY, "teamplay","0"}; +cvar_t fraglimit = {CVAR_NOTIFY, "fraglimit","0"}; +cvar_t timelimit = {CVAR_NOTIFY, "timelimit","0"}; +cvar_t teamplay = {CVAR_NOTIFY, "teamplay","0"}; -cvar_t samelevel = {0, "samelevel","0"}; -cvar_t noexit = {CVAR_NOTIFY, "noexit","0"}; +cvar_t samelevel = {0, "samelevel","0"}; +cvar_t noexit = {CVAR_NOTIFY, "noexit","0"}; -cvar_t developer = {0, "developer","0"}; +cvar_t developer = {0, "developer","0"}; -cvar_t skill = {0, "skill","1"}; // 0 - 3 -cvar_t deathmatch = {0, "deathmatch","0"}; // 0, 1, or 2 -cvar_t coop = {0, "coop","0"}; // 0 or 1 +cvar_t skill = {0, "skill","1"}; +cvar_t deathmatch = {0, "deathmatch","0"}; +cvar_t coop = {0, "coop","0"}; -cvar_t pausable = {0, "pausable","1"}; +cvar_t pausable = {0, "pausable","1"}; -cvar_t temp1 = {0, "temp1","0"}; +cvar_t temp1 = {0, "temp1","0"}; -cvar_t timestamps = {CVAR_SAVE, "timestamps", "0"}; -cvar_t timeformat = {CVAR_SAVE, "timeformat", "[%b %e %X] "}; +cvar_t timestamps = {CVAR_SAVE, "timestamps", "0"}; +cvar_t timeformat = {CVAR_SAVE, "timeformat", "[%b %e %X] "}; /* ================ Host_EndGame ================ */ -void Host_EndGame (char *message, ...) +void Host_EndGame (const char *format, ...) { - va_list argptr; - char string[1024]; + va_list argptr; + char string[1024]; - va_start (argptr,message); - vsprintf (string,message,argptr); + va_start (argptr,format); + vsprintf (string,format,argptr); va_end (argptr); Con_DPrintf ("Host_EndGame: %s\n",string); @@ -118,10 +133,10 @@ This shuts down both the client and server ================ */ char hosterrorstring[4096]; -void Host_Error (char *error, ...) +void Host_Error (const char *error, ...) { - va_list argptr; - static qboolean inerror = false; + va_list argptr; + static qboolean inerror = false; // LordHavoc: if first frame has not been shown, or currently shutting // down, do Sys_Error instead @@ -279,7 +294,7 @@ Writes key bindings and archived cvars to config.cfg */ void Host_WriteConfiguration (void) { - QFile *f; + QFile *f; // dedicated servers initialize the host but don't parse and set the // config.cfg cvars @@ -291,7 +306,7 @@ void Host_WriteConfiguration (void) Con_Printf ("Couldn't write config.cfg.\n"); return; } - + Key_WriteBindings (f); Cvar_WriteVariables (f); @@ -308,15 +323,15 @@ Sends text across to be displayed FIXME: make this just a stuffed echo? ================= */ -void SV_ClientPrintf (char *fmt, ...) +void SV_ClientPrintf (const char *fmt, ...) { - va_list argptr; - char string[1024]; - + va_list argptr; + char string[1024]; + va_start (argptr,fmt); vsprintf (string, fmt,argptr); va_end (argptr); - + MSG_WriteByte (&host_client->message, svc_print); MSG_WriteString (&host_client->message, string); } @@ -328,16 +343,16 @@ SV_BroadcastPrintf Sends text to all active clients ================= */ -void SV_BroadcastPrintf (char *fmt, ...) +void SV_BroadcastPrintf (const char *fmt, ...) { - va_list argptr; - char string[1024]; - int i; - + va_list argptr; + char string[1024]; + int i; + va_start (argptr,fmt); vsprintf (string, fmt,argptr); va_end (argptr); - + for (i=0 ; imessage, svc_disconnect); NET_SendMessage (host_client->netconnection, &host_client->message); } - + if (sv.active && host_client->edict && host_client->spawned) // LordHavoc: don't call QC if server is dead (avoids recursive Host_Error in some mods when they run out of edicts) { // call the prog function for removing a client @@ -441,11 +456,10 @@ This only happens at the end of a game, not between levels */ void Host_ShutdownServer(qboolean crash) { - int i; - int count; - sizebuf_t buf; - char message[4]; - double start; + int i, count; + sizebuf_t buf; + char message[4]; + double start; if (!sv.active) return; @@ -603,7 +617,7 @@ Add them exactly as if they had been typed at the console */ void Host_GetConsoleCommands (void) { - char *cmd; + char *cmd; while (1) { @@ -664,10 +678,10 @@ Runs all active servers */ void _Host_Frame (float time) { - static double time1 = 0; - static double time2 = 0; - static double time3 = 0; - int pass1, pass2, pass3; + static double time1 = 0; + static double time2 = 0; + static double time3 = 0; + int pass1, pass2, pass3; if (setjmp (host_abortserver) ) return; // something bad happened, or the server disconnected @@ -767,10 +781,10 @@ void _Host_Frame (float time) void Host_Frame (float time) { - double time1, time2; - static double timetotal; - static int timecount; - int i, c, m; + double time1, time2; + static double timetotal; + static int timecount; + int i, c, m; if (!serverprofile.integer) { diff --git a/host_cmd.c b/host_cmd.c index 507188bf..2fbc012f 100644 --- a/host_cmd.c +++ b/host_cmd.c @@ -48,12 +48,9 @@ Host_Status_f */ void Host_Status_f (void) { - client_t *client; - int seconds; - int minutes; - int hours = 0; - int j; - void (*print) (char *fmt, ...); + client_t *client; + int seconds, minutes, hours = 0, j; + void (*print) (const char *fmt, ...); if (cmd_source == src_command) { @@ -513,17 +510,18 @@ Host_Loadgame_f */ void Host_Loadgame_f (void) { - char name[MAX_OSPATH]; - QFile *f; - char mapname[MAX_QPATH]; - float time, tfloat; - char buf[32768], *start; - char *str; - int i, r; - edict_t *ent; - int entnum; - int version; - float spawn_parms[NUM_SPAWN_PARMS]; + char name[MAX_OSPATH]; + QFile *f; + char mapname[MAX_QPATH]; + float time, tfloat; + char buf[32768]; + const char *start; + char *str; + int i, r; + edict_t *ent; + int entnum; + int version; + float spawn_parms[NUM_SPAWN_PARMS]; if (cmd_source != src_command) return; @@ -595,7 +593,8 @@ void Host_Loadgame_f (void) } // load the edicts out of the savegame file - entnum = -1; // -1 is the globals + // -1 is the globals + entnum = -1; while (!Qeof(f)) { for (i=0 ; iv, 0, progs->entityfields * 4); ent->free = false; ED_ParseEdict (start, ent); - - // link it into the bsp tree + + // link it into the bsp tree if (!ent->free) SV_LinkEdict (ent, false); } entnum++; } - + sv.num_edicts = entnum; sv.time = time; @@ -701,7 +703,7 @@ void Host_Name_f (void) MSG_WriteString (&sv.reliable_datagram, host_client->name); } - + void Host_Version_f (void) { Con_Printf ("Version: %s build %s\n", gamename, buildstring); @@ -711,11 +713,11 @@ void Host_Say(qboolean teamonly) { client_t *client; client_t *save; - int j; - char *p; + int j; + const char *p1, *p2; // LordHavoc: 256 char say messages - unsigned char text[256]; - qboolean fromServer = false; + unsigned char text[256]; + qboolean fromServer = false; if (cmd_source == src_command) { @@ -734,28 +736,34 @@ void Host_Say(qboolean teamonly) if (Cmd_Argc () < 2) return; - save = host_client; - - p = Cmd_Args(); -// remove quotes if present - if (*p == '"') - { - p++; - p[strlen(p)-1] = 0; - } - // turn on color set 1 if (!fromServer) - sprintf (text, "%c%s: ", 1, save->name); + sprintf (text, "%c%s: ", 1, host_client->name); else sprintf (text, "%c<%s> ", 1, hostname.string); - j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator - if (strlen(p) > j) - p[j] = 0; + save = host_client; - strcat (text, p); - strcat (text, "\n"); + p1 = Cmd_Args(); + p2 = p1 + strlen(p1); + // remove trailing newlines + while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r')) + p2--; + // remove quotes if present + if (*p1 == '"') + { + p1++; + if (p2[-1] == '"') + p2--; + else + Con_Printf("Host_Say: missing end quote\n"); + } + while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r')) + p2--; + for (j = strlen(text);j < (sizeof(text) - 2) && p1 < p2;) + text[j++] = *p1++; + text[j++] = '\n'; + text[j++] = 0; for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++) { @@ -788,38 +796,55 @@ void Host_Tell_f(void) { client_t *client; client_t *save; - int j; - char *p; - char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64) + int j; + const char *p1, *p2; + char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64) + qboolean fromServer = false; if (cmd_source == src_command) { - Cmd_ForwardToServer (); - return; + if (cls.state == ca_dedicated) + fromServer = true; + else + { + Cmd_ForwardToServer (); + return; + } } if (Cmd_Argc () < 3) return; - strcpy(text, host_client->name); - strcat(text, ": "); - - p = Cmd_Args(); - -// remove quotes if present - if (*p == '"') - { - p++; - p[strlen(p)-1] = 0; + if (!fromServer) + sprintf (text, "%s: ", host_client->name); + else + sprintf (text, "<%s> ", hostname.string); + + p1 = Cmd_Args(); + p2 = p1 + strlen(p1); + // remove the target name + while (p1 < p2 && *p1 != ' ') + p1++; + while (p1 < p2 && *p1 == ' ') + p1++; + // remove trailing newlines + while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r')) + p2--; + // remove quotes if present + if (*p1 == '"') + { + p1++; + if (p2[-1] == '"') + p2--; + else + Con_Printf("Host_Say: missing end quote\n"); } - -// check length & truncate if necessary - j = sizeof(text) - 2 - strlen(text); // -2 for /n and null terminator - if (strlen(p) > j) - p[j] = 0; - - strcat (text, p); - strcat (text, "\n"); + while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r')) + p2--; + for (j = strlen(text);j < (sizeof(text) - 2) && p1 < p2;) + text[j++] = *p1++; + text[j++] = '\n'; + text[j++] = 0; save = host_client; for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++) @@ -862,7 +887,7 @@ void Host_Color_f(void) top = atoi(Cmd_Argv(1)); bottom = atoi(Cmd_Argv(2)); } - + top &= 15; // LordHavoc: allow skin colormaps 14 and 15 (was 13) if (top > 15) @@ -920,7 +945,7 @@ void Host_Kill_f (void) SV_ClientPrintf ("Can't suicide -- already dead!\n"); return; } - + pr_global_struct->time = sv.time; pr_global_struct->self = EDICT_TO_PROG(sv_player); PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing"); @@ -1155,11 +1180,11 @@ Kicks a user off of the server */ void Host_Kick_f (void) { - char *who; - char *message = NULL; - client_t *save; - int i; - qboolean byNumber = false; + char *who; + const char *message = NULL; + client_t *save; + int i; + qboolean byNumber = false; if (cmd_source == src_command) { @@ -1198,10 +1223,12 @@ void Host_Kick_f (void) if (i < svs.maxclients) { if (cmd_source == src_command) + { if (cls.state == ca_dedicated) who = "Console"; else who = cl_name.string; + } else who = save->name; @@ -1211,7 +1238,8 @@ void Host_Kick_f (void) if (Cmd_Argc() > 2) { - message = COM_Parse(Cmd_Args()); + message = Cmd_Args(); + COM_ParseToken(&message); if (byNumber) { message++; // skip the # @@ -1247,9 +1275,9 @@ Host_Give_f */ void Host_Give_f (void) { - char *t; - int v; - eval_t *val; + const char *t; + int v; + eval_t *val; if (cmd_source == src_command) { diff --git a/model_brush.c b/model_brush.c index 85c0b0c4..a3f4a314 100644 --- a/model_brush.c +++ b/model_brush.c @@ -678,22 +678,20 @@ static void Mod_LoadVisibility (lump_t *l) } // used only for HalfLife maps -void Mod_ParseWadsFromEntityLump(char *data) +void Mod_ParseWadsFromEntityLump(const char *data) { char key[128], value[4096]; char wadname[128]; int i, j, k; if (!data) return; - data = COM_Parse(data); - if (!data) + if (!COM_ParseToken(&data)) return; // error if (com_token[0] != '{') return; // error while (1) { - data = COM_Parse(data); - if (!data) + if (!COM_ParseToken(&data)) return; // error if (com_token[0] == '}') break; // end of worldspawn @@ -703,8 +701,7 @@ void Mod_ParseWadsFromEntityLump(char *data) strcpy(key, com_token); while (key[strlen(key)-1] == ' ') // remove trailing spaces key[strlen(key)-1] = 0; - data = COM_Parse(data); - if (!data) + if (!COM_ParseToken(&data)) return; // error strcpy(value, com_token); if (!strcmp("wad", key)) // for HalfLife maps diff --git a/model_shared.c b/model_shared.c index 4ece6a32..9da66893 100644 --- a/model_shared.c +++ b/model_shared.c @@ -276,7 +276,7 @@ Mod_FindName ================== */ -model_t *Mod_FindName (char *name) +model_t *Mod_FindName (const char *name) { int i; model_t *mod, *freemod; @@ -319,7 +319,7 @@ Mod_TouchModel ================== */ -void Mod_TouchModel (char *name) +void Mod_TouchModel (const char *name) { model_t *mod; @@ -334,7 +334,7 @@ Mod_ForName Loads in a model for the given name ================== */ -model_t *Mod_ForName (char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel) +model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel) { return Mod_LoadModel (Mod_FindName (name), crash, checkdisk, isworldmodel); } diff --git a/model_shared.h b/model_shared.h index d58fc9bc..4fb9af4f 100644 --- a/model_shared.h +++ b/model_shared.h @@ -223,8 +223,9 @@ extern cvar_t r_fullbrights; void Mod_Init (void); void Mod_CheckLoaded (model_t *mod); void Mod_ClearAll (void); -model_t *Mod_ForName (char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel); -void Mod_TouchModel (char *name); +model_t *Mod_FindName (const char *name); +model_t *Mod_ForName (const char *name, qboolean crash, qboolean checkdisk, qboolean isworldmodel); +void Mod_TouchModel (const char *name); void Mod_UnloadModel (model_t *mod); void Mod_ClearUsed(void); @@ -233,7 +234,5 @@ void Mod_PurgeUnused(void); extern model_t *loadmodel; extern char loadname[32]; // for hunk tags -extern model_t *Mod_FindName (char *name); - #endif // __MODEL__ diff --git a/net.h b/net.h index 126dbe03..c111bf0e 100644 --- a/net.h +++ b/net.h @@ -148,7 +148,6 @@ typedef struct qsocket_s struct qsockaddr addr; char address[NET_NAMELEN]; - } qsocket_t; extern qsocket_t *net_activeSockets; @@ -170,10 +169,10 @@ typedef struct int (*Write) (int socket, qbyte *buf, int len, struct qsockaddr *addr); int (*Broadcast) (int socket, qbyte *buf, int len); char * (*AddrToString) (struct qsockaddr *addr); - int (*StringToAddr) (char *string, struct qsockaddr *addr); + int (*StringToAddr) (const char *string, struct qsockaddr *addr); int (*GetSocketAddr) (int socket, struct qsockaddr *addr); int (*GetNameFromAddr) (struct qsockaddr *addr, char *name); - int (*GetAddrFromName) (char *name, struct qsockaddr *addr); + int (*GetAddrFromName) (const char *name, struct qsockaddr *addr); int (*AddrCompare) (struct qsockaddr *addr1, struct qsockaddr *addr2); int (*GetSocketPort) (struct qsockaddr *addr); int (*SetSocketPort) (struct qsockaddr *addr, int port); diff --git a/net_dgrm.c b/net_dgrm.c index 7829b1c6..20f06c58 100644 --- a/net_dgrm.c +++ b/net_dgrm.c @@ -103,7 +103,7 @@ void NET_Ban_f (void) { char addrStr [32]; char maskStr [32]; - void (*print) (char *fmt, ...); + void (*print) (const char *fmt, ...); if (cmd_source == src_command) { @@ -568,9 +568,8 @@ static void Test_Poll(void) static void Test_f (void) { - char *host; - int n; - int max = MAX_SCOREBOARD; + const char *host; + int n, max = MAX_SCOREBOARD; struct qsockaddr sendaddr; if (testInProgress) @@ -699,8 +698,8 @@ Done: static void Test2_f (void) { - char *host; - int n; + const char *host; + int n; struct qsockaddr sendaddr; if (test2InProgress) diff --git a/net_udp.c b/net_udp.c index 18471851..b7762980 100644 --- a/net_udp.c +++ b/net_udp.c @@ -167,7 +167,7 @@ this lets you type only as much of the net address as required, using the local network components to fill in the rest ============ */ -static int PartialIPAddress (char *in, struct qsockaddr *hostaddr) +static int PartialIPAddress (const char *in, struct qsockaddr *hostaddr) { char buff[256]; char *b; @@ -316,7 +316,7 @@ char *UDP_AddrToString (struct qsockaddr *addr) //============================================================================= -int UDP_StringToAddr (char *string, struct qsockaddr *addr) +int UDP_StringToAddr (const char *string, struct qsockaddr *addr) { int ha1, ha2, ha3, ha4, hp; int ipaddr; @@ -366,7 +366,7 @@ int UDP_GetNameFromAddr (struct qsockaddr *addr, char *name) //============================================================================= -int UDP_GetAddrFromName(char *name, struct qsockaddr *addr) +int UDP_GetAddrFromName(const char *name, struct qsockaddr *addr) { struct hostent *hostentry; diff --git a/net_udp.h b/net_udp.h index bc58657d..06b531bf 100644 --- a/net_udp.h +++ b/net_udp.h @@ -33,10 +33,10 @@ int UDP_Read (int socket, qbyte *buf, int len, struct qsockaddr *addr); int UDP_Write (int socket, qbyte *buf, int len, struct qsockaddr *addr); int UDP_Broadcast (int socket, qbyte *buf, int len); char *UDP_AddrToString (struct qsockaddr *addr); -int UDP_StringToAddr (char *string, struct qsockaddr *addr); +int UDP_StringToAddr (const char *string, struct qsockaddr *addr); int UDP_GetSocketAddr (int socket, struct qsockaddr *addr); int UDP_GetNameFromAddr (struct qsockaddr *addr, char *name); -int UDP_GetAddrFromName (char *name, struct qsockaddr *addr); +int UDP_GetAddrFromName (const char *name, struct qsockaddr *addr); int UDP_AddrCompare (struct qsockaddr *addr1, struct qsockaddr *addr2); int UDP_GetSocketPort (struct qsockaddr *addr); int UDP_SetSocketPort (struct qsockaddr *addr, int port); diff --git a/pr_edict.c b/pr_edict.c index 037f90cd..4fc99507 100644 --- a/pr_edict.c +++ b/pr_edict.c @@ -40,7 +40,7 @@ mempool_t *edictstring_mempool; int type_size[8] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(void *)/4}; ddef_t *ED_FieldAtOfs (int ofs); -qboolean ED_ParseEpair (void *base, ddef_t *key, char *s); +qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s); cvar_t pr_checkextension = {0, "pr_checkextension", "1"}; cvar_t nomonsters = {0, "nomonsters", "0"}; @@ -79,8 +79,8 @@ typedef struct { static gefv_cache gefvCache[GEFV_CACHESIZE] = {{NULL, ""}, {NULL, ""}}; -ddef_t *ED_FindField (char *name); -dfunction_t *ED_FindFunction (char *name); +ddef_t *ED_FindField (const char *name); +dfunction_t *ED_FindFunction (const char *name); // LordHavoc: in an effort to eliminate time wasted on GetEdictFieldValue... these are defined as externs in progs.h int eval_gravity; @@ -121,7 +121,7 @@ int eval_viewzoom; dfunction_t *SV_PlayerPhysicsQC; dfunction_t *EndFrameQC; -int FindFieldOffset(char *field) +int FindFieldOffset(const char *field) { ddef_t *d; d = ED_FindField(field); @@ -296,10 +296,10 @@ ddef_t *ED_FieldAtOfs (int ofs) ED_FindField ============ */ -ddef_t *ED_FindField (char *name) +ddef_t *ED_FindField (const char *name) { - ddef_t *def; - int i; + ddef_t *def; + int i; for (i=0 ; inumfielddefs ; i++) { @@ -315,11 +315,11 @@ ddef_t *ED_FindField (char *name) ED_FindGlobal ============ */ -ddef_t *ED_FindGlobal (char *name) +ddef_t *ED_FindGlobal (const char *name) { - ddef_t *def; - int i; - + ddef_t *def; + int i; + for (i=0 ; inumglobaldefs ; i++) { def = &pr_globaldefs[i]; @@ -335,11 +335,11 @@ ddef_t *ED_FindGlobal (char *name) ED_FindFunction ============ */ -dfunction_t *ED_FindFunction (char *name) +dfunction_t *ED_FindFunction (const char *name) { dfunction_t *func; int i; - + for (i=0 ; inumfunctions ; i++) { func = &pr_functions[i]; @@ -782,25 +782,23 @@ void ED_WriteGlobals (QFile *f) ED_ParseGlobals ============= */ -void ED_ParseGlobals (char *data) +void ED_ParseGlobals (const char *data) { - char keyname[1024]; // LordHavoc: good idea? bad idea? was 64 - ddef_t *key; + char keyname[1024]; // LordHavoc: good idea? bad idea? was 64 + ddef_t *key; while (1) { - // parse key - data = COM_Parse (data); + // parse key + if (!COM_ParseToken (&data)) + Host_Error ("ED_ParseEntity: EOF without closing brace"); if (com_token[0] == '}') break; - if (!data) - Host_Error ("ED_ParseEntity: EOF without closing brace"); strcpy (keyname, com_token); - // parse value - data = COM_Parse (data); - if (!data) + // parse value + if (!COM_ParseToken (&data)) Host_Error ("ED_ParseEntity: EOF without closing brace"); if (com_token[0] == '}') @@ -826,10 +824,10 @@ void ED_ParseGlobals (char *data) ED_NewString ============= */ -char *ED_NewString (char *string) +char *ED_NewString (const char *string) { - char *new, *new_p; - int i,l; + char *new, *new_p; + int i,l; l = strlen(string) + 1; new = Mem_Alloc(edictstring_mempool, l); @@ -861,7 +859,7 @@ Can parse either fields or globals returns false if error ============= */ -qboolean ED_ParseEpair (void *base, ddef_t *key, char *s) +qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s) { int i; char string[128]; @@ -937,13 +935,13 @@ ed should be a properly initialized empty edict. Used for initial level load and for savegames. ==================== */ -char *ED_ParseEdict (char *data, edict_t *ent) +const char *ED_ParseEdict (const char *data, edict_t *ent) { - ddef_t *key; - qboolean anglehack; - qboolean init; - char keyname[256]; - int n; + ddef_t *key; + qboolean anglehack; + qboolean init; + char keyname[256]; + int n; init = false; @@ -955,11 +953,10 @@ char *ED_ParseEdict (char *data, edict_t *ent) while (1) { // parse key - data = COM_Parse (data); + if (!COM_ParseToken (&data)) + Host_Error ("ED_ParseEntity: EOF without closing brace"); if (com_token[0] == '}') break; - if (!data) - Host_Error ("ED_ParseEntity: EOF without closing brace"); // anglehack is to allow QuakeEd to write single scalar angles // and allow them to be turned into vectors. (FIXME...) @@ -986,8 +983,7 @@ char *ED_ParseEdict (char *data, edict_t *ent) } // parse value - data = COM_Parse (data); - if (!data) + if (!COM_ParseToken (&data)) Host_Error ("ED_ParseEntity: EOF without closing brace"); if (com_token[0] == '}') @@ -1040,11 +1036,11 @@ Used for both fresh maps and savegame loads. A fresh map would also need to call ED_CallSpawnFunctions () to let the objects initialize themselves. ================ */ -void ED_LoadFromFile (char *data) -{ - edict_t *ent; - int inhibit; - dfunction_t *func; +void ED_LoadFromFile (const char *data) +{ + edict_t *ent; + int inhibit; + dfunction_t *func; ent = NULL; inhibit = 0; @@ -1054,8 +1050,7 @@ void ED_LoadFromFile (char *data) while (1) { // parse the opening brace - data = COM_Parse (data); - if (!data) + if (!COM_ParseToken (&data)) break; if (com_token[0] != '{') Host_Error ("ED_LoadFromFile: found %s when expecting {",com_token); diff --git a/pr_exec.c b/pr_exec.c index 368f485b..2481b1b3 100644 --- a/pr_exec.c +++ b/pr_exec.c @@ -365,7 +365,7 @@ PR_ExecuteProgram #define OPB ((eval_t *)&pr_globals[(unsigned short) st->b]) #define OPC ((eval_t *)&pr_globals[(unsigned short) st->c]) extern cvar_t pr_boundscheck; -void PR_ExecuteProgram (func_t fnum, char *errormessage) +void PR_ExecuteProgram (func_t fnum, const char *errormessage) { dstatement_t *st; dfunction_t *f, *newf; diff --git a/progs.h b/progs.h index 874ba9f9..b69e0caa 100644 --- a/progs.h +++ b/progs.h @@ -117,7 +117,7 @@ extern int pr_edictareasize; // LordHavoc: for bounds checking void PR_Init (void); -void PR_ExecuteProgram (func_t fnum, char *errormessage); +void PR_ExecuteProgram (func_t fnum, const char *errormessage); void PR_LoadProgs (void); void PR_Profile_f (void); @@ -127,17 +127,17 @@ void PR_Crash (void); edict_t *ED_Alloc (void); void ED_Free (edict_t *ed); -char *ED_NewString (char *string); +char *ED_NewString (const char *string); // returns a copy of the string allocated from the server's string heap void ED_Print (edict_t *ed); void ED_Write (QFile *f, edict_t *ed); -char *ED_ParseEdict (char *data, edict_t *ent); +const char *ED_ParseEdict (const char *data, edict_t *ent); void ED_WriteGlobals (QFile *f); -void ED_ParseGlobals (char *data); +void ED_ParseGlobals (const char *data); -void ED_LoadFromFile (char *data); +void ED_LoadFromFile (const char *data); edict_t *EDICT_NUM_ERROR(int n); #define EDICT_NUM(n) (n >= 0 ? (n < sv.max_edicts ? (edict_t *)((qbyte *)sv.edicts + (n) * pr_edict_size) : EDICT_NUM_ERROR(n)) : EDICT_NUM_ERROR(n)) diff --git a/quakedef.h b/quakedef.h index 201cd783..0c809003 100644 --- a/quakedef.h +++ b/quakedef.h @@ -200,40 +200,42 @@ extern qboolean noclip_anglehack; // // host // -extern cvar_t sys_ticrate; -extern cvar_t developer; - -extern qboolean host_initialized; // true if into command execution -extern double host_frametime; -extern double host_realframetime; // LordHavoc: the real frametime, before slowmo and clamping are applied (used for console scrolling) -extern int host_framecount; // incremented every frame, never reset -extern double realtime; // not bounded in any way, changed at - // start of every frame, never reset +extern cvar_t sys_ticrate; +extern cvar_t developer; + +// true if into command execution +extern qboolean host_initialized; +extern double host_frametime; +// LordHavoc: the real frametime, before slowmo and clamping are applied (used for console scrolling) +extern double host_realframetime; +// incremented every frame, never reset +extern int host_framecount; +// not bounded in any way, changed at start of every frame, never reset +extern double realtime; void Host_ClearMemory (void); void Host_ServerFrame (void); void Host_InitCommands (void); void Host_Init (void); void Host_Shutdown(void); -void Host_Error (char *error, ...); -void Host_EndGame (char *message, ...); +void Host_Error (const char *error, ...); +void Host_EndGame (const char *message, ...); void Host_Frame (float time); void Host_Quit_f (void); -void Host_ClientCommands (char *fmt, ...); +void Host_ClientCommands (const char *fmt, ...); void Host_ShutdownServer (qboolean crash); -extern qboolean msg_suppress_1; // suppresses resolution and cache size console output - // an fullscreen DIB focus gain/loss -extern int current_skill; // skill level for currently loaded level (in case - // the user changes the cvar while the level is - // running, this reflects the level actually in use) +// suppresses resolution and cache size console output and fullscreen DIB focus gain/loss +extern qboolean msg_suppress_1; +// skill level for currently loaded level (in case the user changes the cvar while the level is running, this reflects the level actually in use) +extern int current_skill; -extern int minimum_memory; +extern int minimum_memory; // // chase // -extern cvar_t chase_active; +extern cvar_t chase_active; void Chase_Init (void); void Chase_Reset (void); diff --git a/server.h b/server.h index 27c50c47..dd0bc421 100644 --- a/server.h +++ b/server.h @@ -8,7 +8,7 @@ of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -24,10 +24,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. typedef struct { - int maxclients; - struct client_s *clients; // [maxclients] - int serverflags; // episode completion information - qboolean changelevel_issued; // cleared when at SV_SpawnServer + int maxclients; + // [maxclients] + struct client_s *clients; + // episode completion information + int serverflags; + // cleared when at SV_SpawnServer + qboolean changelevel_issued; } server_static_t; //============================================================================= @@ -36,96 +39,119 @@ typedef enum {ss_loading, ss_active} server_state_t; typedef struct { - qboolean active; // false if only a net client - - qboolean paused; - qboolean loadgame; // handle connections specially - - double time; - - double frametime; - - int lastcheck; // used by PF_checkclient - double lastchecktime; - - char name[64]; // map name - char modelname[64]; // maps/.bsp, for model_precache[0] - struct model_s *worldmodel; - char *model_precache[MAX_MODELS]; // NULL terminated - struct model_s *models[MAX_MODELS]; - char *sound_precache[MAX_SOUNDS]; // NULL terminated - char *lightstyles[MAX_LIGHTSTYLES]; - int num_edicts; - int max_edicts; - edict_t *edicts; // can NOT be array indexed, because - // edict_t is variable sized, but can - // be used to reference the world ent - server_state_t state; // some actions are only valid during load - - sizebuf_t datagram; - qbyte datagram_buf[MAX_DATAGRAM]; - - sizebuf_t reliable_datagram; // copied to all clients at end of frame - qbyte reliable_datagram_buf[MAX_DATAGRAM]; - - sizebuf_t signon; - qbyte signon_buf[32768]; // LordHavoc: increased signon message buffer from 8192 to 32768 + // false if only a net client + qboolean active; + + qboolean paused; + // handle connections specially + qboolean loadgame; + + double time; + + double frametime; + + // used by PF_checkclient + int lastcheck; + double lastchecktime; + + // map name + char name[64]; + // maps/.bsp, for model_precache[0] + char modelname[64]; + struct model_s *worldmodel; + // NULL terminated + char *model_precache[MAX_MODELS]; + struct model_s *models[MAX_MODELS]; + // NULL terminated + char *sound_precache[MAX_SOUNDS]; + char *lightstyles[MAX_LIGHTSTYLES]; + int num_edicts; + int max_edicts; + // can NOT be array indexed, because edict_t is variable sized, but can be used to reference the world ent + edict_t *edicts; + // some actions are only valid during load + server_state_t state; + + sizebuf_t datagram; + qbyte datagram_buf[MAX_DATAGRAM]; + + // copied to all clients at end of frame + sizebuf_t reliable_datagram; + qbyte reliable_datagram_buf[MAX_DATAGRAM]; + + sizebuf_t signon; + // LordHavoc: increased signon message buffer from 8192 to 32768 + qbyte signon_buf[32768]; } server_t; -#define NUM_PING_TIMES 16 -#define NUM_SPAWN_PARMS 16 +#define NUM_PING_TIMES 16 +#define NUM_SPAWN_PARMS 16 typedef struct client_s { - qboolean active; // false = client is free - qboolean spawned; // false = don't send datagrams - qboolean dropasap; // has been told to go to another level - qboolean sendsignon; // only valid before spawned + // false = client is free + qboolean active; + // false = don't send datagrams + qboolean spawned; + // has been told to go to another level + qboolean dropasap; + // only valid before spawned + qboolean sendsignon; #ifndef NOROUTINGFIX // LordHavoc: to make netquake protocol get through NAT routers, have to wait for client to ack - qboolean waitingforconnect; // waiting for connect from client (stage 1) - qboolean sendserverinfo; // send server info in next datagram (stage 2) + // waiting for connect from client (stage 1) + qboolean waitingforconnect; + // send server info in next datagram (stage 2) + qboolean sendserverinfo; #endif - double last_message; // reliable messages must be sent - // periodically - - struct qsocket_s *netconnection; // communications handle - - usercmd_t cmd; // movement - vec3_t wishdir; // intended motion calced from cmd - - sizebuf_t message; // can be added to at any time, - // copied and clear once per frame - qbyte msgbuf[MAX_MSGLEN]; - edict_t *edict; // EDICT_NUM(clientnum+1) - char name[32]; // for printing to other people - int colors; - - float ping_times[NUM_PING_TIMES]; - int num_pings; // ping_times[num_pings%NUM_PING_TIMES] - float ping; // LordHavoc: can be used for prediction or whatever... - float latency; // LordHavoc: specifically used for prediction, accounts for sys_ticrate too + // reliable messages must be sent periodically + double last_message; + + // communications handle + struct qsocket_s *netconnection; + + // movement + usercmd_t cmd; + // intended motion calced from cmd + vec3_t wishdir; + + // can be added to at any time, copied and clear once per frame + sizebuf_t message; + qbyte msgbuf[MAX_MSGLEN]; + // EDICT_NUM(clientnum+1) + edict_t *edict; + // for printing to other people + char name[32]; + int colors; + + float ping_times[NUM_PING_TIMES]; + // ping_times[num_pings%NUM_PING_TIMES] + int num_pings; + // LordHavoc: can be used for prediction or whatever... + float ping; + // LordHavoc: specifically used for prediction, accounts for sys_ticrate too + float latency; // spawn parms are carried from level to level - float spawn_parms[NUM_SPAWN_PARMS]; + float spawn_parms[NUM_SPAWN_PARMS]; // client known data for deltas - int old_frags; - int pmodel; + int old_frags; + int pmodel; #ifdef QUAKEENTITIES // delta compression state - float nextfullupdate[MAX_EDICTS]; + float nextfullupdate[MAX_EDICTS]; #endif // visibility state - float visibletime[MAX_EDICTS]; + float visibletime[MAX_EDICTS]; #ifndef QUAKEENTITIES entity_database_t entitydatabase; - int entityframenumber; // incremented each time an entity frame is sent + int entityframenumber; // incremented each time an entity frame is sent #endif } client_t; @@ -221,8 +247,10 @@ extern cvar_t sv_predict; extern cvar_t sv_stepheight; extern cvar_t sv_jumpstep; -extern server_static_t svs; // persistant server info -extern server_t sv; // local server +// persistant server info +extern server_static_t svs; +// local server +extern server_t sv; extern client_t *host_client; @@ -243,7 +271,7 @@ void SV_DropClient (qboolean crash); void SV_SendClientMessages (void); void SV_ClearDatagram (void); -int SV_ModelIndex (char *name); +int SV_ModelIndex (const char *name); void SV_SetIdealPitch (void); @@ -252,8 +280,8 @@ void SV_AddUpdates (void); void SV_ClientThink (void); void SV_AddClientToServer (struct qsocket_s *ret); -void SV_ClientPrintf (char *fmt, ...); -void SV_BroadcastPrintf (char *fmt, ...); +void SV_ClientPrintf (const char *fmt, ...); +void SV_BroadcastPrintf (const char *fmt, ...); void SV_Physics (void); @@ -267,7 +295,7 @@ void SV_MoveToGoal (void); void SV_CheckForNewClients (void); void SV_RunClients (void); void SV_SaveSpawnparms (void); -void SV_SpawnServer (char *server); +void SV_SpawnServer (const char *server); void SV_SetMaxClients(int n); diff --git a/sv_main.c b/sv_main.c index a65938f1..c945e285 100644 --- a/sv_main.c +++ b/sv_main.c @@ -1505,9 +1505,9 @@ SV_ModelIndex ================ */ -int SV_ModelIndex (char *name) +int SV_ModelIndex (const char *name) { - int i; + int i; if (!name || !name[0]) return 0; @@ -1656,7 +1656,7 @@ This is called at the start of each level */ extern float scr_centertime_off; -void SV_SpawnServer (char *server) +void SV_SpawnServer (const char *server) { edict_t *ent; int i; diff --git a/sys_linux.c b/sys_linux.c index 87c36913..abe5a454 100644 --- a/sys_linux.c +++ b/sys_linux.c @@ -139,7 +139,7 @@ void Sys_Sleep(void) usleep(1); } -int main (int argc, char **argv) +int main (int argc, const char **argv) { double frameoldtime, framenewtime; diff --git a/zone.c b/zone.c index b0decee9..941f9327 100644 --- a/zone.c +++ b/zone.c @@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. mempool_t *poolchain = NULL; -void *_Mem_Alloc(mempool_t *pool, int size, char *filename, int fileline) +void *_Mem_Alloc(mempool_t *pool, int size, const char *filename, int fileline) { #if MEMCLUMPING int i, j, k, needed, endbit, largest; @@ -119,7 +119,7 @@ choseclump: return (void *)((qbyte *) mem + sizeof(memheader_t)); } -void _Mem_Free(void *data, char *filename, int fileline) +void _Mem_Free(void *data, const char *filename, int fileline) { #if MEMCLUMPING int i, firstblock, endblock; @@ -197,7 +197,7 @@ void _Mem_Free(void *data, char *filename, int fileline) #endif } -mempool_t *_Mem_AllocPool(char *name, char *filename, int fileline) +mempool_t *_Mem_AllocPool(const char *name, const char *filename, int fileline) { mempool_t *pool; pool = malloc(sizeof(mempool_t)); @@ -217,7 +217,7 @@ mempool_t *_Mem_AllocPool(char *name, char *filename, int fileline) return pool; } -void _Mem_FreePool(mempool_t **pool, char *filename, int fileline) +void _Mem_FreePool(mempool_t **pool, const char *filename, int fileline) { mempool_t **chainaddress; if (*pool) @@ -243,7 +243,7 @@ void _Mem_FreePool(mempool_t **pool, char *filename, int fileline) } } -void _Mem_EmptyPool(mempool_t *pool, char *filename, int fileline) +void _Mem_EmptyPool(mempool_t *pool, const char *filename, int fileline) { if (pool == NULL) Sys_Error("Mem_EmptyPool: pool == NULL (emptypool at %s:%i)", filename, fileline); @@ -257,7 +257,7 @@ void _Mem_EmptyPool(mempool_t *pool, char *filename, int fileline) Mem_Free((void *)((qbyte *) pool->chain + sizeof(memheader_t))); } -void _Mem_CheckSentinels(void *data, char *filename, int fileline) +void _Mem_CheckSentinels(void *data, const char *filename, int fileline) { memheader_t *mem; @@ -272,7 +272,7 @@ void _Mem_CheckSentinels(void *data, char *filename, int fileline) } #if MEMCLUMPING -static void _Mem_CheckClumpSentinels(memclump_t *clump, char *filename, int fileline) +static void _Mem_CheckClumpSentinels(memclump_t *clump, const char *filename, int fileline) { // this isn't really very useful if (clump->sentinel1 != MEMCLUMP_SENTINEL) @@ -282,7 +282,7 @@ static void _Mem_CheckClumpSentinels(memclump_t *clump, char *filename, int file } #endif -void _Mem_CheckSentinelsGlobal(char *filename, int fileline) +void _Mem_CheckSentinelsGlobal(const char *filename, int fileline) { memheader_t *mem; #if MEMCLUMPING diff --git a/zone.h b/zone.h index 3396707c..8db00453 100644 --- a/zone.h +++ b/zone.h @@ -52,7 +52,7 @@ typedef struct memheader_s // size of the memory after the header (excluding header and sentinel2) int size; // file name and line where Mem_Alloc was called - char *filename; + const char *filename; int fileline; // should always be MEMHEADER_SENTINEL1 int sentinel1; @@ -104,7 +104,7 @@ typedef struct mempool_s // linked into global mempool list struct mempool_s *next; // file name and line where Mem_AllocPool was called - char *filename; + const char *filename; int fileline; // should always be MEMHEADER_SENTINEL1 int sentinel2; @@ -119,13 +119,13 @@ mempool_t; #define Mem_FreePool(pool) _Mem_FreePool(pool, __FILE__, __LINE__) #define Mem_EmptyPool(pool) _Mem_EmptyPool(pool, __FILE__, __LINE__) -void *_Mem_Alloc(mempool_t *pool, int size, char *filename, int fileline); -void _Mem_Free(void *data, char *filename, int fileline); -mempool_t *_Mem_AllocPool(char *name, char *filename, int fileline); -void _Mem_FreePool(mempool_t **pool, char *filename, int fileline); -void _Mem_EmptyPool(mempool_t *pool, char *filename, int fileline); -void _Mem_CheckSentinels(void *data, char *filename, int fileline); -void _Mem_CheckSentinelsGlobal(char *filename, int fileline); +void *_Mem_Alloc(mempool_t *pool, int size, const char *filename, int fileline); +void _Mem_Free(void *data, const char *filename, int fileline); +mempool_t *_Mem_AllocPool(const char *name, const char *filename, int fileline); +void _Mem_FreePool(mempool_t **pool, const char *filename, int fileline); +void _Mem_EmptyPool(mempool_t *pool, const char *filename, int fileline); +void _Mem_CheckSentinels(void *data, const char *filename, int fileline); +void _Mem_CheckSentinelsGlobal(const char *filename, int fileline); // used for temporary allocations mempool_t *tempmempool;