Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 1 | /* |
Michael Clark | 837240f | 2007-03-13 08:26:25 +0000 | [diff] [blame] | 2 | * $Id: debug.h,v 1.5 2006/01/30 23:07:57 mclark Exp $ |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 3 | * |
Michael Clark | f6a6e48 | 2007-03-13 08:26:23 +0000 | [diff] [blame] | 4 | * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 5 | * Michael Clark <michael@metaparadigm.com> |
Keith Derrick | 74d830d | 2012-04-12 11:40:44 -0700 | [diff] [blame^] | 6 | * Copyright (c) 2009 Hewlett-Packard Development Company, L.P. |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 7 | * |
Michael Clark | f6a6e48 | 2007-03-13 08:26:23 +0000 | [diff] [blame] | 8 | * This library is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the MIT license. See COPYING for details. |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 10 | * |
| 11 | */ |
| 12 | |
| 13 | #ifndef _DEBUG_H_ |
| 14 | #define _DEBUG_H_ |
| 15 | |
Keith Derrick | 74d830d | 2012-04-12 11:40:44 -0700 | [diff] [blame^] | 16 | #include <stdlib.h> |
| 17 | |
Michael Clark | aaec1ef | 2009-02-25 02:31:32 +0000 | [diff] [blame] | 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
| 21 | |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 22 | extern void mc_set_debug(int debug); |
Michael Clark | 14862b1 | 2007-12-07 02:50:42 +0000 | [diff] [blame] | 23 | extern int mc_get_debug(void); |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 24 | |
| 25 | extern void mc_set_syslog(int syslog); |
| 26 | extern void mc_abort(const char *msg, ...); |
| 27 | extern void mc_debug(const char *msg, ...); |
| 28 | extern void mc_error(const char *msg, ...); |
| 29 | extern void mc_info(const char *msg, ...); |
| 30 | |
Keith Derrick | 74d830d | 2012-04-12 11:40:44 -0700 | [diff] [blame^] | 31 | #ifndef __STRING |
| 32 | #define __STRING(x) #x |
| 33 | #endif |
| 34 | |
| 35 | #ifndef PARSER_BROKEN_FIXED |
| 36 | |
| 37 | #define JASSERT(cond) do {} while(0) |
| 38 | |
| 39 | #else |
| 40 | |
| 41 | #define JASSERT(cond) do { \ |
| 42 | if (!(cond)) { \ |
| 43 | mc_error("cjson assert failure %s:%d : cond \"" __STRING(cond) "failed\n", __FILE__, __LINE__); \ |
| 44 | *(int *)0 = 1;\ |
| 45 | abort(); \ |
| 46 | }\ |
| 47 | } while(0) |
| 48 | |
| 49 | #endif |
| 50 | |
| 51 | #define MC_ABORT(x, ...) mc_abort(x, ##__VA_ARGS__) |
| 52 | #define MC_ERROR(x, ...) mc_error(x, ##__VA_ARGS__) |
| 53 | |
Michael Clark | dfaf670 | 2007-10-25 02:26:00 +0000 | [diff] [blame] | 54 | #ifdef MC_MAINTAINER_MODE |
| 55 | #define MC_SET_DEBUG(x) mc_set_debug(x) |
| 56 | #define MC_GET_DEBUG() mc_get_debug() |
| 57 | #define MC_SET_SYSLOG(x) mc_set_syslog(x) |
Michael Clark | dfaf670 | 2007-10-25 02:26:00 +0000 | [diff] [blame] | 58 | #define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__) |
Michael Clark | dfaf670 | 2007-10-25 02:26:00 +0000 | [diff] [blame] | 59 | #define MC_INFO(x, ...) mc_info(x, ##__VA_ARGS__) |
| 60 | #else |
| 61 | #define MC_SET_DEBUG(x) if (0) mc_set_debug(x) |
| 62 | #define MC_GET_DEBUG() (0) |
| 63 | #define MC_SET_SYSLOG(x) if (0) mc_set_syslog(x) |
Michael Clark | dfaf670 | 2007-10-25 02:26:00 +0000 | [diff] [blame] | 64 | #define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__) |
Michael Clark | dfaf670 | 2007-10-25 02:26:00 +0000 | [diff] [blame] | 65 | #define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__) |
| 66 | #endif |
| 67 | |
Michael Clark | aaec1ef | 2009-02-25 02:31:32 +0000 | [diff] [blame] | 68 | #ifdef __cplusplus |
| 69 | } |
| 70 | #endif |
| 71 | |
Michael Clark | f0d0888 | 2007-03-13 08:26:18 +0000 | [diff] [blame] | 72 | #endif |