/*	generic debugging module.

Copyright (C) 1998 Ogochan

This module is generic debugging module.

	debug is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
to anyone for the consequences of using it or for whether it serves
any particular purpose or works at all, unless he says so in writing.
Refer to the GNU General Public License for full details. 

	Everyone is granted permission to copy, modify and redistribute
MACE, but only under the conditions described in the GNU General
Public License.  A copy of this license is supposed to have been given
to you along with MACE so you can know your rights and
responsibilities.  It should be in a file named COPYING.  Among other
things, the copyright notice and this notice must be preserved on all
copies. 
*/
/*
*	debug macros
*
*	98.07.14.	Ogochan	V0.0 create & release
*/

#include	<stdio.h>

#ifndef	byte
#define	byte	unsigned char
#endif

#ifdef	TRACE
#define	CASE(x)				case	(x):printf("%s\n",#x)
#define	dbgmsg(x)			_dbgmsg(x)
#define	PASS(x)				printf("%s(%d):%s\n",__FILE__,__LINE__,(x))
#define	DUMP_VALUE(val)		printf("%s:%ld\n",#val,(long)(val))
#else
#define	CASE(x)				case	(x):
#define	dbgmsg(x)			/*	*/
#define	PASS(x)				/*	*/
#define	DUMP_VALUE(val)		/*	*/
#endif

#define	error(s)		_error((s),__FILE__,__LINE__)

#ifdef	DEBUG
#define	fdbgopen(n)		_dbgopen(n)
#define	dbgopen			_dbgopen(NULL)
#define	dbgclose		_dbgclose()
extern	FILE	*dbgout;
#else
#define	fdbgopen(n)		/*	*/
#define	dbgopen			/*	*/
#define	dbgclose		/*	*/
#define	dbgout			stdout
#endif

#ifdef	ERROR
#undef	ERROR
#endif
#ifdef	DEBUG
#define	ERROR			error("")
#else
#define	ERROR			/*	*/
#endif

/* #define NO_XMALLOC */
#ifndef NO_XMALLOC

#ifdef	xmalloc
#undef	xmalloc
#endif
#define	xmalloc(s)			_xmalloc((s),__FILE__,__LINE__)
#define	xfree(p)			_xfree((p),__FILE__,__LINE__)

#else

#define	xmalloc(s)	malloc(s)
#define	xfree(p)	free(p)

#endif /* not def NO_XMALLOC */

#define	Exit()				_Exit(__FILE__,__LINE__)

#define	PARAM			byte
#define	PARA_NULL		(PARAM)0
#define	PARA_BINARY		(PARAM)0x01
#define	PARA_OCTAL		(PARAM)0x02
#define	PARA_DECIMAL	(PARAM)0x04
#define	PARA_HEX		(PARAM)0x08
#define	PARA_ASCII		(PARAM)0x10
#define	PARA_SET		(PARAM)0x40
#define	PARA_CHAR		(PARAM)0x80

#include	<stdlib.h>

#define	PRINT_BOOL(b)	((b) ? "T" : "F")

extern	void	_DumpArray(byte *,size_t,byte);
extern	void	_DumpChar(char);
extern	void	_dbgmsg(char *);
extern	void	_error(char *,char *,int);
extern	void	_dbgopen(char *);
extern	void	_dbgclose(void);
