home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Entertainment / tblt / tblt⁄error.c < prev    next >
Encoding:
Text File  |  1986-09-06  |  2.0 KB  |  74 lines  |  [TEXT/MACA]

  1. /*
  2.  * error.c - error notification routines
  3.  */
  4.  
  5. #include <quickdraw.h>
  6. #include <dialog.h>
  7. #include <toolutil.h>
  8. #include <memory.h>
  9. #include <syserr.h>
  10. #include <packages.h>
  11.  
  12. #define ALTBOMB        401    /* Resource ID of our generic alert    */
  13. #define DISKSTRS    401    /* System error strings            */
  14. #define PROGSTRS    402    /* Program-specific error strings    */
  15.  
  16. static short errstr[] = {    /* string # to error-number mapping    */
  17.   dirFulErr, dskFulErr, nsvErr, ioErr, bdNamErr,
  18.   fnOpnErr, eofErr, posErr, mFulErr, tmfoErr,
  19.   fnfErr, wPrErr, fLckdErr, vLckdErr, fBsyErr,
  20.   dupFNErr, opWrErr, paramErr, rfNumErr, gfpErr,
  21.   volOffLinErr, permErr, volOnLinErr, nsDrvErr, noMacDskErr,
  22.   extFSErr, fsRnErr, badMDBErr, wrPermErr, memFullErr
  23. };
  24.  
  25. static char msg[256];    /* the text to say    */
  26.  
  27. /*
  28.  * diskerr() - given a system error number, notify the user of the error.
  29.  */
  30. diskerr(err)
  31. OSErr err;
  32. {
  33.     short sidx;        /* index of the string to say    */
  34.  
  35.     for (sidx = 1; sidx <= sizeof(errstr) / sizeof(errstr[0]); ++sidx) {
  36.     if (errstr[sidx - 1] == err) break;
  37.     }
  38.     if (sidx <= sizeof(errstr) / sizeof(errstr[0])) {
  39.     GetIndString(msg, DISKSTRS, sidx);
  40.     } else {
  41.     NumToString((long) err, msg);
  42.     }
  43.     ParamText(msg, (char *) 0, (char *) 0, (char *) 0);
  44.     (void) StopAlert(ALTBOMB, (ProcPtr) 0);
  45.     ResetAlrtStage();
  46. }
  47.  
  48. /*
  49.  * progstop(), prognote(), progcaution() - given a string ID from
  50.  *  the program's error strings, say that string inside a Stop, Note, or
  51.  *  Caution alert.
  52.  */
  53. progstop(sidx) short sidx; { progmsg(sidx, stopIcon); }
  54. prognote(sidx) short sidx; { progmsg(sidx, noteIcon); }
  55. progcaution(sidx) short sidx; { progmsg(sidx, ctnIcon); }
  56.  
  57. /*
  58.  * progmsg() - server to progstop(), etc.
  59.  */
  60. static
  61. progmsg(sidx, severity)
  62. short sidx;
  63. short severity;
  64. {
  65.     GetIndString(msg, PROGSTRS, sidx);
  66.     ParamText(msg, (char *) 0, (char *) 0, (char *) 0);
  67.     switch (severity) {
  68.     case stopIcon: (void) StopAlert(ALTBOMB, (ProcPtr) 0); break;
  69.     case noteIcon: (void) StopAlert(ALTBOMB, (ProcPtr) 0); break;
  70.     case ctnIcon:  (void) StopAlert(ALTBOMB, (ProcPtr) 0); break;
  71.     }
  72.     ResetAlrtStage();
  73. }
  74.