]> icculus.org git repositories - btb/d2x.git/blob - unused/win95/error.c
use the orientation parameter of g3_draw_bitmap
[btb/d2x.git] / unused / win95 / error.c
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-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 #if defined(__NT__)
15 #define WIN32_LEAN_AND_MEAN
16 #include <windows.h>
17 #endif
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <stdarg.h>
22 #include <string.h>
23
24 #include "mono.h"
25 #include "dxxerror.h"
26 #include "args.h"
27
28 #ifdef MACINTOSH
29         #include <Types.h>
30         #include <Strings.h>
31         #include <LowMem.h>
32         
33         #include "resource.h"
34 #endif
35
36 #define MAX_MSG_LEN 256
37
38 int initialized=0;
39
40 static void (*ErrorPrintFunc)(char *);
41
42 char exit_message[MAX_MSG_LEN]="";
43 char warn_message[MAX_MSG_LEN];
44
45 //takes string in register, calls printf with string on stack
46 void warn_printf(char *s)
47 {
48         printf("%s\n",s);
49 }
50
51 void (*warn_func)(char *s)=warn_printf;
52
53 //provides a function to call with warning messages
54 void set_warn_func(void (*f)(char *s))
55 {
56         warn_func = f;
57 }
58
59 //uninstall warning function - install default printf
60 void clear_warn_func(void (*f)(char *s))
61 {
62         warn_func = warn_printf;
63 }
64
65 void set_exit_message(char *fmt,...)
66 {
67         va_list arglist;
68         int len;
69
70         va_start(arglist,fmt);
71         len = vsprintf(exit_message,fmt,arglist);
72         va_end(arglist);
73
74         if (len==-1 || len>MAX_MSG_LEN) Error("Message too long in set_exit_message (len=%d, max=%d)",len,MAX_MSG_LEN);
75
76 }
77
78 #ifdef __NT__
79 void _Assert(int expr, char *expr_text, char *filename, int linenum)
80 {
81         if (!(expr)) {
82         #ifndef NDEBUG
83                 if (FindArg("-debugmode")) DebugBreak();
84         #endif
85                 Error("Assertion failed: %s, file %s, line %d", expr_text, filename, linenum);
86         }
87 }
88 #else
89 void _Assert(int expr,char *expr_text,char *filename,int linenum)
90 {
91         if (!(expr)) Error("Assertion failed: %s, file %s, line %d",expr_text,filename,linenum);
92
93 }
94 #endif
95
96 void print_exit_message()
97 {
98         if (*exit_message)
99         {
100                 if (ErrorPrintFunc)
101                 {
102                         (*ErrorPrintFunc)(exit_message);
103                 }
104                 else
105                 {
106                         #if (defined(MACINTOSH) && defined(NDEBUG) && defined(RELEASE))
107                                 
108                                 c2pstr(exit_message);
109                                 ShowCursor();
110                                 ParamText(exit_message, "\p", "\p", "\p");
111                                 StopAlert(ERROR_ALERT, nil);
112                                 
113                         #else
114                                 
115                                 printf("%s\n",exit_message);
116                         
117                         #endif
118                 }
119         }
120 }
121
122 //terminates with error code 1, printing message
123 void Error(char *fmt,...)
124 {
125         va_list arglist;
126
127         #if (defined(MACINTOSH) && defined(NDEBUG) && defined(RELEASE))
128                 strcpy(exit_message,"Error: ");         // don't put the new line in for dialog output
129         #else
130                 strcpy(exit_message,"\nError: ");
131         #endif
132         va_start(arglist,fmt);
133         vsprintf(exit_message+strlen(exit_message),fmt,arglist);
134         va_end(arglist);
135
136         Int3();
137
138         if (!initialized) print_exit_message();
139
140         exit(1);
141 }
142
143 //print out warning message to user
144 void Warning(char *fmt,...)
145 {
146         va_list arglist;
147
148         if (warn_func == NULL)
149                 return;
150
151         strcpy(warn_message,"Warning: ");
152
153         va_start(arglist,fmt);
154         vsprintf(warn_message+strlen(warn_message),fmt,arglist);
155         va_end(arglist);
156
157         mprintf((0, "%s\n", warn_message));
158         (*warn_func)(warn_message);
159
160 }
161
162 //initialize error handling system, and set default message. returns 0=ok
163 int error_init(void (*func)(char *), char *fmt,...)
164 {
165         va_list arglist;
166         int len;
167
168         atexit(print_exit_message);             //last thing at exit is print message
169
170         ErrorPrintFunc = func;                          // Set Error Print Functions
171
172         if (fmt != NULL) {
173                 va_start(arglist,fmt);
174                 len = vsprintf(exit_message,fmt,arglist);
175                 va_end(arglist);
176                 if (len==-1 || len>MAX_MSG_LEN) Error("Message too long in error_init (len=%d, max=%d)",len,MAX_MSG_LEN);
177         }
178
179         initialized=1;
180
181         return 0;
182 }
183
184 #ifdef MACINTOSH
185
186 int MacEnableInt3 = 1;
187
188 void MacAssert(int expr, char *expr_text, char *filename, int linenum)
189 {
190         if (!(expr)) {
191                 Int3();
192 //              Error("Assertion failed: %s, file %s, line %d", expr_text, filename, linenum);
193         }
194 }
195
196 #endif
197
198 #if defined(__NT__)
199
200 int WinEnableInt3 = 1;
201
202 void WinInt3()
203 {
204         if (WinEnableInt3) 
205                 DebugBreak();
206 }
207 #endif