Version:
~ [ 10.0 ] ~
** Warning: Cannot open xref database.
1
2 /* $Id: error.c,v 1.4 2005/01/11 22:48:05 andreradke Exp $ */
3
4 /******************************************************************************
5
6 UserLand Frontier(tm) -- High performance Web content management,
7 object database, system-level and Internet scripting environment,
8 including source code editing and debugging.
9
10 Copyright (C) 1992-2004 UserLand Software, Inc.
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
26 ******************************************************************************/
27
28 #include "frontier.h"
29 #include "standard.h"
30
31 #include "memory.h"
32 #include "strings.h"
33 #include "dialogs.h"
34 #include "ops.h"
35 #include "resources.h"
36 #include "shell.h"
37 #include "shellhooks.h"
38 #include "error.h"
39
40
41 #ifdef WIN95VERSION
42 #define memFullErr -20000
43 #define userCanceledErr -20001
44 #endif
45
46 #define systemerrorlist 258
47
48 #define ctsystemerrors 92
49
50
51 struct {
52
53 short errornumber; /*an error result passed back by a Mac system routine*/
54
55 /***short errorindex; #*index into the STR# resource for the appropriate message*/
56 }
57
58 #ifdef MACVERSION
59
60 systemerrortable [ctsystemerrors] = {
61
62 {-33}, //dirFulErr
63 {-34}, //dskFulErr
64 {-35}, //nsvErr
65 {-36}, //ioErr
66 {-37}, //bdNamErr
67 {-38}, //fnOpnErr
68 {-39}, //eofErr
69 {-40}, //posErr
70 {-41}, //mFulErr
71 {-42}, //tmfoErr
72 {-43}, //fnfErr
73 {-44}, //wPrErr
74 {-45}, //fLckdErr
75 {-46}, //vLckdErr
76 {-47}, //fBsyErr
77 {-48}, //dupFNErr
78 {-49}, //opWrErr
79 {-50},
80 {-51}, //rfNumErr
81 {-52}, //gfpErr
82 {-53}, //volOffLinErr
83 {-54}, //permErr
84 {-55}, //volOnLinErr
85 {-56}, //nsDrvErr
86 {-57}, //noMacDskErr
87 {-58}, //extFSErr
88 {-59}, //fsRnErr
89 {-60}, //badMDBErr
90 {-61}, //wrPermErr
91 {-64}, //noDriveErr
92 {-65}, //offLinErr
93 {-66}, //noNybErr
94 {-67}, //noAdrMkErr
95 {-68}, //dataVerErr
96 {-69}, //badCksmErr
97 {-70}, //badBtSlpErr
98 {-71}, //noDtaMkErr
99 {-72}, //badDCksum
100 {-73},
101 {-74},
102 {-75},
103 {-76},
104 {-77},
105 {-78},
106 {-79},
107 {-80},
108 {-81},
109 {-120}, //dirNFErr
110 {-121},
111 {-122}, //badMovErr
112 {-123}, //wrgVolTypErr
113 {-192}, //resNotFound
114 {-193}, //resFNotFound
115 {-194}, //addResFailed
116 {-196}, //rmvResFailed
117 {-198}, //resAttrErr
118 {-199}, //mapReadErr
119 {-100},
120 {-102},
121 {-108}, //memFullErr
122 {-109}, //nilHandleErr
123 {-111},
124 {-112},
125 {-117},
126 {-1703},
127 {-1719},
128 {-1704},
129 {-1705},
130 {-1708},
131 {-1712},
132 {-1711},
133 {-906},
134 {-1700},
135 {-1701},
136 {-1723},
137 {-1728},
138 {-5000},
139 {-5016},
140 {-5019},
141 {-5023},
142 {-5063},
143 {-10000},
144 {-10007},
145 {-10011},
146 {-10003},
147 {-10014},
148
149 {errAENewerVersion},
150 {errOSAScriptError},
151 {errAECantHandleClass},
152 {connectionInvalid},
153 {noUserInteractionAllowed},
154 {errOSASourceNotAvailable}
155
156 }; /*systemerrortable*/
157
158 #endif
159
160 #ifdef WIN95VERSION
161
162 systemerrortable [ctsystemerrors] = {
163
164 {-33}, //dirFulErr
165 {-34}, //dskFulErr
166 {-35}, //nsvErr
167 {-36}, //ioErr
168 {-37}, //bdNamErr
169 {-38}, //fnOpnErr
170 {-39}, //eofErr
171 {-40}, //posErr
172 {-41}, //mFulErr
173 {ERROR_TOO_MANY_OPEN_FILES}, //tmfoErr
174 {ERROR_FILE_NOT_FOUND}, //fnfErr
175 {-44}, //wPrErr
176 {-45}, //fLckdErr
177 {-46}, //vLckdErr
178 {ERROR_SHARING_VIOLATION}, //fBsyErr
179 {-48}, //dupFNErr
180 {-49}, //opWrErr
181 {-50},
182 {-51}, //rfNumErr
183 {-52}, //gfpErr
184 {-53}, //volOffLinErr
185 {-54}, //permErr
186 {-55}, //volOnLinErr
187 {-56}, //nsDrvErr
188 {-57}, //noMacDskErr
189 {-58}, //extFSErr
190 {-59}, //fsRnErr
191 {-60}, //badMDBErr
192 {-61}, //wrPermErr
193 {-64}, //noDriveErr
194 {-65}, //offLinErr
195 {-66}, //noNybErr
196 {-67}, //noAdrMkErr
197 {-68}, //dataVerErr
198 {-69}, //badCksmErr
199 {-70}, //badBtSlpErr
200 {-71}, //noDtaMkErr
201 {-72}, //badDCksum
202 {-73},
203 {-74},
204 {-75},
205 {-76},
206 {-77},
207 {-78},
208 {-79},
209 {-80},
210 {-81},
211 {ERROR_PATH_NOT_FOUND}, //dirNFErr
212 {-121},
213 {-122}, //badMovErr
214 {-123}, //wrgVolTypErr
215 {-192}, //resNotFound
216 {-193}, //resFNotFound
217 {-194}, //addResFailed
218 {-196}, //rmvResFailed
219 {-198}, //resAttrErr
220 {-199}, //mapReadErr
221 {-100},
222 {-102},
223 {ERROR_OUTOFMEMORY}, //memFullErr
224 {-109}, //nilHandleErr
225 {-111},
226 {-112},
227 {-117},
228 {-1703},
229 {-1719},
230 {-1704},
231 {-1705},
232 {-1708},
233 {-1712},
234 {-1711},
235 {-906},
236 {-1700},
237 {-1701},
238 {-1723},
239 {-1728},
240 {ERROR_ACCESS_DENIED},
241 {-5016},
242 {-5019},
243 {-5023},
244 {-5063},
245 {-10000},
246 {-10007},
247 {-10011},
248 {-10003},
249 {-10014},
250
251 }; /*systemerrortable*/
252
253 #endif
254
255 #define unknownsystemerror ctsystemerrors + 1
256
257 #define errorcushionsize 0x1800 /*6K*/
258
259 static Handle herrorcushion = nil; /*a buffer to allow memory error reporting*/
260
261 static OSErr lasterror = noErr;
262
263 /*
264 static bigstring lasterrormessage = "";
265 */
266
267
268 boolean setoserrorparam (bigstring bs) {
269
270 return (setparseparams (bs, nil, nil, nil));
271 } /*setoserrorparam*/
272
273
274 OSErr getoserror (void) {
275
276 return (lasterror);
277 } /*getoserror*/
278
279 /*
280 void getoserrormessage (bigstring bs) {
281
282 copystring (lasterrormessage, bs);
283 } #*getoserrormessage*/
284
285
286 boolean getsystemerrorstring (OSErr errcode, bigstring bs) {
287
288 /*
289 errcode is a result code returned by a Macintosh system routine.
290
291 we search the systemerrortable to see if we have a string for the
292 error, if so we load the string from the resource file and return
293 true.
294
295 10/28/91 dmb: return false any time we don't find a specific error string
296 */
297
298 register short i;
299 register short errnum = errcode;
300 bigstring bsos;
301
302 for (i = 0; i < ctsystemerrors; i++)
303
304 if (systemerrortable [i].errornumber == errnum) {
305
306 getstringlist (systemerrorlist, i + 1, bs);
307
308 return (!isemptystring (bs));
309 }
310
311 getstringlist (systemerrorlist, unknownsystemerror, bs); /*loop satisfied, no message for this error*/
312
313 if (isemptystring (bs))
314 return (false);
315
316 #ifdef MACVERSION
317 shorttostring (errcode, bsos);
318 #endif
319
320 #ifdef WIN95VERSION
321 if (getwinerrormessage (errcode, bsos)) {
322
323 firstword (bsos, '.', bsos); //skip the cr
324 }
325 else {
326
327 /* THe format failed, therefore we have no further info */
328 wsprintf (stringbaseaddress(bsos), "error number %ld." , errcode);
329
330 setstringlength (bsos, strlen (stringbaseaddress(bsos)));
331 }
332 #endif
333
334 parsedialogstring (bs, bsos, nil, nil, nil, bs);
335
336 return (true);
337 } /*getsystemerrorstring*/
338
339
340 static boolean getsafetycushion (void) {
341
342 if (herrorcushion == nil)
343 herrorcushion = NewHandle (errorcushionsize);
344
345 return (herrorcushion != nil);
346 } /*getsafetycushion*/
347
348
349 boolean memoryerror (void) {
350
351 /*
352 returns true if there was a memory error, detected by calling the Mac
353 routine MemError.
354
355 wired off because we need a fancier solution, when we're out of memory,
356 there's no room in the heap for a dialog box! must pre-allocate this
357 one...
358
359 1/31/91 dmb: we'll deal with the heap space problem by using herrorcushion.
360 CouldDialog is also used to ensure that the resources are already in memory.
361
362 3/4/91 dmb: now always generate an error message, and always return true
363 */
364
365 register OSErr errcode = MemError ();
366 bigstring bs;
367 #ifdef WIN95VERSION
368 long ctbytes = longinfinity;
369
370 shellcallmemoryhooks (&ctbytes);
371 #endif
372
373 if (errcode == noErr) /*specific error code has been overwritten*/
374 errcode = memFullErr;
375
376 DisposeHandle (herrorcushion); /*make room*/
377
378 herrorcushion = nil;
379
380 getsystemerrorstring (errcode, bs);
381
382 lasterror = errcode;
383
384 /*
385 copystring (bs, lasterrormessage);
386 */
387
388 shellerrormessage (bs);
389
390 getsafetycushion (); /*hopefully, we should be able to get it back now*/
391
392 return (true);
393 } /*memoryerror*/
394
395
396 boolean oserror (OSErr errcode) {
397
398 /*
399 return true if there is a Macintosh OS error, false otherwise.
400
401 we display a text string explaining any errors we find.
402
403 1/31/91 dmb: now call shellerrormessage instead of alertdialog
404
405 2.1b5: don't post a message for user cancelled
406 */
407
408 register OSErr x = errcode;
409 bigstring bs;
410
411 lasterror = x;
412
413 if (x == noErr) /*there wasn't an error*/
414 return (false);
415
416 if (x != userCanceledErr) {
417
418 getsystemerrorstring (x, bs);
419
420 if (isemptystring (bs)) { /*resource missing*/
421
422 copystring ((ptrstring) STR_Mac_OS_Error, bs); /*create error string*/
423
424 pushint (x, bs);
425 }
426
427 parseparamstring (bs);
428
429 /*
430 copystring (bs, lasterrormessage);
431 */
432
433 shellerrormessage (bs);
434 }
435
436 setparseparams (nil, nil, nil, nil);
437
438 return (true); /*there was an error*/
439 } /*oserror*/
440
441
442 #ifdef WIN95VERSION
443
444 boolean winerror (void) {
445
446 /*
447 5.0.1 dmb: the callerk has already detected an error. we're
448 just reporting it.
449 */
450
451 oserror (GetLastError ());
452
453 return (true);
454 } /*winerror*/
455
456
457 boolean getwinerrormessage (OSErr err, bigstring bserr) {
458
459 LPVOID lpMsgBuf;
460
461 if (FormatMessage(
462 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
463 NULL,
464 err,
465 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
466 (LPTSTR) &lpMsgBuf,
467 0,
468 NULL) == 0) {
469
470 setemptystring (bserr);
471
472 return (false);
473 }
474
475 strcpy (stringbaseaddress (bserr), lpMsgBuf);
476
477 setstringlength (bserr, strlen(lpMsgBuf));
478
479 LocalFree (lpMsgBuf);
480
481 return (true);
482 } /*getwinerrormessage*/
483
484 #endif
485
486
487 boolean initerror (void) {
488
489 return (getsafetycushion ());
490 } /*initerror*/
491
492
493
494
495
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.