2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 // MSVC has a different name for several standard functions
27 # define strcasecmp stricmp
28 # define strncasecmp strnicmp
31 // Create our own define for Mac OS X
32 #if defined(__APPLE__) && defined(__MACH__)
37 //============================================================================
39 typedef struct sizebuf_s
41 qboolean allowoverflow; // if false, do a Sys_Error
42 qboolean overflowed; // set to true if the buffer size failed
48 void SZ_Clear (sizebuf_t *buf);
49 void *SZ_GetSpace (sizebuf_t *buf, int length);
50 void SZ_Write (sizebuf_t *buf, const void *data, int length);
51 void SZ_Print(sizebuf_t *buf, const char *data); // strcats onto the sizebuf
52 void SZ_HexDumpToConsole(const sizebuf_t *buf);
54 void Com_HexDumpToConsole(const qbyte *data, int size);
56 unsigned short CRC_Block(const qbyte *data, int size);
59 //============================================================================
61 //============================================================================
63 // We use BSD-style defines: BYTE_ORDER is defined to either BIG_ENDIAN or LITTLE_ENDIAN
66 #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
70 # define LITTLE_ENDIAN 1234
71 # define BIG_ENDIAN 4321
74 // If we still don't know the CPU endianess at this point, we try to guess
77 # define BYTE_ORDER LITTLE_ENDIAN
79 # warning "Unable to determine the CPU endianess. Defaulting to little endian"
80 # define BYTE_ORDER LITTLE_ENDIAN
85 short ShortSwap (short l);
87 float FloatSwap (float f);
89 #if BYTE_ORDER == LITTLE_ENDIAN
91 #define BigShort(l) ShortSwap(l)
92 #define LittleShort(l) (l)
93 #define BigLong(l) LongSwap(l)
94 #define LittleLong(l) (l)
95 #define BigFloat(l) FloatSwap(l)
96 #define LittleFloat(l) (l)
99 #define BigShort(l) (l)
100 #define LittleShort(l) ShortSwap(l)
101 #define BigLong(l) (l)
102 #define LittleLong(l) LongSwap(l)
103 #define BigFloat(l) (l)
104 #define LittleFloat(l) FloatSwap(l)
107 unsigned int BuffBigLong (const qbyte *buffer);
108 unsigned short BuffBigShort (const qbyte *buffer);
109 unsigned int BuffLittleLong (const qbyte *buffer);
110 unsigned short BuffLittleShort (const qbyte *buffer);
113 //============================================================================
115 void MSG_WriteChar (sizebuf_t *sb, int c);
116 void MSG_WriteByte (sizebuf_t *sb, int c);
117 void MSG_WriteShort (sizebuf_t *sb, int c);
118 void MSG_WriteLong (sizebuf_t *sb, int c);
119 void MSG_WriteFloat (sizebuf_t *sb, float f);
120 void MSG_WriteString (sizebuf_t *sb, const char *s);
121 void MSG_WriteAngle8i (sizebuf_t *sb, float f);
122 void MSG_WriteAngle16i (sizebuf_t *sb, float f);
123 void MSG_WriteAngle32f (sizebuf_t *sb, float f);
124 void MSG_WriteCoord13i (sizebuf_t *sb, float f);
125 void MSG_WriteCoord16i (sizebuf_t *sb, float f);
126 void MSG_WriteCoord32f (sizebuf_t *sb, float f);
127 void MSG_WriteCoord (sizebuf_t *sb, float f, int protocol);
128 void MSG_WriteVector (sizebuf_t *sb, float *v, int protocol);
129 void MSG_WriteAngle (sizebuf_t *sb, float f, int protocol);
131 extern int msg_readcount;
132 extern qboolean msg_badread; // set if a read goes beyond end of message
134 void MSG_BeginReading (void);
135 int MSG_ReadLittleShort (void);
136 int MSG_ReadBigShort (void);
137 int MSG_ReadLittleLong (void);
138 int MSG_ReadBigLong (void);
139 float MSG_ReadLittleFloat (void);
140 float MSG_ReadBigFloat (void);
141 char *MSG_ReadString (void);
142 int MSG_ReadBytes (int numbytes, unsigned char *out);
144 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
145 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
146 #define MSG_ReadShort MSG_ReadLittleShort
147 #define MSG_ReadLong MSG_ReadLittleLong
148 #define MSG_ReadFloat MSG_ReadLittleFloat
150 float MSG_ReadAngle8i (void);
151 float MSG_ReadAngle16i (void);
152 float MSG_ReadAngle32f (void);
153 float MSG_ReadCoord13i (void);
154 float MSG_ReadCoord16i (void);
155 float MSG_ReadCoord32f (void);
156 float MSG_ReadCoord (int protocol);
157 void MSG_ReadVector (float *v, int protocol);
158 float MSG_ReadAngle (int protocol);
160 //============================================================================
162 extern char com_token[1024];
164 int COM_ParseToken(const char **datapointer, int returnnewline);
165 int COM_ParseTokenConsole(const char **datapointer);
168 extern const char **com_argv;
170 int COM_CheckParm (const char *parm);
171 void COM_Init (void);
172 void COM_Shutdown (void);
173 void COM_InitArgv (void);
174 void COM_InitGameType (void);
176 char *va(const char *format, ...);
177 // does a varargs printf into a temp buffer
180 // snprintf and vsnprintf are NOT portable. Use their DP counterparts instead
181 #define snprintf DO_NOT_USE_SNPRINTF__USE_DPSNPRINTF
182 #define vsnprintf DO_NOT_USE_VSNPRINTF__USE_DPVSNPRINTF
184 // dpsnprintf and dpvsnprintf
185 // return the number of printed characters, excluding the final '\0'
186 // or return -1 if the buffer isn't big enough to contain the entire string.
187 // buffer is ALWAYS null-terminated
188 extern int dpsnprintf (char *buffer, size_t buffersize, const char *format, ...);
189 extern int dpvsnprintf (char *buffer, size_t buffersize, const char *format, va_list args);
192 //============================================================================
194 extern struct cvar_s registered;
195 extern struct cvar_s cmdline;
197 typedef enum gamemode_e
212 GAME_TENEBRAE, // full of evil hackery
214 GAME_OPENQUARTZ, //this game sucks
221 extern gamemode_t gamemode;
222 extern const char *gamename;
223 extern const char *gamedirname1;
224 extern const char *gamedirname2;
225 extern const char *gamescreenshotname;
226 extern const char *gameuserdirname;
227 extern char com_modname[MAX_OSPATH];
229 void COM_ToLowerString (const char *in, char *out, size_t size_out);
230 void COM_ToUpperString (const char *in, char *out, size_t size_out);
231 int COM_StringBeginsWith(const char *s, const char *match);
233 int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *tokenbuf, int tokenbufsize, const char *commentprefix);
235 typedef struct stringlist_s
237 struct stringlist_s *next;
241 int matchpattern(char *in, char *pattern, int caseinsensitive);
242 stringlist_t *stringlistappend(stringlist_t *current, char *text);
243 void stringlistfree(stringlist_t *current);
244 stringlist_t *stringlistsort(stringlist_t *start);
245 stringlist_t *listdirectory(const char *path);
246 void freedirectory(stringlist_t *list);
248 char *SearchInfostring(const char *infostring, const char *key);
251 // strlcat and strlcpy, from OpenBSD
252 // Most (all?) BSDs already have them
253 #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || defined(MACOSX)
254 # define HAVE_STRLCAT 1
255 # define HAVE_STRLCPY 1
260 * Appends src to string dst of size siz (unlike strncat, siz is the
261 * full size of dst, not space left). At most siz-1 characters
262 * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
263 * Returns strlen(src) + MIN(siz, strlen(initial dst)).
264 * If retval >= siz, truncation occurred.
266 size_t strlcat(char *dst, const char *src, size_t siz);
267 #endif // #ifndef HAVE_STRLCAT
271 * Copy src to string dst of size siz. At most siz-1 characters
272 * will be copied. Always NUL terminates (unless siz == 0).
273 * Returns strlen(src); if retval >= siz, truncation occurred.
275 size_t strlcpy(char *dst, const char *src, size_t siz);
277 #endif // #ifndef HAVE_STRLCPY