/*****************************************************************************

 @(#) debug.h,v 0.7.8.1 2001/12/11 13:15:00 brian Exp

 -----------------------------------------------------------------------------

 Copyright (C) 1997-2001  Brian Bidulock <bidulock@dallas.net>

 All Rights Reserved.

 This program is free software; you can redistribute it and/or modify it under
 the terms of the GNU General Public License as published by the Free Software
 Foundation; either version 2 of the License, or (at your option) any later
 version.

 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.  See the GNU General Public License for more
 details.

 You should have received a copy of the GNU General Public License along with
 this program; if not, write to the Free Software Foundation, Inc., 675 Mass
 Ave, Cambridge, MA 02139, USA.

 -----------------------------------------------------------------------------

 Last Modified 2001/12/11 13:15:00 by brian

 *****************************************************************************/

#ifndef __DEBUG_H__
#define __DEBUG_H__

#if 1
#define DDTRACE          do { printk("%s [%s %d] trace\n",__FUNCTION__,__FILE__, __LINE__); } while(0)
#define DDPRINT(n,args)  do { printk args; } while(0)

#ifdef  _DEBUG
#define DTRACE           do { if ( DEBUG_LEVEL ) { printk("%s [%s %d] trace\n",__FUNCTION__,__FILE__, __LINE__); } } while(0)
#define DPRINT(n,args)   do { if (DEBUG_LEVEL>n) { printk args; } } while(0)
#define DBLOCK(n,block)     { if (DEBUG_LEVEL>n) { block } }
#else
#define DTRACE    
#define DPRINT(n,args)
#define DBLOCK(n,block)
#endif
#endif

#define __never() \
do { printk(KERN_EMERG __FUNCTION__ ": never() at "__FILE__ " +%d\n", __LINE__); *(int *)0 = 0; } while(0)

#define __rare() \
do { printk(KERN_NOTICE __FUNCTION__ ": rare() at "__FILE__ " +%d\n", __LINE__); } while(0)

#define __seldom() \
do { printk(KERN_NOTICE __FUNCTION__ ": seldom() at "__FILE__ " +%d\n", __LINE__); } while(0)

#define __usual(__exp) \
do { if (!(__exp)) printk(KERN_WARNING __FUNCTION__ ": usual(" #__exp ") failed at " __FILE__ " +%d\n",__LINE__); } while(0)

#define __normal(__exp) \
do { if (!(__exp)) printk(KERN_WARNING __FUNCTION__ ": normal(" #__exp ") failed at " __FILE__ " +%d\n",__LINE__); } while(0)

#define __assert(__exp) \
do { if (!(__exp)) { printk(KERN_EMERG __FUNCTION__ ": assert(" #__exp ") failed at " __FILE__ " +%d\n",__LINE__); *(int *)0 = 0; } } while(0)

#define __assure(__exp) \
do { if (!(__exp)) printk(KERN_WARNING __FUNCTION__ ": assure(" #__exp ") failed at " __FILE__ " +%d\n",__LINE__); } while(0)

#define __ensure(__exp,__sta) \
do { if (!(__exp)) { printk(KERN_WARNING __FUNCTION__ ": ensure(" #__exp ") failed at " __FILE__ " +%d\n",__LINE__); __sta; } } while(0)

#define __trace() \
do { printk(KERN_INFO __FUNCTION__ ": trace() at " __FILE__ " +%d\n", __LINE__); } while(0)

#define __ptrace(__pkspec) \
do { printk(KERN_INFO __FUNCTION__ ": ptrace() at " __FILE__ " +%d\n", __LINE__); printk __pkspec; } while(0)

#define __fixme(__pkspec) \
do { printk(KERN_INFO __FUNCTION__ ": fixme() at " __FILE__ " +%d\n", __LINE__); printk __pkspec; } while(0)

#define __ctrace(__fnc) \
({ printk(KERN_INFO __FUNCTION__ ": calling " #__fnc " at " __FILE__ " +%d\n", __LINE__); __fnc; })

#define __printd(__pkspec) \
do { printk __pkspec; } while(0)

#ifdef _DEBUG

#define   never()		__never()
#define    rare()		__rare()
#define  seldom()		__seldom()
#define   usual(__exp)		__usual(__exp)
#define unusual(__exp)		__usual(!(__exp))
#define  normal(__exp)		__normal(__exp)
#define abnormal(__exp)		__normal(!(__exp))
#define  assert(__exp)		__assert(__exp)
#define  assure(__exp)		__assure(__exp)
#define  ensure(__exp,__sta)	__ensure(__exp,__sta)
#define  unless(__exp,__sta)	__ensure(!(__exp),__sta)
#define   trace()		__trace()
#define  ptrace(__pks)		__ptrace(__pks)
#define   fixme(__pks)		__fixme(__pks)
#define  printd(__pks)		__printd(__pks)

#else
#ifdef _SAFE

#define   never()		do { *(int *)0 = 0; } while(0)
#define    rare()		do { } while(0)
#define  seldom()		do { } while(0)
#define   usual(__exp)		do { } while(0)
#define unusual(__exp)		do { } while(0)
#define  normal(__exp)		do { } while(0)
#define abnormal(__exp)		do { } while(0)
#define  assert(__exp)		{ if (!(__exp)) *(int *)0 = 0; } while(0)
#define  assure(__exp)		__assure(__exp)
#define  ensure(__exp,__sta)	__ensure(__exp,__sta)
#define  unless(__exp,__sta)	__ensure(!(__exp),__sta)
#define   trace()		do { } while(0)
#define  ptrace(__pks)		do { } while(0)
#define   fixme(__pks)		__fixme(__pks)
#define  printd(__pks)		do { } while(0)

#else

#define   never()		do { } while(0)
#define	   rare()		do { } while(0)
#define	 seldom()		do { } while(0)
#define   usual(__exp)		do { } while(0)
#define unusual(__exp)		do { } while(0)
#define  normal(__exp)		do { } while(0)
#define abnormal(__exp)		do { } while(0)
#define  assert(__exp)		do { } while(0)
#define  assure(__exp)		do { } while(0)
#define  ensure(__exp,__sta)	do { } while(0)
#define  unless(__exp,__sta)	do { } while(0)
#define  trace()		do { } while(0)
#define  ptrace(__pks)		do { } while(0)
#define   fixme(__pks)		__fixme(__pks)
#define  printd(__pks)		do { } while(0)

#endif

#endif

#endif  __DEBUG_H__
