]> icculus.org git repositories - btb/d2x.git/blob - include/error.h
remove rcs tags
[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 /*
15  *
16  * Header for error handling/printing/exiting code
17  *
18  */
19
20 #ifndef _ERROR_H
21 #define _ERROR_H
22
23 #include <stdio.h>
24
25 #ifdef __GNUC__
26 #define __noreturn __attribute__ ((noreturn))
27 #define __format __attribute__ ((format (printf, 1, 2)))
28 #else
29 #define __noreturn
30 #define __format
31 #endif
32
33 int error_init(void (*func)(char *), char *fmt,...);    //init error system, set default message, returns 0=ok
34 void set_exit_message(char *fmt,...);   //specify message to print at exit
35 void Warning(char *fmt,...);                            //print out warning message to user
36 void set_warn_func(void (*f)(char *s));//specifies the function to call with warning messages
37 void clear_warn_func(void (*f)(char *s));//say this function no longer valid
38 void _Assert(int expr,char *expr_text,char *filename,int linenum);      //assert func
39 void Error(char *fmt,...) __noreturn __format;                          //exit with error code=1, print message
40 void Assert(int expr);
41 void Int3(void);
42
43 #ifndef NDEBUG          //macros for debugging
44
45 /* generate a debug break */
46 #if defined(__clang__)
47 #define Int3() __builtin_debugtrap()
48 #elif defined(__GNUC__) && (defined(__i386__) || defined(__amd64__))
49 #define Int3() ({ asm volatile ("int $3") })
50 #elif defined __WATCOMC__
51 #pragma aux Int3 = "int 3h";
52 #elif defined _MSC_VER
53 #define Int3() __debugbreak()
54 #elif defined(__APPLE__) || defined(macintosh)
55 #include <CoreServices/CoreServices.h>
56 #define Int3() Debugger()
57 #else
58 #error Debug break not defined for your compiler or platform.
59 #endif
60
61 #define Assert(expr) ((expr)?(void)0:(void)_Assert(0,#expr,__FILE__,__LINE__))
62
63 #ifdef __GNUC__
64 //#define Error(format, args...) ({ /*Int3();*/ Error(format , ## args); })
65 #elif defined __WATCOMC__
66 //make error do int3, then call func
67 #pragma aux Error aborts = \
68         "int    3"      \
69         "jmp Error";
70
71 //#pragma aux Error aborts;
72 #else
73 // DPH: I'm not going to bother... it's not needed... :-)
74 #endif
75
76 #ifdef __WATCOMC__
77 //make assert do int3 (if expr false), then call func
78 #pragma aux _Assert parm [eax] [edx] [ebx] [ecx] = \
79         "test eax,eax"          \
80         "jnz    no_int3"                \
81         "int    3"                              \
82         "no_int3:"                      \
83         "call _Assert";
84 #endif
85
86 #else                                   //macros for real game
87
88 #ifdef __WATCOMC__
89 #pragma aux Error aborts;
90 #endif
91 //Changed Assert and Int3 because I couldn't get the macros to compile -KRB
92 #define Assert(__ignore) ((void)0)
93 //void Assert(int expr);
94 #define Int3() ((void)0)
95 //void Int3();
96 #endif
97
98 #endif /* _ERROR_H */