error.c

Go to the documentation of this file.
00001 
00002 /*  $Id: error.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /******************************************************************************
00005 
00006     UserLand Frontier(tm) -- High performance Web content management,
00007     object database, system-level and Internet scripting environment,
00008     including source code editing and debugging.
00009 
00010     Copyright (C) 1992-2004 UserLand Software, Inc.
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; if not, write to the Free Software
00024     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 
00026 ******************************************************************************/
00027 
00028 #include "frontier.h"
00029 #include "standard.h"
00030 
00031 #include "memory.h"
00032 #include "strings.h"
00033 #include "dialogs.h"
00034 #include "ops.h"
00035 #include "resources.h"
00036 #include "shell.h"
00037 #include "shellhooks.h"
00038 #include "error.h"
00039 
00040 
00041 #ifdef WIN95VERSION
00042     #define memFullErr -20000
00043     #define userCanceledErr -20001
00044 #endif
00045 
00046 #define systemerrorlist 258 
00047 
00048 #define ctsystemerrors 92
00049 
00050 
00051 struct {
00052 
00053     short errornumber; /*an error result passed back by a Mac system routine*/
00054     
00055     /***short errorindex; #*index into the STR# resource for the appropriate message*/
00056     }
00057 
00058 #ifdef MACVERSION
00059 
00060 systemerrortable [ctsystemerrors] = {
00061     
00062     {-33},  //dirFulErr
00063     {-34},  //dskFulErr
00064     {-35},  //nsvErr
00065     {-36},  //ioErr
00066     {-37},  //bdNamErr
00067     {-38},  //fnOpnErr
00068     {-39},  //eofErr
00069     {-40},  //posErr
00070     {-41},  //mFulErr
00071     {-42},  //tmfoErr
00072     {-43},  //fnfErr
00073     {-44},  //wPrErr
00074     {-45},  //fLckdErr
00075     {-46},  //vLckdErr
00076     {-47},  //fBsyErr
00077     {-48},  //dupFNErr
00078     {-49},  //opWrErr
00079     {-50},
00080     {-51},  //rfNumErr
00081     {-52},  //gfpErr
00082     {-53},  //volOffLinErr
00083     {-54},  //permErr
00084     {-55},  //volOnLinErr
00085     {-56},  //nsDrvErr
00086     {-57},  //noMacDskErr
00087     {-58},  //extFSErr
00088     {-59},  //fsRnErr
00089     {-60},  //badMDBErr
00090     {-61},  //wrPermErr
00091     {-64},  //noDriveErr
00092     {-65},  //offLinErr
00093     {-66},  //noNybErr
00094     {-67},  //noAdrMkErr
00095     {-68},  //dataVerErr
00096     {-69},  //badCksmErr
00097     {-70},  //badBtSlpErr
00098     {-71},  //noDtaMkErr
00099     {-72},  //badDCksum
00100     {-73},
00101     {-74},
00102     {-75},
00103     {-76},
00104     {-77},
00105     {-78},
00106     {-79},
00107     {-80},
00108     {-81},
00109     {-120}, //dirNFErr
00110     {-121},
00111     {-122}, //badMovErr
00112     {-123}, //wrgVolTypErr
00113     {-192}, //resNotFound
00114     {-193}, //resFNotFound
00115     {-194}, //addResFailed
00116     {-196}, //rmvResFailed
00117     {-198}, //resAttrErr
00118     {-199}, //mapReadErr
00119     {-100},
00120     {-102},
00121     {-108}, //memFullErr
00122     {-109}, //nilHandleErr
00123     {-111},
00124     {-112},
00125     {-117},
00126     {-1703},
00127     {-1719},
00128     {-1704},
00129     {-1705},
00130     {-1708},
00131     {-1712},
00132     {-1711},
00133     {-906},
00134     {-1700},
00135     {-1701},
00136     {-1723},
00137     {-1728},
00138     {-5000},
00139     {-5016},
00140     {-5019},
00141     {-5023},
00142     {-5063},
00143     {-10000},
00144     {-10007},
00145     {-10011},
00146     {-10003},
00147     {-10014},
00148 
00149     {errAENewerVersion},
00150     {errOSAScriptError},
00151     {errAECantHandleClass},
00152     {connectionInvalid},
00153     {noUserInteractionAllowed},
00154     {errOSASourceNotAvailable}
00155     
00156     }; /*systemerrortable*/
00157 
00158 #endif
00159 
00160 #ifdef WIN95VERSION
00161 
00162 systemerrortable [ctsystemerrors] = {
00163     
00164     {-33},  //dirFulErr
00165     {-34},  //dskFulErr
00166     {-35},  //nsvErr
00167     {-36},  //ioErr
00168     {-37},  //bdNamErr
00169     {-38},  //fnOpnErr
00170     {-39},  //eofErr
00171     {-40},  //posErr
00172     {-41},  //mFulErr
00173     {ERROR_TOO_MANY_OPEN_FILES},    //tmfoErr
00174     {ERROR_FILE_NOT_FOUND}, //fnfErr
00175     {-44},  //wPrErr
00176     {-45},  //fLckdErr
00177     {-46},  //vLckdErr
00178     {ERROR_SHARING_VIOLATION},  //fBsyErr
00179     {-48},  //dupFNErr
00180     {-49},  //opWrErr
00181     {-50},
00182     {-51},  //rfNumErr
00183     {-52},  //gfpErr
00184     {-53},  //volOffLinErr
00185     {-54},  //permErr
00186     {-55},  //volOnLinErr
00187     {-56},  //nsDrvErr
00188     {-57},  //noMacDskErr
00189     {-58},  //extFSErr
00190     {-59},  //fsRnErr
00191     {-60},  //badMDBErr
00192     {-61},  //wrPermErr
00193     {-64},  //noDriveErr
00194     {-65},  //offLinErr
00195     {-66},  //noNybErr
00196     {-67},  //noAdrMkErr
00197     {-68},  //dataVerErr
00198     {-69},  //badCksmErr
00199     {-70},  //badBtSlpErr
00200     {-71},  //noDtaMkErr
00201     {-72},  //badDCksum
00202     {-73},
00203     {-74},
00204     {-75},
00205     {-76},
00206     {-77},
00207     {-78},
00208     {-79},
00209     {-80},
00210     {-81},
00211     {ERROR_PATH_NOT_FOUND}, //dirNFErr
00212     {-121},
00213     {-122}, //badMovErr
00214     {-123}, //wrgVolTypErr
00215     {-192}, //resNotFound
00216     {-193}, //resFNotFound
00217     {-194}, //addResFailed
00218     {-196}, //rmvResFailed
00219     {-198}, //resAttrErr
00220     {-199}, //mapReadErr
00221     {-100},
00222     {-102},
00223     {ERROR_OUTOFMEMORY},    //memFullErr
00224     {-109}, //nilHandleErr
00225     {-111},
00226     {-112},
00227     {-117},
00228     {-1703},
00229     {-1719},
00230     {-1704},
00231     {-1705},
00232     {-1708},
00233     {-1712},
00234     {-1711},
00235     {-906},
00236     {-1700},
00237     {-1701},
00238     {-1723},
00239     {-1728},
00240     {ERROR_ACCESS_DENIED},
00241     {-5016},
00242     {-5019},
00243     {-5023},
00244     {-5063},
00245     {-10000},
00246     {-10007},
00247     {-10011},
00248     {-10003},
00249     {-10014},
00250     
00251     }; /*systemerrortable*/
00252 
00253 #endif
00254 
00255 #define unknownsystemerror ctsystemerrors + 1
00256 
00257 #define errorcushionsize 0x1800 /*6K*/
00258 
00259 static Handle herrorcushion = nil; /*a buffer to allow memory error reporting*/
00260 
00261 static OSErr lasterror = noErr;
00262 
00263 /*
00264 static bigstring lasterrormessage = "";
00265 */
00266 
00267 
00268 boolean setoserrorparam (bigstring bs) {
00269     
00270     return (setparseparams (bs, nil, nil, nil));
00271     } /*setoserrorparam*/
00272 
00273 
00274 OSErr getoserror (void) {
00275     
00276     return (lasterror);
00277     } /*getoserror*/
00278 
00279 /*
00280 void getoserrormessage (bigstring bs) {
00281     
00282     copystring (lasterrormessage, bs);
00283     } #*getoserrormessage*/
00284 
00285 
00286 boolean getsystemerrorstring (OSErr errcode, bigstring bs) {
00287 
00288     /*
00289     errcode is a result code returned by a Macintosh system routine.
00290     
00291     we search the systemerrortable to see if we have a string for the 
00292     error, if so we load the string from the resource file and return
00293     true.
00294     
00295     10/28/91 dmb: return false any time we don't find a specific error string
00296     */
00297     
00298     register short i;
00299     register short errnum = errcode;
00300     bigstring bsos;
00301 
00302     for (i = 0; i < ctsystemerrors; i++) 
00303     
00304         if (systemerrortable [i].errornumber == errnum) {
00305             
00306             getstringlist (systemerrorlist, i + 1, bs);
00307             
00308             return (!isemptystring (bs));
00309             }
00310     
00311     getstringlist (systemerrorlist, unknownsystemerror, bs); /*loop satisfied, no message for this error*/
00312     
00313     if (isemptystring (bs))
00314         return (false);
00315         
00316     #ifdef MACVERSION
00317         shorttostring (errcode, bsos);
00318     #endif
00319 
00320     #ifdef WIN95VERSION
00321         if (getwinerrormessage (errcode, bsos)) {
00322             
00323             firstword (bsos, '.', bsos); //skip the cr
00324             }
00325         else {
00326         
00327             /* THe format failed, therefore we have no further info */
00328             wsprintf (stringbaseaddress(bsos), "error number %ld." , errcode);
00329             
00330             setstringlength (bsos, strlen (stringbaseaddress(bsos)));
00331             }
00332     #endif
00333 
00334     parsedialogstring (bs, bsos, nil, nil, nil, bs);
00335 
00336     return (true);
00337     } /*getsystemerrorstring*/
00338 
00339 
00340 static boolean getsafetycushion (void) {
00341     
00342     if (herrorcushion == nil)
00343         herrorcushion = NewHandle (errorcushionsize);
00344     
00345     return (herrorcushion != nil);
00346     } /*getsafetycushion*/
00347 
00348 
00349 boolean memoryerror (void) {
00350 
00351     /*
00352     returns true if there was a memory error, detected by calling the Mac
00353     routine MemError.
00354     
00355     wired off because we need a fancier solution, when we're out of memory,
00356     there's no room in the heap for a dialog box!  must pre-allocate this
00357     one...
00358     
00359     1/31/91 dmb: we'll deal with the heap space problem by using herrorcushion.
00360     CouldDialog is also used to ensure that the resources are already in memory.
00361     
00362     3/4/91 dmb: now always generate an error message, and always return true
00363     */
00364     
00365     register OSErr errcode = MemError ();
00366     bigstring bs;
00367     #ifdef WIN95VERSION
00368         long ctbytes = longinfinity;
00369         
00370         shellcallmemoryhooks (&ctbytes);
00371     #endif
00372     
00373     if (errcode == noErr) /*specific error code has been overwritten*/
00374         errcode = memFullErr;
00375     
00376     DisposeHandle (herrorcushion); /*make room*/
00377     
00378     herrorcushion = nil;
00379     
00380     getsystemerrorstring (errcode, bs);
00381     
00382     lasterror = errcode;
00383     
00384     /*
00385     copystring (bs, lasterrormessage);
00386     */
00387     
00388     shellerrormessage (bs);
00389     
00390     getsafetycushion (); /*hopefully, we should be able to get it back now*/
00391     
00392     return (true);
00393     } /*memoryerror*/
00394 
00395 
00396 boolean oserror (OSErr errcode) {
00397     
00398     /*
00399     return true if there is a Macintosh OS error, false otherwise.
00400     
00401     we display a text string explaining any errors we find.
00402     
00403     1/31/91 dmb: now call shellerrormessage instead of alertdialog
00404     
00405     2.1b5: don't post a message for user cancelled
00406     */
00407     
00408     register OSErr x = errcode;
00409     bigstring bs;
00410     
00411     lasterror = x;
00412     
00413     if (x == noErr) /*there wasn't an error*/
00414         return (false);
00415     
00416     if (x != userCanceledErr) {
00417 
00418         getsystemerrorstring (x, bs);
00419         
00420         if (isemptystring (bs)) { /*resource missing*/
00421         
00422             copystring ((ptrstring) STR_Mac_OS_Error, bs); /*create error string*/
00423             
00424             pushint (x, bs);
00425             }
00426         
00427         parseparamstring (bs);
00428         
00429         /*
00430         copystring (bs, lasterrormessage);
00431         */
00432         
00433         shellerrormessage (bs);
00434         }
00435     
00436     setparseparams (nil, nil, nil, nil);
00437     
00438     return (true); /*there was an error*/
00439     } /*oserror*/
00440 
00441 
00442 #ifdef WIN95VERSION
00443 
00444 boolean winerror (void) {
00445     
00446     /*
00447     5.0.1 dmb: the callerk has already detected an error. we're
00448     just reporting it.
00449     */
00450 
00451     oserror (GetLastError ());
00452 
00453     return (true);
00454     } /*winerror*/
00455 
00456 
00457 boolean getwinerrormessage (OSErr err, bigstring bserr) {
00458 
00459     LPVOID lpMsgBuf;
00460 
00461     if (FormatMessage(
00462         FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
00463         NULL,
00464         err,
00465         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
00466         (LPTSTR) &lpMsgBuf,
00467         0,
00468         NULL) == 0) {
00469         
00470         setemptystring (bserr);
00471         
00472         return (false);
00473         }
00474     
00475     strcpy (stringbaseaddress (bserr), lpMsgBuf);
00476     
00477     setstringlength (bserr, strlen(lpMsgBuf));
00478     
00479     LocalFree (lpMsgBuf);
00480     
00481     return (true);
00482     } /*getwinerrormessage*/
00483 
00484 #endif
00485 
00486 
00487 boolean initerror (void) {
00488     
00489     return (getsafetycushion ());
00490     } /*initerror*/
00491 
00492 
00493 
00494 

Generated on Wed May 31 18:19:46 2006 for frontierkernel 10.1.10a by  doxygen 1.4.6