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.
14 #pragma off (unreferenced)
15 static char rcsid[] = "$Id: error.c,v 1.1.1.1 2001-01-19 03:30:15 bradleyb Exp $";
16 #pragma on (unreferenced)
19 #define WIN32_LEAN_AND_MEAN
40 #define MAX_MSG_LEN 256
44 static void (*ErrorPrintFunc)(char *);
46 char exit_message[MAX_MSG_LEN]="";
47 char warn_message[MAX_MSG_LEN];
49 //takes string in register, calls printf with string on stack
50 void warn_printf(char *s)
55 void (*warn_func)(char *s)=warn_printf;
57 //provides a function to call with warning messages
58 void set_warn_func(void (*f)(char *s))
63 //uninstall warning function - install default printf
64 void clear_warn_func(void (*f)(char *s))
66 warn_func = warn_printf;
69 void set_exit_message(char *fmt,...)
74 va_start(arglist,fmt);
75 len = vsprintf(exit_message,fmt,arglist);
78 if (len==-1 || len>MAX_MSG_LEN) Error("Message too long in set_exit_message (len=%d, max=%d)",len,MAX_MSG_LEN);
83 void _Assert(int expr, char *expr_text, char *filename, int linenum)
87 if (FindArg("-debugmode")) DebugBreak();
89 Error("Assertion failed: %s, file %s, line %d", expr_text, filename, linenum);
93 void _Assert(int expr,char *expr_text,char *filename,int linenum)
95 if (!(expr)) Error("Assertion failed: %s, file %s, line %d",expr_text,filename,linenum);
100 void print_exit_message()
106 (*ErrorPrintFunc)(exit_message);
110 #if (defined(MACINTOSH) && defined(NDEBUG) && defined(RELEASE))
112 c2pstr(exit_message);
114 ParamText(exit_message, "\p", "\p", "\p");
115 StopAlert(ERROR_ALERT, nil);
119 printf("%s\n",exit_message);
126 //terminates with error code 1, printing message
127 void Error(char *fmt,...)
131 #if (defined(MACINTOSH) && defined(NDEBUG) && defined(RELEASE))
132 strcpy(exit_message,"Error: "); // don't put the new line in for dialog output
134 strcpy(exit_message,"\nError: ");
136 va_start(arglist,fmt);
137 vsprintf(exit_message+strlen(exit_message),fmt,arglist);
142 if (!initialized) print_exit_message();
147 //print out warning message to user
148 void Warning(char *fmt,...)
152 if (warn_func == NULL)
155 strcpy(warn_message,"Warning: ");
157 va_start(arglist,fmt);
158 vsprintf(warn_message+strlen(warn_message),fmt,arglist);
161 mprintf((0, "%s\n", warn_message));
162 (*warn_func)(warn_message);
166 //initialize error handling system, and set default message. returns 0=ok
167 int error_init(void (*func)(char *), char *fmt,...)
172 atexit(print_exit_message); //last thing at exit is print message
174 ErrorPrintFunc = func; // Set Error Print Functions
177 va_start(arglist,fmt);
178 len = vsprintf(exit_message,fmt,arglist);
180 if (len==-1 || len>MAX_MSG_LEN) Error("Message too long in error_init (len=%d, max=%d)",len,MAX_MSG_LEN);
190 int MacEnableInt3 = 1;
192 void MacAssert(int expr, char *expr_text, char *filename, int linenum)
196 // Error("Assertion failed: %s, file %s, line %d", expr_text, filename, linenum);
204 int WinEnableInt3 = 1;