btmux/autom4te.cache/
btmux/doc/.svn/
btmux/event/.svn/
btmux/game/.svn/
btmux/game/bin/.svn/
btmux/game/data/.svn/
btmux/game/logs/.svn/
btmux/game/maps/
btmux/game/maps/.svn/
btmux/game/maps/.svn/prop-base/
btmux/game/maps/.svn/props/
btmux/game/maps/.svn/text-base/
btmux/game/maps/.svn/wcprops/
btmux/game/mechs/
btmux/game/mechs/.svn/
btmux/game/mechs/.svn/prop-base/
btmux/game/mechs/.svn/props/
btmux/game/mechs/.svn/text-base/
btmux/game/mechs/.svn/wcprops/
btmux/game/text/.svn/
btmux/include/.svn/
btmux/misc/
btmux/misc/.svn/
btmux/misc/.svn/prop-base/
btmux/misc/.svn/props/
btmux/misc/.svn/text-base/
btmux/misc/.svn/wcprops/
btmux/python/
btmux/python/.svn/
btmux/python/.svn/prop-base/
btmux/python/.svn/props/
btmux/python/.svn/text-base/
btmux/python/.svn/wcprops/
btmux/src/.svn/prop-base/
btmux/src/.svn/props/
btmux/src/.svn/text-base/
btmux/src/.svn/wcprops/
btmux/src/hcode/.svn/
btmux/src/hcode/btech/
btmux/src/hcode/btech/.svn/
btmux/src/hcode/btech/.svn/prop-base/
btmux/src/hcode/btech/.svn/props/
btmux/src/hcode/btech/.svn/text-base/
btmux/src/hcode/btech/.svn/wcprops/
btmux/src/hcode/include/.svn/
#ifndef _DEBUG_H_
#define _DEBUG_H_

#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>

#ifndef assert
#define assert(x) if(!(x)) do { perror(__FUNCTION__); abort(); } while(0)
#endif
#ifndef assert_valid
#define assert_valid(x) if((x) == NULL) do { perror(__FUNCTION__); abort(); } while(0)
#endif

/* DEBUG only error messages */
#ifdef DEBUG
	/* debug test: 
 	* if the first argument `test' evaluates as true,
 	* the rest of the arguments are passed to fprintf */ 
	#define dtest(test, args...)	\
	do { if (test) {	\
		fprintf(stderr, "%5d %s (%s:%d)] ", getpid(), __FUNCTION__, __FILE__, __LINE__);	\
		fprintf(stderr, args);	\
		fprintf(stderr, "\n");	\
	}} while(0)

	/* debug print 
	 * prints arguments */
	#define dprintk(args...)	\
	do {	\
        fprintf(stderr, "%5d %s (%s:%d)] ", getpid(), __FUNCTION__, __FILE__, __LINE__);	\
        fprintf(stderr, args);	\
        fprintf(stderr, "\n");	\
	} while(0)
#else
	#define dtest(args...)
	#define dprintk(args...)
#endif /* DEBUG */

#define printk(args...)	\
do {	\
    fprintf(stderr, "%s (%s:%d)] ", __FILE__, __FUNCTION__, __LINE__);	\
    fprintf(stderr, args);	\
    fprintf(stderr, "\n");	\
} while(0)

#define IF_FAIL(condition, args...)	\
	do {	\
	if (!(condition)) {	\
		fprintf(stderr, "%s (%s:%d)] ", __FUNCTION__, __FILE__, __LINE__);	\
		fprintf(stderr, args);	\
		fprintf(stderr, "\n");	\
	    abort(); \
    }} while (0)

#define IF_FAIL_ERRNO(condition, args...)	\
	do {	\
	if (!(condition)) {	\
		fprintf(stderr, "%s (%s:%d)] ", __FUNCTION__, __FILE__, __LINE__);	\
		fprintf(stderr, args);	\
		fprintf(stderr, ": ");	\
		perror(NULL);	\
		abort();	\
    }} while (0)

#define handle_errno(x) if((x)<0) do { fprintf(stderr, "%s (%s:%d)] %s\n", __FUNCTION__, __FILE__,  __LINE__, strerror(errno)); abort(); } while(0)

#endif /* !_DEBUG_H_ */