1/*
2Copyright (C) 1996-1997 Id Software, Inc.
3
4This program is free software; you can redistribute it and/or
5modify it under the terms of the GNU General Public License
6as published by the Free Software Foundation; either version 2
7of the License, or (at your option) any later version.
8
9This program is distributed in the hope that it will be useful,
10but WITHOUT ANY WARRANTY; without even the implied warranty of
11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13See the GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19*/
20// comndef.h  -- general definitions
21
22#if !defined BYTE_DEFINED
23typedef unsigned char 		byte;
24#define BYTE_DEFINED 1
25#endif
26
27// #undef true
28// #undef false
29// typedef enum _qboolean {false, true} qboolean;
30
31// NOTE: qboolean must not be typedefed as a C++ bool because it is
32// used to store values other than 0 or 1 in the global array "used". See
33// the implementation of FanLength()
34
35typedef unsigned int qboolean;
36
37//============================================================================
38
39typedef struct sizebuf_s
40{
41	qboolean	allowoverflow;	// if false, do a Sys_Error
42	qboolean	overflowed;		// set to true if the buffer size failed
43	byte	*data;
44	int		maxsize;
45	int		cursize;
46} sizebuf_t;
47
48void SZ_Alloc (sizebuf_t *buf, int startsize);
49void SZ_Free (sizebuf_t *buf);
50void SZ_Clear (sizebuf_t *buf);
51void *SZ_GetSpace (sizebuf_t *buf, int length);
52void SZ_Write (sizebuf_t *buf, const void *data, int length);
53void SZ_Print (sizebuf_t *buf, const char *data);	// strcats onto the sizebuf
54
55//============================================================================
56
57typedef struct link_s
58{
59	struct link_s	*prev, *next;
60} link_t;
61
62
63void ClearLink (link_t *l);
64void RemoveLink (link_t *l);
65void InsertLinkBefore (link_t *l, link_t *before);
66void InsertLinkAfter (link_t *l, link_t *after);
67
68// (type *)STRUCT_FROM_LINK(link_t *link, type, member)
69// ent = STRUCT_FROM_LINK(link,entity_t,order)
70// FIXME: remove this mess!
71#define	STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
72
73//============================================================================
74
75#ifndef NULL
76#define NULL ((void *)0)
77#endif
78
79#define Q_MAXCHAR ((char)0x7f)
80#define Q_MAXSHORT ((short)0x7fff)
81#define Q_MAXINT	((int)0x7fffffff)
82#define Q_MAXLONG ((int)0x7fffffff)
83#define Q_MAXFLOAT ((int)0x7fffffff)
84
85#define Q_MINCHAR ((char)0x80)
86#define Q_MINSHORT ((short)0x8000)
87#define Q_MININT 	((int)0x80000000)
88#define Q_MINLONG ((int)0x80000000)
89#define Q_MINFLOAT ((int)0x7fffffff)
90
91//============================================================================
92
93extern	qboolean		bigendien;
94
95extern	short	(*BigShort) (short l);
96extern	short	(*LittleShort) (short l);
97extern	int	(*BigLong) (int l);
98extern	int	(*LittleLong) (int l);
99extern	float	(*BigFloat) (float l);
100extern	float	(*LittleFloat) (float l);
101
102//============================================================================
103
104void MSG_WriteChar (sizebuf_t *sb, int c);
105void MSG_WriteByte (sizebuf_t *sb, int c);
106void MSG_WriteShort (sizebuf_t *sb, int c);
107void MSG_WriteLong (sizebuf_t *sb, int c);
108void MSG_WriteFloat (sizebuf_t *sb, float f);
109void MSG_WriteString (sizebuf_t *sb, const char *s);
110void MSG_WriteCoord (sizebuf_t *sb, float f);
111void MSG_WriteAngle (sizebuf_t *sb, float f);
112
113extern	int			msg_readcount;
114extern	qboolean	msg_badread;		// set if a read goes beyond end of message
115
116void MSG_BeginReading (void);
117int MSG_ReadChar (void);
118int MSG_ReadByte (void);
119int MSG_ReadShort (void);
120int MSG_ReadLong (void);
121float MSG_ReadFloat (void);
122char *MSG_ReadString (void);
123
124float MSG_ReadCoord (void);
125float MSG_ReadAngle (void);
126
127//============================================================================
128
129void Q_memset (void *dest, int fill, int count);
130void Q_memcpy (void *dest, const void *src, int count);
131int Q_memcmp (const void *m1, const void *m2, int count);
132void Q_strcpy (char *dest, const char *src);
133void Q_strncpy (char *dest, const char *src, int count);
134int Q_strlen (const char *str);
135char *Q_strrchr (const char *s, char c);
136void Q_strcat (char *dest, const char *src);
137int Q_strcmp (const char *s1, const char *s2);
138int Q_strncmp (const char *s1, const char *s2, int count);
139int Q_strcasecmp (const char *s1, const char *s2);
140int Q_strncasecmp (const char *s1, const char *s2, int n);
141int	Q_atoi (const char *str);
142float Q_atof (const char *str);
143
144//============================================================================
145
146extern	char		com_token[1024];
147extern	qboolean	com_eof;
148
149char *COM_Parse (char *data);
150
151
152extern	int		com_argc;
153extern	const char	**com_argv;
154
155int COM_CheckParm (const char *parm);
156void COM_Init (const char *path);
157void COM_InitArgv (int argc, const char **argv);
158
159const char *COM_SkipPath (const char *pathname);
160void COM_StripExtension (const char *in, char *out);
161void COM_FileBase (const char *in, char *out, size_t outLength);
162void COM_DefaultExtension (char *path, const char *extension);
163
164char	*va(const char *format, ...);
165// does a varargs printf into a temp buffer
166
167
168//============================================================================
169
170extern int com_filesize;
171struct cache_user_s;
172
173extern	char	com_gamedir[MAX_OSPATH];
174
175void COM_WriteFile (const char *filename, void *data, int len);
176int COM_OpenFile (const char *filename, int *hndl);
177int COM_FOpenFile (const char *filename, FILE **file);
178void COM_CloseFile (int h);
179
180byte *COM_LoadStackFile (const char *path, void *buffer, int bufsize);
181byte *COM_LoadTempFile (const char *path);
182byte *COM_LoadHunkFile (const char *path);
183void COM_LoadCacheFile (const char *path, struct cache_user_s *cu);
184
185
186extern	struct cvar_s	registered;
187
188extern qboolean		standard_quake, rogue, hipnotic;
189