blob: 1e0970173636ec694b328329a184178e0c68f47a [file] [log] [blame]
Michael Clarkf0d08882007-03-13 08:26:18 +00001/*
Michael Clark837240f2007-03-13 08:26:25 +00002 * $Id: debug.h,v 1.5 2006/01/30 23:07:57 mclark Exp $
Michael Clarkf0d08882007-03-13 08:26:18 +00003 *
Michael Clarkf6a6e482007-03-13 08:26:23 +00004 * Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd.
Michael Clarkf0d08882007-03-13 08:26:18 +00005 * Michael Clark <michael@metaparadigm.com>
Keith Derrick74d830d2012-04-12 11:40:44 -07006 * Copyright (c) 2009 Hewlett-Packard Development Company, L.P.
Michael Clarkf0d08882007-03-13 08:26:18 +00007 *
Michael Clarkf6a6e482007-03-13 08:26:23 +00008 * 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 Clarkf0d08882007-03-13 08:26:18 +000010 *
11 */
12
13#ifndef _DEBUG_H_
14#define _DEBUG_H_
15
Keith Derrick74d830d2012-04-12 11:40:44 -070016#include <stdlib.h>
17
Michael Clarkaaec1ef2009-02-25 02:31:32 +000018#ifdef __cplusplus
19extern "C" {
20#endif
21
Michael Clarkf0d08882007-03-13 08:26:18 +000022extern void mc_set_debug(int debug);
Michael Clark14862b12007-12-07 02:50:42 +000023extern int mc_get_debug(void);
Michael Clarkf0d08882007-03-13 08:26:18 +000024
25extern void mc_set_syslog(int syslog);
26extern void mc_abort(const char *msg, ...);
27extern void mc_debug(const char *msg, ...);
28extern void mc_error(const char *msg, ...);
29extern void mc_info(const char *msg, ...);
30
Keith Derrick74d830d2012-04-12 11:40:44 -070031#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 Clarkdfaf6702007-10-25 02:26:00 +000054#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 Clarkdfaf6702007-10-25 02:26:00 +000058#define MC_DEBUG(x, ...) mc_debug(x, ##__VA_ARGS__)
Michael Clarkdfaf6702007-10-25 02:26:00 +000059#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 Clarkdfaf6702007-10-25 02:26:00 +000064#define MC_DEBUG(x, ...) if (0) mc_debug(x, ##__VA_ARGS__)
Michael Clarkdfaf6702007-10-25 02:26:00 +000065#define MC_INFO(x, ...) if (0) mc_info(x, ##__VA_ARGS__)
66#endif
67
Michael Clarkaaec1ef2009-02-25 02:31:32 +000068#ifdef __cplusplus
69}
70#endif
71
Michael Clarkf0d08882007-03-13 08:26:18 +000072#endif