[game-data-packager] 01/293: [svn-inject] Installing original source of quake3

Simon McVittie smcv at debian.org
Fri Oct 14 00:11:50 UTC 2016


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch quake
in repository game-data-packager.

commit 25c85e31623a132b11b9fb91a02f8a1d1ba4b300
Author: Marc Leeman <marc.leeman at gmail.com>
Date:   Sun Jan 29 19:44:51 2006 +0000

    [svn-inject] Installing original source of quake3
---
 code/qcommon/q_shared.h     | 1215 +++++++++++++++++++++++++++++++++++++++++++
 code/qcommon/qcommon.h      | 1096 ++++++++++++++++++++++++++++++++++++++
 code/server/sv_init.c       |  701 +++++++++++++++++++++++++
 code/tools/lcc/lburg/gram.c |  682 ++++++++++++++++++++++++
 4 files changed, 3694 insertions(+)

diff --git a/code/qcommon/q_shared.h b/code/qcommon/q_shared.h
new file mode 100644
index 0000000..6e55a4d
--- /dev/null
+++ b/code/qcommon/q_shared.h
@@ -0,0 +1,1215 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+
+This file is part of Quake III Arena source code.
+
+Quake III Arena source code 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.
+
+Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+===========================================================================
+*/
+//
+#ifndef __Q_SHARED_H
+#define __Q_SHARED_H
+
+// q_shared.h -- included first by ALL program modules.
+// A user mod should never modify this file
+
+#define	Q3_VERSION		"ioQ3 1.33"
+// 1.32 released 7-10-2002
+
+#define MAX_TEAMNAME 32
+
+#ifdef _MSC_VER
+
+#pragma warning(disable : 4018)     // signed/unsigned mismatch
+#pragma warning(disable : 4032)
+#pragma warning(disable : 4051)
+#pragma warning(disable : 4057)		// slightly different base types
+#pragma warning(disable : 4100)		// unreferenced formal parameter
+#pragma warning(disable : 4115)
+#pragma warning(disable : 4125)		// decimal digit terminates octal escape sequence
+#pragma warning(disable : 4127)		// conditional expression is constant
+#pragma warning(disable : 4136)
+#pragma warning(disable : 4152)		// nonstandard extension, function/data pointer conversion in expression
+//#pragma warning(disable : 4201)
+//#pragma warning(disable : 4214)
+#pragma warning(disable : 4244)
+#pragma warning(disable : 4142)		// benign redefinition
+//#pragma warning(disable : 4305)		// truncation from const double to float
+//#pragma warning(disable : 4310)		// cast truncates constant value
+//#pragma warning(disable:  4505) 	// unreferenced local function has been removed
+#pragma warning(disable : 4514)
+#pragma warning(disable : 4702)		// unreachable code
+#pragma warning(disable : 4711)		// selected for automatic inline expansion
+#pragma warning(disable : 4220)		// varargs matches remaining parameters
+//#pragma intrinsic( memset, memcpy )
+#endif
+
+//Ignore __attribute__ on non-gcc platforms
+#ifndef __GNUC__
+#ifndef __attribute__
+#define __attribute__(x)
+#endif
+#endif
+
+/**********************************************************************
+  VM Considerations
+
+  The VM can not use the standard system headers because we aren't really
+  using the compiler they were meant for.  We use bg_lib.h which contains
+  prototypes for the functions we define for our own use in bg_lib.c.
+
+  When writing mods, please add needed headers HERE, do not start including
+  stuff like <stdio.h> in the various .c files that make up each of the VMs
+  since you will be including system headers files can will have issues.
+
+  Remember, if you use a C library function that is not defined in bg_lib.c,
+  you will have to add your own version for support in the VM.
+
+ **********************************************************************/
+
+#ifdef Q3_VM
+
+#include "../game/bg_lib.h"
+
+#else
+
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <ctype.h>
+#include <limits.h>
+
+#endif
+
+#include "q_platform.h"
+
+//=============================================================
+
+typedef unsigned char 		byte;
+
+typedef enum {qfalse, qtrue}	qboolean;
+
+typedef int		qhandle_t;
+typedef int		sfxHandle_t;
+typedef int		fileHandle_t;
+typedef int		clipHandle_t;
+
+#define PAD(x,y) (((x)+(y)-1) & ~((y)-1))
+
+#ifdef __GNUC__
+#define ALIGN(x) __attribute__((aligned(x)))
+#else
+#define ALIGN(x)
+#endif
+
+#ifndef NULL
+#define NULL ((void *)0)
+#endif
+
+#define	MAX_QINT			0x7fffffff
+#define	MIN_QINT			(-MAX_QINT-1)
+
+
+// angle indexes
+#define	PITCH				0		// up / down
+#define	YAW					1		// left / right
+#define	ROLL				2		// fall over
+
+// the game guarantees that no string from the network will ever
+// exceed MAX_STRING_CHARS
+#define	MAX_STRING_CHARS	1024	// max length of a string passed to Cmd_TokenizeString
+#define	MAX_STRING_TOKENS	1024	// max tokens resulting from Cmd_TokenizeString
+#define	MAX_TOKEN_CHARS		1024	// max length of an individual token
+
+#define	MAX_INFO_STRING		1024
+#define	MAX_INFO_KEY		  1024
+#define	MAX_INFO_VALUE		1024
+
+#define	BIG_INFO_STRING		8192  // used for system info key only
+#define	BIG_INFO_KEY		  8192
+#define	BIG_INFO_VALUE		8192
+
+
+#define	MAX_QPATH			64		// max length of a quake game pathname
+#ifdef PATH_MAX
+#define MAX_OSPATH			PATH_MAX
+#else
+#define	MAX_OSPATH			256		// max length of a filesystem pathname
+#endif
+
+#define	MAX_NAME_LENGTH		32		// max length of a client name
+
+#define	MAX_SAY_TEXT	150
+
+// paramters for command buffer stuffing
+typedef enum {
+	EXEC_NOW,			// don't return until completed, a VM should NEVER use this,
+						// because some commands might cause the VM to be unloaded...
+	EXEC_INSERT,		// insert at current position, but don't run yet
+	EXEC_APPEND			// add to end of the command buffer (normal case)
+} cbufExec_t;
+
+
+//
+// these aren't needed by any of the VMs.  put in another header?
+//
+#define	MAX_MAP_AREA_BYTES		32		// bit vector of area visibility
+
+
+// print levels from renderer (FIXME: set up for game / cgame?)
+typedef enum {
+	PRINT_ALL,
+	PRINT_DEVELOPER,		// only print when "developer 1"
+	PRINT_WARNING,
+	PRINT_ERROR
+} printParm_t;
+
+
+#ifdef ERR_FATAL
+#undef ERR_FATAL			// this is be defined in malloc.h
+#endif
+
+// parameters to the main Error routine
+typedef enum {
+	ERR_FATAL,					// exit the entire game with a popup window
+	ERR_DROP,					// print to console and disconnect from game
+	ERR_SERVERDISCONNECT,		// don't kill server
+	ERR_DISCONNECT,				// client disconnected from the server
+	ERR_NEED_CD					// pop up the need-cd dialog
+} errorParm_t;
+
+
+// font rendering values used by ui and cgame
+
+#define PROP_GAP_WIDTH			3
+#define PROP_SPACE_WIDTH		8
+#define PROP_HEIGHT				27
+#define PROP_SMALL_SIZE_SCALE	0.75
+
+#define BLINK_DIVISOR			200
+#define PULSE_DIVISOR			75
+
+#define UI_LEFT			0x00000000	// default
+#define UI_CENTER		0x00000001
+#define UI_RIGHT		0x00000002
+#define UI_FORMATMASK	0x00000007
+#define UI_SMALLFONT	0x00000010
+#define UI_BIGFONT		0x00000020	// default
+#define UI_GIANTFONT	0x00000040
+#define UI_DROPSHADOW	0x00000800
+#define UI_BLINK		0x00001000
+#define UI_INVERSE		0x00002000
+#define UI_PULSE		0x00004000
+
+#if defined(_DEBUG) && !defined(BSPC)
+	#define HUNK_DEBUG
+#endif
+
+typedef enum {
+	h_high,
+	h_low,
+	h_dontcare
+} ha_pref;
+
+#ifdef HUNK_DEBUG
+#define Hunk_Alloc( size, preference )				Hunk_AllocDebug(size, preference, #size, __FILE__, __LINE__)
+void *Hunk_AllocDebug( int size, ha_pref preference, char *label, char *file, int line );
+#else
+void *Hunk_Alloc( int size, ha_pref preference );
+#endif
+
+#if defined(__GNUC__) && !defined(__MINGW32__) && !defined(MACOS_X)
+// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=371
+// custom Snd_Memset implementation for glibc memset bug workaround
+void Snd_Memset (void* dest, const int val, const size_t count);
+#else
+#define Snd_Memset Com_Memset
+#endif
+
+#define Com_Memset memset
+#define Com_Memcpy memcpy
+
+#define CIN_system	1
+#define CIN_loop	2
+#define	CIN_hold	4
+#define CIN_silent	8
+#define CIN_shader	16
+
+/*
+==============================================================
+
+MATHLIB
+
+==============================================================
+*/
+
+
+typedef float vec_t;
+typedef vec_t vec2_t[2];
+typedef vec_t vec3_t[3];
+typedef vec_t vec4_t[4];
+typedef vec_t vec5_t[5];
+
+typedef	int	fixed4_t;
+typedef	int	fixed8_t;
+typedef	int	fixed16_t;
+
+#ifndef M_PI
+#define M_PI		3.14159265358979323846f	// matches value in gcc v2 math.h
+#endif
+
+#define NUMVERTEXNORMALS	162
+extern	vec3_t	bytedirs[NUMVERTEXNORMALS];
+
+// all drawing is done to a 640*480 virtual screen size
+// and will be automatically scaled to the real resolution
+#define	SCREEN_WIDTH		640
+#define	SCREEN_HEIGHT		480
+
+#define TINYCHAR_WIDTH		(SMALLCHAR_WIDTH)
+#define TINYCHAR_HEIGHT		(SMALLCHAR_HEIGHT/2)
+
+#define SMALLCHAR_WIDTH		8
+#define SMALLCHAR_HEIGHT	16
+
+#define BIGCHAR_WIDTH		16
+#define BIGCHAR_HEIGHT		16
+
+#define	GIANTCHAR_WIDTH		32
+#define	GIANTCHAR_HEIGHT	48
+
+extern	vec4_t		colorBlack;
+extern	vec4_t		colorRed;
+extern	vec4_t		colorGreen;
+extern	vec4_t		colorBlue;
+extern	vec4_t		colorYellow;
+extern	vec4_t		colorMagenta;
+extern	vec4_t		colorCyan;
+extern	vec4_t		colorWhite;
+extern	vec4_t		colorLtGrey;
+extern	vec4_t		colorMdGrey;
+extern	vec4_t		colorDkGrey;
+
+#define Q_COLOR_ESCAPE	'^'
+#define Q_IsColorString(p)	( p && *(p) == Q_COLOR_ESCAPE && *((p)+1) && *((p)+1) != Q_COLOR_ESCAPE )
+
+#define COLOR_BLACK		'0'
+#define COLOR_RED		'1'
+#define COLOR_GREEN		'2'
+#define COLOR_YELLOW	'3'
+#define COLOR_BLUE		'4'
+#define COLOR_CYAN		'5'
+#define COLOR_MAGENTA	'6'
+#define COLOR_WHITE		'7'
+#define ColorIndex(c)	( ( (c) - '0' ) & 7 )
+
+#define S_COLOR_BLACK	"^0"
+#define S_COLOR_RED		"^1"
+#define S_COLOR_GREEN	"^2"
+#define S_COLOR_YELLOW	"^3"
+#define S_COLOR_BLUE	"^4"
+#define S_COLOR_CYAN	"^5"
+#define S_COLOR_MAGENTA	"^6"
+#define S_COLOR_WHITE	"^7"
+
+extern vec4_t	g_color_table[8];
+
+#define	MAKERGB( v, r, g, b ) v[0]=r;v[1]=g;v[2]=b
+#define	MAKERGBA( v, r, g, b, a ) v[0]=r;v[1]=g;v[2]=b;v[3]=a
+
+#define DEG2RAD( a ) ( ( (a) * M_PI ) / 180.0F )
+#define RAD2DEG( a ) ( ( (a) * 180.0f ) / M_PI )
+
+struct cplane_s;
+
+extern	vec3_t	vec3_origin;
+extern	vec3_t	axisDefault[3];
+
+#define	nanmask (255<<23)
+
+#define	IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask)
+
+#if idppc
+
+static ID_INLINE float Q_rsqrt( float number ) {
+		float x = 0.5f * number;
+                float y;
+#ifdef __GNUC__            
+                asm("frsqrte %0,%1" : "=f" (y) : "f" (number));
+#else
+		y = __frsqrte( number );
+#endif
+		return y * (1.5f - (x * y * y));
+	}
+
+#ifdef __GNUC__            
+static ID_INLINE float Q_fabs(float x) {
+    float abs_x;
+    
+    asm("fabs %0,%1" : "=f" (abs_x) : "f" (x));
+    return abs_x;
+}
+#else
+#define Q_fabs __fabsf
+#endif
+
+#else
+float Q_fabs( float f );
+float Q_rsqrt( float f );		// reciprocal square root
+#endif
+
+#define SQRTFAST( x ) ( (x) * Q_rsqrt( x ) )
+
+signed char ClampChar( int i );
+signed short ClampShort( int i );
+
+// this isn't a real cheap function to call!
+int DirToByte( vec3_t dir );
+void ByteToDir( int b, vec3_t dir );
+
+#if	1
+
+#define DotProduct(x,y)			((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
+#define VectorSubtract(a,b,c)	((c)[0]=(a)[0]-(b)[0],(c)[1]=(a)[1]-(b)[1],(c)[2]=(a)[2]-(b)[2])
+#define VectorAdd(a,b,c)		((c)[0]=(a)[0]+(b)[0],(c)[1]=(a)[1]+(b)[1],(c)[2]=(a)[2]+(b)[2])
+#define VectorCopy(a,b)			((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2])
+#define	VectorScale(v, s, o)	((o)[0]=(v)[0]*(s),(o)[1]=(v)[1]*(s),(o)[2]=(v)[2]*(s))
+#define	VectorMA(v, s, b, o)	((o)[0]=(v)[0]+(b)[0]*(s),(o)[1]=(v)[1]+(b)[1]*(s),(o)[2]=(v)[2]+(b)[2]*(s))
+
+#else
+
+#define DotProduct(x,y)			_DotProduct(x,y)
+#define VectorSubtract(a,b,c)	_VectorSubtract(a,b,c)
+#define VectorAdd(a,b,c)		_VectorAdd(a,b,c)
+#define VectorCopy(a,b)			_VectorCopy(a,b)
+#define	VectorScale(v, s, o)	_VectorScale(v,s,o)
+#define	VectorMA(v, s, b, o)	_VectorMA(v,s,b,o)
+
+#endif
+
+#ifdef Q3_VM
+#ifdef VectorCopy
+#undef VectorCopy
+// this is a little hack to get more efficient copies in our interpreter
+typedef struct {
+	float	v[3];
+} vec3struct_t;
+#define VectorCopy(a,b)	(*(vec3struct_t *)b=*(vec3struct_t *)a)
+#endif
+#endif
+
+#define VectorClear(a)			((a)[0]=(a)[1]=(a)[2]=0)
+#define VectorNegate(a,b)		((b)[0]=-(a)[0],(b)[1]=-(a)[1],(b)[2]=-(a)[2])
+#define VectorSet(v, x, y, z)	((v)[0]=(x), (v)[1]=(y), (v)[2]=(z))
+#define Vector4Copy(a,b)		((b)[0]=(a)[0],(b)[1]=(a)[1],(b)[2]=(a)[2],(b)[3]=(a)[3])
+
+#define	SnapVector(v) {v[0]=((int)(v[0]));v[1]=((int)(v[1]));v[2]=((int)(v[2]));}
+// just in case you do't want to use the macros
+vec_t _DotProduct( const vec3_t v1, const vec3_t v2 );
+void _VectorSubtract( const vec3_t veca, const vec3_t vecb, vec3_t out );
+void _VectorAdd( const vec3_t veca, const vec3_t vecb, vec3_t out );
+void _VectorCopy( const vec3_t in, vec3_t out );
+void _VectorScale( const vec3_t in, float scale, vec3_t out );
+void _VectorMA( const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc );
+
+unsigned ColorBytes3 (float r, float g, float b);
+unsigned ColorBytes4 (float r, float g, float b, float a);
+
+float NormalizeColor( const vec3_t in, vec3_t out );
+
+float RadiusFromBounds( const vec3_t mins, const vec3_t maxs );
+void ClearBounds( vec3_t mins, vec3_t maxs );
+void AddPointToBounds( const vec3_t v, vec3_t mins, vec3_t maxs );
+
+#if !defined( Q3_VM ) || ( defined( Q3_VM ) && defined( __Q3_VM_MATH ) )
+static ID_INLINE int VectorCompare( const vec3_t v1, const vec3_t v2 ) {
+	if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2]) {
+		return 0;
+	}			
+	return 1;
+}
+
+static ID_INLINE vec_t VectorLength( const vec3_t v ) {
+	return (vec_t)sqrt (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
+}
+
+static ID_INLINE vec_t VectorLengthSquared( const vec3_t v ) {
+	return (v[0]*v[0] + v[1]*v[1] + v[2]*v[2]);
+}
+
+static ID_INLINE vec_t Distance( const vec3_t p1, const vec3_t p2 ) {
+	vec3_t	v;
+
+	VectorSubtract (p2, p1, v);
+	return VectorLength( v );
+}
+
+static ID_INLINE vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 ) {
+	vec3_t	v;
+
+	VectorSubtract (p2, p1, v);
+	return v[0]*v[0] + v[1]*v[1] + v[2]*v[2];
+}
+
+// fast vector normalize routine that does not check to make sure
+// that length != 0, nor does it return length, uses rsqrt approximation
+static ID_INLINE void VectorNormalizeFast( vec3_t v )
+{
+	float ilength;
+
+	ilength = Q_rsqrt( DotProduct( v, v ) );
+
+	v[0] *= ilength;
+	v[1] *= ilength;
+	v[2] *= ilength;
+}
+
+static ID_INLINE void VectorInverse( vec3_t v ){
+	v[0] = -v[0];
+	v[1] = -v[1];
+	v[2] = -v[2];
+}
+
+static ID_INLINE void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross ) {
+	cross[0] = v1[1]*v2[2] - v1[2]*v2[1];
+	cross[1] = v1[2]*v2[0] - v1[0]*v2[2];
+	cross[2] = v1[0]*v2[1] - v1[1]*v2[0];
+}
+
+#else
+int VectorCompare( const vec3_t v1, const vec3_t v2 );
+
+vec_t VectorLength( const vec3_t v );
+
+vec_t VectorLengthSquared( const vec3_t v );
+
+vec_t Distance( const vec3_t p1, const vec3_t p2 );
+
+vec_t DistanceSquared( const vec3_t p1, const vec3_t p2 );
+ 
+void VectorNormalizeFast( vec3_t v );
+
+void VectorInverse( vec3_t v );
+
+void CrossProduct( const vec3_t v1, const vec3_t v2, vec3_t cross );
+
+#endif
+
+vec_t VectorNormalize (vec3_t v);		// returns vector length
+vec_t VectorNormalize2( const vec3_t v, vec3_t out );
+void Vector4Scale( const vec4_t in, vec_t scale, vec4_t out );
+void VectorRotate( vec3_t in, vec3_t matrix[3], vec3_t out );
+int Q_log2(int val);
+
+float Q_acos(float c);
+
+int		Q_rand( int *seed );
+float	Q_random( int *seed );
+float	Q_crandom( int *seed );
+
+#define random()	((rand () & 0x7fff) / ((float)0x7fff))
+#define crandom()	(2.0 * (random() - 0.5))
+
+void vectoangles( const vec3_t value1, vec3_t angles);
+void AnglesToAxis( const vec3_t angles, vec3_t axis[3] );
+
+void AxisClear( vec3_t axis[3] );
+void AxisCopy( vec3_t in[3], vec3_t out[3] );
+
+void SetPlaneSignbits( struct cplane_s *out );
+int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct cplane_s *plane);
+
+float	AngleMod(float a);
+float	LerpAngle (float from, float to, float frac);
+float	AngleSubtract( float a1, float a2 );
+void	AnglesSubtract( vec3_t v1, vec3_t v2, vec3_t v3 );
+
+float AngleNormalize360 ( float angle );
+float AngleNormalize180 ( float angle );
+float AngleDelta ( float angle1, float angle2 );
+
+qboolean PlaneFromPoints( vec4_t plane, const vec3_t a, const vec3_t b, const vec3_t c );
+void ProjectPointOnPlane( vec3_t dst, const vec3_t p, const vec3_t normal );
+void RotatePointAroundVector( vec3_t dst, const vec3_t dir, const vec3_t point, float degrees );
+void RotateAroundDirection( vec3_t axis[3], float yaw );
+void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up );
+// perpendicular vector could be replaced by this
+
+//int	PlaneTypeForNormal (vec3_t normal);
+
+void MatrixMultiply(float in1[3][3], float in2[3][3], float out[3][3]);
+void AngleVectors( const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up);
+void PerpendicularVector( vec3_t dst, const vec3_t src );
+int Q_isnan( float x );
+
+
+//=============================================
+
+float Com_Clamp( float min, float max, float value );
+
+char	*COM_SkipPath( char *pathname );
+void	COM_StripExtension( const char *in, char *out );
+void	COM_DefaultExtension( char *path, int maxSize, const char *extension );
+
+void	COM_BeginParseSession( const char *name );
+int		COM_GetCurrentParseLine( void );
+char	*COM_Parse( char **data_p );
+char	*COM_ParseExt( char **data_p, qboolean allowLineBreak );
+int		COM_Compress( char *data_p );
+void	COM_ParseError( char *format, ... );
+void	COM_ParseWarning( char *format, ... );
+//int		COM_ParseInfos( char *buf, int max, char infos[][MAX_INFO_STRING] );
+
+#define MAX_TOKENLENGTH		1024
+
+#ifndef TT_STRING
+//token types
+#define TT_STRING					1			// string
+#define TT_LITERAL					2			// literal
+#define TT_NUMBER					3			// number
+#define TT_NAME						4			// name
+#define TT_PUNCTUATION				5			// punctuation
+#endif
+
+typedef struct pc_token_s
+{
+	int type;
+	int subtype;
+	int intvalue;
+	float floatvalue;
+	char string[MAX_TOKENLENGTH];
+} pc_token_t;
+
+// data is an in/out parm, returns a parsed out token
+
+void	COM_MatchToken( char**buf_p, char *match );
+
+void SkipBracedSection (char **program);
+void SkipRestOfLine ( char **data );
+
+void Parse1DMatrix (char **buf_p, int x, float *m);
+void Parse2DMatrix (char **buf_p, int y, int x, float *m);
+void Parse3DMatrix (char **buf_p, int z, int y, int x, float *m);
+
+void	QDECL Com_sprintf (char *dest, int size, const char *fmt, ...);
+
+char *Com_SkipTokens( char *s, int numTokens, char *sep );
+char *Com_SkipCharset( char *s, char *sep );
+
+// mode parm for FS_FOpenFile
+typedef enum {
+	FS_READ,
+	FS_WRITE,
+	FS_APPEND,
+	FS_APPEND_SYNC
+} fsMode_t;
+
+typedef enum {
+	FS_SEEK_CUR,
+	FS_SEEK_END,
+	FS_SEEK_SET
+} fsOrigin_t;
+
+//=============================================
+
+int Q_isprint( int c );
+int Q_islower( int c );
+int Q_isupper( int c );
+int Q_isalpha( int c );
+
+// portable case insensitive compare
+int		Q_stricmp (const char *s1, const char *s2);
+int		Q_strncmp (const char *s1, const char *s2, int n);
+int		Q_stricmpn (const char *s1, const char *s2, int n);
+char	*Q_strlwr( char *s1 );
+char	*Q_strupr( char *s1 );
+char	*Q_strrchr( const char* string, int c );
+
+// buffer size safe library replacements
+void	Q_strncpyz( char *dest, const char *src, int destsize );
+void	Q_strcat( char *dest, int size, const char *src );
+
+// strlen that discounts Quake color sequences
+int Q_PrintStrlen( const char *string );
+// removes color sequences from string
+char *Q_CleanStr( char *string );
+
+//=============================================
+
+// 64-bit integers for global rankings interface
+// implemented as a struct for qvm compatibility
+typedef struct
+{
+	byte	b0;
+	byte	b1;
+	byte	b2;
+	byte	b3;
+	byte	b4;
+	byte	b5;
+	byte	b6;
+	byte	b7;
+} qint64;
+
+//=============================================
+/*
+short	BigShort(short l);
+short	LittleShort(short l);
+int		BigLong (int l);
+int		LittleLong (int l);
+qint64  BigLong64 (qint64 l);
+qint64  LittleLong64 (qint64 l);
+float	BigFloat (const float *l);
+float	LittleFloat (const float *l);
+
+void	Swap_Init (void);
+*/
+char	* QDECL va(char *format, ...);
+
+#define TRUNCATE_LENGTH	64
+void Com_TruncateLongString( char *buffer, const char *s );
+
+//=============================================
+
+//
+// key / value info strings
+//
+char *Info_ValueForKey( const char *s, const char *key );
+void Info_RemoveKey( char *s, const char *key );
+void Info_RemoveKey_big( char *s, const char *key );
+void Info_SetValueForKey( char *s, const char *key, const char *value );
+void Info_SetValueForKey_Big( char *s, const char *key, const char *value );
+qboolean Info_Validate( const char *s );
+void Info_NextPair( const char **s, char *key, char *value );
+
+// this is only here so the functions in q_shared.c and bg_*.c can link
+void	QDECL Com_Error( int level, const char *error, ... );
+void	QDECL Com_Printf( const char *msg, ... );
+
+
+/*
+==========================================================
+
+CVARS (console variables)
+
+Many variables can be used for cheating purposes, so when
+cheats is zero, force all unspecified variables to their
+default values.
+==========================================================
+*/
+
+#define	CVAR_ARCHIVE		1	// set to cause it to be saved to vars.rc
+								// used for system variables, not for player
+								// specific configurations
+#define	CVAR_USERINFO		2	// sent to server on connect or change
+#define	CVAR_SERVERINFO		4	// sent in response to front end requests
+#define	CVAR_SYSTEMINFO		8	// these cvars will be duplicated on all clients
+#define	CVAR_INIT			16	// don't allow change from console at all,
+								// but can be set from the command line
+#define	CVAR_LATCH			32	// will only change when C code next does
+								// a Cvar_Get(), so it can't be changed
+								// without proper initialization.  modified
+								// will be set, even though the value hasn't
+								// changed yet
+#define	CVAR_ROM			64	// display only, cannot be set by user at all
+#define	CVAR_USER_CREATED	128	// created by a set command
+#define	CVAR_TEMP			256	// can be set even when cheats are disabled, but is not archived
+#define CVAR_CHEAT			512	// can not be changed if cheats are disabled
+#define CVAR_NORESTART		1024	// do not clear when a cvar_restart is issued
+
+// nothing outside the Cvar_*() functions should modify these fields!
+typedef struct cvar_s {
+	char		*name;
+	char		*string;
+	char		*resetString;		// cvar_restart will reset to this value
+	char		*latchedString;		// for CVAR_LATCH vars
+	int			flags;
+	qboolean	modified;			// set each time the cvar is changed
+	int			modificationCount;	// incremented each time the cvar is changed
+	float		value;				// atof( string )
+	int			integer;			// atoi( string )
+	struct cvar_s *next;
+	struct cvar_s *hashNext;
+} cvar_t;
+
+#define	MAX_CVAR_VALUE_STRING	256
+
+typedef int	cvarHandle_t;
+
+// the modules that run in the virtual machine can't access the cvar_t directly,
+// so they must ask for structured updates
+typedef struct {
+	cvarHandle_t	handle;
+	int			modificationCount;
+	float		value;
+	int			integer;
+	char		string[MAX_CVAR_VALUE_STRING];
+} vmCvar_t;
+
+/*
+==============================================================
+
+COLLISION DETECTION
+
+==============================================================
+*/
+
+#include "surfaceflags.h"			// shared with the q3map utility
+
+// plane types are used to speed some tests
+// 0-2 are axial planes
+#define	PLANE_X			0
+#define	PLANE_Y			1
+#define	PLANE_Z			2
+#define	PLANE_NON_AXIAL	3
+
+
+/*
+=================
+PlaneTypeForNormal
+=================
+*/
+
+#define PlaneTypeForNormal(x) (x[0] == 1.0 ? PLANE_X : (x[1] == 1.0 ? PLANE_Y : (x[2] == 1.0 ? PLANE_Z : PLANE_NON_AXIAL) ) )
+
+// plane_t structure
+// !!! if this is changed, it must be changed in asm code too !!!
+typedef struct cplane_s {
+	vec3_t	normal;
+	float	dist;
+	byte	type;			// for fast side tests: 0,1,2 = axial, 3 = nonaxial
+	byte	signbits;		// signx + (signy<<1) + (signz<<2), used as lookup during collision
+	byte	pad[2];
+} cplane_t;
+
+
+// a trace is returned when a box is swept through the world
+typedef struct {
+	qboolean	allsolid;	// if true, plane is not valid
+	qboolean	startsolid;	// if true, the initial point was in a solid area
+	float		fraction;	// time completed, 1.0 = didn't hit anything
+	vec3_t		endpos;		// final position
+	cplane_t	plane;		// surface normal at impact, transformed to world space
+	int			surfaceFlags;	// surface hit
+	int			contents;	// contents on other side of surface hit
+	int			entityNum;	// entity the contacted sirface is a part of
+} trace_t;
+
+// trace->entityNum can also be 0 to (MAX_GENTITIES-1)
+// or ENTITYNUM_NONE, ENTITYNUM_WORLD
+
+
+// markfragments are returned by CM_MarkFragments()
+typedef struct {
+	int		firstPoint;
+	int		numPoints;
+} markFragment_t;
+
+
+
+typedef struct {
+	vec3_t		origin;
+	vec3_t		axis[3];
+} orientation_t;
+
+//=====================================================================
+
+
+// in order from highest priority to lowest
+// if none of the catchers are active, bound key strings will be executed
+#define KEYCATCH_CONSOLE		0x0001
+#define	KEYCATCH_UI					0x0002
+#define	KEYCATCH_MESSAGE		0x0004
+#define	KEYCATCH_CGAME			0x0008
+
+
+// sound channels
+// channel 0 never willingly overrides
+// other channels will allways override a playing sound on that channel
+typedef enum {
+	CHAN_AUTO,
+	CHAN_LOCAL,		// menu sounds, etc
+	CHAN_WEAPON,
+	CHAN_VOICE,
+	CHAN_ITEM,
+	CHAN_BODY,
+	CHAN_LOCAL_SOUND,	// chat messages, etc
+	CHAN_ANNOUNCER		// announcer voices, etc
+} soundChannel_t;
+
+
+/*
+========================================================================
+
+  ELEMENTS COMMUNICATED ACROSS THE NET
+
+========================================================================
+*/
+
+#define	ANGLE2SHORT(x)	((int)((x)*65536/360) & 65535)
+#define	SHORT2ANGLE(x)	((x)*(360.0/65536))
+
+#define	SNAPFLAG_RATE_DELAYED	1
+#define	SNAPFLAG_NOT_ACTIVE		2	// snapshot used during connection and for zombies
+#define SNAPFLAG_SERVERCOUNT	4	// toggled every map_restart so transitions can be detected
+
+//
+// per-level limits
+//
+#define	MAX_CLIENTS			64		// absolute limit
+#define MAX_LOCATIONS		64
+
+#define	GENTITYNUM_BITS		10		// don't need to send any more
+#define	MAX_GENTITIES		(1<<GENTITYNUM_BITS)
+
+// entitynums are communicated with GENTITY_BITS, so any reserved
+// values that are going to be communcated over the net need to
+// also be in this range
+#define	ENTITYNUM_NONE		(MAX_GENTITIES-1)
+#define	ENTITYNUM_WORLD		(MAX_GENTITIES-2)
+#define	ENTITYNUM_MAX_NORMAL	(MAX_GENTITIES-2)
+
+
+#define	MAX_MODELS			256		// these are sent over the net as 8 bits
+#define	MAX_SOUNDS			256		// so they cannot be blindly increased
+
+
+#define	MAX_CONFIGSTRINGS	1024
+
+// these are the only configstrings that the system reserves, all the
+// other ones are strictly for servergame to clientgame communication
+#define	CS_SERVERINFO		0		// an info string with all the serverinfo cvars
+#define	CS_SYSTEMINFO		1		// an info string for server system to client system configuration (timescale, etc)
+
+#define	RESERVED_CONFIGSTRINGS	2	// game can't modify below this, only the system can
+
+#define	MAX_GAMESTATE_CHARS	16000
+typedef struct {
+	int			stringOffsets[MAX_CONFIGSTRINGS];
+	char		stringData[MAX_GAMESTATE_CHARS];
+	int			dataCount;
+} gameState_t;
+
+//=========================================================
+
+// bit field limits
+#define	MAX_STATS				16
+#define	MAX_PERSISTANT			16
+#define	MAX_POWERUPS			16
+#define	MAX_WEAPONS				16		
+
+#define	MAX_PS_EVENTS			2
+
+#define PS_PMOVEFRAMECOUNTBITS	6
+
+// playerState_t is the information needed by both the client and server
+// to predict player motion and actions
+// nothing outside of pmove should modify these, or some degree of prediction error
+// will occur
+
+// you can't add anything to this without modifying the code in msg.c
+
+// playerState_t is a full superset of entityState_t as it is used by players,
+// so if a playerState_t is transmitted, the entityState_t can be fully derived
+// from it.
+typedef struct playerState_s {
+	int			commandTime;	// cmd->serverTime of last executed command
+	int			pm_type;
+	int			bobCycle;		// for view bobbing and footstep generation
+	int			pm_flags;		// ducked, jump_held, etc
+	int			pm_time;
+
+	vec3_t		origin;
+	vec3_t		velocity;
+	int			weaponTime;
+	int			gravity;
+	int			speed;
+	int			delta_angles[3];	// add to command angles to get view direction
+									// changed by spawns, rotating objects, and teleporters
+
+	int			groundEntityNum;// ENTITYNUM_NONE = in air
+
+	int			legsTimer;		// don't change low priority animations until this runs out
+	int			legsAnim;		// mask off ANIM_TOGGLEBIT
+
+	int			torsoTimer;		// don't change low priority animations until this runs out
+	int			torsoAnim;		// mask off ANIM_TOGGLEBIT
+
+	int			movementDir;	// a number 0 to 7 that represents the reletive angle
+								// of movement to the view angle (axial and diagonals)
+								// when at rest, the value will remain unchanged
+								// used to twist the legs during strafing
+
+	vec3_t		grapplePoint;	// location of grapple to pull towards if PMF_GRAPPLE_PULL
+
+	int			eFlags;			// copied to entityState_t->eFlags
+
+	int			eventSequence;	// pmove generated events
+	int			events[MAX_PS_EVENTS];
+	int			eventParms[MAX_PS_EVENTS];
+
+	int			externalEvent;	// events set on player from another source
+	int			externalEventParm;
+	int			externalEventTime;
+
+	int			clientNum;		// ranges from 0 to MAX_CLIENTS-1
+	int			weapon;			// copied to entityState_t->weapon
+	int			weaponstate;
+
+	vec3_t		viewangles;		// for fixed views
+	int			viewheight;
+
+	// damage feedback
+	int			damageEvent;	// when it changes, latch the other parms
+	int			damageYaw;
+	int			damagePitch;
+	int			damageCount;
+
+	int			stats[MAX_STATS];
+	int			persistant[MAX_PERSISTANT];	// stats that aren't cleared on death
+	int			powerups[MAX_POWERUPS];	// level.time that the powerup runs out
+	int			ammo[MAX_WEAPONS];
+
+	int			generic1;
+	int			loopSound;
+	int			jumppad_ent;	// jumppad entity hit this frame
+
+	// not communicated over the net at all
+	int			ping;			// server to game info for scoreboard
+	int			pmove_framecount;	// FIXME: don't transmit over the network
+	int			jumppad_frame;
+	int			entityEventSequence;
+} playerState_t;
+
+
+//====================================================================
+
+
+//
+// usercmd_t->button bits, many of which are generated by the client system,
+// so they aren't game/cgame only definitions
+//
+#define	BUTTON_ATTACK		1
+#define	BUTTON_TALK			2			// displays talk balloon and disables actions
+#define	BUTTON_USE_HOLDABLE	4
+#define	BUTTON_GESTURE		8
+#define	BUTTON_WALKING		16			// walking can't just be infered from MOVE_RUN
+										// because a key pressed late in the frame will
+										// only generate a small move value for that frame
+										// walking will use different animations and
+										// won't generate footsteps
+#define BUTTON_AFFIRMATIVE	32
+#define	BUTTON_NEGATIVE		64
+
+#define BUTTON_GETFLAG		128
+#define BUTTON_GUARDBASE	256
+#define BUTTON_PATROL		512
+#define BUTTON_FOLLOWME		1024
+
+#define	BUTTON_ANY			2048			// any key whatsoever
+
+#define	MOVE_RUN			120			// if forwardmove or rightmove are >= MOVE_RUN,
+										// then BUTTON_WALKING should be set
+
+// usercmd_t is sent to the server each client frame
+typedef struct usercmd_s {
+	int				serverTime;
+	int				angles[3];
+	int 			buttons;
+	byte			weapon;           // weapon 
+	signed char	forwardmove, rightmove, upmove;
+} usercmd_t;
+
+//===================================================================
+
+// if entityState->solid == SOLID_BMODEL, modelindex is an inline model number
+#define	SOLID_BMODEL	0xffffff
+
+typedef enum {
+	TR_STATIONARY,
+	TR_INTERPOLATE,				// non-parametric, but interpolate between snapshots
+	TR_LINEAR,
+	TR_LINEAR_STOP,
+	TR_SINE,					// value = base + sin( time / duration ) * delta
+	TR_GRAVITY
+} trType_t;
+
+typedef struct {
+	trType_t	trType;
+	int		trTime;
+	int		trDuration;			// if non 0, trTime + trDuration = stop time
+	vec3_t	trBase;
+	vec3_t	trDelta;			// velocity, etc
+} trajectory_t;
+
+// entityState_t is the information conveyed from the server
+// in an update message about entities that the client will
+// need to render in some way
+// Different eTypes may use the information in different ways
+// The messages are delta compressed, so it doesn't really matter if
+// the structure size is fairly large
+
+typedef struct entityState_s {
+	int		number;			// entity index
+	int		eType;			// entityType_t
+	int		eFlags;
+
+	trajectory_t	pos;	// for calculating position
+	trajectory_t	apos;	// for calculating angles
+
+	int		time;
+	int		time2;
+
+	vec3_t	origin;
+	vec3_t	origin2;
+
+	vec3_t	angles;
+	vec3_t	angles2;
+
+	int		otherEntityNum;	// shotgun sources, etc
+	int		otherEntityNum2;
+
+	int		groundEntityNum;	// -1 = in air
+
+	int		constantLight;	// r + (g<<8) + (b<<16) + (intensity<<24)
+	int		loopSound;		// constantly loop this sound
+
+	int		modelindex;
+	int		modelindex2;
+	int		clientNum;		// 0 to (MAX_CLIENTS - 1), for players and corpses
+	int		frame;
+
+	int		solid;			// for client side prediction, trap_linkentity sets this properly
+
+	int		event;			// impulse events -- muzzle flashes, footsteps, etc
+	int		eventParm;
+
+	// for players
+	int		powerups;		// bit flags
+	int		weapon;			// determines weapon and flash model, etc
+	int		legsAnim;		// mask off ANIM_TOGGLEBIT
+	int		torsoAnim;		// mask off ANIM_TOGGLEBIT
+
+	int		generic1;
+} entityState_t;
+
+typedef enum {
+	CA_UNINITIALIZED,
+	CA_DISCONNECTED, 	// not talking to a server
+	CA_AUTHORIZING,		// not used any more, was checking cd key 
+	CA_CONNECTING,		// sending request packets to the server
+	CA_CHALLENGING,		// sending challenge packets to the server
+	CA_CONNECTED,		// netchan_t established, getting gamestate
+	CA_LOADING,			// only during cgame initialization, never during main loop
+	CA_PRIMED,			// got gamestate, waiting for first frame
+	CA_ACTIVE,			// game views should be displayed
+	CA_CINEMATIC		// playing a cinematic or a static pic, not connected to a server
+} connstate_t;
+
+// font support 
+
+#define GLYPH_START 0
+#define GLYPH_END 255
+#define GLYPH_CHARSTART 32
+#define GLYPH_CHAREND 127
+#define GLYPHS_PER_FONT GLYPH_END - GLYPH_START + 1
+typedef struct {
+  int height;       // number of scan lines
+  int top;          // top of glyph in buffer
+  int bottom;       // bottom of glyph in buffer
+  int pitch;        // width for copying
+  int xSkip;        // x adjustment
+  int imageWidth;   // width of actual image
+  int imageHeight;  // height of actual image
+  float s;          // x offset in image where glyph starts
+  float t;          // y offset in image where glyph starts
+  float s2;
+  float t2;
+  qhandle_t glyph;  // handle to the shader with the glyph
+  char shaderName[32];
+} glyphInfo_t;
+
+typedef struct {
+  glyphInfo_t glyphs [GLYPHS_PER_FONT];
+  float glyphScale;
+  char name[MAX_QPATH];
+} fontInfo_t;
+
+#define Square(x) ((x)*(x))
+
+// real time
+//=============================================
+
+
+typedef struct qtime_s {
+	int tm_sec;     /* seconds after the minute - [0,59] */
+	int tm_min;     /* minutes after the hour - [0,59] */
+	int tm_hour;    /* hours since midnight - [0,23] */
+	int tm_mday;    /* day of the month - [1,31] */
+	int tm_mon;     /* months since January - [0,11] */
+	int tm_year;    /* years since 1900 */
+	int tm_wday;    /* days since Sunday - [0,6] */
+	int tm_yday;    /* days since January 1 - [0,365] */
+	int tm_isdst;   /* daylight savings time flag */
+} qtime_t;
+
+
+// server browser sources
+// TTimo: AS_MPLAYER is no longer used
+#define AS_LOCAL			0
+#define AS_MPLAYER		1
+#define AS_GLOBAL			2
+#define AS_FAVORITES	3
+
+
+// cinematic states
+typedef enum {
+	FMV_IDLE,
+	FMV_PLAY,		// play
+	FMV_EOF,		// all other conditions, i.e. stop/EOF/abort
+	FMV_ID_BLT,
+	FMV_ID_IDLE,
+	FMV_LOOPED,
+	FMV_ID_WAIT
+} e_status;
+
+typedef enum _flag_status {
+	FLAG_ATBASE = 0,
+	FLAG_TAKEN,			// CTF
+	FLAG_TAKEN_RED,		// One Flag CTF
+	FLAG_TAKEN_BLUE,	// One Flag CTF
+	FLAG_DROPPED
+} flagStatus_t;
+
+
+
+#define	MAX_GLOBAL_SERVERS				4096
+#define	MAX_OTHER_SERVERS					128
+#define MAX_PINGREQUESTS					32
+#define MAX_SERVERSTATUSREQUESTS	16
+
+#define SAY_ALL		0
+#define SAY_TEAM	1
+#define SAY_TELL	2
+
+#define CDKEY_LEN 16
+#define CDCHKSUM_LEN 2
+
+
+#endif	// __Q_SHARED_H
diff --git a/code/qcommon/qcommon.h b/code/qcommon/qcommon.h
new file mode 100644
index 0000000..21c74e9
--- /dev/null
+++ b/code/qcommon/qcommon.h
@@ -0,0 +1,1096 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+
+This file is part of Quake III Arena source code.
+
+Quake III Arena source code 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.
+
+Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+===========================================================================
+*/
+// qcommon.h -- definitions common between client and server, but not game.or ref modules
+#ifndef _QCOMMON_H_
+#define _QCOMMON_H_
+
+#include "../qcommon/cm_public.h"
+
+//Ignore __attribute__ on non-gcc platforms
+#ifndef __GNUC__
+#ifndef __attribute__
+#define __attribute__(x)
+#endif
+#endif
+
+//#define	PRE_RELEASE_DEMO
+
+//============================================================================
+
+//
+// msg.c
+//
+typedef struct {
+	qboolean	allowoverflow;	// if false, do a Com_Error
+	qboolean	overflowed;		// set to true if the buffer size failed (with allowoverflow set)
+	qboolean	oob;			// set to true if the buffer size failed (with allowoverflow set)
+	byte	*data;
+	int		maxsize;
+	int		cursize;
+	int		readcount;
+	int		bit;				// for bitwise reads and writes
+} msg_t;
+
+void MSG_Init (msg_t *buf, byte *data, int length);
+void MSG_InitOOB( msg_t *buf, byte *data, int length );
+void MSG_Clear (msg_t *buf);
+void MSG_WriteData (msg_t *buf, const void *data, int length);
+void MSG_Bitstream( msg_t *buf );
+
+// TTimo
+// copy a msg_t in case we need to store it as is for a bit
+// (as I needed this to keep an msg_t from a static var for later use)
+// sets data buffer as MSG_Init does prior to do the copy
+void MSG_Copy(msg_t *buf, byte *data, int length, msg_t *src);
+
+struct usercmd_s;
+struct entityState_s;
+struct playerState_s;
+
+void MSG_WriteBits( msg_t *msg, int value, int bits );
+
+void MSG_WriteChar (msg_t *sb, int c);
+void MSG_WriteByte (msg_t *sb, int c);
+void MSG_WriteShort (msg_t *sb, int c);
+void MSG_WriteLong (msg_t *sb, int c);
+void MSG_WriteFloat (msg_t *sb, float f);
+void MSG_WriteString (msg_t *sb, const char *s);
+void MSG_WriteBigString (msg_t *sb, const char *s);
+void MSG_WriteAngle16 (msg_t *sb, float f);
+
+void	MSG_BeginReading (msg_t *sb);
+void	MSG_BeginReadingOOB(msg_t *sb);
+
+int		MSG_ReadBits( msg_t *msg, int bits );
+
+int		MSG_ReadChar (msg_t *sb);
+int		MSG_ReadByte (msg_t *sb);
+int		MSG_ReadShort (msg_t *sb);
+int		MSG_ReadLong (msg_t *sb);
+float	MSG_ReadFloat (msg_t *sb);
+char	*MSG_ReadString (msg_t *sb);
+char	*MSG_ReadBigString (msg_t *sb);
+char	*MSG_ReadStringLine (msg_t *sb);
+float	MSG_ReadAngle16 (msg_t *sb);
+void	MSG_ReadData (msg_t *sb, void *buffer, int size);
+
+
+void MSG_WriteDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
+void MSG_ReadDeltaUsercmd( msg_t *msg, struct usercmd_s *from, struct usercmd_s *to );
+
+void MSG_WriteDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
+void MSG_ReadDeltaUsercmdKey( msg_t *msg, int key, usercmd_t *from, usercmd_t *to );
+
+void MSG_WriteDeltaEntity( msg_t *msg, struct entityState_s *from, struct entityState_s *to
+						   , qboolean force );
+void MSG_ReadDeltaEntity( msg_t *msg, entityState_t *from, entityState_t *to, 
+						 int number );
+
+void MSG_WriteDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
+void MSG_ReadDeltaPlayerstate( msg_t *msg, struct playerState_s *from, struct playerState_s *to );
+
+
+void MSG_ReportChangeVectors_f( void );
+
+//============================================================================
+
+/*
+==============================================================
+
+NET
+
+==============================================================
+*/
+
+#define	PACKET_BACKUP	32	// number of old messages that must be kept on client and
+							// server for delta comrpession and ping estimation
+#define	PACKET_MASK		(PACKET_BACKUP-1)
+
+#define	MAX_PACKET_USERCMDS		32		// max number of usercmd_t in a packet
+
+#define	PORT_ANY			-1
+
+#define	MAX_RELIABLE_COMMANDS	64			// max string commands buffered for restransmit
+
+typedef enum {
+	NA_BOT,
+	NA_BAD,					// an address lookup failed
+	NA_LOOPBACK,
+	NA_BROADCAST,
+	NA_IP,
+	NA_IPX,
+	NA_BROADCAST_IPX
+} netadrtype_t;
+
+typedef enum {
+	NS_CLIENT,
+	NS_SERVER
+} netsrc_t;
+
+typedef struct {
+	netadrtype_t	type;
+
+	byte	ip[4];
+	byte	ipx[10];
+
+	unsigned short	port;
+} netadr_t;
+
+void		NET_Init( void );
+void		NET_Shutdown( void );
+void		NET_Restart( void );
+void		NET_Config( qboolean enableNetworking );
+
+void		NET_SendPacket (netsrc_t sock, int length, const void *data, netadr_t to);
+void		QDECL NET_OutOfBandPrint( netsrc_t net_socket, netadr_t adr, const char *format, ...);
+void		QDECL NET_OutOfBandData( netsrc_t sock, netadr_t adr, byte *format, int len );
+
+qboolean	NET_CompareAdr (netadr_t a, netadr_t b);
+qboolean	NET_CompareBaseAdr (netadr_t a, netadr_t b);
+qboolean	NET_IsLocalAddress (netadr_t adr);
+const char	*NET_AdrToString (netadr_t a);
+qboolean	NET_StringToAdr ( const char *s, netadr_t *a);
+qboolean	NET_GetLoopPacket (netsrc_t sock, netadr_t *net_from, msg_t *net_message);
+void		NET_Sleep(int msec);
+
+
+#define	MAX_MSGLEN				16384		// max length of a message, which may
+											// be fragmented into multiple packets
+
+#define MAX_DOWNLOAD_WINDOW			8		// max of eight download frames
+#define MAX_DOWNLOAD_BLKSIZE		2048	// 2048 byte block chunks
+ 
+
+/*
+Netchan handles packet fragmentation and out of order / duplicate suppression
+*/
+
+typedef struct {
+	netsrc_t	sock;
+
+	int			dropped;			// between last packet and previous
+
+	netadr_t	remoteAddress;
+	int			qport;				// qport value to write when transmitting
+
+	// sequencing variables
+	int			incomingSequence;
+	int			outgoingSequence;
+
+	// incoming fragment assembly buffer
+	int			fragmentSequence;
+	int			fragmentLength;	
+	byte		fragmentBuffer[MAX_MSGLEN];
+
+	// outgoing fragment buffer
+	// we need to space out the sending of large fragmented messages
+	qboolean	unsentFragments;
+	int			unsentFragmentStart;
+	int			unsentLength;
+	byte		unsentBuffer[MAX_MSGLEN];
+} netchan_t;
+
+void Netchan_Init( int qport );
+void Netchan_Setup( netsrc_t sock, netchan_t *chan, netadr_t adr, int qport );
+
+void Netchan_Transmit( netchan_t *chan, int length, const byte *data );
+void Netchan_TransmitNextFragment( netchan_t *chan );
+
+qboolean Netchan_Process( netchan_t *chan, msg_t *msg );
+
+
+/*
+==============================================================
+
+PROTOCOL
+
+==============================================================
+*/
+
+#define	PROTOCOL_VERSION	68
+// 1.31 - 67
+
+// maintain a list of compatible protocols for demo playing
+// NOTE: that stuff only works with two digits protocols
+extern int demo_protocols[];
+
+#define	UPDATE_SERVER_NAME	"update.quake3arena.com"
+// override on command line, config files etc.
+#ifndef MASTER_SERVER_NAME
+#define MASTER_SERVER_NAME	"master.quake3arena.com"
+#endif
+#ifndef AUTHORIZE_SERVER_NAME
+#define	AUTHORIZE_SERVER_NAME	"authorize.quake3arena.com"
+#endif
+
+#define	PORT_MASTER			27950
+#define	PORT_UPDATE			27951
+#ifndef PORT_AUTHORIZE
+#define	PORT_AUTHORIZE		27952
+#endif
+#define	PORT_SERVER			27960
+#define	NUM_SERVER_PORTS	4		// broadcast scan this many ports after
+									// PORT_SERVER so a single machine can
+									// run multiple servers
+
+
+// the svc_strings[] array in cl_parse.c should mirror this
+//
+// server to client
+//
+enum svc_ops_e {
+	svc_bad,
+	svc_nop,
+	svc_gamestate,
+	svc_configstring,			// [short] [string] only in gamestate messages
+	svc_baseline,				// only in gamestate messages
+	svc_serverCommand,			// [string] to be executed by client game module
+	svc_download,				// [short] size [size bytes]
+	svc_snapshot,
+	svc_EOF
+};
+
+
+//
+// client to server
+//
+enum clc_ops_e {
+	clc_bad,
+	clc_nop, 		
+	clc_move,				// [[usercmd_t]
+	clc_moveNoDelta,		// [[usercmd_t]
+	clc_clientCommand,		// [string] message
+	clc_EOF
+};
+
+/*
+==============================================================
+
+VIRTUAL MACHINE
+
+==============================================================
+*/
+
+typedef struct vm_s vm_t;
+
+typedef enum {
+	VMI_NATIVE,
+	VMI_BYTECODE,
+	VMI_COMPILED
+} vmInterpret_t;
+
+typedef enum {
+	TRAP_MEMSET = 100,
+	TRAP_MEMCPY,
+	TRAP_STRNCPY,
+	TRAP_SIN,
+	TRAP_COS,
+	TRAP_ATAN2,
+	TRAP_SQRT,
+	TRAP_MATRIXMULTIPLY,
+	TRAP_ANGLEVECTORS,
+	TRAP_PERPENDICULARVECTOR,
+	TRAP_FLOOR,
+	TRAP_CEIL,
+
+	TRAP_TESTPRINTINT,
+	TRAP_TESTPRINTFLOAT
+} sharedTraps_t;
+
+void	VM_Init( void );
+vm_t	*VM_Create( const char *module, long (*systemCalls)(long *), 
+				   vmInterpret_t interpret );
+// module should be bare: "cgame", not "cgame.dll" or "vm/cgame.qvm"
+
+void	VM_Free( vm_t *vm );
+void	VM_Clear(void);
+vm_t	*VM_Restart( vm_t *vm );
+
+long		QDECL VM_Call( vm_t *vm, long callNum, ... );
+
+void	VM_Debug( int level );
+
+void	*VM_ArgPtr( long intValue );
+void	*VM_ExplicitArgPtr( vm_t *vm, long intValue );
+
+#define	VMA(x) VM_ArgPtr(args[x])
+static ID_INLINE float _vmf(long x)
+{
+	union {
+		long l;
+		float f;
+	} t;
+	t.l = x;
+	return t.f;
+}
+#define	VMF(x)	_vmf(args[x])
+
+
+/*
+==============================================================
+
+CMD
+
+Command text buffering and command execution
+
+==============================================================
+*/
+
+/*
+
+Any number of commands can be added in a frame, from several different sources.
+Most commands come from either keybindings or console line input, but entire text
+files can be execed.
+
+*/
+
+void Cbuf_Init (void);
+// allocates an initial text buffer that will grow as needed
+
+void Cbuf_AddText( const char *text );
+// Adds command text at the end of the buffer, does NOT add a final \n
+
+void Cbuf_ExecuteText( int exec_when, const char *text );
+// this can be used in place of either Cbuf_AddText or Cbuf_InsertText
+
+void Cbuf_Execute (void);
+// Pulls off \n terminated lines of text from the command buffer and sends
+// them through Cmd_ExecuteString.  Stops when the buffer is empty.
+// Normally called once per frame, but may be explicitly invoked.
+// Do not call inside a command function, or current args will be destroyed.
+
+//===========================================================================
+
+/*
+
+Command execution takes a null terminated string, breaks it into tokens,
+then searches for a command or variable that matches the first token.
+
+*/
+
+typedef void (*xcommand_t) (void);
+
+void	Cmd_Init (void);
+
+void	Cmd_AddCommand( const char *cmd_name, xcommand_t function );
+// called by the init functions of other parts of the program to
+// register commands and functions to call for them.
+// The cmd_name is referenced later, so it should not be in temp memory
+// if function is NULL, the command will be forwarded to the server
+// as a clc_clientCommand instead of executed locally
+
+void	Cmd_RemoveCommand( const char *cmd_name );
+
+void	Cmd_CommandCompletion( void(*callback)(const char *s) );
+// callback with each valid string
+
+int		Cmd_Argc (void);
+char	*Cmd_Argv (int arg);
+void	Cmd_ArgvBuffer( int arg, char *buffer, int bufferLength );
+char	*Cmd_Args (void);
+char	*Cmd_ArgsFrom( int arg );
+void	Cmd_ArgsBuffer( char *buffer, int bufferLength );
+char	*Cmd_Cmd (void);
+// The functions that execute commands get their parameters with these
+// functions. Cmd_Argv () will return an empty string, not a NULL
+// if arg > argc, so string operations are allways safe.
+
+void	Cmd_TokenizeString( const char *text );
+void	Cmd_TokenizeStringIgnoreQuotes( const char *text_in );
+// Takes a null terminated string.  Does not need to be /n terminated.
+// breaks the string up into arg tokens.
+
+void	Cmd_ExecuteString( const char *text );
+// Parses a single line of text into arguments and tries to execute it
+// as if it was typed at the console
+
+
+/*
+==============================================================
+
+CVAR
+
+==============================================================
+*/
+
+/*
+
+cvar_t variables are used to hold scalar or string variables that can be changed
+or displayed at the console or prog code as well as accessed directly
+in C code.
+
+The user can access cvars from the console in three ways:
+r_draworder			prints the current value
+r_draworder 0		sets the current value to 0
+set r_draworder 0	as above, but creates the cvar if not present
+
+Cvars are restricted from having the same names as commands to keep this
+interface from being ambiguous.
+
+The are also occasionally used to communicated information between different
+modules of the program.
+
+*/
+
+cvar_t *Cvar_Get( const char *var_name, const char *value, int flags );
+// creates the variable if it doesn't exist, or returns the existing one
+// if it exists, the value will not be changed, but flags will be ORed in
+// that allows variables to be unarchived without needing bitflags
+// if value is "", the value will not override a previously set value.
+
+void	Cvar_Register( vmCvar_t *vmCvar, const char *varName, const char *defaultValue, int flags );
+// basically a slightly modified Cvar_Get for the interpreted modules
+
+void	Cvar_Update( vmCvar_t *vmCvar );
+// updates an interpreted modules' version of a cvar
+
+void 	Cvar_Set( const char *var_name, const char *value );
+// will create the variable with no flags if it doesn't exist
+
+void Cvar_SetLatched( const char *var_name, const char *value);
+// don't set the cvar immediately
+
+void	Cvar_SetValue( const char *var_name, float value );
+// expands value to a string and calls Cvar_Set
+
+float	Cvar_VariableValue( const char *var_name );
+int		Cvar_VariableIntegerValue( const char *var_name );
+// returns 0 if not defined or non numeric
+
+char	*Cvar_VariableString( const char *var_name );
+void	Cvar_VariableStringBuffer( const char *var_name, char *buffer, int bufsize );
+// returns an empty string if not defined
+
+void	Cvar_CommandCompletion( void(*callback)(const char *s) );
+// callback with each valid string
+
+void 	Cvar_Reset( const char *var_name );
+
+void	Cvar_SetCheatState( void );
+// reset all testing vars to a safe value
+
+qboolean Cvar_Command( void );
+// called by Cmd_ExecuteString when Cmd_Argv(0) doesn't match a known
+// command.  Returns true if the command was a variable reference that
+// was handled. (print or change)
+
+void 	Cvar_WriteVariables( fileHandle_t f );
+// writes lines containing "set variable value" for all variables
+// with the archive flag set to true.
+
+void	Cvar_Init( void );
+
+char	*Cvar_InfoString( int bit );
+char	*Cvar_InfoString_Big( int bit );
+// returns an info string containing all the cvars that have the given bit set
+// in their flags ( CVAR_USERINFO, CVAR_SERVERINFO, CVAR_SYSTEMINFO, etc )
+void	Cvar_InfoStringBuffer( int bit, char *buff, int buffsize );
+
+void	Cvar_Restart_f( void );
+
+extern	int			cvar_modifiedFlags;
+// whenever a cvar is modifed, its flags will be OR'd into this, so
+// a single check can determine if any CVAR_USERINFO, CVAR_SERVERINFO,
+// etc, variables have been modified since the last check.  The bit
+// can then be cleared to allow another change detection.
+
+/*
+==============================================================
+
+FILESYSTEM
+
+No stdio calls should be used by any part of the game, because
+we need to deal with all sorts of directory and seperator char
+issues.
+==============================================================
+*/
+
+// referenced flags
+// these are in loop specific order so don't change the order
+#define FS_GENERAL_REF	0x01
+#define FS_UI_REF		0x02
+#define FS_CGAME_REF	0x04
+#define FS_QAGAME_REF	0x08
+// number of id paks that will never be autodownloaded from baseq3
+#define NUM_ID_PAKS		9
+
+#define	MAX_FILE_HANDLES	64
+
+#define BASEGAME "baseq3"
+
+qboolean FS_Initialized( void );
+
+void	FS_InitFilesystem ( void );
+void	FS_Shutdown( qboolean closemfp );
+
+qboolean	FS_ConditionalRestart( int checksumFeed );
+void	FS_Restart( int checksumFeed );
+// shutdown and restart the filesystem so changes to fs_gamedir can take effect
+
+char	**FS_ListFiles( const char *directory, const char *extension, int *numfiles );
+// directory should not have either a leading or trailing /
+// if extension is "/", only subdirectories will be returned
+// the returned files will not include any directories or /
+
+void	FS_FreeFileList( char **list );
+
+qboolean FS_FileExists( const char *file );
+
+char   *FS_BuildOSPath( const char *base, const char *game, const char *qpath );
+
+int		FS_LoadStack( void );
+
+int		FS_GetFileList(  const char *path, const char *extension, char *listbuf, int bufsize );
+int		FS_GetModList(  char *listbuf, int bufsize );
+
+fileHandle_t	FS_FOpenFileWrite( const char *qpath );
+// will properly create any needed paths and deal with seperater character issues
+
+int		FS_filelength( fileHandle_t f );
+fileHandle_t FS_SV_FOpenFileWrite( const char *filename );
+int		FS_SV_FOpenFileRead( const char *filename, fileHandle_t *fp );
+void	FS_SV_Rename( const char *from, const char *to );
+int		FS_FOpenFileRead( const char *qpath, fileHandle_t *file, qboolean uniqueFILE );
+// if uniqueFILE is true, then a new FILE will be fopened even if the file
+// is found in an already open pak file.  If uniqueFILE is false, you must call
+// FS_FCloseFile instead of fclose, otherwise the pak FILE would be improperly closed
+// It is generally safe to always set uniqueFILE to true, because the majority of
+// file IO goes through FS_ReadFile, which Does The Right Thing already.
+
+int		FS_FileIsInPAK(const char *filename, int *pChecksum );
+// returns 1 if a file is in the PAK file, otherwise -1
+
+int		FS_Write( const void *buffer, int len, fileHandle_t f );
+
+int		FS_Read2( void *buffer, int len, fileHandle_t f );
+int		FS_Read( void *buffer, int len, fileHandle_t f );
+// properly handles partial reads and reads from other dlls
+
+void	FS_FCloseFile( fileHandle_t f );
+// note: you can't just fclose from another DLL, due to MS libc issues
+
+int		FS_ReadFile( const char *qpath, void **buffer );
+// returns the length of the file
+// a null buffer will just return the file length without loading
+// as a quick check for existance. -1 length == not present
+// A 0 byte will always be appended at the end, so string ops are safe.
+// the buffer should be considered read-only, because it may be cached
+// for other uses.
+
+void	FS_ForceFlush( fileHandle_t f );
+// forces flush on files we're writing to.
+
+void	FS_FreeFile( void *buffer );
+// frees the memory returned by FS_ReadFile
+
+void	FS_WriteFile( const char *qpath, const void *buffer, int size );
+// writes a complete file, creating any subdirectories needed
+
+int		FS_filelength( fileHandle_t f );
+// doesn't work for files that are opened from a pack file
+
+int		FS_FTell( fileHandle_t f );
+// where are we?
+
+void	FS_Flush( fileHandle_t f );
+
+void 	QDECL FS_Printf( fileHandle_t f, const char *fmt, ... ) __attribute__ ((format (printf, 2, 3)));
+// like fprintf
+
+int		FS_FOpenFileByMode( const char *qpath, fileHandle_t *f, fsMode_t mode );
+// opens a file for reading, writing, or appending depending on the value of mode
+
+int		FS_Seek( fileHandle_t f, long offset, int origin );
+// seek on a file (doesn't work for zip files!!!!!!!!)
+
+qboolean FS_FilenameCompare( const char *s1, const char *s2 );
+
+const char *FS_GamePureChecksum( void );
+// Returns the checksum of the pk3 from which the server loaded the qagame.qvm
+
+const char *FS_LoadedPakNames( void );
+const char *FS_LoadedPakChecksums( void );
+const char *FS_LoadedPakPureChecksums( void );
+// Returns a space separated string containing the checksums of all loaded pk3 files.
+// Servers with sv_pure set will get this string and pass it to clients.
+
+const char *FS_ReferencedPakNames( void );
+const char *FS_ReferencedPakChecksums( void );
+const char *FS_ReferencedPakPureChecksums( void );
+// Returns a space separated string containing the checksums of all loaded 
+// AND referenced pk3 files. Servers with sv_pure set will get this string 
+// back from clients for pure validation 
+
+void FS_ClearPakReferences( int flags );
+// clears referenced booleans on loaded pk3s
+
+void FS_PureServerSetReferencedPaks( const char *pakSums, const char *pakNames );
+void FS_PureServerSetLoadedPaks( const char *pakSums, const char *pakNames );
+// If the string is empty, all data sources will be allowed.
+// If not empty, only pk3 files that match one of the space
+// separated checksums will be checked for files, with the
+// sole exception of .cfg files.
+
+qboolean FS_idPak( char *pak, char *base );
+qboolean FS_ComparePaks( char *neededpaks, int len, qboolean dlstring );
+
+void FS_Rename( const char *from, const char *to );
+
+void FS_Remove( const char *osPath );
+void FS_HomeRemove( const char *homePath );
+
+void	FS_FilenameCompletion( const char *dir, const char *ext,
+		qboolean stripExt, void(*callback)(const char *s) );
+/*
+==============================================================
+
+Edit fields and command line history/completion
+
+==============================================================
+*/
+
+#define	MAX_EDIT_LINE	256
+typedef struct {
+	int		cursor;
+	int		scroll;
+	int		widthInChars;
+	char	buffer[MAX_EDIT_LINE];
+} field_t;
+
+void Field_Clear( field_t *edit );
+void Field_AutoComplete( field_t *edit );
+
+/*
+==============================================================
+
+MISC
+
+==============================================================
+*/
+
+// TTimo
+// vsnprintf is ISO/IEC 9899:1999
+// abstracting this to make it portable
+#ifdef WIN32
+#define Q_vsnprintf _vsnprintf
+#else
+// TODO: do we need Mac define?
+#define Q_vsnprintf vsnprintf
+#endif
+
+// centralizing the declarations for cl_cdkey
+// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=470
+extern char cl_cdkey[34];
+
+// returnbed by Sys_GetProcessorId
+#define CPUID_GENERIC			0			// any unrecognized processor
+
+#define CPUID_AXP				0x10
+
+#define CPUID_INTEL_UNSUPPORTED	0x20			// Intel 386/486
+#define CPUID_INTEL_PENTIUM		0x21			// Intel Pentium or PPro
+#define CPUID_INTEL_MMX			0x22			// Intel Pentium/MMX or P2/MMX
+#define CPUID_INTEL_KATMAI		0x23			// Intel Katmai
+
+#define CPUID_AMD_3DNOW			0x30			// AMD K6 3DNOW!
+
+// TTimo
+// centralized and cleaned, that's the max string you can send to a Com_Printf / Com_DPrintf (above gets truncated)
+#define	MAXPRINTMSG	4096
+
+char		*CopyString( const char *in );
+void		Info_Print( const char *s );
+
+void		Com_BeginRedirect (char *buffer, int buffersize, void (*flush)(char *));
+void		Com_EndRedirect( void );
+void 		QDECL Com_Printf( const char *fmt, ... );
+void 		QDECL Com_DPrintf( const char *fmt, ... );
+void 		QDECL Com_Error( int code, const char *fmt, ... );
+void 		Com_Quit_f( void );
+int			Com_EventLoop( void );
+int			Com_Milliseconds( void );	// will be journaled properly
+unsigned	Com_BlockChecksum( const void *buffer, int length );
+int			Com_HashKey(char *string, int maxlen);
+int			Com_Filter(char *filter, char *name, int casesensitive);
+int			Com_FilterPath(char *filter, char *name, int casesensitive);
+int			Com_RealTime(qtime_t *qtime);
+qboolean	Com_SafeMode( void );
+
+void		Com_StartupVariable( const char *match );
+// checks for and removes command line "+set var arg" constructs
+// if match is NULL, all set commands will be executed, otherwise
+// only a set with the exact name.  Only used during startup.
+
+
+extern	cvar_t	*com_developer;
+extern	cvar_t	*com_dedicated;
+extern	cvar_t	*com_speeds;
+extern	cvar_t	*com_timescale;
+extern	cvar_t	*com_sv_running;
+extern	cvar_t	*com_cl_running;
+extern	cvar_t	*com_viewlog;			// 0 = hidden, 1 = visible, 2 = minimized
+extern	cvar_t	*com_version;
+extern	cvar_t	*com_blood;
+extern	cvar_t	*com_buildScript;		// for building release pak files
+extern	cvar_t	*com_journal;
+extern	cvar_t	*com_cameraMode;
+extern	cvar_t	*com_altivec;
+
+// both client and server must agree to pause
+extern	cvar_t	*cl_paused;
+extern	cvar_t	*sv_paused;
+
+// com_speeds times
+extern	int		time_game;
+extern	int		time_frontend;
+extern	int		time_backend;		// renderer backend time
+
+extern	int		com_frameTime;
+extern	int		com_frameMsec;
+
+extern	qboolean	com_errorEntered;
+
+extern	fileHandle_t	com_journalFile;
+extern	fileHandle_t	com_journalDataFile;
+
+typedef enum {
+	TAG_FREE,
+	TAG_GENERAL,
+	TAG_BOTLIB,
+	TAG_RENDERER,
+	TAG_SMALL,
+	TAG_STATIC
+} memtag_t;
+
+/*
+
+--- low memory ----
+server vm
+server clipmap
+---mark---
+renderer initialization (shaders, etc)
+UI vm
+cgame vm
+renderer map
+renderer models
+
+---free---
+
+temp file loading
+--- high memory ---
+
+*/
+
+#if defined(_DEBUG) && !defined(BSPC)
+	#define ZONE_DEBUG
+#endif
+
+#ifdef ZONE_DEBUG
+#define Z_TagMalloc(size, tag)			Z_TagMallocDebug(size, tag, #size, __FILE__, __LINE__)
+#define Z_Malloc(size)					Z_MallocDebug(size, #size, __FILE__, __LINE__)
+#define S_Malloc(size)					S_MallocDebug(size, #size, __FILE__, __LINE__)
+void *Z_TagMallocDebug( int size, int tag, char *label, char *file, int line );	// NOT 0 filled memory
+void *Z_MallocDebug( int size, char *label, char *file, int line );			// returns 0 filled memory
+void *S_MallocDebug( int size, char *label, char *file, int line );			// returns 0 filled memory
+#else
+void *Z_TagMalloc( int size, int tag );	// NOT 0 filled memory
+void *Z_Malloc( int size );			// returns 0 filled memory
+void *S_Malloc( int size );			// NOT 0 filled memory only for small allocations
+#endif
+void Z_Free( void *ptr );
+void Z_FreeTags( int tag );
+int Z_AvailableMemory( void );
+void Z_LogHeap( void );
+
+void Hunk_Clear( void );
+void Hunk_ClearToMark( void );
+void Hunk_SetMark( void );
+qboolean Hunk_CheckMark( void );
+void Hunk_ClearTempMemory( void );
+void *Hunk_AllocateTempMemory( int size );
+void Hunk_FreeTempMemory( void *buf );
+int	Hunk_MemoryRemaining( void );
+void Hunk_Log( void);
+void Hunk_Trash( void );
+
+void Com_TouchMemory( void );
+
+// commandLine should not include the executable name (argv[0])
+void Com_Init( char *commandLine );
+void Com_Frame( void );
+void Com_Shutdown( void );
+
+
+/*
+==============================================================
+
+CLIENT / SERVER SYSTEMS
+
+==============================================================
+*/
+
+//
+// client interface
+//
+void CL_InitKeyCommands( void );
+// the keyboard binding interface must be setup before execing
+// config files, but the rest of client startup will happen later
+
+void CL_Init( void );
+void CL_Disconnect( qboolean showMainMenu );
+void CL_Shutdown( void );
+void CL_Frame( int msec );
+qboolean CL_GameCommand( void );
+void CL_KeyEvent (int key, qboolean down, unsigned time);
+
+void CL_CharEvent( int key );
+// char events are for field typing, not game control
+
+void CL_MouseEvent( int dx, int dy, int time );
+
+void CL_JoystickEvent( int axis, int value, int time );
+
+void CL_PacketEvent( netadr_t from, msg_t *msg );
+
+void CL_ConsolePrint( char *text );
+
+void CL_MapLoading( void );
+// do a screen update before starting to load a map
+// when the server is going to load a new map, the entire hunk
+// will be cleared, so the client must shutdown cgame, ui, and
+// the renderer
+
+void	CL_ForwardCommandToServer( const char *string );
+// adds the current command line as a clc_clientCommand to the client message.
+// things like godmode, noclip, etc, are commands directed to the server,
+// so when they are typed in at the console, they will need to be forwarded.
+
+void CL_CDDialog( void );
+// bring up the "need a cd to play" dialog
+
+void CL_ShutdownAll( void );
+// shutdown all the client stuff
+
+void CL_FlushMemory( void );
+// dump all memory on an error
+
+void CL_StartHunkUsers( void );
+// start all the client stuff using the hunk
+
+void Key_WriteBindings( fileHandle_t f );
+// for writing the config files
+
+void S_ClearSoundBuffer( void );
+// call before filesystem access
+
+void SCR_DebugGraph (float value, int color);	// FIXME: move logging to common?
+
+//
+// server interface
+//
+void SV_Init( void );
+void SV_Shutdown( char *finalmsg );
+void SV_Frame( int msec );
+void SV_PacketEvent( netadr_t from, msg_t *msg );
+qboolean SV_GameCommand( void );
+
+
+//
+// UI interface
+//
+qboolean UI_GameCommand( void );
+qboolean UI_usesUniqueCDKey(void);
+
+/*
+==============================================================
+
+NON-PORTABLE SYSTEM SERVICES
+
+==============================================================
+*/
+
+typedef enum {
+	AXIS_SIDE,
+	AXIS_FORWARD,
+	AXIS_UP,
+	AXIS_ROLL,
+	AXIS_YAW,
+	AXIS_PITCH,
+	MAX_JOYSTICK_AXIS
+} joystickAxis_t;
+
+typedef enum {
+  // bk001129 - make sure SE_NONE is zero
+	SE_NONE = 0,	// evTime is still valid
+	SE_KEY,		// evValue is a key code, evValue2 is the down flag
+	SE_CHAR,	// evValue is an ascii char
+	SE_MOUSE,	// evValue and evValue2 are reletive signed x / y moves
+	SE_JOYSTICK_AXIS,	// evValue is an axis number and evValue2 is the current state (-127 to 127)
+	SE_CONSOLE,	// evPtr is a char*
+	SE_PACKET	// evPtr is a netadr_t followed by data bytes to evPtrLength
+} sysEventType_t;
+
+typedef struct {
+	int				evTime;
+	sysEventType_t	evType;
+	int				evValue, evValue2;
+	int				evPtrLength;	// bytes of data pointed to by evPtr, for journaling
+	void			*evPtr;			// this must be manually freed if not NULL
+} sysEvent_t;
+
+sysEvent_t	Sys_GetEvent( void );
+
+void	Sys_Init (void);
+
+// general development dll loading for virtual machine testing
+// fqpath param added 7/20/02 by T.Ray - Sys_LoadDll is only called in vm.c at this time
+void	* QDECL Sys_LoadDll( const char *name, char *fqpath , long (QDECL **entryPoint)(long, ...),
+				  long (QDECL *systemcalls)(long, ...) );
+void	Sys_UnloadDll( void *dllHandle );
+
+void	Sys_UnloadGame( void );
+void	*Sys_GetGameAPI( void *parms );
+
+void	Sys_UnloadCGame( void );
+void	*Sys_GetCGameAPI( void );
+
+void	Sys_UnloadUI( void );
+void	*Sys_GetUIAPI( void );
+
+//bot libraries
+void	Sys_UnloadBotLib( void );
+void	*Sys_GetBotLibAPI( void *parms );
+
+char	*Sys_GetCurrentUser( void );
+
+void	QDECL Sys_Error( const char *error, ...);
+void	Sys_Quit (void);
+char	*Sys_GetClipboardData( void );	// note that this isn't journaled...
+
+void	Sys_Print( const char *msg );
+
+// Sys_Milliseconds should only be used for profiling purposes,
+// any game related timing information should come from event timestamps
+int		Sys_Milliseconds (void);
+
+void	Sys_SnapVector( float *v );
+
+// the system console is shown when a dedicated server is running
+void	Sys_DisplaySystemConsole( qboolean show );
+
+int		Sys_GetProcessorId( void );
+
+void	Sys_BeginStreamedFile( fileHandle_t f, int readahead );
+void	Sys_EndStreamedFile( fileHandle_t f );
+int		Sys_StreamedRead( void *buffer, int size, int count, fileHandle_t f );
+void	Sys_StreamSeek( fileHandle_t f, int offset, int origin );
+
+void	Sys_ShowConsole( int level, qboolean quitOnClose );
+void	Sys_SetErrorText( const char *text );
+
+void	Sys_SendPacket( int length, const void *data, netadr_t to );
+
+qboolean	Sys_StringToAdr( const char *s, netadr_t *a );
+//Does NOT parse port numbers, only base addresses.
+
+qboolean	Sys_IsLANAddress (netadr_t adr);
+void		Sys_ShowIP(void);
+
+qboolean	Sys_CheckCD( void );
+
+void	Sys_Mkdir( const char *path );
+char	*Sys_Cwd( void );
+void	Sys_SetDefaultCDPath(const char *path);
+char	*Sys_DefaultCDPath(void);
+void	Sys_SetDefaultInstallPath(const char *path);
+char	*Sys_DefaultInstallPath(void);
+void  Sys_SetDefaultHomePath(const char *path);
+char	*Sys_DefaultHomePath(void);
+
+char **Sys_ListFiles( const char *directory, const char *extension, char *filter, int *numfiles, qboolean wantsubs );
+void	Sys_FreeFileList( char **list );
+
+void	Sys_BeginProfiling( void );
+void	Sys_EndProfiling( void );
+
+qboolean Sys_LowPhysicalMemory( void );
+unsigned int Sys_ProcessorCount( void );
+
+int Sys_MonkeyShouldBeSpanked( void );
+
+qboolean Sys_DetectAltivec( void );
+
+/* This is based on the Adaptive Huffman algorithm described in Sayood's Data
+ * Compression book.  The ranks are not actually stored, but implicitly defined
+ * by the location of a node within a doubly-linked list */
+
+#define NYT HMAX					/* NYT = Not Yet Transmitted */
+#define INTERNAL_NODE (HMAX+1)
+
+typedef struct nodetype {
+	struct	nodetype *left, *right, *parent; /* tree structure */ 
+	struct	nodetype *next, *prev; /* doubly-linked list */
+	struct	nodetype **head; /* highest ranked node in block */
+	int		weight;
+	int		symbol;
+} node_t;
+
+#define HMAX 256 /* Maximum symbol */
+
+typedef struct {
+	int			blocNode;
+	int			blocPtrs;
+
+	node_t*		tree;
+	node_t*		lhead;
+	node_t*		ltail;
+	node_t*		loc[HMAX+1];
+	node_t**	freelist;
+
+	node_t		nodeList[768];
+	node_t*		nodePtrs[768];
+} huff_t;
+
+typedef struct {
+	huff_t		compressor;
+	huff_t		decompressor;
+} huffman_t;
+
+void	Huff_Compress(msg_t *buf, int offset);
+void	Huff_Decompress(msg_t *buf, int offset);
+void	Huff_Init(huffman_t *huff);
+void	Huff_addRef(huff_t* huff, byte ch);
+int		Huff_Receive (node_t *node, int *ch, byte *fin);
+void	Huff_transmit (huff_t *huff, int ch, byte *fout);
+void	Huff_offsetReceive (node_t *node, int *ch, byte *fin, int *offset);
+void	Huff_offsetTransmit (huff_t *huff, int ch, byte *fout, int *offset);
+void	Huff_putBit( int bit, byte *fout, int *offset);
+int		Huff_getBit( byte *fout, int *offset);
+
+extern huffman_t clientHuffTables;
+
+#define	SV_ENCODE_START		4
+#define SV_DECODE_START		12
+#define	CL_ENCODE_START		12
+#define CL_DECODE_START		4
+
+#endif // _QCOMMON_H_
diff --git a/code/server/sv_init.c b/code/server/sv_init.c
new file mode 100644
index 0000000..4ce424e
--- /dev/null
+++ b/code/server/sv_init.c
@@ -0,0 +1,701 @@
+/*
+===========================================================================
+Copyright (C) 1999-2005 Id Software, Inc.
+
+This file is part of Quake III Arena source code.
+
+Quake III Arena source code 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.
+
+Quake III Arena source code 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 Quake III Arena source code; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+===========================================================================
+*/
+
+#include "server.h"
+
+/*
+===============
+SV_SetConfigstring
+
+===============
+*/
+void SV_SetConfigstring (int index, const char *val) {
+	int		len, i;
+	int		maxChunkSize = MAX_STRING_CHARS - 24;
+	client_t	*client;
+
+	if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
+		Com_Error (ERR_DROP, "SV_SetConfigstring: bad index %i\n", index);
+	}
+
+	if ( !val ) {
+		val = "";
+	}
+
+	// don't bother broadcasting an update if no change
+	if ( !strcmp( val, sv.configstrings[ index ] ) ) {
+		return;
+	}
+
+	// change the string in sv
+	Z_Free( sv.configstrings[index] );
+	sv.configstrings[index] = CopyString( val );
+
+	// send it to all the clients if we aren't
+	// spawning a new server
+	if ( sv.state == SS_GAME || sv.restarting ) {
+
+		// send the data to all relevent clients
+		for (i = 0, client = svs.clients; i < sv_maxclients->integer ; i++, client++) {
+			if ( client->state < CS_PRIMED ) {
+				continue;
+			}
+			// do not always send server info to all clients
+			if ( index == CS_SERVERINFO && client->gentity && (client->gentity->r.svFlags & SVF_NOSERVERINFO) ) {
+				continue;
+			}
+
+			len = strlen( val );
+			if( len >= maxChunkSize ) {
+				int		sent = 0;
+				int		remaining = len;
+				char	*cmd;
+				char	buf[MAX_STRING_CHARS];
+
+				while (remaining > 0 ) {
+					if ( sent == 0 ) {
+						cmd = "bcs0";
+					}
+					else if( remaining < maxChunkSize ) {
+						cmd = "bcs2";
+					}
+					else {
+						cmd = "bcs1";
+					}
+					Q_strncpyz( buf, &val[sent], maxChunkSize );
+
+					SV_SendServerCommand( client, "%s %i \"%s\"\n", cmd, index, buf );
+
+					sent += (maxChunkSize - 1);
+					remaining -= (maxChunkSize - 1);
+				}
+			} else {
+				// standard cs, just send it
+				SV_SendServerCommand( client, "cs %i \"%s\"\n", index, val );
+			}
+		}
+	}
+}
+
+
+
+/*
+===============
+SV_GetConfigstring
+
+===============
+*/
+void SV_GetConfigstring( int index, char *buffer, int bufferSize ) {
+	if ( bufferSize < 1 ) {
+		Com_Error( ERR_DROP, "SV_GetConfigstring: bufferSize == %i", bufferSize );
+	}
+	if ( index < 0 || index >= MAX_CONFIGSTRINGS ) {
+		Com_Error (ERR_DROP, "SV_GetConfigstring: bad index %i\n", index);
+	}
+	if ( !sv.configstrings[index] ) {
+		buffer[0] = 0;
+		return;
+	}
+
+	Q_strncpyz( buffer, sv.configstrings[index], bufferSize );
+}
+
+
+/*
+===============
+SV_SetUserinfo
+
+===============
+*/
+void SV_SetUserinfo( int index, const char *val ) {
+	if ( index < 0 || index >= sv_maxclients->integer ) {
+		Com_Error (ERR_DROP, "SV_SetUserinfo: bad index %i\n", index);
+	}
+
+	if ( !val ) {
+		val = "";
+	}
+
+	Q_strncpyz( svs.clients[index].userinfo, val, sizeof( svs.clients[ index ].userinfo ) );
+	Q_strncpyz( svs.clients[index].name, Info_ValueForKey( val, "name" ), sizeof(svs.clients[index].name) );
+}
+
+
+
+/*
+===============
+SV_GetUserinfo
+
+===============
+*/
+void SV_GetUserinfo( int index, char *buffer, int bufferSize ) {
+	if ( bufferSize < 1 ) {
+		Com_Error( ERR_DROP, "SV_GetUserinfo: bufferSize == %i", bufferSize );
+	}
+	if ( index < 0 || index >= sv_maxclients->integer ) {
+		Com_Error (ERR_DROP, "SV_GetUserinfo: bad index %i\n", index);
+	}
+	Q_strncpyz( buffer, svs.clients[ index ].userinfo, bufferSize );
+}
+
+
+/*
+================
+SV_CreateBaseline
+
+Entity baselines are used to compress non-delta messages
+to the clients -- only the fields that differ from the
+baseline will be transmitted
+================
+*/
+void SV_CreateBaseline( void ) {
+	sharedEntity_t *svent;
+	int				entnum;	
+
+	for ( entnum = 1; entnum < sv.num_entities ; entnum++ ) {
+		svent = SV_GentityNum(entnum);
+		if (!svent->r.linked) {
+			continue;
+		}
+		svent->s.number = entnum;
+
+		//
+		// take current state as baseline
+		//
+		sv.svEntities[entnum].baseline = svent->s;
+	}
+}
+
+
+/*
+===============
+SV_BoundMaxClients
+
+===============
+*/
+void SV_BoundMaxClients( int minimum ) {
+	// get the current maxclients value
+	Cvar_Get( "sv_maxclients", "8", 0 );
+
+	sv_maxclients->modified = qfalse;
+
+	if ( sv_maxclients->integer < minimum ) {
+		Cvar_Set( "sv_maxclients", va("%i", minimum) );
+	} else if ( sv_maxclients->integer > MAX_CLIENTS ) {
+		Cvar_Set( "sv_maxclients", va("%i", MAX_CLIENTS) );
+	}
+}
+
+
+/*
+===============
+SV_Startup
+
+Called when a host starts a map when it wasn't running
+one before.  Successive map or map_restart commands will
+NOT cause this to be called, unless the game is exited to
+the menu system first.
+===============
+*/
+void SV_Startup( void ) {
+	if ( svs.initialized ) {
+		Com_Error( ERR_FATAL, "SV_Startup: svs.initialized" );
+	}
+	SV_BoundMaxClients( 1 );
+
+	svs.clients = Z_Malloc (sizeof(client_t) * sv_maxclients->integer );
+	if ( com_dedicated->integer ) {
+		svs.numSnapshotEntities = sv_maxclients->integer * PACKET_BACKUP * 64;
+	} else {
+		// we don't need nearly as many when playing locally
+		svs.numSnapshotEntities = sv_maxclients->integer * 4 * 64;
+	}
+	svs.initialized = qtrue;
+
+	Cvar_Set( "sv_running", "1" );
+}
+
+
+/*
+==================
+SV_ChangeMaxClients
+==================
+*/
+void SV_ChangeMaxClients( void ) {
+	int		oldMaxClients;
+	int		i;
+	client_t	*oldClients;
+	int		count;
+
+	// get the highest client number in use
+	count = 0;
+	for ( i = 0 ; i < sv_maxclients->integer ; i++ ) {
+		if ( svs.clients[i].state >= CS_CONNECTED ) {
+			if (i > count)
+				count = i;
+		}
+	}
+	count++;
+
+	oldMaxClients = sv_maxclients->integer;
+	// never go below the highest client number in use
+	SV_BoundMaxClients( count );
+	// if still the same
+	if ( sv_maxclients->integer == oldMaxClients ) {
+		return;
+	}
+
+	oldClients = Hunk_AllocateTempMemory( count * sizeof(client_t) );
+	// copy the clients to hunk memory
+	for ( i = 0 ; i < count ; i++ ) {
+		if ( svs.clients[i].state >= CS_CONNECTED ) {
+			oldClients[i] = svs.clients[i];
+		}
+		else {
+			Com_Memset(&oldClients[i], 0, sizeof(client_t));
+		}
+	}
+
+	// free old clients arrays
+	Z_Free( svs.clients );
+
+	// allocate new clients
+	svs.clients = Z_Malloc ( sv_maxclients->integer * sizeof(client_t) );
+	Com_Memset( svs.clients, 0, sv_maxclients->integer * sizeof(client_t) );
+
+	// copy the clients over
+	for ( i = 0 ; i < count ; i++ ) {
+		if ( oldClients[i].state >= CS_CONNECTED ) {
+			svs.clients[i] = oldClients[i];
+		}
+	}
+
+	// free the old clients on the hunk
+	Hunk_FreeTempMemory( oldClients );
+	
+	// allocate new snapshot entities
+	if ( com_dedicated->integer ) {
+		svs.numSnapshotEntities = sv_maxclients->integer * PACKET_BACKUP * 64;
+	} else {
+		// we don't need nearly as many when playing locally
+		svs.numSnapshotEntities = sv_maxclients->integer * 4 * 64;
+	}
+}
+
+/*
+================
+SV_ClearServer
+================
+*/
+void SV_ClearServer(void) {
+	int i;
+
+	for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) {
+		if ( sv.configstrings[i] ) {
+			Z_Free( sv.configstrings[i] );
+		}
+	}
+	Com_Memset (&sv, 0, sizeof(sv));
+}
+
+/*
+================
+SV_TouchCGame
+
+  touch the cgame.vm so that a pure client can load it if it's in a seperate pk3
+================
+*/
+void SV_TouchCGame(void) {
+	fileHandle_t	f;
+	char filename[MAX_QPATH];
+
+	Com_sprintf( filename, sizeof(filename), "vm/%s.qvm", "cgame" );
+	FS_FOpenFileRead( filename, &f, qfalse );
+	if ( f ) {
+		FS_FCloseFile( f );
+	}
+}
+
+/*
+================
+SV_SpawnServer
+
+Change the server to a new map, taking all connected
+clients along with it.
+This is NOT called for map_restart
+================
+*/
+void SV_SpawnServer( char *server, qboolean killBots ) {
+	int			i;
+	int			checksum;
+	qboolean	isBot;
+	char		systemInfo[16384];
+	const char	*p;
+
+	// shut down the existing game if it is running
+	SV_ShutdownGameProgs();
+
+	Com_Printf ("------ Server Initialization ------\n");
+	Com_Printf ("Server: %s\n",server);
+
+	// if not running a dedicated server CL_MapLoading will connect the client to the server
+	// also print some status stuff
+	CL_MapLoading();
+
+	// make sure all the client stuff is unloaded
+	CL_ShutdownAll();
+
+	// clear the whole hunk because we're (re)loading the server
+	Hunk_Clear();
+
+	// clear collision map data
+	CM_ClearMap();
+
+	// init client structures and svs.numSnapshotEntities 
+	if ( !Cvar_VariableValue("sv_running") ) {
+		SV_Startup();
+	} else {
+		// check for maxclients change
+		if ( sv_maxclients->modified ) {
+			SV_ChangeMaxClients();
+		}
+	}
+
+	// clear pak references
+	FS_ClearPakReferences(0);
+
+	// allocate the snapshot entities on the hunk
+	svs.snapshotEntities = Hunk_Alloc( sizeof(entityState_t)*svs.numSnapshotEntities, h_high );
+	svs.nextSnapshotEntities = 0;
+
+	// toggle the server bit so clients can detect that a
+	// server has changed
+	svs.snapFlagServerBit ^= SNAPFLAG_SERVERCOUNT;
+
+	// set nextmap to the same map, but it may be overriden
+	// by the game startup or another console command
+	Cvar_Set( "nextmap", "map_restart 0");
+//	Cvar_Set( "nextmap", va("map %s", server) );
+
+	for (i=0 ; i<sv_maxclients->integer ; i++) {
+		// save when the server started for each client already connected
+		if (svs.clients[i].state >= CS_CONNECTED) {
+			svs.clients[i].oldServerTime = sv.time;
+		}
+	}
+
+	// wipe the entire per-level structure
+	SV_ClearServer();
+	for ( i = 0 ; i < MAX_CONFIGSTRINGS ; i++ ) {
+		sv.configstrings[i] = CopyString("");
+	}
+
+	// make sure we are not paused
+	Cvar_Set("cl_paused", "0");
+
+	// get a new checksum feed and restart the file system
+	srand(Com_Milliseconds());
+	sv.checksumFeed = ( ((int) rand() << 16) ^ rand() ) ^ Com_Milliseconds();
+	FS_Restart( sv.checksumFeed );
+
+	CM_LoadMap( va("maps/%s.bsp", server), qfalse, &checksum );
+
+	// set serverinfo visible name
+	Cvar_Set( "mapname", server );
+
+	Cvar_Set( "sv_mapChecksum", va("%i",checksum) );
+
+	// serverid should be different each time
+	sv.serverId = com_frameTime;
+	sv.restartedServerId = sv.serverId; // I suppose the init here is just to be safe
+	sv.checksumFeedServerId = sv.serverId;
+	Cvar_Set( "sv_serverid", va("%i", sv.serverId ) );
+
+	// clear physics interaction links
+	SV_ClearWorld ();
+	
+	// media configstring setting should be done during
+	// the loading stage, so connected clients don't have
+	// to load during actual gameplay
+	sv.state = SS_LOADING;
+
+	// load and spawn all other entities
+	SV_InitGameProgs();
+
+	// don't allow a map_restart if game is modified
+	sv_gametype->modified = qfalse;
+
+	// run a few frames to allow everything to settle
+	for (i = 0;i < 3; i++)
+	{
+		VM_Call (gvm, GAME_RUN_FRAME, sv.time);
+		SV_BotFrame (sv.time);
+		sv.time += 100;
+		svs.time += 100;
+	}
+
+	// create a baseline for more efficient communications
+	SV_CreateBaseline ();
+
+	for (i=0 ; i<sv_maxclients->integer ; i++) {
+		// send the new gamestate to all connected clients
+		if (svs.clients[i].state >= CS_CONNECTED) {
+			char	*denied;
+
+			if ( svs.clients[i].netchan.remoteAddress.type == NA_BOT ) {
+				if ( killBots ) {
+					SV_DropClient( &svs.clients[i], "" );
+					continue;
+				}
+				isBot = qtrue;
+			}
+			else {
+				isBot = qfalse;
+			}
+
+			// connect the client again
+			denied = VM_ExplicitArgPtr( gvm, VM_Call( gvm, GAME_CLIENT_CONNECT, i, qfalse, isBot ) );	// firstTime = qfalse
+			if ( denied ) {
+				// this generally shouldn't happen, because the client
+				// was connected before the level change
+				SV_DropClient( &svs.clients[i], denied );
+			} else {
+				if( !isBot ) {
+					// when we get the next packet from a connected client,
+					// the new gamestate will be sent
+					svs.clients[i].state = CS_CONNECTED;
+				}
+				else {
+					client_t		*client;
+					sharedEntity_t	*ent;
+
+					client = &svs.clients[i];
+					client->state = CS_ACTIVE;
+					ent = SV_GentityNum( i );
+					ent->s.number = i;
+					client->gentity = ent;
+
+					client->deltaMessage = -1;
+					client->nextSnapshotTime = svs.time;	// generate a snapshot immediately
+
+					VM_Call( gvm, GAME_CLIENT_BEGIN, i );
+				}
+			}
+		}
+	}	
+
+	// run another frame to allow things to look at all the players
+	VM_Call (gvm, GAME_RUN_FRAME, sv.time);
+	SV_BotFrame (sv.time);
+	sv.time += 100;
+	svs.time += 100;
+
+	if ( sv_pure->integer ) {
+		// the server sends these to the clients so they will only
+		// load pk3s also loaded at the server
+		p = FS_LoadedPakChecksums();
+		Cvar_Set( "sv_paks", p );
+		if (strlen(p) == 0) {
+			Com_Printf( "WARNING: sv_pure set but no PK3 files loaded\n" );
+		}
+		p = FS_LoadedPakNames();
+		Cvar_Set( "sv_pakNames", p );
+
+		// if a dedicated pure server we need to touch the cgame because it could be in a
+		// seperate pk3 file and the client will need to load the latest cgame.qvm
+		if ( com_dedicated->integer ) {
+			SV_TouchCGame();
+		}
+	}
+	else {
+		Cvar_Set( "sv_paks", "" );
+		Cvar_Set( "sv_pakNames", "" );
+	}
+	// the server sends these to the clients so they can figure
+	// out which pk3s should be auto-downloaded
+	p = FS_ReferencedPakChecksums();
+	Cvar_Set( "sv_referencedPaks", p );
+	p = FS_ReferencedPakNames();
+	Cvar_Set( "sv_referencedPakNames", p );
+
+	// save systeminfo and serverinfo strings
+	Q_strncpyz( systemInfo, Cvar_InfoString_Big( CVAR_SYSTEMINFO ), sizeof( systemInfo ) );
+	cvar_modifiedFlags &= ~CVAR_SYSTEMINFO;
+	SV_SetConfigstring( CS_SYSTEMINFO, systemInfo );
+
+	SV_SetConfigstring( CS_SERVERINFO, Cvar_InfoString( CVAR_SERVERINFO ) );
+	cvar_modifiedFlags &= ~CVAR_SERVERINFO;
+
+	// any media configstring setting now should issue a warning
+	// and any configstring changes should be reliably transmitted
+	// to all clients
+	sv.state = SS_GAME;
+
+	// send a heartbeat now so the master will get up to date info
+	SV_Heartbeat_f();
+
+	Hunk_SetMark();
+
+	Com_Printf ("-----------------------------------\n");
+}
+
+/*
+===============
+SV_Init
+
+Only called at main exe startup, not for each game
+===============
+*/
+void SV_BotInitBotLib(void);
+
+void SV_Init (void) {
+	SV_AddOperatorCommands ();
+
+	// serverinfo vars
+	Cvar_Get ("dmflags", "0", CVAR_SERVERINFO);
+	Cvar_Get ("fraglimit", "20", CVAR_SERVERINFO);
+	Cvar_Get ("timelimit", "0", CVAR_SERVERINFO);
+	sv_gametype = Cvar_Get ("g_gametype", "0", CVAR_SERVERINFO | CVAR_LATCH );
+	Cvar_Get ("sv_keywords", "", CVAR_SERVERINFO);
+	Cvar_Get ("protocol", va("%i", PROTOCOL_VERSION), CVAR_SERVERINFO | CVAR_ROM);
+	sv_mapname = Cvar_Get ("mapname", "nomap", CVAR_SERVERINFO | CVAR_ROM);
+	sv_privateClients = Cvar_Get ("sv_privateClients", "0", CVAR_SERVERINFO);
+	sv_hostname = Cvar_Get ("sv_hostname", "noname", CVAR_SERVERINFO | CVAR_ARCHIVE );
+	sv_maxclients = Cvar_Get ("sv_maxclients", "8", CVAR_SERVERINFO | CVAR_LATCH);
+
+	sv_maxRate = Cvar_Get ("sv_maxRate", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
+	sv_minPing = Cvar_Get ("sv_minPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
+	sv_maxPing = Cvar_Get ("sv_maxPing", "0", CVAR_ARCHIVE | CVAR_SERVERINFO );
+	sv_floodProtect = Cvar_Get ("sv_floodProtect", "1", CVAR_ARCHIVE | CVAR_SERVERINFO );
+
+	// systeminfo
+	Cvar_Get ("sv_cheats", "1", CVAR_SYSTEMINFO | CVAR_ROM );
+	sv_serverid = Cvar_Get ("sv_serverid", "0", CVAR_SYSTEMINFO | CVAR_ROM );
+	sv_pure = Cvar_Get ("sv_pure", "1", CVAR_SYSTEMINFO );
+	Cvar_Get ("sv_paks", "", CVAR_SYSTEMINFO | CVAR_ROM );
+	Cvar_Get ("sv_pakNames", "", CVAR_SYSTEMINFO | CVAR_ROM );
+	Cvar_Get ("sv_referencedPaks", "", CVAR_SYSTEMINFO | CVAR_ROM );
+	Cvar_Get ("sv_referencedPakNames", "", CVAR_SYSTEMINFO | CVAR_ROM );
+
+	// server vars
+	sv_rconPassword = Cvar_Get ("rconPassword", "", CVAR_TEMP );
+	sv_privatePassword = Cvar_Get ("sv_privatePassword", "", CVAR_TEMP );
+	sv_fps = Cvar_Get ("sv_fps", "20", CVAR_TEMP );
+	sv_timeout = Cvar_Get ("sv_timeout", "200", CVAR_TEMP );
+	sv_zombietime = Cvar_Get ("sv_zombietime", "2", CVAR_TEMP );
+	Cvar_Get ("nextmap", "", CVAR_TEMP );
+
+	sv_allowDownload = Cvar_Get ("sv_allowDownload", "0", CVAR_SERVERINFO);
+	sv_master[0] = Cvar_Get ("sv_master1", MASTER_SERVER_NAME, 0 );
+	sv_master[1] = Cvar_Get ("sv_master2", "", CVAR_ARCHIVE );
+	sv_master[2] = Cvar_Get ("sv_master3", "", CVAR_ARCHIVE );
+	sv_master[3] = Cvar_Get ("sv_master4", "", CVAR_ARCHIVE );
+	sv_master[4] = Cvar_Get ("sv_master5", "", CVAR_ARCHIVE );
+	sv_reconnectlimit = Cvar_Get ("sv_reconnectlimit", "3", 0);
+	sv_showloss = Cvar_Get ("sv_showloss", "0", 0);
+	sv_padPackets = Cvar_Get ("sv_padPackets", "0", 0);
+	sv_killserver = Cvar_Get ("sv_killserver", "0", 0);
+	sv_mapChecksum = Cvar_Get ("sv_mapChecksum", "", CVAR_ROM);
+	sv_lanForceRate = Cvar_Get ("sv_lanForceRate", "1", CVAR_ARCHIVE );
+	sv_strictAuth = Cvar_Get ("sv_strictAuth", "1", CVAR_ARCHIVE );
+
+	// initialize bot cvars so they are listed and can be set before loading the botlib
+	SV_BotInitCvars();
+
+	// init the botlib here because we need the pre-compiler in the UI
+	SV_BotInitBotLib();
+}
+
+
+/*
+==================
+SV_FinalMessage
+
+Used by SV_Shutdown to send a final message to all
+connected clients before the server goes down.  The messages are sent immediately,
+not just stuck on the outgoing message list, because the server is going
+to totally exit after returning from this function.
+==================
+*/
+void SV_FinalMessage( char *message ) {
+	int			i, j;
+	client_t	*cl;
+	
+	// send it twice, ignoring rate
+	for ( j = 0 ; j < 2 ; j++ ) {
+		for (i=0, cl = svs.clients ; i < sv_maxclients->integer ; i++, cl++) {
+			if (cl->state >= CS_CONNECTED) {
+				// don't send a disconnect to a local client
+				if ( cl->netchan.remoteAddress.type != NA_LOOPBACK ) {
+					SV_SendServerCommand( cl, "print \"%s\"", message );
+					SV_SendServerCommand( cl, "disconnect" );
+				}
+				// force a snapshot to be sent
+				cl->nextSnapshotTime = -1;
+				SV_SendClientSnapshot( cl );
+			}
+		}
+	}
+}
+
+
+/*
+================
+SV_Shutdown
+
+Called when each game quits,
+before Sys_Quit or Sys_Error
+================
+*/
+void SV_Shutdown( char *finalmsg ) {
+	if ( !com_sv_running || !com_sv_running->integer ) {
+		return;
+	}
+
+	Com_Printf( "----- Server Shutdown -----\n" );
+
+	if ( svs.clients && !com_errorEntered ) {
+		SV_FinalMessage( finalmsg );
+	}
+
+	SV_RemoveOperatorCommands();
+	SV_MasterShutdown();
+	SV_ShutdownGameProgs();
+
+	// free current level
+	SV_ClearServer();
+
+	// free server static data
+	if ( svs.clients ) {
+		Z_Free( svs.clients );
+	}
+	Com_Memset( &svs, 0, sizeof( svs ) );
+
+	Cvar_Set( "sv_running", "0" );
+	Cvar_Set("ui_singlePlayerActive", "0");
+
+	Com_Printf( "---------------------------\n" );
+
+	// disconnect any local clients
+	CL_Disconnect( qfalse );
+}
+
diff --git a/code/tools/lcc/lburg/gram.c b/code/tools/lcc/lburg/gram.c
new file mode 100644
index 0000000..a1cc890
--- /dev/null
+++ b/code/tools/lcc/lburg/gram.c
@@ -0,0 +1,682 @@
+#if defined(__STDC__) || defined(__cplusplus)
+#define YYCONST const
+#define YYPARAMS(x) x
+#define YYDEFUN(name, arglist, args) name(args)
+#define YYAND ,
+#define YYPTR void *
+#else
+#define YYCONST
+#define YYPARAMS(x) ()
+#define YYDEFUN(name, arglist, args) name arglist args;
+#define YYAND ;
+#define YYPTR char *
+#endif
+#ifndef lint
+YYCONST static char yysccsid[] = "@(#)yaccpar	1.8 (Berkeley +Cygnus.28) 01/20/91";
+#endif
+#define YYBYACC 1
+#ifndef YYDONT_INCLUDE_STDIO
+#include <stdio.h>
+#endif
+//#ifdef __cplusplus TA <tim at ngus.net> stdlib.h applies to C too
+#include <stdlib.h> /* for malloc/realloc/free */
+//#endif
+#line 2 "lburg/gram.y"
+#include <stdio.h>
+#include "lburg.h"
+/*lint -e616 -e527 -e652 -esym(552,yynerrs) -esym(563,yynewstate,yyerrlab) */
+static int yylineno = 0;
+#line 8 "lburg/gram.y"
+typedef union {
+	int n;
+	char *string;
+	Tree tree;
+} YYSTYPE;
+#line 37 "y.tab.c"
+#define TERMINAL 257
+#define START 258
+#define PPERCENT 259
+#define ID 260
+#define TEMPLATE 261
+#define CODE 262
+#define INT 263
+#define YYERRCODE 256
+static YYCONST short yylhs[] = {                                        -1,
+    0,    0,    4,    4,    6,    6,    6,    6,    7,    7,
+    5,    5,    5,    5,    1,    3,    3,    3,    2,
+};
+static YYCONST short yylen[] = {                                         2,
+    3,    1,    0,    2,    3,    3,    1,    2,    0,    4,
+    0,    7,    2,    3,    1,    1,    4,    6,    1,
+};
+static YYCONST short yydefred[] = {                                      3,
+    0,    0,    0,    9,    0,   11,    7,    4,    8,    0,
+   15,    0,    0,    0,    5,    6,    0,   13,    0,    0,
+   14,    0,   10,    0,    0,    0,    0,    0,   19,    0,
+   17,    0,   12,    0,   18,
+};
+static YYCONST short yydgoto[] = {                                       1,
+   12,   30,   25,    2,   13,    8,   10,
+};
+static YYCONST short yysindex[] = {                                      0,
+    0,   -4,   -2,    0, -250,    0,    0,    0,    0,   -9,
+    0,    1,  -10,  -49,    0,    0,    3,    0,  -44, -248,
+    0, -244,    0,  -22, -242, -244, -245,  -37,    0,   10,
+    0, -244,    0,  -20,    0,
+};
+static YYCONST short yyrindex[] = {                                      0,
+    0,   22,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,   23,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,  -39,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,
+};
+static YYCONST short yygindex[] = {                                      0,
+   11,    0,  -23,    0,    0,    0,    0,
+};
+#define YYTABLESIZE 255
+static YYCONST short yytable[] = {                                      18,
+   15,   16,   28,   31,   16,    7,   32,    9,   34,   11,
+   16,   20,   21,   22,   23,   24,   29,   26,   27,   33,
+   35,    2,    1,   19,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,   16,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
+    0,    0,    0,    0,    0,   17,    0,    0,    0,   11,
+   14,    3,    4,    5,    6,
+};
+static YYCONST short yycheck[] = {                                      10,
+   10,   41,   26,   41,   44,   10,   44,   10,   32,  260,
+   10,   61,   10,   58,  263,  260,  262,   40,  261,   10,
+   41,    0,    0,   13,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,  261,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
+   -1,   -1,   -1,   -1,   -1,  256,   -1,   -1,   -1,  260,
+  260,  256,  257,  258,  259,
+};
+#define YYFINAL 1
+#ifndef YYDEBUG
+#define YYDEBUG 0
+#endif
+#define YYMAXTOKEN 263
+#if YYDEBUG
+static YYCONST char *YYCONST yyname[] = {
+"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,"'('","')'",0,0,"','",0,0,0,0,0,0,0,0,0,0,0,0,0,"':'",0,0,
+"'='",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
+"TERMINAL","START","PPERCENT","ID","TEMPLATE","CODE","INT",
+};
+static YYCONST char *YYCONST yyrule[] = {
+"$accept : spec",
+"spec : decls PPERCENT rules",
+"spec : decls",
+"decls :",
+"decls : decls decl",
+"decl : TERMINAL blist '\\n'",
+"decl : START nonterm '\\n'",
+"decl : '\\n'",
+"decl : error '\\n'",
+"blist :",
+"blist : blist ID '=' INT",
+"rules :",
+"rules : rules nonterm ':' tree TEMPLATE cost '\\n'",
+"rules : rules '\\n'",
+"rules : rules error '\\n'",
+"nonterm : ID",
+"tree : ID",
+"tree : ID '(' tree ')'",
+"tree : ID '(' tree ',' tree ')'",
+"cost : CODE",
+};
+#endif
+#define YYLEX yylex()
+#define YYEMPTY -1
+#define yyclearin (yychar=(YYEMPTY))
+#define yyerrok (yyerrflag=0)
+#ifndef YYINITDEPTH
+#define YYINITDEPTH 200
+#endif
+#ifdef YYSTACKSIZE
+#ifndef YYMAXDEPTH
+#define YYMAXDEPTH YYSTACKSIZE
+#endif
+#else
+#ifdef YYMAXDEPTH
+#define YYSTACKSIZE YYMAXDEPTH
+#else
+#define YYSTACKSIZE 500
+#define YYMAXDEPTH 500
+#endif
+#endif
+#ifndef YYMAXSTACKSIZE
+#define YYMAXSTACKSIZE 10000
+#endif
+int yydebug;
+int yynerrs;
+int yyerrflag;
+int yychar;
+YYSTYPE yyval;
+YYSTYPE yylval;
+static short *yyss;
+static YYSTYPE *yyvs;
+static int yystacksize;
+#define yyfree(x) free(x)
+extern int yylex();
+
+static YYPTR
+YYDEFUN (yymalloc, (bytes), unsigned bytes)
+{
+    YYPTR ptr = (YYPTR) malloc (bytes);
+    if (ptr != 0) return (ptr);
+    yyerror ("yyparse: memory exhausted");
+    return (0);
+}
+
+static YYPTR
+YYDEFUN (yyrealloc, (old, bytes), YYPTR old YYAND unsigned bytes)
+{
+    YYPTR ptr = (YYPTR) realloc (old, bytes);
+    if (ptr != 0) return (ptr);
+    yyerror ("yyparse: memory exhausted");
+    return (0);
+}
+
+static int
+#ifdef __GNUC__
+inline
+#endif
+yygrow ()
+{
+#if YYDEBUG
+    int old_stacksize = yystacksize;
+#endif
+    short *new_yyss;
+    YYSTYPE *new_yyvs;
+
+    if (yystacksize == YYMAXSTACKSIZE)
+        return (1);
+    yystacksize += (yystacksize + 1 ) / 2;
+    if (yystacksize > YYMAXSTACKSIZE)
+        yystacksize = YYMAXSTACKSIZE;
+#if YYDEBUG
+    if (yydebug)
+        printf("yydebug: growing stack size from %d to %d\n",
+               old_stacksize, yystacksize);
+#endif
+    new_yyss = (short *) yyrealloc ((char *)yyss, yystacksize * sizeof (short));
+    if (new_yyss == 0)
+        return (1);
+    new_yyvs = (YYSTYPE *) yyrealloc ((char *)yyvs, yystacksize * sizeof (YYSTYPE));
+    if (new_yyvs == 0)
+    {
+        yyfree (new_yyss);
+        return (1);
+    }
+    yyss = new_yyss;
+    yyvs = new_yyvs;
+    return (0);
+}
+#line 60 "lburg/gram.y"
+#include <assert.h>
+#include <stdarg.h>
+#include <ctype.h>
+#include <string.h>
+#include <limits.h>
+
+int errcnt = 0;
+FILE *infp = NULL;
+FILE *outfp = NULL;
+static char buf[BUFSIZ], *bp = buf;
+static int ppercent = 0;
+static int code = 0;
+
+static int get(void) {
+	if (*bp == 0) {
+		bp = buf;
+		*bp = 0;
+		if (fgets(buf, sizeof buf, infp) == NULL)
+			return EOF;
+		yylineno++;
+		while (buf[0] == '%' && buf[1] == '{' && buf[2] == '\n') {
+			for (;;) {
+				if (fgets(buf, sizeof buf, infp) == NULL) {
+					yywarn("unterminated %{...%}\n");
+					return EOF;
+				}
+				yylineno++;
+				if (strcmp(buf, "%}\n") == 0)
+					break;
+				fputs(buf, outfp);
+			}
+			if (fgets(buf, sizeof buf, infp) == NULL)
+				return EOF;
+			yylineno++;
+		}
+	}
+	return *bp++;
+}
+
+void yyerror(char *fmt, ...) {
+	va_list ap;
+
+	va_start(ap, fmt);
+	if (yylineno > 0)
+		fprintf(stderr, "line %d: ", yylineno);
+	vfprintf(stderr, fmt, ap);
+	if (fmt[strlen(fmt)-1] != '\n')
+		 fprintf(stderr, "\n");
+	errcnt++;
+	va_end(ap);
+}
+
+int yylex(void) {
+	int c;
+
+	if (code) {
+		char *p;
+		bp += strspn(bp, " \t\f");
+		p = strchr(bp, '\n');
+		if (p == NULL)
+			p = strchr(bp, '\n');
+		while (p > bp && isspace(p[-1]))
+			p--;
+		yylval.string = alloc(p - bp + 1);
+		strncpy(yylval.string, bp, p - bp);
+		yylval.string[p - bp] = 0;
+		bp = p;
+		code--;
+		return CODE;
+	}
+	while ((c = get()) != EOF) {
+		switch (c) {
+		case ' ': case '\f': case '\t':
+			continue;
+		case '\n':
+		case '(': case ')': case ',':
+		case ':': case '=':
+			return c;
+		}
+		if (c == '%' && *bp == '%') {
+			bp++;
+			return ppercent++ ? 0 : PPERCENT;
+		} else if (c == '%' && strncmp(bp, "term", 4) == 0
+		&& isspace(bp[4])) {
+			bp += 4;
+			return TERMINAL;
+		} else if (c == '%' && strncmp(bp, "start", 5) == 0
+		&& isspace(bp[5])) {
+			bp += 5;
+			return START;
+		} else if (c == '"') {
+			char *p = strchr(bp, '"');
+			if (p == NULL) {
+				yyerror("missing \" in assembler template\n");
+				p = strchr(bp, '\n');
+				if (p == NULL)
+					p = strchr(bp, '\0');
+			}
+			assert(p);
+			yylval.string = alloc(p - bp + 1);
+			strncpy(yylval.string, bp, p - bp);
+			yylval.string[p - bp] = 0;
+			bp = *p == '"' ? p + 1 : p;
+			code++;
+			return TEMPLATE;
+		} else if (isdigit(c)) {
+			int n = 0;
+			do {
+				int d = c - '0';
+				if (n > (INT_MAX - d)/10)
+					yyerror("integer greater than %d\n", INT_MAX);
+				else
+					n = 10*n + d;
+				c = get();
+			} while (c != EOF && isdigit(c));
+			bp--;
+			yylval.n = n;
+			return INT;
+		} else if (isalpha(c)) {
+			char *p = bp - 1;
+			while (isalpha(*bp) || isdigit(*bp) || *bp == '_')
+				bp++;
+			yylval.string = alloc(bp - p + 1);
+			strncpy(yylval.string, p, bp - p);
+			yylval.string[bp - p] = 0;
+			return ID;
+		} else if (isprint(c))
+			yyerror("invalid character `%c'\n", c);
+		else
+			yyerror("invalid character `\\%03o'\n", (unsigned char)c);
+	}
+	return 0;
+}
+
+void yywarn(char *fmt, ...) {
+	va_list ap;
+
+	va_start(ap, fmt);
+	if (yylineno > 0)
+		fprintf(stderr, "line %d: ", yylineno);
+	fprintf(stderr, "warning: ");
+	vfprintf(stderr, fmt, ap);
+}
+#line 403 "y.tab.c"
+#define YYABORT goto yyabort
+#define YYACCEPT goto yyaccept
+#define YYERROR goto yyerrlab
+
+#if YYDEBUG
+#ifdef __cplusplus
+extern "C" char *getenv();
+#else
+extern char *getenv();
+#endif
+#endif
+
+int
+yyparse()
+{
+    register int yym, yyn, yystate;
+    register YYSTYPE *yyvsp;
+    register short *yyssp;
+    short *yysse;
+#if YYDEBUG
+    register YYCONST char *yys;
+
+    if (yys = getenv("YYDEBUG"))
+    {
+        yyn = *yys;
+        if (yyn >= '0' && yyn <= '9')
+            yydebug = yyn - '0';
+    }
+#endif
+
+    yynerrs = 0;
+    yyerrflag = 0;
+    yychar = (-1);
+
+    if (yyss == 0)
+    {
+        yyss = (short *) yymalloc (YYSTACKSIZE * sizeof (short));
+        if (yyss == 0)
+          goto yyabort;
+        yyvs = (YYSTYPE *) yymalloc (YYSTACKSIZE * sizeof (YYSTYPE));
+        if (yyvs == 0)
+        {
+            yyfree (yyss);
+            goto yyabort;
+        }
+        yystacksize = YYSTACKSIZE;
+    }
+    yysse = yyss + yystacksize - 1;
+    yyssp = yyss;
+    yyvsp = yyvs;
+    *yyssp = yystate = 0;
+    goto yyloop;
+
+yypush_lex:
+    yyval = yylval;
+    yystate = yytable[yyn];
+yypush:
+    if (yyssp >= yysse)
+    {
+        int depth = yyssp - yyss;
+        if (yygrow() != 0)
+             goto yyoverflow;
+        yysse = yyss + yystacksize -1;
+        yyssp = depth + yyss;
+        yyvsp = depth + yyvs;
+    }
+    *++yyssp = yystate;
+    *++yyvsp = yyval;
+
+yyloop:
+    if ((yyn = yydefred[yystate])) goto yyreduce;
+    yyn = yysindex[yystate];
+    if (yychar < 0)
+    {
+        if ((yychar = yylex()) < 0) yychar = 0;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("yydebug: state %d, reading %d (%s)\n", yystate,
+                    yychar, yys);
+        }
+#endif
+    }
+    if (yyn != 0
+        && ((yyn += yychar), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
+        && yycheck[yyn] == yychar)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("yydebug: state %d, shifting to state %d\n",
+                    yystate, yytable[yyn]);
+#endif
+        if (yyerrflag > 0)  --yyerrflag;
+        yychar = (-1);
+        goto yypush_lex;
+    }
+    yyn = yyrindex[yystate];
+    if (yyn != 0
+        && ((yyn += yychar), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
+        && yycheck[yyn] == yychar)
+    {
+        yyn = yytable[yyn];
+        goto yyreduce;
+    }
+    if (yyerrflag) goto yyinrecovery;
+#ifdef lint
+    goto yynewerror;
+yynewerror:
+#endif
+    yyerror("syntax error");
+#ifdef lint
+    goto yyerrlab;
+yyerrlab:
+#endif
+    ++yynerrs;
+yyinrecovery:
+    if (yyerrflag < 3)
+    {
+        yyerrflag = 3;
+        for (;;)
+        {
+            yyn = yysindex[*yyssp];
+            if (yyn != 0
+                && ((yyn += YYERRCODE), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
+                && yycheck[yyn] == YYERRCODE)
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("yydebug: state %d, error recovery shifting\
+ to state %d\n", *yyssp, yytable[yyn]);
+#endif
+                goto yypush_lex;
+            }
+            else
+            {
+#if YYDEBUG
+                if (yydebug)
+                    printf("yydebug: error recovery discarding state %d\n",
+                            *yyssp);
+#endif
+                if (yyssp <= yyss) goto yyabort;
+                --yyssp;
+                --yyvsp;
+            }
+        }
+    }
+    else
+    {
+        if (yychar == 0) goto yyabort;
+#if YYDEBUG
+        if (yydebug)
+        {
+            yys = 0;
+            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+            if (!yys) yys = "illegal-symbol";
+            printf("yydebug: state %d, error recovery discards token %d (%s)\n",
+                    yystate, yychar, yys);
+        }
+#endif
+        yychar = (-1);
+        goto yyloop;
+    }
+yyreduce:
+#if YYDEBUG
+    if (yydebug)
+        printf("yydebug: state %d, reducing by rule %d (%s)\n",
+                yystate, yyn, yyrule[yyn]);
+#endif
+    yym = yylen[yyn];
+    yyval = yyvsp[1-yym];
+    switch (yyn)
+    {
+case 1:
+#line 22 "lburg/gram.y"
+{ yylineno = 0; }
+break;
+case 2:
+#line 23 "lburg/gram.y"
+{ yylineno = 0; }
+break;
+case 6:
+#line 31 "lburg/gram.y"
+{
+		if (nonterm(yyvsp[-1].string)->number != 1)
+			yyerror("redeclaration of the start symbol\n");
+		}
+break;
+case 8:
+#line 36 "lburg/gram.y"
+{ yyerrok; }
+break;
+case 10:
+#line 40 "lburg/gram.y"
+{ term(yyvsp[-2].string, yyvsp[0].n); }
+break;
+case 12:
+#line 44 "lburg/gram.y"
+{ rule(yyvsp[-5].string, yyvsp[-3].tree, yyvsp[-2].string, yyvsp[-1].string); }
+break;
+case 14:
+#line 46 "lburg/gram.y"
+{ yyerrok; }
+break;
+case 15:
+#line 49 "lburg/gram.y"
+{ nonterm(yyval.string = yyvsp[0].string); }
+break;
+case 16:
+#line 52 "lburg/gram.y"
+{ yyval.tree = tree(yyvsp[0].string,  0,  0); }
+break;
+case 17:
+#line 53 "lburg/gram.y"
+{ yyval.tree = tree(yyvsp[-3].string, yyvsp[-1].tree,  0); }
+break;
+case 18:
+#line 54 "lburg/gram.y"
+{ yyval.tree = tree(yyvsp[-5].string, yyvsp[-3].tree, yyvsp[-1].tree); }
+break;
+case 19:
+#line 57 "lburg/gram.y"
+{ if (*yyvsp[0].string == 0) yyval.string = "0"; }
+break;
+#line 630 "y.tab.c"
+    }
+    yyssp -= yym;
+    yyvsp -= yym;
+    yym = yylhs[yyn];
+    yystate = *yyssp;
+    if (yystate == 0 && yym == 0)
+    {
+#if YYDEBUG
+        if (yydebug)
+            printf("yydebug: after reduction, shifting from state 0 to\
+ state %d\n", YYFINAL);
+#endif
+        yystate = YYFINAL;
+        *++yyssp = YYFINAL;
+        *++yyvsp = yyval;
+        if (yychar < 0)
+        {
+            if ((yychar = yylex()) < 0) yychar = 0;
+#if YYDEBUG
+            if (yydebug)
+            {
+                yys = 0;
+                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
+                if (!yys) yys = "illegal-symbol";
+                printf("yydebug: state %d, reading %d (%s)\n",
+                        YYFINAL, yychar, yys);
+            }
+#endif
+        }
+        if (yychar == 0) goto yyaccept;
+        goto yyloop;
+    }
+    yyn = yygindex[yym];
+	 if (yyn != 0
+        && ((yyn += yystate), ((unsigned)yyn <= (unsigned)YYTABLESIZE))
+        && yycheck[yyn] == yystate)
+        yystate = yytable[yyn];
+    else
+        yystate = yydgoto[yym];
+#if YYDEBUG
+    if (yydebug)
+        printf("yydebug: after reduction, shifting from state %d \
+to state %d\n", *yyssp, yystate);
+#endif
+    goto yypush;
+yyoverflow:
+    yyerror("yacc stack overflow");
+yyabort:
+    return (1);
+yyaccept:
+    return (0);
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/game-data-packager.git



More information about the Pkg-games-commits mailing list