3 * Just like the old one, only nicer.
7 * © 1993-1998 Straylight
10 /*----- Licensing note ----------------------------------------------------*
12 * This file is part of Straylight's Steel library.
14 * Steel is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * Steel is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with Steel. If not, write to the Free Software Foundation,
26 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 #include "exception.h"
42 #include "calltrace.h"
50 #define werr__CANCEL 6
52 #define werr__BACKTRACE 7
54 static dbox werr__errorBox;
55 static BOOL werr__initialised;
58 * void werr_bleepy(void)
61 * Bleeps if and only if the appropriate WimpFlags bit is right for
65 void werr_bleepy(void)
67 int bleepy=_kernel_osbyte(161,197,0);
76 * void werr_init(void)
79 * Sets up the werr system ready for action.
84 char *title=template_syshandle("error")->title.indirecttext.buffer;
85 if (!win_anyWindows())
87 werr(FALSE,msgs_lookup("werrSEM:Could not initialise."));
90 sprintf(title,"Error from %s",wimpt_programname());
91 werr__errorBox=dbox_create("error");
92 werr__initialised=TRUE;
96 * wimp_icon *werr__idef(wimp_wind *w,wimp_i i)
99 * Vaguely similar to the dbox version, only different. Returns a pointer
100 * to the icon, at any rate.
103 * wimp_wind *w == the window definition.
104 * wimp_i i == the icon number
107 * Pointer to the icon definition.
110 static wimp_icon *werr__idef(wimp_wind *w,wimp_i i)
112 return ((wimp_icon *)(w+1)+i);
116 * int werr__wimpBox(char *string,int buttons)
119 * Displays a WIMP error box to show the specified message
122 * char *string == the error string to display
123 * int buttons == the number of buttons to display
126 static int werr__wimpBox(char *string,int buttons)
129 static BOOL threaded;
132 /* --- If we crashed in here before, abort damned quick --- */
136 _swi(Wimp_CommandWindow,_in(0),"Unrecoverable error");
138 "%s has suffered a fatal error and must quit.",
139 wimpt_programname());
143 /* --- Display the error message --- */
146 strcpy(err.errmess,string);
147 err.errnum=1; /* Stop new WindowManglers thinking this is serious :-/ */
151 f=wimp_EOK | wimp_ECANCEL;
152 f=_swi(Wimp_ReportError,_inr(0,2)+_return(1),&err,f,wimpt_programname());
155 return (f==2 ? 0 : 1);
159 * int werr__reportError(int buttons,char *error,va_list ap)
162 * Error reporting primitive. Called by all both the old and new werr()s.
165 * int buttons == how many buttons we need (1 or 2)
166 * char *error == a printf() type format string for the error text
167 * va_list ap == the variable arg list to use.
170 * 1 if OK clicked, 0 if Cancel clicked.
173 static int werr__reportError(int buttons,char *error,va_list ap)
178 wimp_icon *backtrace=(wimp_icon *)(-80);
185 /* --- Set up the dialogue box --- */
187 vsprintf(errString,error,ap);
188 if (werr__initialised==FALSE)
189 return (werr__wimpBox(errString,buttons));
191 /* --- Find all the definitions we need --- */
193 werr__initialised=FALSE; /* Use the WIMP box if this fails */
194 wind=template_syshandle("error");
195 hasBacktrace=(wind->nicons>=werr__BACKTRACE);
196 ok=werr__idef(wind,werr__OK);
197 cancel=werr__idef(wind,werr__CANCEL);
199 backtrace=werr__idef(wind,werr__BACKTRACE);
200 dbox_delete(werr__errorBox);
202 /* --- Zap any unwanted buttons --- */
206 cancel->flags&=~(1<<23);
207 cancelButt=werr__CANCEL;
210 cancel->flags|=(1<<23);
216 backtrace->flags&=~(1<<23);
217 backButt=werr__BACKTRACE;
220 backtrace->flags|=(1<<23);
223 /* --- Display the error box on the screen --- */
225 werr__errorBox=dbox_create("error");
227 return (werr__wimpBox(errString,buttons));
228 if (!dbox_hasTitle(werr__errorBox))
229 dbox_setEmbeddedTitle(werr__errorBox,werr__TITLE,FALSE);
230 dbox_setfield(werr__errorBox,werr__ERROR,"%s",errString);
232 /* --- Display backtraces for as long we're asked to --- */
237 clicked=nopoll_doDbox(werr__errorBox,
242 if (clicked==nopoll_OTHER)
245 while (clicked==nopoll_OTHER);
247 /* --- Return the result to the user --- */
249 werr__initialised=TRUE; /* Use fancy box for next error */
250 return (clicked==nopoll_OK);
254 * void werr(int fatal,char *error,...)
257 * Compatibility with the old werr segment mainly. If the error is fatal,
258 * a STEEL exception is generated, which eventually gets round to the
259 * error box handlers and dumps back out to top level.
262 * int fatal == 1 if the error is fatal, or 0 otherwise.
263 * char *error == printf()-type format string.
266 void werr(int fatal,char *error,...)
272 werr__reportError(1,error,ap);
278 vsprintf(buffer,error,ap);
280 exception_generate("%s",buffer);
285 * int werr_error(int buttons,char *error,...)
288 * Reports an error. You can have two buttons, OK and Cancel if you really
292 * int buttons == 1 for 1 button, 2 for 2 buttons, or anything else for an
293 * unpredictable result.
294 * char *error == printf()-like format string.
297 * 1 for OK, 0 for cancel.
300 int werr_error(int buttons,char *error,...)
305 clicked=werr__reportError(buttons,error,ap);