]> icculus.org git repositories - divverent/darkplaces.git/blob - common.h
remove +use and -use commands because they prevent mods from defining them (and they...
[divverent/darkplaces.git] / common.h
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
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.
8
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.
12
13 See the GNU General Public License for more details.
14
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.
18
19 */
20
21 #ifndef COMMON_H
22 #define COMMON_H
23
24 // MSVC has a different name for several standard functions
25 #ifdef WIN32
26 # define snprintf _snprintf
27 # define vsnprintf _vsnprintf
28 # define strcasecmp stricmp
29 # define strncasecmp strnicmp
30 #endif
31
32
33 //============================================================================
34
35 typedef struct sizebuf_s
36 {
37         qboolean        allowoverflow;  // if false, do a Sys_Error
38         qboolean        overflowed;             // set to true if the buffer size failed
39         qbyte           *data;
40         mempool_t       *mempool;
41         int                     maxsize;
42         int                     cursize;
43 } sizebuf_t;
44
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);
52
53 void Com_HexDumpToConsole(const qbyte *data, int size);
54
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__)
58 #define ENDIAN_LITTLE
59 #else
60 #define ENDIAN_BIG
61 #endif
62 #endif
63
64 short ShortSwap (short l);
65 int LongSwap (int l);
66 float FloatSwap (float f);
67
68 #ifdef ENDIAN_LITTLE
69 // little endian
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 ENDIAN_BIG
77 // big endian
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)
84 #else
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);
92 #endif
93
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);
98
99
100 //============================================================================
101
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);
112
113 extern  int                     msg_readcount;
114 extern  qboolean        msg_badread;            // set if a read goes beyond end of message
115
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);
125
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
131
132 float MSG_ReadCoord (void);
133
134 float MSG_ReadDPCoord (void);
135
136 #define MSG_ReadAngle() (MSG_ReadByte() * (360.0f / 256.0f))
137 #define MSG_ReadPreciseAngle() (MSG_ReadShort() * (360.0f / 65536.0f))
138
139 #define MSG_ReadVector(v) {(v)[0] = MSG_ReadCoord();(v)[1] = MSG_ReadCoord();(v)[2] = MSG_ReadCoord();}
140
141 //============================================================================
142
143 extern char com_token[1024];
144
145 int COM_ParseToken(const char **datapointer, int returnnewline);
146
147 extern int com_argc;
148 extern const char **com_argv;
149
150 int COM_CheckParm (const char *parm);
151 void COM_Init (void);
152 void COM_InitArgv (void);
153 void COM_InitGameType (void);
154
155 char    *va(const char *format, ...);
156 // does a varargs printf into a temp buffer
157
158
159 //============================================================================
160
161 extern  struct cvar_s   registered;
162
163 #define GAME_NORMAL 0
164 #define GAME_HIPNOTIC 1
165 #define GAME_ROGUE 2
166 #define GAME_NEHAHRA 3
167 #define GAME_NEXUIZ 4
168 #define GAME_TRANSFUSION 5
169 #define GAME_GOODVSBAD2 6
170 #define GAME_TEU 7
171 #define GAME_BATTLEMECH 8
172 #define GAME_ZYMOTIC 9
173
174 extern int gamemode;
175 extern char *gamename;
176 extern char *gamedirname;
177 extern char com_modname[MAX_OSPATH];
178
179 void COM_ToLowerString (const char *in, char *out, size_t size_out);
180 void COM_ToUpperString (const char *in, char *out, size_t size_out);
181 int COM_StringBeginsWith(const char *s, const char *match);
182
183 int COM_ReadAndTokenizeLine(const char **text, char **argv, int maxargc, char *tokenbuf, int tokenbufsize);
184
185 typedef struct stringlist_s
186 {
187         struct stringlist_s *next;
188         char *text;
189 } stringlist_t;
190
191 int matchpattern(char *in, char *pattern, int caseinsensitive);
192 stringlist_t *listdirectory(char *path);
193 void freedirectory(stringlist_t *list);
194
195 char *SearchInfostring(const char *infostring, const char *key);
196
197
198 // strlcat and strlcpy, from OpenBSD
199 // Most (all?) BSDs already have them
200 #if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
201
202 /*
203  * Appends src to string dst of size siz (unlike strncat, siz is the
204  * full size of dst, not space left).  At most siz-1 characters
205  * will be copied.  Always NUL terminates (unless siz <= strlen(dst)).
206  * Returns strlen(src) + MIN(siz, strlen(initial dst)).
207  * If retval >= siz, truncation occurred.
208  */
209 size_t strlcat(char *dst, const char *src, size_t siz);
210
211 /*
212  * Copy src to string dst of size siz.  At most siz-1 characters
213  * will be copied.  Always NUL terminates (unless siz == 0).
214  * Returns strlen(src); if retval >= siz, truncation occurred.
215  */
216 size_t strlcpy(char *dst, const char *src, size_t siz);
217
218 #endif  // #if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__)
219
220 #endif
221