//	utf-8

/*	Copyright  (c)	Günter Woigk   1994-2003
  					mailto:kio@little-bat.de

	This file is free software

 	This program 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.

 	Permission to use, copy, modify, distribute, and sell this software and
 	its documentation for any purpose is hereby granted without fee, provided
 	that the above copyright notice appear in all copies and that both that
 	copyright notice and this permission notice appear in supporting
 	documentation, and that the name of the copyright holder not be used
 	in advertising or publicity pertaining to distribution of the software
 	without specific, written prior permission. The copyright holder makes no
 	representations about the suitability of this software for any purpose.
 	It is provided "as is" without express or implied warranty.

 	THE COPYRIGHT HOLDER DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
 	INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
 	EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY SPECIAL, INDIRECT OR
 	CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 	DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
 	TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 	PERFORMANCE OF THIS SOFTWARE.

	Kio's universal standard header.

	2003-11-26 kio	today i found /usr/include/sys/isa_defs.h on Sparc/Solaris. i'm not alone!
*/

#ifndef	_kio_h_
#define	_kio_h_


#define	myName					"Günter Woigk"
#define	myAddress				"Sankt Johann 6/246, 91056 Erlangen, Germany"
#define	myEmail					"kio@little-bat.de"
#define	myHomepage				"little-bat.de"



/* ----	include "config.h" ----------------------------------------
		on unix systems "config.h" should be generated from "configure.in"
		using autoconf and should not be part of the cvs repository.

		on other systems put this file into the platform specific subfolder
		and edit this file directly. this platform specific variant should
		go into the cvs.
*/
#include "config.h"



/* ----	determine platform ----------------------------------------

		platform identifier:
		guarantee that platform is detected.
		_UNIX, _WINDOWS, _BEOS, _MACINTOSH      undefined or 1

		sub platform identifier:
		guarantee that sub platform is detected.
		_LINUX, _BSD, _MINIX					undefined or 1

		vendor identifier:
		not guaranteed that a vendor is detected.
		_FREEBSD, _OPENBSD, _NETBSD, _MACOSX	undefined or 1 ((or version number))
		_SUSE, _DEBIAN, _REDHAT, _YELLOWDOG		undefined or 1 ((or version number))
*/
#if defined(_UNIX) + defined(_WINDOWS) + defined(_BEOS) + defined(_MACINTOSH) != 1
	#error platform not #defined in "config.h"  ((or multiple platforms detected))!
#endif

#if defined(_UNIX) && ( defined(_LINUX) + defined(_BSD) + defined(_MINIX) + defined(_SOLARIS) != 1 )
	#error UNIX sub platform not #defined in "config.h"  ((or multiple sub platforms detected))!
#endif

//#if defined(_BSD) && ( defined(_FREEBSD) + defined(_OPENBSD) + defined(_NETBSD) + defined(_MACOSX) != 1 )
//	#error BSD sub platform not #defined in "config.h"  ((or multiple sub platforms detected))!
//#endif

//#if defined(_LINUX) && ( defined(_SUSE) + defined(_DEBIAN) + defined(_REDHAT) + defined(_YELLOWDOG) != 1 )
//	#error LINUX sub platform not #defined in "config.h"  ((or multiple sub platforms detected))!
//#endif



/* ----	determine compiler ----------------------------------
		guarantee that compiler is detected.
		_METROWERKS, _GCC, _MPW
*/
#if !defined(_METROWERKS) && !defined(_GCC) && !defined(_MPW)
	#if defined(_MPW_C) || defined(_MPW_CPLUS)
		#define _MPW			1

	#elif defined(_MACINTOSH)
		#define	_METROWERKS 	1

	#elif defined(__GNUC__) || defined(__GNUG__)
		#define _GCC			1

	#else
		#error "can't determine compiler"
	#endif
#endif



/* ----	basic system headers -----------------------
*/
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#if HAVE_STDARG_H
#include <stdarg.h>
#endif
#if HAVE_STDIO_H
#include <stdio.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_CTYPE_H
#include <ctype.h>
#endif
#if HAVE_ASSERT_H
#include <assert.h>
#endif
#if defined(_BSD)
#include <machine/endian.h>
#elif defined(_LINUX)
#include <endian.h>
#elif defined(_SOLARIS)
#include </usr/include/sys/isa_defs.h>
#endif



/* ----	determine processor -----------------------------------
		guarantee that processor is detected.
		_POWERPC, _M68K, _I386, _ALPHA, _SPARC, _I386x64
*/
#if defined(_POWERPC) + defined(_M68K) + defined(_I386) + defined(_ALPHA) + defined(_SPARC) + defined(_I386x64) != 1
	#if defined(__i386__) || defined(__i386)
		#define	_I386		1

	#elif defined(__ppc__) || defined(__PPC__) || defined(__powerpc__)
		#define	_POWERPC	1

	#elif defined(__alpha__)
		#define	_ALPHA		1

	#elif defined(__sparc__) || defined(__sparc)
		#if defined(__sparcv8)	// 32 bit cpu
			#define	_SPARC		"V8"
		#elif defined(__sparcv9)	// 64 bit cpu
			#define	_SPARC		"V9"
		#else
			#define _SPARC		1
		#endif
	#endif
	#if defined(_POWERPC) + defined(_M68K) + defined(_I386) + defined(_ALPHA) + defined(_SPARC) + defined(_I386x64) != 1
		#error "can't determine processor type. ((or multiple processor types detected))"
	#endif
#endif



/* ==== dependencies ==============================================
*/



/* ---- directory separator ------------------------
		guaranteed constant.
*/
#if defined(_MACINTOSH)
	const char		dirsep	=	':';
#elif defined(_WINDOWS)
	const char		dirsep	=	'\\';
#else
	const char		dirsep	=	'/';
#endif



/* ----	newline separator ------------------------------
		guaranteed constant.
		note: *MAYBE* we'll support DOS a little better?
*/
#if defined(_MACINTOSH)
	const char		nl		=	13;		// MacOS classic
#else
	const char		nl		=	10;
#endif



/* ----	no_index --------------------------------------
		guaranteed macro.
		in structs and classes the last data member may be a variable length array.
		this is handled differently by different compilers:
		either you set the index to 0 or you leave it completely out.
*/
#if defined(_GCC)
	#define		no_index		0
#elif defined(_METROWERKS)
	#define		no_index		/* ((empty)) */
#elif defined(_MPW)
	#error "please set no_index to what is supported by MPW. thanks."
#else
	#error
#endif



/* ----	processor characteristics ---------------------
		2003-11-26 kio: switch to Sun's names
*/
#if defined(_SPARC)
// all should be setup by /usr/include/sys/isa_defs.h
//	#define	_BIG_ENDIAN
//	#define	_SHORT_ALIGNMENT		2
//	#define	_INT_ALIGNMENT			4
//	#define	_LONG_LONG_ALIGNMENT	8
//	#define	_DOUBLE_ALIGNMENT		8
//	#define	_ALIGNMENT_REQUIRED		1
//	#if _SPARC=="V8"
//		#define	_LONG_ALIGNMENT			4
//		#define	_LONG_DOUBLE_ALIGNMENT	8
//		#define	_POINTER_ALIGNMENT		4
//		#define	_MAX_ALIGNMENT			8
//	#elif _SPARC=="V9"
//		#define	_LONG_ALIGNMENT			8
//		#define	_LONG_DOUBLE_ALIGNMENT	16
//		#define	_POINTER_ALIGNMENT		8
//		#define	_MAX_ALIGNMENT			16
#endif


#if defined(__ia64)
	#undef	_LITTLE_ENDIAN
	#undef	_BIG_ENDIAN
	#undef	_PDP_ENDIAN
	#undef	_SHORT_ALIGNMENT
	#undef	_INT_ALIGNMENT
	#undef	_LONG_ALIGNMENT
	#undef	_LONG_LONG_ALIGNMENT
	#undef	_DOUBLE_ALIGNMENT
	#undef	_POINTER_ALIGNMENT
	#undef	_MAX_ALIGNMENT
	#undef	_ALIGNMENT_REQUIRED

	#define	_LITTLE_ENDIAN			1
	#define	_SHORT_ALIGNMENT		2
	#define	_INT_ALIGNMENT			4
	#define	_LONG_ALIGNMENT			8
	#define	_LONG_LONG_ALIGNMENT	8
	#define	_DOUBLE_ALIGNMENT		8
	#define	_LONG_DOUBLE_ALIGNMENT	16
	#define	_POINTER_ALIGNMENT		8
	#define	_MAX_ALIGNMENT			16
	#define	_ALIGNMENT_REQUIRED		1
#endif


#if defined(_I386)
	#undef	_LITTLE_ENDIAN
	#undef	_BIG_ENDIAN
	#undef	_PDP_ENDIAN
	#undef	_SHORT_ALIGNMENT
	#undef	_INT_ALIGNMENT
	#undef	_LONG_ALIGNMENT
	#undef	_LONG_LONG_ALIGNMENT
	#undef	_DOUBLE_ALIGNMENT
	#undef	_POINTER_ALIGNMENT
	#undef	_MAX_ALIGNMENT
	#undef	_ALIGNMENT_REQUIRED

	#define	_LITTLE_ENDIAN			1
	#define	_SHORT_ALIGNMENT		2
	#define	_INT_ALIGNMENT			4
	#define	_LONG_ALIGNMENT			4
	#define	_LONG_LONG_ALIGNMENT	4
	#define	_DOUBLE_ALIGNMENT		4
	#define	_POINTER_ALIGNMENT		4
	#define	_MAX_ALIGNMENT			4
	#define	_ALIGNMENT_REQUIRED		0
#endif


#if defined(_POWERPC)
	#undef	_LITTLE_ENDIAN
	#undef	_BIG_ENDIAN
	#undef	_PDP_ENDIAN
	#undef	_SHORT_ALIGNMENT
	#undef	_INT_ALIGNMENT
	#undef	_LONG_ALIGNMENT
	#undef	_LONG_LONG_ALIGNMENT
	#undef	_DOUBLE_ALIGNMENT
	#undef	_POINTER_ALIGNMENT
	#undef	_MAX_ALIGNMENT
	#undef	_ALIGNMENT_REQUIRED

	#define	_BIG_ENDIAN				1
	#define	_SHORT_ALIGNMENT		2
	#define	_INT_ALIGNMENT			4
	#define	_LONG_ALIGNMENT			4
	#define	_LONG_LONG_ALIGNMENT	4
	#define	_DOUBLE_ALIGNMENT		4
	#define	_POINTER_ALIGNMENT		4
	#define	_MAX_ALIGNMENT			4
	#define	_ALIGNMENT_REQUIRED		0
	// note: missaligned access to float/double is handled _very_ _slowly_ (~2000clocks) by trap on G3/G4!
	// 		 don't know about G5
#endif


#if defined(_M68K)
	#undef	_BIG_ENDIAN
	#define	_BIG_ENDIAN				1
#endif


#if defined(_PDP)
	#undef	_PDP_ENDIAN
	#define	_PDP_ENDIAN				1
#endif



/* ----	byte order ---------------------------------
		guarantee that byte order is detected.
		_BIG_ENDIAN  	e.g. M68k	dc.l '4321' = dc.b '4','3','2','1'	(ok.)
		_LITTLE_ENDIAN	e.g. i386	dc.l '4321' = dc.b '1','2','3','4'	(idiotic!)
		_PDP_ENDIAN  	e.g. PDP	dc.l '4321' = dc.b '3','4','1','2'	(even more brain dead!)
*/
#if defined(BYTE_ORDER) && ( defined(_LITTLE_ENDIAN) + defined(_BIG_ENDIAN) + defined(_PDP_ENDIAN) == 0 )
	#if defined(BIG_ENDIAN) && BYTE_ORDER==BIG_ENDIAN
		#define			_BIG_ENDIAN		1		// dc.l '4321' = dc.b '4','3','2','1'	-> POWERPC, M68K, SPARC
	#elif defined(LITTLE_ENDIAN) && BYTE_ORDER==LITTLE_ENDIAN
		#define			_LITTLE_ENDIAN	1		// dc.l '4321' = dc.b '1','2','3','4'	-> I386, ALPHA
	#elif defined(PDP_ENDIAN) && BYTE_ORDER==PDP_ENDIAN
		#define			_PDP_ENDIAN		1		// dc.l '4321' = dc.b '3','4','1','2'	-> PDP
	#endif
#endif



/* ----	verify that all processor characteristics are set --------------------
*/
#if defined(_LITTLE_ENDIAN) + defined(_BIG_ENDIAN) + defined(_PDP_ENDIAN) != 1
	#error "can't detect byte order  ((or multiple byte orders detected))"
#endif
#if !defined(_SHORT_ALIGNMENT) || !defined(_INT_ALIGNMENT) || !defined(_LONG_ALIGNMENT) || !defined(_LONG_LONG_ALIGNMENT)
	#error "missing CPU characteristics. (1) fixme!"
#elif !defined(_ALIGNMENT_REQUIRED) || !defined(_DOUBLE_ALIGNMENT) || !defined(_POINTER_ALIGNMENT) || !defined(_MAX_ALIGNMENT)
	#error "missing CPU characteristics. (2) fixme!"
#endif



/* ----	LOG and SAFE -----------------------------------
		guaranteed macros.
		each file should contain a #define for the LOG and SAFE level
		before the first include. the LOG and SAFE level given there may be
		overridden by global settings in "config.h".
*/
#ifdef GLOB_LOG
	#undef	LOG
	#define	LOG	GLOB_LOG
#else
	#ifndef LOG
	#define LOG 0
	#endif
#endif

#ifdef GLOB_SAFE
	#undef	SAFE
	#define	SAFE GLOB_SAFE
#else
	#ifndef SAFE
	#define SAFE 1
	#endif
#endif



/* ----	other standard headers ---------------------
*/
#include	"kio/standard_types.h"
#include	"kio/nice_defines.h"
#include	"cstrings/cstrings.h"
#include	"kio/abort.h"
#include	"kio/errors.h"
#include	"kio/log.h"
#include	"random/random.h"



#if defined(_MACINTOSH)
	#include	"macos_classic/kio headers/apple_glue.h"
	#include	"kio/atexit.h"

	#if USE_KIOS_MALLOC
	#include	"malloc/malloc.h"
	#endif

	extern int strcasecmp  ( cstr s1, cstr s2 );
	extern int strncasecmp ( cstr s1, cstr s2, int n );
#endif


#endif






