#include <../source/TAL/objbase.h>
#include <../source/PAL/dataman.h>
#include <../source/PAL/oshead.h>

/*
 *	Defined in "PAL/dataman.h"
 */
global_data_t		libv_global_data=
{
	LIBV_GLOBAL_MAGIC,	/* magic */
	0,					/* number of successful calls to threadCreate() */
	LIBV_INVALID_HANDLE,/* log_file */
	LOG_ERROR,			/* log_upper_level */
#ifdef	MALLOC_DEBUG
	0,					/* Total number of pointers and handles */
	NULL,				/* Pointer hash table */
	NULL,				/* Handle hash table */
#endif	/* MALLOC_DEBUG */
#ifdef	CONFIG_NT_CONSOLE
	INVALID_HANDLE_VALUE,	/* input handle */
	INVALID_HANDLE_VALUE,	/* output handle */
	FALSE,					/* console was AllocConsole()'d */
#endif	/* CONFIG_NT_CONSOLE */
	TYPED_STACK_EMPTY_INITIALIZER	/* log callbacks */
};

thread_data_t		libv_thread_data=
{
	LIBV_TSD_MAGIC,		/* magic */
	0xFF,				/* constant_alpha - opaque */
	1000,1000			/* metafile extents */
	/* All other members must be 0/NULL */
};

#ifdef		__WIN32__

void	V_CALL
libvError(char *msg)
{
	MessageBoxA(NULL,msg,"LibV",MB_OK|MB_ICONHAND);
	ExitProcess(1);
}

V_LOCAL		int	nt_version = -2;

int	V_CALL
ntGetVersion(void)
{
	if(nt_version==-2)
	{
    	/* First call */
		OSVERSIONINFO vi;
		memZero(&vi,sizeof(OSVERSIONINFO));
		vi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
		GetVersionEx(&vi);
		if(vi.dwPlatformId == VER_PLATFORM_WIN32_NT)
        	nt_version=(int)vi.dwMajorVersion;
		else
        	nt_version=-1;
	}
	return nt_version;
}

#elif		defined(__UNIX__) /* !__WIN32__ */

void		V_CALL
libvError(char *msg)
{
	fprintf(stderr,"LibV error: %s.\n",msg);
	fflush(stderr);
	abort();
}

#endif		/* __UNIX__ */

#if		defined(BUILD_DLL) && defined(__WIN32__)

#include <../source/PAL/argsused.h>
BOOL WINAPI
DllMain(HINSTANCE hInstance,DWORD fdwReason,LPVOID lpvReserved)
{
	/* Nothing to do */
	switch(fdwReason)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
	}
	return TRUE;
}

#endif	/* BUILD_DLL && __WIN32__ */
