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.
24 // MSVC has a different name for several standard functions
26 # define snprintf _snprintf
27 # define vsnprintf _vsnprintf
28 # define strcasecmp stricmp
29 # define strncasecmp strnicmp
33 //============================================================================
35 typedef struct sizebuf_s
37 qboolean allowoverflow; // if false, do a Sys_Error
38 qboolean overflowed; // set to true if the buffer size failed
45 void SZ_Alloc (sizebuf_t *buf, int startsize, const char *name);
46 void SZ_Free (sizebuf_t *buf);
47 void SZ_Clear (sizebuf_t *buf);
48 void *SZ_GetSpace (sizebuf_t *buf, int length);
49 void SZ_Write (sizebuf_t *buf, const void *data, int length);
50 void SZ_Print(sizebuf_t *buf, const char *data); // strcats onto the sizebuf
51 void SZ_HexDumpToConsole(const sizebuf_t *buf);
53 void Com_HexDumpToConsole(const qbyte *data, int size);
56 //============================================================================
58 //============================================================================
60 // We use BSD-style defines: BYTE_ORDER is defined to either BIG_ENDIAN or LITTLE_ENDIAN
63 #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN) || (BYTE_ORDER != LITTLE_ENDIAN && BYTE_ORDER != BIG_ENDIAN)
67 # define LITTLE_ENDIAN 1234
68 # define BIG_ENDIAN 4321
71 // If we still don't know the CPU endianess at this point, we try to guess
74 # define BYTE_ORDER LITTLE_ENDIAN
76 # warning "Unable to determine the CPU endianess. Defaulting to little endian"
77 # define BYTE_ORDER LITTLE_ENDIAN
82 short ShortSwap (short l);
84 float FloatSwap (float f);
86 #if BYTE_ORDER == LITTLE_ENDIAN
88 #define BigShort(l) ShortSwap(l)
89 #define LittleShort(l) (l)
90 #define BigLong(l) LongSwap(l)
91 #define LittleLong(l) (l)
92 #define BigFloat(l) FloatSwap(l)
93 #define LittleFloat(l) (l)
96 #define BigShort(l) (l)
97 #define LittleShort(l) ShortSwap(l)
98 #define BigLong(l) (l)
99 #define LittleLong(l) LongSwap(l)
100 #define BigFloat(l) (l)
101 #define LittleFloat(l) FloatSwap(l)
104 unsigned int BuffBigLong (const qbyte *buffer);
105 unsigned short BuffBigShort (const qbyte *buffer);
106 unsigned int BuffLittleLong (const qbyte *buffer);
107 unsigned short BuffLittleShort (const qbyte *buffer);
110 //============================================================================
112 void MSG_WriteChar (sizebuf_t *sb, int c);
113 void MSG_WriteByte (sizebuf_t *sb, int c);
114 void MSG_WriteShort (sizebuf_t *sb, int c);
115 void MSG_WriteLong (sizebuf_t *sb, int c);
116 void MSG_WriteFloat (sizebuf_t *sb, float f);
117 void MSG_WriteString (sizebuf_t *sb, const char *s);
118 void MSG_WriteCoord (sizebuf_t *sb, float f);
119 void MSG_WriteAngle (sizebuf_t *sb, float f);
120 void MSG_WritePreciseAngle (sizebuf_t *sb, float f);
121 void MSG_WriteDPCoord (sizebuf_t *sb, float f);
123 extern int msg_readcount;
124 extern qboolean msg_badread; // set if a read goes beyond end of message
126 void MSG_BeginReading (void);
127 int MSG_ReadLittleShort (void);
128 int MSG_ReadBigShort (void);
129 int MSG_ReadLittleLong (void);
130 int MSG_ReadBigLong (void);
131 float MSG_ReadLittleFloat (void);
132 float MSG_ReadBigFloat (void);
133 char *MSG_ReadString (void);
134 int MSG_ReadBytes (int numbytes, unsigned char *out);
136 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
137 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
138 #define MSG_ReadShort MSG_ReadLittleShort
139 #define MSG_ReadLong MSG_ReadLittleLong
140 #define MSG_ReadFloat MSG_ReadLittleFloat
142 float MSG_ReadCoord (void);
144 #define MSG_ReadAngle() (MSG_ReadByte() * (360.0f / 256.0f))
145 #define MSG_ReadPreciseAngle() (MSG_ReadShort() * (360.0f / 65536.0f))
147 #define MSG_ReadVector(v) ((v)[0] = MSG_ReadCoord(), (v)[1] = MSG_ReadCoord(), (v)[2] = MSG_ReadCoord())
149 //============================================================================
151 extern char com_token[1024];
153 int COM_ParseToken(const char **datapointer, int returnnewline);
154 int COM_ParseTokenConsole(const char **datapointer);
157 extern const char **com_argv;
159 int COM_CheckParm (const char *parm);
160 void COM_Init (void);
161 void COM_InitArgv (void);
162 void COM_InitGameType (void);
164 char *va(const char *format, ...);
165 // does a varargs printf into a temp buffer
168 //============================================================================
170 extern struct cvar_s registered;
171 extern struct cvar_s cmdline;
173 #define GAME_NORMAL 0
174 #define GAME_HIPNOTIC 1
176 #define GAME_NEHAHRA 3
177 #define GAME_NEXUIZ 4
178 #define GAME_TRANSFUSION 5
179 #define GAME_GOODVSBAD2 6
181 #define GAME_BATTLEMECH 8
182 #define GAME_ZYMOTIC 9
183 #define GAME_FNIGGIUM 10
184 #define GAME_SETHERAL 11
186 #define GAME_TENEBRAE 13 // full of evil hackery
187 #define GAME_NEOTERIC 14
188 #define GAME_OPENQUARTZ 15 //this game sucks
189 #define GAME_PRYDON 16
190 #define GAME_NETHERWORLD 17
193 extern const char *gamename;
194 extern const char *gamedirname;
195 extern const char *gamescreenshotname;
196 extern char com_modname[MAX_OSPATH];
198 void COM_ToLowerString (const char *in, char *out, size_t size_out);
199 void COM_ToUpperString (const char *in, char *out, size_t size_out);
200 int COM_StringBeginsWith(const char *s, const char *match);
202 int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *tokenbuf, int tokenbufsize, const char *commentprefix);
204 typedef struct stringlist_s
206 struct stringlist_s *next;
210 int matchpattern(char *in, char *pattern, int caseinsensitive);
211 stringlist_t *stringlistappend(stringlist_t *current, char *text);
212 void stringlistfree(stringlist_t *current);
213 stringlist_t *stringlistsort(stringlist_t *start);
214 stringlist_t *listdirectory(char *path);
215 void freedirectory(stringlist_t *list);
217 char *SearchInfostring(const char *infostring, const char *key);
220 // strlcat and strlcpy, from OpenBSD
221 // Most (all?) BSDs already have them
222 #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__))
223 # define HAVE_STRLCAT 1
224 # define HAVE_STRLCPY 1
229 * Appends src to string dst of size siz (unlike strncat, siz is the
230 * full size of dst, not space left). At most siz-1 characters
231 * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
232 * Returns strlen(src) + MIN(siz, strlen(initial dst)).
233 * If retval >= siz, truncation occurred.
235 size_t strlcat(char *dst, const char *src, size_t siz);
236 #endif // #ifndef HAVE_STRLCAT
240 * Copy src to string dst of size siz. At most siz-1 characters
241 * will be copied. Always NUL terminates (unless siz == 0).
242 * Returns strlen(src); if retval >= siz, truncation occurred.
244 size_t strlcpy(char *dst, const char *src, size_t siz);
246 #endif // #ifndef HAVE_STRLCPY