home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Snippets / CustomDialog Demo / Source / TrapUtils.c < prev   
Encoding:
C/C++ Source or Header  |  1995-08-31  |  3.3 KB  |  131 lines  |  [TEXT/MMCC]

  1. /**********************************************************************
  2.  *
  3.  *                        CustomGetFile Dialog Demo
  4.  *
  5.  *    TrapUtils.c
  6.  *
  7.  *    Written in CodeWarrior Gold 5.5
  8.  *    August 31, 1995
  9.  *
  10.  *    Copyright © 1995 Carl B. Constantine
  11.  *    Some portions Copyright © 1995 MetroWerks, Inc.
  12.  *    Some portions Copyright © 1995 Apple Computer, Inc.
  13.  *
  14.  **********************************************************************/
  15.  
  16.  /*------------------------------------------------------------------
  17.   #
  18.   #                            File History
  19.   #
  20.   #        Date                Description of Change
  21.   #        ----                ---------------------
  22.   #        Aug 31/93            — Original creation of file
  23.   #
  24.   #
  25.   -------------------------------------------------------------------*/
  26.  
  27. #include <Traps.h>
  28. #include <GestaltEqu.h>
  29.  
  30. #include "AppGlobals.h"
  31. #include "TrapUtils.h"
  32.  
  33.  
  34. /*======================== Checking for Gestalt ===========================*/
  35.  
  36. /*     Call GestaltAvailable to determine whether the system software version is
  37.     6.04 or higher. If Gestalt is not available, then we are running on a system
  38.     that we don't want to.  If Gestalt is available, then we can find out what
  39.     system we are running on.     */
  40.  
  41. Boolean GestaltAvailable( void )
  42. {    
  43.     if ( !TrapAvailable( _Gestalt ) )
  44.         return( false );
  45.     else
  46.         return( true );
  47. }
  48.  
  49. /*==================== Checking for Gestalt Attributes =======================*/
  50.  
  51. /*    Call HasGestaltAttr to determine if the system software version supports
  52.     certain capabilities.  Handy routine checks to see if the specified bit in 
  53.     the result of the specifed Gestalt Selector is set or not. This routine comes
  54.     directly from "Macintosh Programming Secrets, 3rd Ed." by Scott Knaster & 
  55.     Keith Rollin Chapter 10 page 509.  */
  56.  
  57. Boolean HasGestaltAttr( OSType itsAttr, short itsBit )
  58. {
  59.     long response;
  60.     
  61.     return( Gestalt( itsAttr, &response) == noErr ) && 
  62.         (((response >> itsBit) & 1L) != 0 );
  63. }
  64.     
  65.     
  66. /*========================= Checking for System 7 =============================*/
  67.  
  68. /*     Call System607Available to determine whether the system software version is
  69.     7 or higher. If not, tell the user and exit gracefully. */
  70.  
  71. Boolean System7Available( void )
  72. {
  73.     long        sysVersion;
  74.     
  75.     
  76.     Gestalt( gestaltSystemVersion, &sysVersion );
  77.     return( sysVersion >= 0x0700 );
  78.     
  79. }
  80.  
  81. //    Everything from this point on shouldn't be new to anyone.  You can find
  82. //    similar routines in almost any code you look at (particularlly shell code).
  83. //    With that assumtion, here is the rest of the code for this file.
  84.  
  85.  
  86. /*----------------------------------------------------------------------------*/
  87.  
  88. Boolean TrapAvailable( short theTrap )
  89. {
  90.     TrapType    tType;
  91.     
  92.     tType = GetTrapType( theTrap );
  93.     
  94.     if ( tType == ToolTrap ) 
  95.     {
  96.         theTrap = ( theTrap & 0x07FF );
  97.         if ( theTrap >= NumToolboxTraps() ) theTrap = _Unimplemented;
  98.     }
  99.     return( NGetTrapAddress( theTrap, tType ) !=
  100.             NGetTrapAddress( _Unimplemented, ToolTrap ) );
  101. }
  102.  
  103. /*----------------------------------------------------------------------------*/
  104.  
  105. TrapType GetTrapType( short theTrap )
  106. {
  107.     if ( ( theTrap & 0x0800 ) > 0 ) 
  108.     {
  109.         return( ToolTrap );
  110.     } else 
  111.     {
  112.         return( OSTrap );
  113.     }
  114. }
  115.  
  116. /*----------------------------------------------------------------------------*/
  117.  
  118. short NumToolboxTraps( void )
  119. {
  120.     if ( NGetTrapAddress( _InitGraf, ToolTrap ) ==
  121.         NGetTrapAddress( 0xAA6E, ToolTrap ) ) 
  122.     {
  123.         return( 0x0200 );
  124.     } else 
  125.     {
  126.         return( 0x0400 );
  127.     }
  128. }
  129.  
  130. /*============================ End of File ===================================*/
  131.