home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / System / Swatch / Development / swatch 1.2 / swatch INIT / post init error / post.init.error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-17  |  3.5 KB  |  159 lines  |  [TEXT/KAHL]

  1. /**
  2.  
  3.     post.init.error.c
  4.     Copyright (c) 1990, joe holt
  5.  
  6.  **/
  7.  
  8.  
  9. /**-------------------------------------------------------------------------
  10.  **
  11.  ** Headers
  12.  **
  13.  **/
  14.  
  15. #include "post.init.error.h"
  16.  
  17.  
  18. /**-------------------------------------------------------------------------
  19.  **
  20.  ** Private Macros
  21.  **
  22.  **/
  23.  
  24. /**
  25.  
  26.     TRAP_NMInstall and TRAP_Unimplemented are Mac toolbox trap numbers used
  27.     to test for the existence of the Notification Manager.
  28.  
  29.  **/
  30.  
  31. #define TRAP_NMInstall            0xA05E
  32. #define TRAP_Unimplemented        0xA89F
  33.  
  34. /**
  35.  
  36.     INIT_ERROR_STR_ is the resource ID of the STR# containing the
  37.     error message corresponding to the error number passed to
  38.     Post_init_error().
  39.  
  40.     RESPONSE_CODE is the resource ID of the code resource compiled
  41.     separately and stuck in your INIT's resources.
  42.  
  43.  **/
  44.  
  45. #define INIT_ERROR_STR_        1000
  46. #define INIT_RESPONSE_CODE    1000
  47.  
  48.  
  49. /***************************************************************************
  50.  ***
  51.  *** void Post_init_error( int16 error_strx );
  52.  ***
  53.  *** When your INIT runs into a problem, clean things up, show the X'ed
  54.  *** version of your icon and call Post_init_error() with an error number
  55.  *** corresponding to the message you want displayed.
  56.  ***
  57.  *** History:
  58.  ***   jhh 18 jun 90 -- response to news posting
  59.  ***
  60.  ***/
  61.  
  62. void Post_init_error( int16 error_strx )
  63. {
  64.     register NMRec *note;
  65.     register Handle response_code;
  66.     register long size;
  67.     register THz svZone;
  68.     Str255 error_text;
  69.  
  70. /**
  71.  
  72.     Make sure we've got a Notification Manager.
  73.  
  74.  **/
  75.  
  76.     if ( NGetTrapAddress( TRAP_NMInstall, OSTrap ) !=
  77.             NGetTrapAddress( TRAP_Unimplemented, ToolTrap ) ) {
  78.  
  79. /**
  80.  
  81.     All of the memory we allocate from here on out is in the System
  82.     Heap.  First create a Notification Manager record and fill it in.
  83.     Note that you can expand this notification method with sounds and
  84.     icons by adding the appropriate code.  See the Notification
  85.     Manager technote #184 for details.
  86.  
  87.  **/
  88.  
  89.         svZone = TheZone;
  90.         TheZone = SysZone;
  91.         note = (NMRec *) NewPtr( sizeof( NMRec ) );
  92.         if ( !note )
  93.             goto exit;
  94.         note->qType = nmType;
  95.         note->nmMark = 0;
  96.         note->nmSIcon = 0L;
  97.         note->nmSound = (Handle) -1;
  98.  
  99. /**
  100.  
  101.     Get the error message corresponding to the error number given.
  102.     For maximum performance, the STR# resource should be tagged
  103.     "Preload" and not "System Heap".  This way, you can be sure
  104.     the messages will be there even if memory space is the cause of
  105.     the error.
  106.  
  107.     We create a pointer in the System Heap just big enough for the
  108.     string and copy the string into it.  Point the NM record at this
  109.     string.
  110.  
  111.  **/
  112.  
  113.         GetIndString( error_text, INIT_ERROR_STR_, error_strx );
  114.         size = *(unsigned char *) error_text + 1;
  115.         note->nmStr = (StringPtr) NewPtr( size );
  116.         if ( !note->nmStr ) {
  117.             DisposPtr( note );
  118.             goto exit;
  119.         }
  120.         BlockMove( error_text, note->nmStr, size );
  121.  
  122. /**
  123.  
  124.     The response procedure also must be in a pointer in the System
  125.     Heap.  You need to include the compiled code resource in your
  126.     INIT's resources of type 'CODE'.
  127.  
  128.     Create a pointer just big enough for it and point the NM record
  129.     at it, also.
  130.  
  131.  **/
  132.  
  133.         response_code = GetResource( 'CODE', INIT_RESPONSE_CODE );
  134.         if ( !response_code ) {
  135.             DisposPtr( note->nmStr );
  136.             DisposPtr( note );
  137.             goto exit;
  138.         }
  139.         size = GetHandleSize( response_code );
  140.         note->nmResp = (ProcPtr) NewPtr( size );
  141.         if ( !note->nmResp ) {
  142.             DisposPtr( note->nmStr );
  143.             DisposPtr( note );
  144.             goto exit;
  145.         }
  146.         BlockMove( *response_code, note->nmResp, size );
  147.  
  148. /**
  149.  
  150.     Now post the note.  As soon as startup is complete, the NM
  151.     will display the note for the user's edification.  Hurrah.
  152.  
  153.  **/
  154.  
  155.         NMInstall( note );
  156. exit:
  157.         TheZone = svZone;
  158.     }
  159. }