1 /* $Id: error.c,v 1.7 2004-08-28 23:17:45 schaffner Exp $ */
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.
16 * Error handling/printing/exiting code
25 static char rcsid[] = "$Id: error.c,v 1.7 2004-08-28 23:17:45 schaffner Exp $";
38 #define MAX_MSG_LEN 256
40 //edited 05/17/99 Matt Mueller added err_ prefix to prevent conflicts with statically linking SDL
41 int err_initialized=0;
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)
52 con_printf(CON_URGENT, "%s\n",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);
82 void _Assert(int expr,char *expr_text,char *filename,int linenum)
85 if (!(expr)) Error("Assertion failed: %s, file %s, line %d",expr_text,filename,linenum);
88 void print_exit_message(void)
94 (*ErrorPrintFunc)(exit_message);
98 #if (defined(MACINTOSH) && defined(NDEBUG) && defined(RELEASE))
101 ParamText(exit_message, "\p", "\p", "\p");
102 StopAlert(ERROR_ALERT, nil);
104 con_printf(CON_CRITICAL, "%s\n",exit_message);
110 //terminates with error code 1, printing message
111 void Error(char *fmt,...)
115 #if (defined(MACINTOSH) && defined(NDEBUG) && defined(RELEASE))
116 strcpy(exit_message,"Error: "); // don't put the new line in for dialog output
118 strcpy(exit_message,"\nError: ");
120 va_start(arglist,fmt);
121 vsprintf(exit_message+strlen(exit_message),fmt,arglist);
126 if (!err_initialized) print_exit_message();
131 //print out warning message to user
132 void Warning(char *fmt,...)
136 if (warn_func == NULL)
139 strcpy(warn_message,"Warning: ");
141 va_start(arglist,fmt);
142 vsprintf(warn_message+strlen(warn_message),fmt,arglist);
145 mprintf((0, "%s\n", warn_message));
146 (*warn_func)(warn_message);
150 //initialize error handling system, and set default message. returns 0=ok
151 int error_init(void (*func)(char *), char *fmt, ...)
156 atexit(print_exit_message); //last thing at exit is print message
158 ErrorPrintFunc = func; // Set Error Print Functions
161 va_start(arglist,fmt);
162 len = vsprintf(exit_message,fmt,arglist);
164 if (len==-1 || len>MAX_MSG_LEN) Error("Message too long in error_init (len=%d, max=%d)",len,MAX_MSG_LEN);