/*
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  File:       V library master header
 *
 *  <please, set tab to 4 spaces and read more :)>
 *
 *  Purpose:    Another one framework library that - or at least should be
 *              - platform-independent. Currently it can be compiled both
 *              under NT (and under MustDie - if you prefer it) and Linux.
 *
 *  Version:    5.2 - 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
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *  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.
 *
 *      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 UN*X 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 a several concatenated file systems (Id's Quake *.pak,
 *  DF and DF_II *.gob, DOOM *.wad), for resources in NT PE executable,
 *  and ZIP archives (*.zip / *.pk3).
 *
 *      5. Much, much more (vectors and matrices, geometry, multimedia
 *  file formats, decompression, GLUT-unlike OpenGL utility toolkit ...).
 *
 *  Project started:    Autumn, 1998
 *  Last update:        Summer, 2004
 *
 *  Copyright:          Copyrighted under GNU GPL.
 *
 *  Bugs:               The project is still in alpha state. And:
 *
 *  Under Win32, some C compilers _are_ broken; use MSVC 6.0 (_no_ SP's)
 *
 *  And I still havn't port code to many different UN*Ces
 *
 *  And I still havn't port code to M$-DOS (yes, I can't forget it :)
 *
 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 */

#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 strange 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, ours header otherwise.
 */
#if         defined(__UNIX__) && !defined(PRIVATE_GL_HEADERS)
#include    <GL/gl.h>
#else       /* !__UNIX__ */
#include    "GL/gl.h"
#endif      /* !__UNIX__ */

/*
 * '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 which are used in LibV routines.
	 *  Some routines return memAlloc()'ed buffers which have to be
	 *  released by memFree() call.
	 *  Implemented in TAL/objbase.c.
	 */
	void_p  V_GLOBAL    memAlloc(size_t size);
	void_p  V_GLOBAL    memAllocZ(size_t size); /* returns zeroed block */
	void_p  V_GLOBAL    memRealloc(void *ptr,size_t newsize);
	void    V_GLOBAL    memFree(void *ptr);
	/*
	 *  Extra debugging stuff.
	 *
	 *  Returns statistics about memory usage. 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);
	/* Returns true if sentinel on every block is intact */
	vboolean	V_GLOBAL	memHeapGood(void);
#endif  /* MALLOC_DEBUG */
#ifdef  __cplusplus
}
#endif  /* __cplusplus */

/*
 * Macros for allocation of variables.
 */
#define	ALLOC_VARIABLE(ptr_ret,base_type) \
	(ptr_ret) = (base_type*)memAlloc(sizeof(base_type))

#define	ALLOC_CLEAN_VARIABLE(ptr_ret,base_type) \
	(ptr_ret) = (base_type*)memAllocZ(sizeof(base_type))

/*
 *  Other LibV headers.
 *  TODO: rename them.
 */
#include    "v_debug.h"

#include    "v_x86.h"
#include    "v_stack.h"
#include    "v_list.h"
#include    "v_tree.h"
#include    "v_fifo.h"
#include    "v_hash.h"
#include    "v_deque.h"
#include    "v_lltree.h"

#include    "v_log.h"
#include    "v_vector.h"
#include    "v_matrix.h"
#include    "v_math.h"
#include    "v_fft.h"
#include    "v_mrsmpl.h"
#include    "v_gpsp.h"
#include    "v_plane.h"
#include    "v_space.h"
#include    "v_parse.h"
#include    "v_nsl.h"
#include    "v_pgrid.h"
#include    "v_pprof.h"
#include    "v_ioctl.h"
#include    "v_fs.h"
#include    "v_image.h"
#include    "v_str.h"
#include    "v_wavlib.h"
#include    "v_reg.h"
#include    "v_rgen.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_dxf.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 */
