Resurrected native codesetslib from r27301
[cake.git] / workbench / libs / codesetslib / src / debug.h
blob9c54f288334f1d90957a7961f01c5928ec956409
1 /***************************************************************************
3 codesets.library - Amiga shared library for handling different codesets
4 Copyright (C) 2001-2005 by Alfonso [alfie] Ranieri <alforan@tin.it>.
5 Copyright (C) 2005-2007 by codesets.library Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
17 codesets.library project: http://sourceforge.net/projects/codesetslib/
19 $Id$
21 ***************************************************************************/
23 #ifndef DEBUG_H
24 #define DEBUG_H
26 // first we make sure all previously defined symbols are undefined now so
27 // that no other debug system interferes with ours.
28 #undef ENTER
29 #undef LEAVE
30 #undef RETURN
31 #undef SHOWVALUE
32 #undef SHOWPOINTER
33 #undef SHOWSTRING
34 #undef SHOWMSG
35 #undef STARTCLOCK
36 #undef STOPCLOCK
37 #undef D
38 #undef E
39 #undef W
40 #undef ASSERT
42 #if defined(DEBUG)
44 #ifndef EXEC_TYPES_H
45 #include <exec/types.h>
46 #endif
48 #if defined(__amigaos4__)
49 #include <proto/exec.h>
50 #ifdef __USE_INLINE__
51 #ifdef DebugPrintF
52 #undef DebugPrintF
53 #endif
54 #endif
55 #ifndef kprintf
56 #define kprintf(format, args...) ((struct ExecIFace *)((*(struct ExecBase **)4)->MainInterface))->DebugPrintF(format, ## args)
57 #endif
58 #elif defined(__MORPHOS__)
59 #include <exec/rawfmt.h>
60 #include <proto/exec.h>
61 #define KPutFmt(format, args) VNewRawDoFmt(format, (APTR)RAWFMTFUNC_SERIAL, NULL, args)
62 void kprintf(const char *formatString,...);
63 #else
64 void kprintf(const char *formatString,...);
65 #endif
67 // debug classes
68 #define DBC_CTRACE (1<<0) // call tracing (ENTER/LEAVE etc.)
69 #define DBC_REPORT (1<<1) // reports (SHOWVALUE/SHOWSTRING etc.)
70 #define DBC_ASSERT (1<<2) // asserts (ASSERT)
71 #define DBC_TIMEVAL (1<<3) // time evaluations (STARTCLOCK/STOPCLOCK)
72 #define DBC_DEBUG (1<<4) // debugging output D()
73 #define DBC_ERROR (1<<5) // error output E()
74 #define DBC_WARNING (1<<6) // warning output W()
75 #define DBC_ALL 0xffffffff
77 // debug flags
78 #define DBF_ALWAYS (1<<0)
79 #define DBF_STARTUP (1<<1) // for startup/shutdown events
80 #define DBF_UTF (1<<2) // for the UTF conversion routines.
81 #define DBF_ALL 0xffffffff
83 void SetupDebug(void);
85 void _ENTER(unsigned long dclass, const char *file, int line, const char *function);
86 void _LEAVE(unsigned long dclass, const char *file, int line, const char *function);
87 void _RETURN(unsigned long dclass, const char *file, int line, const char *function, unsigned long result);
88 void _SHOWVALUE(unsigned long dclass, unsigned long dflags, unsigned long value, int size, const char *name, const char *file, int line);
89 void _SHOWPOINTER(unsigned long dclass, unsigned long dflags, const void *p, const char *name, const char *file, int line);
90 void _SHOWSTRING(unsigned long dclass, unsigned long dflags, const char *string, const char *name, const char *file, int line);
91 void _SHOWMSG(unsigned long dclass, unsigned long dflags, const char *msg, const char *file, int line);
92 void _DPRINTF(unsigned long dclass, unsigned long dflags, const char *file, int line, const char *format, ...);
94 // Core class information class messages
95 #define ENTER() _ENTER(DBC_CTRACE, __FILE__, __LINE__, __FUNCTION__)
96 #define LEAVE() _LEAVE(DBC_CTRACE, __FILE__, __LINE__, __FUNCTION__)
97 #define RETURN(r) _RETURN(DBC_CTRACE, __FILE__, __LINE__, __FUNCTION__, (long)r)
98 #define SHOWVALUE(f, v) _SHOWVALUE(DBC_REPORT, f, (long)v, sizeof(v), #v, __FILE__, __LINE__)
99 #define SHOWPOINTER(f, p) _SHOWPOINTER(DBC_REPORT, f, p, #p, __FILE__, __LINE__)
100 #define SHOWSTRING(f, s) _SHOWSTRING(DBC_REPORT, f, s, #s, __FILE__, __LINE__)
101 #define SHOWMSG(f, m) _SHOWMSG(DBC_REPORT, f, m, __FILE__, __LINE__)
102 #define D(f, s, vargs...) _DPRINTF(DBC_DEBUG, f, __FILE__, __LINE__, s, ## vargs)
103 #define E(f, s, vargs...) _DPRINTF(DBC_ERROR, f, __FILE__, __LINE__, s, ## vargs)
104 #define W(f, s, vargs...) _DPRINTF(DBC_WARNING, f, __FILE__, __LINE__, s, ## vargs)
105 #define ASSERT(expression) \
106 ((void) \
107 ((expression) ? 0 : \
109 _DPRINTF(DBC_ASSERT, \
110 DBF_ALWAYS, \
111 __FILE__, \
112 __LINE__, \
113 "failed assertion '%s'", \
114 #expression), \
115 abort(), \
121 #else // DEBUG
123 #define ENTER() ((void)0)
124 #define LEAVE() ((void)0)
125 #define RETURN(r) ((void)0)
126 #define SHOWVALUE(f, v) ((void)0)
127 #define SHOWPOINTER(f, p) ((void)0)
128 #define SHOWSTRING(f, s) ((void)0)
129 #define SHOWMSG(f, m) ((void)0)
130 #define D(f, s, vargs...) ((void)0)
131 #define E(f, s, vargs...) ((void)0)
132 #define W(f, s, vargs...) ((void)0)
133 #define ASSERT(expression) ((void)0)
135 #endif // DEBUG
137 #endif // DEBUG_H