appletsyserror.c

Go to the documentation of this file.
00001 
00002 /*  $Id: appletsyserror.c 355 2005-01-11 22:48:55Z andreradke $    */
00003 
00004 /* copyright 1991-96 UserLand Software, Inc. All Rights Reserved.*/
00005 
00006 
00007 #include "appletdefs.h"
00008 #include "appletmemory.h"
00009 #include "appletstrings.h"
00010 #include "appletsyserror.h"
00011 
00012 
00013 #define systemerrorlist 258 
00014 
00015 #define ctsystemerrors 86
00016 
00017 
00018 typedef struct tyerrorrecord {
00019 
00020     short errornumber; /*an error result passed back by a Mac system routine*/
00021     
00022     short errorindex; /*index into the STR# resource for the appropriate message*/
00023     } tyerrorrecord;
00024     
00025 
00026 tyerrorrecord systemerrortable [ctsystemerrors] = {
00027     -33,     1,
00028     -34,     2,
00029     -35,     3,
00030     -36,     4,
00031     -37,     5,
00032     -38,     6,
00033     -39,     7,
00034     -40,     8,
00035     -41,     9,
00036     -42,    10,
00037     -43,    11,
00038     -44,    12,
00039     -45,    13,
00040     -46,    14,
00041     -47,    15,
00042     -48,    16,
00043     -49,    17,
00044     -50,    18,
00045     -51,    19,
00046     -52,    20,
00047     -53,    21,
00048     -54,    22,
00049     -55,    23,
00050     -56,    24,
00051     -57,    25,
00052     -58,    26,
00053     -59,    27,
00054     -60,    28,
00055     -61,    29,
00056     -64,    30,
00057     -65,    31,
00058     -66,    32,
00059     -67,    33,
00060     -68,    34,
00061     -69,    35,
00062     -70,    36,
00063     -71,    37,
00064     -72,    38,
00065     -73,    39,
00066     -74,    40,
00067     -75,    41,
00068     -76,    42,
00069     -77,    43,
00070     -78,    44,
00071     -79,    45,
00072     -80,    46,
00073     -81,    47,
00074     -120,   48,
00075     -121,   49,
00076     -122,   50,
00077     -123,   51,
00078     -192,   52,
00079     -193,   53,
00080     -194,   54,
00081     -196,   55,
00082     -198,   56,
00083     -199,   57,
00084     -100,   58,
00085     -102,   59,
00086     -108,   60,
00087     -109,   61,
00088     -111,   62,
00089     -112,   63,
00090     -117,   64,
00091     -1703,  65,
00092     -1719,  66,
00093     -1704,  67,
00094     -1705,  68,
00095     -1708,  69,
00096     -1712,  70,
00097     -1711,  71,
00098     -906,   72,
00099     -1700,  73,
00100     -1701,  74,
00101     -1723,  75,
00102     -1728,  76,
00103     -5000,  77,
00104     -5016,  78,
00105     -5019,  79,
00106     -5023,  80,
00107     -5063,  81,
00108     -10000, 82,
00109     -10007, 83,
00110     -10011, 84,
00111     -10003, 85,
00112     -10014, 86,
00113     }; /*systemerrortable*/
00114 
00115 
00116 #define unknownsystemerror ctsystemerrors + 1
00117 
00118 #define errorcushionsize 0x1800 /*6K*/
00119 
00120 static Handle herrorcushion = nil; /*a buffer to allow memory error reporting*/
00121 
00122 static bigstring syserrorparam = "";
00123 
00124 
00125 
00126 
00127 void setsyserrorparam (bigstring bs) {
00128     
00129     copystring (bs, syserrorparam);
00130     } /*setsyserrorparam*/
00131 
00132 
00133 static boolean getsystemerrorstring (OSErr ec, bigstring bs) {
00134     
00135     /*
00136     ec is a result code returned by a Macintosh system routine.
00137     
00138     we search the systemerrortable to see if we have a string for the 
00139     error, if so we load the string from the resource file and return
00140     true.
00141     
00142     10/28/91 dmb: return false any time we don't find a specific error string
00143     */
00144     
00145     short i;
00146     
00147     for (i = 0; i < ctsystemerrors; i++) {
00148     
00149         if (systemerrortable [i].errornumber == ec) {
00150             
00151             GetIndString (bs, systemerrorlist, systemerrortable [i].errorindex);
00152             
00153             if (stringlength (bs) > 0)
00154                 return (true);
00155             }
00156         } /*for*/
00157     
00158     copystring ("\pMacintosh system error #", bs); /*create error string*/
00159         
00160     pushint (ec, bs);
00161     
00162     return (true); /*loop satisfied, no message for this error*/
00163     } /*getsystemerrorstring*/
00164 
00165 
00166 static boolean getsafetycushion (void) {
00167     
00168     if (herrorcushion == nil)
00169         herrorcushion = appnewhandle (errorcushionsize);
00170     
00171     return (herrorcushion != nil);
00172     } /*getsafetycushion*/
00173 
00174 
00175 boolean syserror (OSErr ec) {
00176     
00177     /*
00178     return true if ec is not noErr, false otherwise.
00179     
00180     we display a text string explaining any errors we find.
00181     */
00182     
00183     bigstring bs;
00184     extern void alertdialog (bigstring);
00185     
00186     if (ec == noErr) /*there wasn't an error*/
00187         return (false); 
00188         
00189     if (ec == userCanceledErr) /*user has already interacted with the OS, it's still an error*/
00190         return (true);
00191     
00192     getsystemerrorstring (ec, bs);
00193     
00194     parseparamstring (bs, syserrorparam, nil, nil, nil, bs);
00195     
00196     alertdialog (bs);
00197     
00198     setstringlength (syserrorparam, 0);
00199     
00200     return (true); /*there was an error*/
00201     } /*syserror*/
00202 
00203 
00204 boolean sysmemoryerror (void) {
00205 
00206     boolean fl;
00207     
00208     DisposHandle (herrorcushion); /*make room*/
00209     
00210     herrorcushion = nil;
00211     
00212     setstringlength (syserrorparam, 0);
00213     
00214     syserror (memFullErr);
00215     
00216     fl = getsafetycushion (); 
00217     
00218     assert (fl); /*unable to reclaim the safety cushion*/
00219     
00220     return (true);
00221     } /*sysmemoryerror*/
00222 
00223 
00224 boolean initsyserror (void) {
00225     
00226     return (getsafetycushion ());
00227     } /*initsyserror*/
00228 
00229 
00230 
00231 

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