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);
55 //============================================================================
56 #if !defined(ENDIAN_LITTLE) && !defined(ENDIAN_BIG)
57 #if defined(__i386__) || defined(__ia64__) || defined(WIN32) || (defined(__alpha__) || defined(__alpha)) || defined(__arm__) || (defined(__mips__) && defined(__MIPSEL__)) || defined(__LITTLE_ENDIAN__)
64 short ShortSwap (short l);
66 float FloatSwap (float f);
70 #define BigShort(l) ShortSwap(l)
71 #define LittleShort(l) (l)
72 #define BigLong(l) LongSwap(l)
73 #define LittleLong(l) (l)
74 #define BigFloat(l) FloatSwap(l)
75 #define LittleFloat(l) (l)
76 #elif defined(ENDIAN_BIG)
78 #define BigShort(l) (l)
79 #define LittleShort(l) ShortSwap(l)
80 #define BigLong(l) (l)
81 #define LittleLong(l) LongSwap(l)
82 #define BigFloat(l) (l)
83 #define LittleFloat(l) FloatSwap(l)
85 // figure it out at runtime
86 extern short (*BigShort) (short l);
87 extern short (*LittleShort) (short l);
88 extern int (*BigLong) (int l);
89 extern int (*LittleLong) (int l);
90 extern float (*BigFloat) (float l);
91 extern float (*LittleFloat) (float l);
94 unsigned int BuffBigLong (const qbyte *buffer);
95 unsigned short BuffBigShort (const qbyte *buffer);
96 unsigned int BuffLittleLong (const qbyte *buffer);
97 unsigned short BuffLittleShort (const qbyte *buffer);
100 //============================================================================
102 void MSG_WriteChar (sizebuf_t *sb, int c);
103 void MSG_WriteByte (sizebuf_t *sb, int c);
104 void MSG_WriteShort (sizebuf_t *sb, int c);
105 void MSG_WriteLong (sizebuf_t *sb, int c);
106 void MSG_WriteFloat (sizebuf_t *sb, float f);
107 void MSG_WriteString (sizebuf_t *sb, const char *s);
108 void MSG_WriteCoord (sizebuf_t *sb, float f);
109 void MSG_WriteAngle (sizebuf_t *sb, float f);
110 void MSG_WritePreciseAngle (sizebuf_t *sb, float f);
111 void MSG_WriteDPCoord (sizebuf_t *sb, float f);
113 extern int msg_readcount;
114 extern qboolean msg_badread; // set if a read goes beyond end of message
116 void MSG_BeginReading (void);
117 int MSG_ReadLittleShort (void);
118 int MSG_ReadBigShort (void);
119 int MSG_ReadLittleLong (void);
120 int MSG_ReadBigLong (void);
121 float MSG_ReadLittleFloat (void);
122 float MSG_ReadBigFloat (void);
123 char *MSG_ReadString (void);
124 int MSG_ReadBytes (int numbytes, unsigned char *out);
126 #define MSG_ReadChar() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (signed char)net_message.data[msg_readcount++])
127 #define MSG_ReadByte() (msg_readcount >= net_message.cursize ? (msg_badread = true, -1) : (unsigned char)net_message.data[msg_readcount++])
128 #define MSG_ReadShort MSG_ReadLittleShort
129 #define MSG_ReadLong MSG_ReadLittleLong
130 #define MSG_ReadFloat MSG_ReadLittleFloat
132 float MSG_ReadCoord (void);
134 float MSG_ReadDPCoord (void);
136 #define MSG_ReadAngle() (MSG_ReadByte() * (360.0f / 256.0f))
137 #define MSG_ReadPreciseAngle() (MSG_ReadShort() * (360.0f / 65536.0f))
139 #define MSG_ReadVector(v) {(v)[0] = MSG_ReadCoord();(v)[1] = MSG_ReadCoord();(v)[2] = MSG_ReadCoord();}
141 //============================================================================
143 extern char com_token[1024];
145 int COM_ParseToken(const char **datapointer, int returnnewline);
146 int COM_ParseTokenConsole(const char **datapointer);
149 extern const char **com_argv;
151 int COM_CheckParm (const char *parm);
152 void COM_Init (void);
153 void COM_InitArgv (void);
154 void COM_InitGameType (void);
156 char *va(const char *format, ...);
157 // does a varargs printf into a temp buffer
160 //============================================================================
162 extern struct cvar_s registered;
164 #define GAME_NORMAL 0
165 #define GAME_HIPNOTIC 1
167 #define GAME_NEHAHRA 3
168 #define GAME_NEXUIZ 4
169 #define GAME_TRANSFUSION 5
170 #define GAME_GOODVSBAD2 6
172 #define GAME_BATTLEMECH 8
173 #define GAME_ZYMOTIC 9
174 #define GAME_FNIGGIUM 10
175 #define GAME_SETHERAL 11
177 #define GAME_TENEBRAE 13 // full of evil hackery
180 extern char *gamename;
181 extern char *gamedirname;
182 extern char com_modname[MAX_OSPATH];
184 void COM_ToLowerString (const char *in, char *out, size_t size_out);
185 void COM_ToUpperString (const char *in, char *out, size_t size_out);
186 int COM_StringBeginsWith(const char *s, const char *match);
188 int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *tokenbuf, int tokenbufsize, const char *commentprefix);
190 typedef struct stringlist_s
192 struct stringlist_s *next;
196 int matchpattern(char *in, char *pattern, int caseinsensitive);
197 stringlist_t *stringlistappend(stringlist_t *current, char *text);
198 void stringlistfree(stringlist_t *current);
199 stringlist_t *stringlistsort(stringlist_t *start);
200 stringlist_t *listdirectory(char *path);
201 void freedirectory(stringlist_t *list);
203 char *SearchInfostring(const char *infostring, const char *key);
206 // strlcat and strlcpy, from OpenBSD
207 // Most (all?) BSDs already have them
208 #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || (defined(__APPLE__) && defined(__MACH__))
209 # define HAVE_STRLCAT 1
210 # define HAVE_STRLCPY 1
215 * Appends src to string dst of size siz (unlike strncat, siz is the
216 * full size of dst, not space left). At most siz-1 characters
217 * will be copied. Always NUL terminates (unless siz <= strlen(dst)).
218 * Returns strlen(src) + MIN(siz, strlen(initial dst)).
219 * If retval >= siz, truncation occurred.
221 size_t strlcat(char *dst, const char *src, size_t siz);
222 #endif // #ifndef HAVE_STRLCAT
226 * Copy src to string dst of size siz. At most siz-1 characters
227 * will be copied. Always NUL terminates (unless siz == 0).
228 * Returns strlen(src); if retval >= siz, truncation occurred.
230 size_t strlcpy(char *dst, const char *src, size_t siz);
232 #endif // #ifndef HAVE_STRLCPY