/*
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *	File:		V library master header
 *
 *	<please, set tab to 4 spaces and read more :)>
 *
 *	Purpose:	Another one framework library that - or only should be ! -
 *				platform-independent. Currently it can be compiled both
 *				under NT (and under MustDie - if you prefer it) and Linux.
 *
 *				Linux seems to be VERY good OS; but NT (I'm talking about
 *				'Cairo' - NT 4.0) is the best. It FASTER than Linux (yes,
 *				I mean it), much SMALLER than Linux, and as stable as Linux
 *				(at least on my ancient P-II (Klamath-233) with AL440LX on
 *				Intel motherboard, SBAWE32 and TNT2M64).
 *
 *	Version:	5.1 - working alpha. Note: version numbers are subject to
 *				change; I'm planning to re-design all source tree soon.
 *
 *	Language:	ANSI C. We can write object-oriented code in C, arn't we ?
 *
 *	Author:		Vladimir A. Smirnov (vladsmirnov@yandex.ru)
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *	Classes of routines:
 *
 *		0. Internal: NT-like object management (although I'm not using
 *	handle tables; handles are pointers) with some king of RTTI (needs
 *	both CHECKED_BUILD and MALLOC_DEBUG to be defined at compile time).
 *	See source/TAL/objbase.h for details.
 *	TODO: UNICODE !
 *
 *		1. Support for abstract data types: list (code borrowed from Linux
 *	kernel), stack (realloc()-able array), fifo, binary and N-way trees.
 *
 *		2. Wrappers for kernel primitives: thread, mutex and event (later
 *	called 'conditional variable'). LibV itself internally maintains
 *	thread-safe global storage (see code of sched.c:libvLockGlobal()) and
 *	per-thread local storage.
 *	TODO: local IPC (named mutex, named event)
 *
 *		3. Support for I/O in UNIX style: both file and device I/O can be
 *	performed via fileXXXX() calls, common for both platforms.
 *	TODO: UDP and TCP I/O
 *
 *		4. Some kind of extendable VFS (read-only). Currently there are
 *	'drivers' for Id's PAK files (Quake / QII) and for resources in NT PE.
 *	TODO: zip / pk3 fs, tar fs. Is these enought ? :)
 *
 *		5. Much, much more (vectors and matrices, geometry, multimedia
 *	file formats, decompression, GLUT-unlike OpenGL utility toolkit ...).
 *
 *	Project started:	Autumn, 1998.
 *	Last update: 		05.03.2002
 *
 *	Copyright:			Copyrighted under GNU GPL.
 *
 *	Bugs:				The project is still in alpha state. And:
 *
 *	UNDER WIN32, SOME C COMPILERS ARE BROKEN. Use MS Visual C 6.0.
 *
 *	UNDER SOME LINUX'ES, HEADER TREES ARE BROKEN (for example, LibV CAN
 *	NOT be compiled - at least, without tricks - on RH 7 and Mandrake 8.0).
 *
 *	And I still havn't tested code on many different UNIXes :(
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

#ifndef V_LIB_H
#define V_LIB_H

/*
 * Configuration information
 */
#include "v_config.h"

/*
 * Main set of system headers: common for both platforms.
 */

/*
 * Some linux distributions come with broken (?) libc headers:
 * for example, both stdio.h and unistd.h can be #include-d only
 * AFTER pthread.h if #defined __USE_UNIX98.
 *
 * FIXME: what's wrong ?
 */
#if	defined(__LIBV__) && defined(__linux)

#include <pthread.h>

#endif /* __LIBV__ && __linux */

#include <string.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>

/*
 * Include system GL header under UN*X, SGI header otherwise.
 */
#ifndef	__UNIX__
#include	"sgi/gl.h"
#else	/* __UNIX__ */
#include	"GL/gl.h"
#endif	/* __UNIX__ */

/*
 * According to Gilles Vollant:
 * There was old Unices (SunOS 4.1.3_U1) without all SEEK_* defined
 */
#ifndef SEEK_CUR
#define SEEK_CUR    1
#endif	/* !SEEK_CUR */

#ifndef SEEK_END
#define SEEK_END    2
#endif	/* !SEEK_END */

#ifndef SEEK_SET
#define SEEK_SET    0
#endif	/* !SEEK_SET */

/*
 * 'math.h' from VisialC 5.0 is ANSI- and C++ - incompliant
 */
#ifdef		_MSC_VER
#pragma 	warning(disable:4001)	/* C++ - style comment */
#pragma 	warning(disable:4146)	/* unary minus applied to unsigned */
#pragma 	warning(disable:4514)	/* unreferenced inline func removed */
#endif		/* _MSC_VER */

#include	<math.h>

#ifdef		_MSC_VER
#pragma 	warning(default:4001)
#endif		/* _MSC_VER */

#ifndef		_MAX_PATH
#ifndef		MAX_PATH
#define		_MAX_PATH		256
#else		/* MAX_PATH */
#define		_MAX_PATH		MAX_PATH
#endif		/* MAX_PATH */
#endif		/* _MAX_PATH */

#ifndef		_MAX_DIR
#ifndef		MAX_DIR
#define		_MAX_DIR		256
#else		/* MAX_DIR */
#define		_MAX_DIR		MAX_DIR
#endif		/* MAX_DIR */
#endif		/* _MAX_DIR */

#ifndef		_MAX_FNAME
#ifndef		MAX_FNAME
#define		_MAX_FNAME		256
#else		/* MAX_FNAME */
#define		_MAX_FNAME		MAX_FNAME
#endif		/* MAX_FNAME */
#endif		/* _MAX_FNAME */

#ifndef		_MAX_EXT
#ifndef		MAX_EXT
#define		_MAX_EXT		256
#else		/* MAX_EXT */
#define		_MAX_EXT		MAX_EXT
#endif		/* MAX_EXT */
#endif		/* _MAX_EXT */

#ifndef		RIGHT_SLASHED
#ifndef		_MAX_DRIVE
#ifndef		MAX_DRIVE
#define		_MAX_DRIVE		4
#else		/* MAX_DRIVE */
#define		_MAX_DRIVE		MAX_DRIVE
#endif		/* MAX_DRIVE */
#endif		/* _MAX_DRIVE */
#endif		/* RIGHT_SLASHED */

#ifdef		CHECKED_BUILD
#include	<assert.h>
#define		V_ASSERT(exp)		assert(exp)
#else		/* CHECKED_BUILD */
#define		V_ASSERT(exp)
#endif		/* CHECKED_BUILD */

/*
 * Base LibV types
 */
#include	"v_types.h"

#ifdef	__cplusplus
extern "C" {
#endif	/* __cplusplus */
	/*
	 *	Memory management functions used in all LibV routines.
     *	Some routines return memAlloc()'ed buffers which than must be
     *	released by memFree() call.
	 *	Implemented in TAL/objbase.c.
	 */
	void_p	V_GLOBAL	memAlloc(size_t size);
	void_p	V_GLOBAL	memRealloc(void *ptr,size_t newsize);
	void	V_GLOBAL	memFree(void *ptr);
	/*
	 *	Extra debugging stuff.
	 *
	 *	Returns memory information. Parameters:
	 *		- bytes_ret - pointer to store amount of allocated memory;
	 *		- blocks_ret - pointer to store number of allocated blocks;
	 *		- handles_ret - pointer to store number of created objects.
	 *	Note: bytes_ret is always 0 if compiled without MALLOC_DEBUG
	 */
	void		V_GLOBAL	memStats(u32_t *bytes_ret,u32_t *blocks_ret,
		u32_t *handles_ret);
    /* Prints memory info (using LibV console output) */
	void		V_GLOBAL	memPrintStats(void);
#ifdef	MALLOC_DEBUG
	/*
	 *	Sets new value for thread-specifig memory tag. Very useful
	 *	for hunting memory leaks.
	 */
	void	V_GLOBAL	memSetOpaque(unsigned opaque);
    /*
     *	Retuns 'true' if 'ptr' refers to memory blocks allocated
     *	by memAlloc().
     */
	vboolean	V_GLOBAL	memIsPointer(void *ptr);
    /* For each allocated object, prints detailed info */
	void		V_GLOBAL	memPrintObjStats(void);
    /* Prints detailed list about all allocated blocks */
	void		V_GLOBAL	memPrintMemStats(void);
#endif	/* MALLOC_DEBUG */
#ifdef	__cplusplus
}
#endif	/* __cplusplus */

/*
 *	Other LibV headers.
 *	TODO: rename them.
 */
#include	"v_x86.h"
#include	"v_stack.h"
#include	"v_list.h"
#include	"v_tree.h"
#include	"v_fifo.h"

#include	"v_log.h"
#include	"v_math.h"
#include	"v_vector.h"
#include	"v_matrix.h"
#include	"v_gpsp.h"
#include	"v_plane.h"
#include	"v_space.h"
#include	"v_parse.h"
#include	"v_pgrid.h"
#include	"v_pprof.h"
#include	"v_fs.h"
#include	"v_image.h"
#include	"v_str.h"
#include	"v_wavlib.h"
#include	"v_reg.h"

#include	"v_sched.h"
#include	"v_time.h"
#include	"v_comm.h"
#include	"v_input.h"
#include	"v_wavin.h"
#include	"v_wavout.h"

#include	"v_objlib.h"
#include	"v_camctl.h"
#include	"v_gl.h"
#include	"v_wmf.h"
#include	"v_tlist.h"
#include	"v_fbdraw.h"

#endif		/* V_LIB_H */
