1
0
Fork 0
mirror of git://git.psyc.eu/libpsyc synced 2024-08-15 03:19:02 +00:00
libpsyc/include/psyc/debug.h
psyc://psyced.org/~lynX 475eeb8121 debug macros
2011-04-16 17:30:03 +02:00

95 lines
1.6 KiB
C

#ifdef DEBUG
# include <stdio.h>
# define PP(args) printf args;
#else
# define PP(args)
#endif
#ifdef TEST
# define PT(MSG) PP(MSG);
# define DT(CODE) CODE
#else
# define PT(MSG)
# define DT(CODE)
#endif
/* simplified form of conditional compilation */
#ifndef DEBUG_FLAGS
# ifdef DEBUG
# if DEBUG == 1
# define DEBUG_FLAGS 0x03
# else
# if DEBUG == 2
# define DEBUG_FLAGS 0x07
# else
# if DEBUG == 3
# define DEBUG_FLAGS 0x0f
# else
# if DEBUG == 4
# define DEBUG_FLAGS 0x1f
# else
# define DEBUG_FLAGS 0x01
# endif
# endif
# endif
# endif
# else
# define DEBUG_FLAGS 0x00 /* no debugging */
# endif
#endif
#if DEBUG_FLAGS & 0x01
# define D0(CODE) CODE
# define P0(MSG) PP(MSG);
#else
# define D0(CODE)
# define P0(MSG)
#endif
#if DEBUG_FLAGS & 0x02
# define D1(CODE) CODE
# define P1(MSG) PP(MSG);
#else
# define D1(CODE)
# define P1(MSG)
#endif
#if DEBUG_FLAGS & 0x04
# define D2(CODE) CODE
# define P2(MSG) PP(MSG);
#else
# define D2(CODE)
# define P2(MSG)
#endif
#if DEBUG_FLAGS & 0x08
# define D3(CODE) CODE
# define P3(MSG) PP(MSG);
#else
# define D3(CODE)
# define P3(MSG)
#endif
#if DEBUG_FLAGS & 0x10
# define D4(CODE) CODE
# define P4(MSG) PP(MSG);
#else
# define D4(CODE)
# define P4(MSG)
#endif
// ASSERT() unused as yet
#if DEBUG > 0
# ifdef STRICT
# define ASSERT(NAME,COND,VALUE) { unless (COND) { \
PP(("Assertion %s failed in %s: %s\n", NAME, ME, VALUE)); \
raise_error("Assertion failed (strict mode).\n"); } }
# else
# define ASSERT(NAME,COND,VALUE) { unless (COND) \
PP(("Assertion %s failed in %s: %s\n", NAME, ME, VALUE)); }
# endif
#else
# define ASSERT(NAME,CONDITION,VALUE)
#endif