1#ifndef DEBUG_H
2#define DEBUG_H
3/* Debug - debug stuff
4**
5** Initial version by Axel D��rfler, axeld@pinc-software.de
6** This file may be used under the terms of the MIT License.
7*/
8#ifndef DEBUG
9#	define DEBUG 0
10#endif
11
12#include <stdio.h>
13
14#include <OS.h>
15
16#ifdef DEBUG_PRINTF
17	#define __out DEBUG_PRINTF
18#else
19	#define __out printf
20#endif
21
22// Short overview over the debug output macros:
23//	PRINT()
24//		is for general messages that very unlikely should appear in a release build
25//	FATAL()
26//		this is for fatal messages, when something has really gone wrong
27//	INFORM()
28//		general information, as disk size, etc.
29//	REPORT_ERROR(status_t)
30//		prints out error information
31//	RETURN_ERROR(status_t)
32//		calls REPORT_ERROR() and return the value
33//	D()
34//		the statements in D() are only included if DEBUG is defined
35
36#define DEBUG_APP "REG"
37#if DEBUG
38	#define PRINT(x...) { __out(DEBUG_APP ": " x); }
39	#define REPORT_ERROR(status) \
40		__out(DEBUG_APP ": %s:%d: %s\n", __FUNCTION__, __LINE__, \
41			strerror(status));
42	#define RETURN_ERROR(err) \
43		{ \
44			status_t _status = err; \
45			if (_status < B_OK) \
46				REPORT_ERROR(_status); \
47			return _status; \
48		}
49	#define SET_ERROR(var, err) \
50		{ \
51			status_t _status = err; \
52			if (_status < B_OK) \
53				REPORT_ERROR(_status); \
54			var = _status; \
55		}
56	#define FATAL(x...) { __out(DEBUG_APP ": " x); }
57	#define ERROR(x...) { __out(DEBUG_APP ": " x); }
58	#define WARNING(x...) { __out(DEBUG_APP ": " x); }
59	#define INFORM(x...) { __out(DEBUG_APP ": " x); }
60	#define FUNCTION(x) { __out(DEBUG_APP ": %s() ",__FUNCTION__); __out x; }
61	#define FUNCTION_START() { __out(DEBUG_APP ": %s()\n",__FUNCTION__); }
62	#define FUNCTION_END() { __out(DEBUG_APP ": %s() done\n",__FUNCTION__); }
63	#define D(x) {x;};
64#else
65	#define PRINT(x...) ;
66	#define REPORT_ERROR(status) ;
67	#define RETURN_ERROR(status) return status;
68	#define SET_ERROR(var, err) var = err;
69	#define FATAL(x...) { __out(DEBUG_APP ": " x); }
70	#define ERROR(x...) { __out(DEBUG_APP ": " x); }
71	#define WARNING(x...) { __out(DEBUG_APP ": " x); }
72	#define INFORM(x...) { __out(DEBUG_APP ": " x); }
73	#define FUNCTION(x...) ;
74	#define FUNCTION_START() ;
75	#define FUNCTION_END() ;
76	#define D(x) ;
77#endif
78
79
80#endif	/* DEBUG_H */
81