#ifndef _CSPDEBUGGING_H_
#define _CSPDEBUGGING_H_
#ifdef NDEBUG
#define DEBUG_ENABLE 0
#define ERROR_LOG_ENABLE 0
#else
#define DEBUG_ENABLE 1
#define ERROR_LOG_ENABLE 1
#endif
#define LOG_VIA_PRINTF 1
#if DEBUG_ENABLE || ERROR_LOG_ENABLE
#include <stdio.h>
#include <stdlib.h>
#if !LOG_VIA_PRINTF
#error Hey, figure out a debug mechanism
#include <string.h>
#include <TextUtils.h>
#ifdef __cplusplus
extern "C" {
#endif
extern void dblog0(char *str);
extern void dblog1(char *str, void * arg1);
extern void dblog2(char *str, void * arg1, void * arg2);
extern void dblog3(char *str, void * arg1, void * arg2, void * arg3);
extern void dblog4(char *str, void * arg1, void * arg2, void * arg3, void * arg4);
#ifdef __cplusplus
}
#endif
#else
#define dblog0(str) printf(str)
#define dblog1(str, arg1) printf(str, arg1)
#define dblog2(str, arg1, arg2) printf(str, arg1, arg2)
#define dblog3(str, arg1, arg2, arg3) printf(str, arg1, arg2, arg3)
#define dblog4(str, arg1, arg2, arg3, arg4) printf(str, arg1, arg2, arg3, arg4)
#endif
#else
#define dblog0(str)
#define dblog1(str, arg1)
#define dblog2(str, arg1, arg2)
#define dblog3(str, arg1, arg2, arg3)
#define dblog4(str, arg1, arg2, arg3, arg4)
#endif
#if DEBUG_ENABLE
#define dprintf0(str) dblog0(str)
#define dprintf1(str, arg1) dblog1(str, arg1)
#define dprintf2(str, arg1, arg2) dblog2(str, arg1, arg2)
#define dprintf3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
#define dprintf4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
#ifdef __cplusplus
extern "C" {
#endif
#include <CrashReporterClient.h>
static inline void _panic(const char *str)
{
printf("%s\n", str);
CRSetCrashLogMessage(str);
abort();
}
#ifdef __cplusplus
}
#endif
#define CASSERT(expression) \
((expression) ? (void)0 : \
(dprintf1 ("Assertion failed: " #expression \
", file " __FILE__ ", line %d.\n", __LINE__), \
_panic("Assertion Failure")))
#else
#define dprintf0(str)
#define dprintf1(str, arg1)
#define dprintf2(str, arg1, arg2)
#define dprintf3(str, arg1, arg2, arg3)
#define dprintf4(str, arg1, arg2, arg3, arg4)
#define CASSERT(expression)
#endif
#if ERROR_LOG_ENABLE
#define errorLog0(str) dblog0(str);
#define errorLog1(str, arg1) dblog1(str, arg1)
#define errorLog2(str, arg1, arg2) dblog2(str, arg1, arg2)
#define errorLog3(str, arg1, arg2, arg3) dblog3(str, arg1, arg2, arg3)
#define errorLog4(str, arg1, arg2, arg3, arg4) dblog4(str, arg1, arg2, arg3, arg4)
#else
#define errorLog0(str)
#define errorLog1(str, arg1)
#define errorLog2(str, arg1, arg2)
#define errorLog3(str, arg1, arg2, arg3)
#define errorLog4(str, arg1, arg2, arg3, arg4)
#endif
#endif