]> icculus.org git repositories - btb/d2x.git/blob - include/error.h
on Mac OS 9 and X, define Int3 to be a Debugger
[btb/d2x.git] / include / error.h
1 /* $Id: error.h,v 1.11 2004-08-06 21:28:27 schaffner Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 /*
16  *
17  * Header for error handling/printing/exiting code
18  *
19  * Old Log:
20  * Revision 1.12  1994/06/17  15:22:46  matt
21  * Added pragma for Error() for when NDEBUG
22  *
23  * Revision 1.11  1994/03/07  13:22:14  matt
24  * Since the Error() function has 'aborts' set in pragma, we do a jmp
25  * to the function rather than call.
26  *
27  * Revision 1.10  1994/02/17  12:37:15  matt
28  * Combined two pragma's for Error(), since second superseded the first
29  *
30  * Revision 1.9  1994/02/10  18:02:53  matt
31  * Changed 'if DEBUG_ON' to 'ifndef NDEBUG'
32  *
33  * Revision 1.8  1994/02/09  15:18:29  matt
34  * Added pragma saying that Error() never returns
35  *
36  * Revision 1.7  1993/10/19  12:57:53  matt
37  * If DEBUG_ON not defined, define it to be 1
38  *
39  * Revision 1.6  1993/10/15  21:40:39  matt
40  * Made error functions generate int3's if debugging on
41  *
42  * Revision 1.5  1993/10/14  15:29:22  matt
43  * Added new function clear_warn_func()
44  *
45  * Revision 1.4  1993/10/08  16:16:47  matt
46  * Made Assert() call function _Assert(), rather to do 'if...' inline.
47  *
48  * Revision 1.3  1993/09/29  11:39:07  matt
49  * Added Assert() macro, like the system one, but calls Error()
50  *
51  * Revision 1.2  1993/09/27  11:47:03  matt
52  * Added function set_warn_func()
53  *
54  * Revision 1.1  1993/09/23  20:17:46  matt
55  * Initial revision
56  *
57  *
58  */
59
60 #ifndef _ERROR_H
61 #define _ERROR_H
62
63 #include <stdio.h>
64
65 #ifdef __GNUC__
66 #define __noreturn __attribute__ ((noreturn))
67 #define __format __attribute__ ((format (printf, 1, 2)))
68 #else
69 #define __noreturn
70 #define __format
71 #endif
72
73 int error_init(void (*func)(char *), char *fmt,...);    //init error system, set default message, returns 0=ok
74 void set_exit_message(char *fmt,...);   //specify message to print at exit
75 void Warning(char *fmt,...);                            //print out warning message to user
76 void set_warn_func(void (*f)(char *s));//specifies the function to call with warning messages
77 void clear_warn_func(void (*f)(char *s));//say this function no longer valid
78 void _Assert(int expr,char *expr_text,char *filename,int linenum);      //assert func
79 void Error(char *fmt,...) __noreturn __format;                          //exit with error code=1, print message
80 void Assert(int expr);
81 void Int3();
82 #ifndef NDEBUG          //macros for debugging
83
84 #ifdef NO_ASM
85 # if defined(__APPLE__) || defined(macintosh)
86 extern void Debugger(void);     // Avoids some name clashes
87 #  define Int3 Debugger
88 # else
89 //# define Int3() Error("int 3 %s:%i\n",__FILE__,__LINE__);
90 //# define Int3() {volatile int a=0,b=1/a;}
91 #  define Int3() ((void)0)
92 # endif // Macintosh
93
94 #else // NO_ASM
95
96 #ifdef __GNUC__
97 #ifdef SDL_INPUT
98 #include <SDL.h>
99 #endif
100 #include "args.h"
101 static inline void _Int3()
102 {
103         if (FindArg("-debug")) {
104 #ifdef SDL_INPUT
105                 SDL_WM_GrabInput(SDL_GRAB_OFF);
106 #endif
107                 asm("int $3");
108         }
109 }
110 #define Int3() _Int3()
111
112 #elif defined __WATCOMC__
113 void Int3(void);                                                                      //generate int3
114 #pragma aux Int3 = "int 3h";
115
116 #elif defined _MSC_VER
117 static __inline void _Int3()
118 {
119         __asm { int 3 }
120 }
121 #define Int3() _Int3()
122
123 #else
124 #error Unknown Compiler!
125 #endif
126
127 #endif // NO_ASM
128
129 #define Assert(expr) ((expr)?(void)0:(void)_Assert(0,#expr,__FILE__,__LINE__))
130
131 #ifdef __GNUC__
132 //#define Error(format, args...) ({ /*Int3();*/ Error(format , ## args); })
133 #elif defined __WATCOMC__
134 //make error do int3, then call func
135 #pragma aux Error aborts = \
136         "int    3"      \
137         "jmp Error";
138
139 //#pragma aux Error aborts;
140 #else
141 // DPH: I'm not going to bother... it's not needed... :-)
142 #endif
143
144 #ifdef __WATCOMC__
145 //make assert do int3 (if expr false), then call func
146 #pragma aux _Assert parm [eax] [edx] [ebx] [ecx] = \
147         "test eax,eax"          \
148         "jnz    no_int3"                \
149         "int    3"                              \
150         "no_int3:"                      \
151         "call _Assert";
152 #endif
153
154 #else                                   //macros for real game
155
156 #ifdef __WATCOMC__
157 #pragma aux Error aborts;
158 #endif
159 //Changed Assert and Int3 because I couldn't get the macros to compile -KRB
160 #define Assert(__ignore) ((void)0)
161 //void Assert(int expr);
162 #define Int3() ((void)0)
163 //void Int3();
164 #endif
165
166 #endif /* _ERROR_H */