home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / ColorSync SDK / Sample Code / CSDemo 2.1 / ShellSources / trapUtils.c < prev    next >
Encoding:
Text File  |  1997-06-13  |  3.0 KB  |  97 lines  |  [TEXT/CWIE]

  1. // Simple framework for Macintosh sample code
  2. // This file contains the trap detection related code code for the framework.
  3. // 
  4. // 9/16/94    david    first cut
  5. // 9/20/95    david    improved comments
  6.  
  7. #include <Types.h>
  8. #include <Traps.h>
  9. #include <OSUtils.h>
  10. #include <Gestalt.h>
  11.  
  12. #include "trapUtils.h"
  13.  
  14.     
  15. /**\
  16. |**| ==============================================================================
  17. |**| PRIVATE FUNCTION PROTOTYPES
  18. |**| ==============================================================================
  19. \**/
  20. short         NumToolboxTraps        ( void ) ;
  21. TrapType    GetTrapType            ( short theTrap ) ;
  22.  
  23.  
  24. /**\
  25. |**| ==============================================================================
  26. |**| PUBLIC FUNCTIONS
  27. |**| ==============================================================================
  28. \**/
  29.  
  30.  
  31. /*------------------------------------------------------------------------------*\
  32.     TrapAvailable
  33.  *------------------------------------------------------------------------------*
  34.         This function determines a traps is available on the user machine.
  35.         This function should only be used in cases where that Gestalt Manager
  36.         cannot be used to determine if a function is available.  (For example,
  37.         there is no way to detimine if the _Gestalt or _WaitNextEvent traps are
  38.         available by calling Gestalt )
  39. \*------------------------------------------------------------------------------*/
  40. Boolean    TrapAvailable ( short theTrap )
  41. {
  42.     TrapType tType;
  43.     Boolean isAvail;
  44.     
  45.     tType = GetTrapType(theTrap) ;
  46.     if (tType == ToolTrap)
  47.     {
  48.         theTrap &= 0x07FF;
  49.         if (theTrap >= NumToolboxTraps() )
  50.             theTrap = _Unimplemented ;
  51.     }
  52.     
  53.     isAvail = NGetTrapAddress(theTrap, tType) !=
  54.               GetToolboxTrapAddress(_Unimplemented) ;
  55.     return isAvail;
  56. }
  57.  
  58.  
  59. /**\
  60. |**| ==============================================================================
  61. |**| PRIVATE FUNCTIONS
  62. |**| ==============================================================================
  63. \**/
  64.  
  65.  
  66. /*------------------------------------------------------------------------------*\
  67.     NumToolboxTraps
  68.  *------------------------------------------------------------------------------*
  69.         This function determines the number of toolbox traps (0x0200 or 0x0400).
  70.         This function relies on the fact the _InitGraf trap (0xA86E) is always
  71.         implimented.  If the trap dispatch table has more than 0x0200 entries
  72.         then 0xAA6E is either unimplimented or not the same as the trap address
  73.         of _InitGraf
  74. \*------------------------------------------------------------------------------*/
  75. static short NumToolboxTraps ( void )
  76. {
  77.     if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xAA6E,ToolTrap))
  78.         return 0x0200 ;
  79.     else
  80.         return 0x0400 ;
  81. }
  82.  
  83.  
  84. /*------------------------------------------------------------------------------*\
  85.     GetTrapType
  86.  *------------------------------------------------------------------------------*
  87.         This function determines the type of trap (toolbox or os ).
  88. \*------------------------------------------------------------------------------*/
  89. static TrapType GetTrapType ( short theTrap )
  90. {
  91.     if ((theTrap & 0x0800) > 0)
  92.         return ToolTrap ;
  93.     else
  94.         return OSTrap ;
  95. }
  96.  
  97.