-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathq_shared.h
291 lines (228 loc) · 8.87 KB
/
q_shared.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
Copyright (C) 1996-1997 Id Software, Inc.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
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.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
$Id: q_shared.h,v 1.36 2007-10-03 14:00:04 dkure Exp $
*/
// q_shared.h -- functions shared by all subsystems
#ifndef __Q_SHARED_H__
#define __Q_SHARED_H__
#include <math.h>
#include <string.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#define wchar unsigned short // 16-bit Unicode char
#undef true
#undef false
typedef enum {false, true} qbool;
#include "mathlib.h"
#include "sys.h"
#if defined(_MSC_VER) | defined (__INTEL_COMPILER)
#define unlink _unlink
#define strdup _strdup
#endif
#ifdef _MSC_VER
#pragma warning( disable : 4244 4127 4201 4214 4514 4305 4115 4018 4996)
#endif
#ifdef __INTEL_COMPILER
#pragma warning( disable : 188)
#endif
typedef unsigned char byte;
#ifndef NULL
#define NULL ((void *) 0)
#endif
#ifdef _WIN32
#define IS_SLASH(c) ((c) == '/' || (c) == '\\')
#else
#define IS_SLASH(c) ((c) == '/')
#endif
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
//#define bound(a,b,c) (max((a), min((b), (c))))
#define bound(a,b,c) ((a) >= (c) ? (a) : \
(b) < (a) ? (a) : (b) > (c) ? (c) : (b))
#define isspace2(c) ((c) == 0x09 || (c) == 0x0D || (c) == 0x0A || (c) == 0x20)
//============================================================================
#define MINIMUM_MEMORY 0x550000
#define MAX_QPATH 64 // max length of a quake game pathname
#define MAX_OSPATH 128 // max length of a filesystem pathname
#define ON_EPSILON 0.1 // point on plane side epsilon
//============================================================================
typedef struct sizebuf_s {
qbool allowoverflow; // if false, do a Sys_Error
qbool overflowed; // set to true if the buffer size failed
byte *data;
int maxsize;
int cursize;
} sizebuf_t;
extern char *com_args_original;
void SZ_Init (sizebuf_t *buf, byte *data, int length);
void SZ_InitEx (sizebuf_t *buf, byte *data, int length, qbool allowoverflow);
void SZ_Clear (sizebuf_t *buf);
void *SZ_GetSpace (sizebuf_t *buf, int length);
void SZ_Write (sizebuf_t *buf, const void *data, int length);
void SZ_Print (sizebuf_t *buf, char *data); // strcats onto the sizebuf
//============================================================================
short ShortSwap (short l);
int LongSwap (int l);
float FloatSwap (float f);
int LongSwapPDP2Big (int l);
int LongSwapPDP2Lit (int l);
float FloatSwapPDP2Big (float f);
float FloatSwapPDP2Lit (float f);
#if defined(_MSC_VER) && _MSC_VER >= 1400
// vc++ 2005 and up has intrinsics for the BSWAP instruction.
#define ShortSwap _byteswap_ushort
#define LongSwap _byteswap_ulong
#endif
//======================= ENDIAN DECTECTION ==================================
//======================= WIN32 DEFINES ======================================
#ifdef _WIN32
#define __LITTLE_ENDIAN__
#endif
//======================= LINUX DEFINES ======================================
#ifdef __linux__
#if __FLOAT_WORD_ORDER == __BIG_ENDIAN
#define __BIG_ENDIAN__
#elif __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
#define __LITTLE_ENDIAN__
#elif __FLOAT_WORD_ORDER == __PDP_ENDIAN
#define __PDP_ENDIAN__
#endif
#endif
//======================= FreeBSD DEFINES ====================================
#ifdef __FreeBSD__
#include <machine/endian.h>
#if BYTE_ORDER == BIG_ENDIAN
#define __BIG_ENDIAN__
#elif BYTE_ORDER == LITTLE_ENDIAN
#define __LITTLE_ENDIAN__
#elif BYTE_ORDER == PDP_ENDIAN
#define __PDP_ENDIAN__
#endif
#endif
//======================= BYTE SWAPS =========================================
#if defined __BIG_ENDIAN__
#define BigShort(x) (x)
#define BigLong(x) (x)
#define BigFloat(x) (x)
#define LittleShort(x) ShortSwap(x)
#define LittleLong(x) LongSwap(x)
#define LittleFloat(x) FloatSwap(x)
#elif defined __LITTLE_ENDIAN__
#define BigShort(x) ShortSwap(x)
#define BigLong(x) LongSwap(x)
#define BigFloat(x) FloatSwap(x)
#define LittleShort(x) (x)
#define LittleLong(x) (x)
#define LittleFloat(x) (x)
#elif defined __PDP_ENDIAN__
#define BigShort(x) ShortSwap(x)
#define BigLong(x) LongSwapPDP2Big(x)
#define BigFloat(x) FloatSwapPDP2Big(x)
#define LittleShort(x) (x)
#define LittleLong(x) LongSwapPDP2Lit(x)
#define LittleFloat(x) FloatSwapPDP2Lit(x)
#else
#error Unknown byte order type!
#endif
unsigned int BuffBigLong (const unsigned char *buffer);
unsigned short BuffBigShort (const unsigned char *buffer);
unsigned int BuffLittleLong (const unsigned char *buffer);
unsigned short BuffLittleShort (const unsigned char *buffer);
/* johnnycz: VVD's change broke e.g. TGA loading (crosshairimage, tom)
VVD: fixed by changing from "int" to "short" in 2nd string - stupid copy&paste bug :-(
#define BuffLittleLong(buffer) LittleLong(*(int*)buffer)
#define BuffLittleShort(buffer) LittleShort(*(short*)buffer)
*/
//============================================================================
int Q_atoi (const char *str);
float Q_atof (const char *str);
char *Q_ftos (float value); // removes trailing zero chars
char *Q_strcpy( char *to, char *from );
char *Q_strlwr( char *s1 );
// Added by VVD {
#ifdef _WIN32
#define strcasecmp(s1, s2) _stricmp ((s1), (s2))
#define strncasecmp(s1, s2, n) _strnicmp ((s1), (s2), (n))
// vc++ snprintf and vsnprintf are non-standard and not compatible with C99.
int qsnprintf(char *str, size_t n, char const *fmt, ...);
int qvsnprintf(char *buffer, size_t count, const char *format, va_list argptr);
#define snprintf qsnprintf
#define vsnprintf qvsnprintf
#endif
char *strstri(const char *text, const char *find); // Case insensitive strstr.
#if defined(__linux__) || defined(_WIN32)
size_t strlcpy (char *dst, const char *src, size_t siz);
size_t strlcat (char *dst, const char *src, size_t siz);
char *strnstr (const char *s, const char *find, size_t slen);
#endif
// Added by VVD }
char *strchrrev(char *str, char chr);
int wildcmp(char *wild, char *string);
wchar char2wc (char c);
char wc2char (wchar wc);
wchar *str2wcs (const char *str);
char *wcs2str (const wchar *ws);
char *wcs2str_malloc (const wchar *ws); // you must freed returned string after it no longer need!!!
#ifdef _WIN32
#define qwcscpy wcscpy
#define qwcschr wcschr
#define qwcsrchr wcsrchr
#define qwcslen wcslen
#define qwcsstr wcsstr
#else
wchar *qwcscpy (wchar *dest, const wchar *src);
wchar *qwcschr (const wchar *ws, wchar wc);
wchar *qwcsrchr (const wchar *ws, wchar wc);
size_t qwcslen (const wchar *s);
wchar *qwcsstr (const wchar *str, const wchar *strSearch);
#endif
// NOTE: size is not the number of bytes to copy, but the number of characters. sizeof(dest) / sizeof(wchar) should be used.
size_t qwcslcpy (wchar *dst, const wchar *src, size_t size);
size_t qwcslcat (wchar *dst, const wchar *src, size_t size);
wchar *Q_wcsdup(const wchar *src);
qbool Q_glob_match (const char *pattern, const char *text);
unsigned int Com_HashKey (const char *name);
//============================================================================
// memory management
void *Q_malloc (size_t size);
void *Q_calloc (size_t n, size_t size);
void *Q_realloc (void *p, size_t newsize);
char *Q_strdup (const char *src);
// might be turned into a function that makes sure all Q_*alloc calls are matched with Q_free
#define Q_free(ptr) if(ptr) { free(ptr); ptr = NULL; }
//============================================================================
// chat icons flags
// used now by client code only, but may be used in future by server code too, so put here
#define CIF_CHAT (1<<0) /* set this flag if user in console, mm1, mm2 etc but not in game */
#define CIF_AFK (1<<1) /* set this flag if app lose focus, ie alt+tab */
//============================================================================
#define MAX_MSGLEN 1450 // max length of a reliable message
#define MAX_DATAGRAM 1450 // max length of unreliable message
#define MSG_BUF_SIZE 8192 // max length of msg buf; MVD demo need it
#define FILE_TRANSFER_BUF_SIZE (MAX_MSGLEN - 100)
// qqshka: Its all messy.
// For example ezquake (and FTE?) expect maximum message is MSG_BUF_SIZE == 8192 with mvd header which have not fixed size,
// however fuhquake uses less msg size as I recall.
// mvd header max size is 10 bytes.
//
// MAX_MVD_SIZE - max size of single mvd message _WITHOUT_ header
#define MAX_MVD_SIZE (MSG_BUF_SIZE - 100)
#endif /* __Q_SHARED_H__ */