1/* 2Copyright (C) 1996-1997 Id Software, Inc. 3 4This program is free software; you can redistribute it and/or 5modify it under the terms of the GNU General Public License 6as published by the Free Software Foundation; either version 2 7of the License, or (at your option) any later version. 8 9This program is distributed in the hope that it will be useful, 10but WITHOUT ANY WARRANTY; without even the implied warranty of 11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 13See the GNU General Public License for more details. 14 15You should have received a copy of the GNU General Public License 16along with this program; if not, write to the Free Software 17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 19*/ 20// comndef.h -- general definitions 21 22typedef unsigned char byte; 23#define _DEF_BYTE_ 24 25// KJB Undefined true and false defined in SciTech's DEBUG.H header 26#undef true 27#undef false 28 29typedef enum {false, true} qboolean; 30 31#define MAX_INFO_STRING 196 32#define MAX_SERVERINFO_STRING 512 33#define MAX_LOCALINFO_STRING 32768 34 35//============================================================================ 36 37typedef struct sizebuf_s 38{ 39 qboolean allowoverflow; // if false, do a Sys_Error 40 qboolean overflowed; // set to true if the buffer size failed 41 byte *data; 42 int maxsize; 43 int cursize; 44} sizebuf_t; 45 46void SZ_Clear (sizebuf_t *buf); 47void *SZ_GetSpace (sizebuf_t *buf, int length); 48void SZ_Write (sizebuf_t *buf, void *data, int length); 49void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf 50 51//============================================================================ 52 53typedef struct link_s 54{ 55 struct link_s *prev, *next; 56} link_t; 57 58 59void ClearLink (link_t *l); 60void RemoveLink (link_t *l); 61void InsertLinkBefore (link_t *l, link_t *before); 62void InsertLinkAfter (link_t *l, link_t *after); 63 64// (type *)STRUCT_FROM_LINK(link_t *link, type, member) 65// ent = STRUCT_FROM_LINK(link,entity_t,order) 66// FIXME: remove this mess! 67#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m))) 68 69//============================================================================ 70 71#ifndef NULL 72#define NULL ((void *)0) 73#endif 74 75#define Q_MAXCHAR ((char)0x7f) 76#define Q_MAXSHORT ((short)0x7fff) 77#define Q_MAXINT ((int)0x7fffffff) 78#define Q_MAXLONG ((int)0x7fffffff) 79#define Q_MAXFLOAT ((int)0x7fffffff) 80 81#define Q_MINCHAR ((char)0x80) 82#define Q_MINSHORT ((short)0x8000) 83#define Q_MININT ((int)0x80000000) 84#define Q_MINLONG ((int)0x80000000) 85#define Q_MINFLOAT ((int)0x7fffffff) 86 87//============================================================================ 88 89extern qboolean bigendien; 90 91extern short (*BigShort) (short l); 92extern short (*LittleShort) (short l); 93extern int (*BigLong) (int l); 94extern int (*LittleLong) (int l); 95extern float (*BigFloat) (float l); 96extern float (*LittleFloat) (float l); 97 98//============================================================================ 99 100struct usercmd_s; 101 102extern struct usercmd_s nullcmd; 103 104void MSG_WriteChar (sizebuf_t *sb, int c); 105void MSG_WriteByte (sizebuf_t *sb, int c); 106void MSG_WriteShort (sizebuf_t *sb, int c); 107void MSG_WriteLong (sizebuf_t *sb, int c); 108void MSG_WriteFloat (sizebuf_t *sb, float f); 109void MSG_WriteString (sizebuf_t *sb, char *s); 110void MSG_WriteCoord (sizebuf_t *sb, float f); 111void MSG_WriteAngle (sizebuf_t *sb, float f); 112void MSG_WriteAngle16 (sizebuf_t *sb, float f); 113void MSG_WriteDeltaUsercmd (sizebuf_t *sb, struct usercmd_s *from, struct usercmd_s *cmd); 114 115extern int msg_readcount; 116extern qboolean msg_badread; // set if a read goes beyond end of message 117 118void MSG_BeginReading (void); 119int MSG_GetReadCount(void); 120int MSG_ReadChar (void); 121int MSG_ReadByte (void); 122int MSG_ReadShort (void); 123int MSG_ReadLong (void); 124float MSG_ReadFloat (void); 125char *MSG_ReadString (void); 126char *MSG_ReadStringLine (void); 127 128float MSG_ReadCoord (void); 129float MSG_ReadAngle (void); 130float MSG_ReadAngle16 (void); 131void MSG_ReadDeltaUsercmd (struct usercmd_s *from, struct usercmd_s *cmd); 132 133//============================================================================ 134 135#define Q_memset(d, f, c) memset((d), (f), (c)) 136#define Q_memcpy(d, s, c) memcpy((d), (s), (c)) 137#define Q_memcmp(m1, m2, c) memcmp((m1), (m2), (c)) 138#define Q_strcpy(d, s) strcpy((d), (s)) 139#define Q_strncpy(d, s, n) strncpy((d), (s), (n)) 140#define Q_strlen(s) ((int)strlen(s)) 141#define Q_strrchr(s, c) strrchr((s), (c)) 142#define Q_strcat(d, s) strcat((d), (s)) 143#define Q_strcmp(s1, s2) strcmp((s1), (s2)) 144#define Q_strncmp(s1, s2, n) strncmp((s1), (s2), (n)) 145 146#ifdef _WIN32 147 148#define Q_strcasecmp(s1, s2) _stricmp((s1), (s2)) 149#define Q_strncasecmp(s1, s2, n) _strnicmp((s1), (s2), (n)) 150 151#else 152 153#define Q_strcasecmp(s1, s2) strcasecmp((s1), (s2)) 154#define Q_strncasecmp(s1, s2, n) strncasecmp((s1), (s2), (n)) 155 156#endif 157 158int Q_atoi (char *str); 159float Q_atof (char *str); 160 161 162 163//============================================================================ 164 165extern char com_token[1024]; 166extern qboolean com_eof; 167 168char *COM_Parse (char *data); 169 170 171extern int com_argc; 172extern char **com_argv; 173 174int COM_CheckParm (char *parm); 175void COM_AddParm (char *parm); 176 177void COM_Init (void); 178void COM_InitArgv (int argc, char **argv); 179 180char *COM_SkipPath (char *pathname); 181void COM_StripExtension (char *in, char *out); 182void COM_FileBase (char *in, char *out); 183void COM_DefaultExtension (char *path, char *extension); 184 185char *va(char *format, ...); 186// does a varargs printf into a temp buffer 187 188 189//============================================================================ 190 191extern int com_filesize; 192struct cache_user_s; 193 194extern char com_gamedir[MAX_OSPATH]; 195 196void COM_WriteFile (char *filename, void *data, int len); 197int COM_FOpenFile (char *filename, FILE **file); 198void COM_CloseFile (FILE *h); 199 200byte *COM_LoadStackFile (char *path, void *buffer, int bufsize); 201byte *COM_LoadTempFile (char *path); 202byte *COM_LoadHunkFile (char *path); 203void COM_LoadCacheFile (char *path, struct cache_user_s *cu); 204void COM_CreatePath (char *path); 205void COM_Gamedir (char *dir); 206 207extern struct cvar_s registered; 208extern qboolean standard_quake, rogue, hipnotic; 209 210char *Info_ValueForKey (char *s, char *key); 211void Info_RemoveKey (char *s, char *key); 212void Info_RemovePrefixedKeys (char *start, char prefix); 213void Info_SetValueForKey (char *s, char *key, char *value, int maxsize); 214void Info_SetValueForStarKey (char *s, char *key, char *value, int maxsize); 215void Info_Print (char *s); 216 217unsigned Com_BlockChecksum (void *buffer, int length); 218void Com_BlockFullChecksum (void *buffer, int len, unsigned char *outbuf); 219byte COM_BlockSequenceCheckByte (byte *base, int length, int sequence, unsigned mapchecksum); 220byte COM_BlockSequenceCRCByte (byte *base, int length, int sequence); 221 222int build_number( void ); 223