]> icculus.org git repositories - btb/d2x.git/blob - include/error.h
add level component saving functions which use PhysicsFS (didn't commit properly...
[btb/d2x.git] / include / error.h
1 /* $Id: error.h,v 1.12 2004-08-28 23:17:45 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  */
20
21 #ifndef _ERROR_H
22 #define _ERROR_H
23
24 #include <stdio.h>
25
26 #ifdef __GNUC__
27 #define __noreturn __attribute__ ((noreturn))
28 #define __format __attribute__ ((format (printf, 1, 2)))
29 #else
30 #define __noreturn
31 #define __format
32 #endif
33
34 int error_init(void (*func)(char *), char *fmt,...);    //init error system, set default message, returns 0=ok
35 void set_exit_message(char *fmt,...);   //specify message to print at exit
36 void Warning(char *fmt,...);                            //print out warning message to user
37 void set_warn_func(void (*f)(char *s));//specifies the function to call with warning messages
38 void clear_warn_func(void (*f)(char *s));//say this function no longer valid
39 void _Assert(int expr,char *expr_text,char *filename,int linenum);      //assert func
40 void Error(char *fmt,...) __noreturn __format;                          //exit with error code=1, print message
41 void Assert(int expr);
42 void Int3();
43 #ifndef NDEBUG          //macros for debugging
44
45 #ifdef NO_ASM
46 # if defined(__APPLE__) || defined(macintosh)
47 extern void Debugger(void);     // Avoids some name clashes
48 #  define Int3 Debugger
49 # else
50 //# define Int3() Error("int 3 %s:%i\n",__FILE__,__LINE__);
51 //# define Int3() {volatile int a=0,b=1/a;}
52 #  define Int3() ((void)0)
53 # endif // Macintosh
54
55 #else // NO_ASM
56
57 #ifdef __GNUC__
58 #ifdef SDL_INPUT
59 #include <SDL.h>
60 #endif
61 #include "args.h"
62 static inline void _Int3()
63 {
64         if (FindArg("-debug")) {
65 #ifdef SDL_INPUT
66                 SDL_WM_GrabInput(SDL_GRAB_OFF);
67 #endif
68                 asm("int $3");
69         }
70 }
71 #define Int3() _Int3()
72
73 #elif defined __WATCOMC__
74 void Int3(void);                                                                      //generate int3
75 #pragma aux Int3 = "int 3h";
76
77 #elif defined _MSC_VER
78 static __inline void _Int3()
79 {
80         __asm { int 3 }
81 }
82 #define Int3() _Int3()
83
84 #else
85 #error Unknown Compiler!
86 #endif
87
88 #endif // NO_ASM
89
90 #define Assert(expr) ((expr)?(void)0:(void)_Assert(0,#expr,__FILE__,__LINE__))
91
92 #ifdef __GNUC__
93 //#define Error(format, args...) ({ /*Int3();*/ Error(format , ## args); })
94 #elif defined __WATCOMC__
95 //make error do int3, then call func
96 #pragma aux Error aborts = \
97         "int    3"      \
98         "jmp Error";
99
100 //#pragma aux Error aborts;
101 #else
102 // DPH: I'm not going to bother... it's not needed... :-)
103 #endif
104
105 #ifdef __WATCOMC__
106 //make assert do int3 (if expr false), then call func
107 #pragma aux _Assert parm [eax] [edx] [ebx] [ecx] = \
108         "test eax,eax"          \
109         "jnz    no_int3"                \
110         "int    3"                              \
111         "no_int3:"                      \
112         "call _Assert";
113 #endif
114
115 #else                                   //macros for real game
116
117 #ifdef __WATCOMC__
118 #pragma aux Error aborts;
119 #endif
120 //Changed Assert and Int3 because I couldn't get the macros to compile -KRB
121 #define Assert(__ignore) ((void)0)
122 //void Assert(int expr);
123 #define Int3() ((void)0)
124 //void Int3();
125 #endif
126
127 #endif /* _ERROR_H */