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