home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Kant Generator Pro 1.0.1 / source / Shell ƒ / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.1 KB  |  61 lines  |  [TEXT/MMCC]

  1. #include "error.h"
  2. #include "main.h"
  3. #include "dialogs.h"
  4. #include "environment.h"
  5. #include "window layer.h"
  6.  
  7. ErrorStateRec        gPendingErrorRec;
  8.  
  9. void FailNilUPP(UniversalProcPtr theUPP)
  10. {
  11.     if (theUPP == nil)
  12.         HandleError(kNoMemory, FALSE, FALSE);
  13. }
  14.  
  15. void HandleError(enum ErrorTypes resultCode, Boolean isFatal, Boolean isSmall)
  16. /* if we're in the foreground, just get the error string (from the .rsrc file) and
  17.    display the error alert; otherwise, we have to queue it, put up a notification
  18.    (if possible), and wait patiently to come back in the foreground.  (see main.c,
  19.    DispatchEvents(), case osEvt. */
  20. /* All error codes are listed in program globals.h */
  21. {
  22.     Str255            tempStr;
  23.     Handle            myResHand;
  24.     
  25.     /* if there is no error, or the error is that the user cancelled an operation
  26.        in progress, don't display anything; it would only confuse them. */
  27.     if ((resultCode==userCancelErr) || (resultCode==allsWell)) return;
  28.     
  29.     if (gIsInBackground)    /* if program is in background, can't display alert immed. */
  30.     {
  31.         if (gHasNotificationManager)    /* if they don't have notification, f*ck 'em */
  32.         {
  33.             myResHand=GetResource('SICN', 1234);    /* small icon for menu bar flashing */
  34.             gPendingErrorRec.notificationRec.qType=nmType;            /* for more detail on these params, */
  35.             gPendingErrorRec.notificationRec.nmMark=1;                /* see IM Processes, 5-8 */
  36.             gPendingErrorRec.notificationRec.nmIcon=myResHand;
  37.             gPendingErrorRec.notificationRec.nmSound=(Handle)-1L;
  38.             gPendingErrorRec.notificationRec.nmStr=0L;
  39.             gPendingErrorRec.notificationRec.nmResp=0L;
  40.             gPendingErrorRec.notificationRec.nmRefCon=0L;
  41.             NMInstall(&gPendingErrorRec.notificationRec);
  42.         }
  43.         gPendingErrorRec.resultCode=resultCode;                /* remember error code for later */
  44.     }
  45.     else
  46.     {
  47.         RemoveHilitePatch();
  48.         GetIndString(tempStr, 129, resultCode);    /* get error string from .rsrc */
  49.         ParamText(tempStr, "\p", "\p", "\p");
  50.         PositionDialog('ALRT', isSmall ? smallAlert : largeAlert);
  51.         StopAlert(isSmall ? smallAlert : largeAlert, 0L);
  52.         InstallHilitePatch();
  53.     }
  54.     
  55.     if (isFatal)        /* for fatal errors */
  56.     {
  57.         ShutDownEnvironment(FALSE);
  58.         ExitToShell();
  59.     }
  60. }
  61.