]> icculus.org git repositories - btb/d2x.git/blob - include/error.h
sparc/sunos support: rename quad to quadint. courtesy of Martin Schaffner <maschaffne...
[btb/d2x.git] / include / error.h
1 /* $Id: error.h,v 1.6 2002-08-02 11:05:25 btb 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  * Header for error handling/printing/exiting code
17  *
18  * Old Log:
19  * Revision 1.12  1994/06/17  15:22:46  matt
20  * Added pragma for Error() for when NDEBUG
21  * 
22  * Revision 1.11  1994/03/07  13:22:14  matt
23  * Since the Error() function has 'aborts' set in pragma, we do a jmp
24  * to the function rather than call.
25  * 
26  * Revision 1.10  1994/02/17  12:37:15  matt
27  * Combined two pragma's for Error(), since second superseded the first
28  * 
29  * Revision 1.9  1994/02/10  18:02:53  matt
30  * Changed 'if DEBUG_ON' to 'ifndef NDEBUG'
31  * 
32  * Revision 1.8  1994/02/09  15:18:29  matt
33  * Added pragma saying that Error() never returns
34  * 
35  * Revision 1.7  1993/10/19  12:57:53  matt
36  * If DEBUG_ON not defined, define it to be 1
37  * 
38  * Revision 1.6  1993/10/15  21:40:39  matt
39  * Made error functions generate int3's if debugging on
40  * 
41  * Revision 1.5  1993/10/14  15:29:22  matt
42  * Added new function clear_warn_func()
43  * 
44  * Revision 1.4  1993/10/08  16:16:47  matt
45  * Made Assert() call function _Assert(), rather to do 'if...' inline.
46  * 
47  * Revision 1.3  1993/09/29  11:39:07  matt
48  * Added Assert() macro, like the system one, but calls Error()
49  * 
50  * Revision 1.2  1993/09/27  11:47:03  matt
51  * Added function set_warn_func()
52  * 
53  * Revision 1.1  1993/09/23  20:17:46  matt
54  * Initial revision
55  * 
56  *
57  */
58
59 #ifndef _ERROR_H
60 #define _ERROR_H
61
62 #include <stdio.h>
63
64 #ifdef __GNUC__
65 #define __noreturn __attribute__ ((noreturn))
66 #define __format __attribute__ ((format (printf, 1, 2)))
67 #else
68 #define __noreturn
69 #define __format
70 #endif
71
72 int error_init(char *fmt,...);                  //init error system, set default message, returns 0=ok
73 void set_exit_message(char *fmt,...);   //specify message to print at exit
74 void Warning(char *fmt,...);                            //print out warning message to user
75 void set_warn_func(void (*f)(char *s));//specifies the function to call with warning messages
76 void clear_warn_func(void (*f)(char *s));//say this function no longer valid
77 void _Assert(int expr,char *expr_text,char *filename,int linenum);      //assert func
78 void Error(char *fmt,...) __noreturn __format;                          //exit with error code=1, print message
79 void Assert(int expr);
80 void Int3();
81 #ifndef NDEBUG          //macros for debugging
82
83 #ifdef __GNUC__
84 #ifdef NO_ASM
85 //#define Int3() Error("int 3 %s:%i\n",__FILE__,__LINE__);
86 //#define Int3() {volatile int a=0,b=1/a;}
87 #define Int3() ((void)0)
88 #else
89 #ifdef SDL_INPUT
90 #include <SDL/SDL.h>
91 #endif
92 #include "args.h"
93 static inline void _Int3()
94 {
95         if (FindArg("-debug")) {
96 #ifdef SDL_INPUT
97                 SDL_WM_GrabInput(SDL_GRAB_OFF);
98 #endif
99                 asm("int $3");
100         }
101 }
102 #define Int3() _Int3()
103 #endif
104
105 #elif defined __WATCOMC__
106 void Int3(void);                                                                      //generate int3
107 #pragma aux Int3 = "int 3h";
108 #elif defined _MSC_VER
109 #define Int3() __asm { int 3 }
110 #else
111 #error Unknown Compiler!
112 #endif
113
114 #define Assert(expr) ((expr)?(void)0:(void)_Assert(0,#expr,__FILE__,__LINE__))
115
116 #ifdef __GNUC__
117 //#define Error(format, args...) ({ /*Int3();*/ Error(format , ## args); })
118 #elif defined __WATCOMC__
119 //make error do int3, then call func
120 #pragma aux Error aborts = \
121         "int    3"      \
122         "jmp Error";
123
124 //#pragma aux Error aborts;
125 #else
126 // DPH: I'm not going to bother... it's not needed... :-)
127 #endif
128
129 #ifdef __WATCOMC__
130 //make assert do int3 (if expr false), then call func
131 #pragma aux _Assert parm [eax] [edx] [ebx] [ecx] = \
132         "test eax,eax"          \
133         "jnz    no_int3"                \
134         "int    3"                              \
135         "no_int3:"                      \
136         "call _Assert";
137 #endif
138
139 #else                                   //macros for real game
140
141 #ifdef __WATCOMC__
142 #pragma aux Error aborts;
143 #endif
144 //Changed Assert and Int3 because I couldn't get the macros to compile -KRB
145 #define Assert(__ignore) ((void)0)
146 //void Assert(int expr);
147 #define Int3() ((void)0)
148 //void Int3();
149 #endif
150
151 #endif /* _ERROR_H */