Make (nearly all) argument values canonical by wrapping them in double
[AROS.git] / test / OOPDemos / include / debug.h
blobf01cd3e88ed3f40483c1d8d10acd3db1fa1bc44a
1 /*
2 Copyright © 1995-96, The AROS Development Team. All rights reserved.
3 Debugging macros.
5 This include file can be included several times !
6 */
8 #include <stdio.h>
10 extern int _SD_SpacesWritten;
12 #ifndef DEBUG
13 # define DEBUG 0
14 #endif
15 #ifndef SDEBUG
16 # define SDEBUG 0
17 #endif
20 /* Remove all macros. They get new values each time this file is
21 included */
22 #undef D
23 #undef DB2
24 #undef ReturnVoid
25 #undef ReturnPtr
26 #undef ReturnStr
27 #undef ReturnInt
28 #undef ReturnXInt
29 #undef ReturnFloat
30 #undef ReturnSpecial
31 #undef ReturnBool
33 /* Macros for "stair debugging" */
34 #undef SDInit
35 #undef EnterFunc
36 #undef Indent
37 #undef ExitFunc
39 #if SDEBUG
41 # ifndef SDEBUG_INDENT
42 # define SDEBUG_INDENT 2
43 # endif
45 /* This is some new macros for making debug output more readable,
46 ** by indenting for each functioncall made.
47 ** Usage: Call the SDInit() macro before anything else in your main().
48 ** Start the functions you want to debug with EnterFunc(bug("something"))
49 ** and ALWAYS match these with a Returnxxxx type macro
50 ** at the end of the func.
51 ** Inside the func you can use the normal D(bug()) macro.
52 **
53 ** To enable the macros, just add a #define SDEBUG 1
56 /* User macro */
57 #define EnterFunc(x) { \
58 int _written; \
59 for (_written = 0; _written < _SD_SpacesWritten; _written ++) printf(" "); \
60 _SD_SpacesWritten += SDEBUG_INDENT; } \
63 /* User macro. Add into start of your main() routine */
64 # define SDInit \
65 int _SD_SpacesWritten = 0
68 /* Internal */
69 # define Indent { \
71 int _written; \
72 for (_written = 0; _written < _SD_SpacesWritten; _written ++) printf(" "); }
74 /* Internal */
75 #define ExitFunc { \
76 int _written; \
77 _SD_SpacesWritten -= SDEBUG_INDENT; \
78 for (_written = 0; _written < _SD_SpacesWritten; _written ++) printf(" "); }
81 #else
83 # define SDInit
84 # define Indent
85 # define EnterFunc(x) D(x)
86 # define ExitFunc
88 #endif
90 #if DEBUG
91 # define D(x) Indent x
93 # if DEBUG > 1
94 # define DB2(x) x
95 # else
96 # define DB2(x) /* eps */
97 # endif
101 /* return-macros. NOTE: I make a copy of the value in __aros_val, because
102 the return-value might have side effects (like return x++;). */
103 # define ReturnVoid(name) { ExitFunc printf ("Exit " name "()\n"); return; }
104 # define ReturnPtr(name,type,val) { type __aros_val = (type)val; \
105 ExitFunc printf ("Exit " name "=%08lx\n", \
106 (ULONG)__aros_val); return __aros_val; }
107 # define ReturnStr(name,type,val) { type __aros_val = (type)val; \
108 ExitFunc printf ("Exit " name "=\"%s\"\n", \
109 __aros_val); return __aros_val; }
110 # define ReturnInt(name,type,val) { type __aros_val = (type)val; \
111 ExitFunc printf ("Exit " name "=%ld\n", \
112 (ULONG)__aros_val); return __aros_val; }
113 # define ReturnXInt(name,type,val) { type __aros_val = (type)val; \
114 ExitFunc printf ("Exit " name "=%lx\n", \
115 (ULONG)__aros_val); return __aros_val; }
116 # define ReturnFloat(name,type,val) { type __aros_val = (type)val; \
117 ExitFunc printf ("Exit " name "=%g\n", \
118 (ULONG)__aros_val); return __aros_val; }
119 # define ReturnSpecial(name,type,val,fmt) { type __aros_val = (type)val; \
120 ExitFunc printf ("Exit " name "=" fmt "\n", \
121 (ULONG)__aros_val); return __aros_val; }
122 # define ReturnBool(name,val) { BOOL __aros_val = (val != 0); \
123 ExitFunc printf ("Exit " name "=%s\n", \
124 __aros_val ? "TRUE" : "FALSE"); \
125 return __aros_val; }
126 #else /* !DEBUG */
127 # define D(x) /* eps */
128 # define DB2(x) /* eps */
130 # define ReturnVoid(name) return
131 # define ReturnPtr(name,type,val) return val
132 # define ReturnStr(name,type,val) return val
133 # define ReturnInt(name,type,val) return val
134 # define ReturnXInt(name,type,val) return val
135 # define ReturnFloat(name,type,val) return val
136 # define ReturnSpecial(name,type,val,fmt) return val
137 # define ReturnBool(name,val) return val
138 #endif /* DEBUG */
140 #ifndef DEBUG_H
141 #define DEBUG_H
143 #define bug printf
145 #endif /* DEBUG_H */