home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / GetVersion 1.0 / GetVersion.c next >
Encoding:
C/C++ Source or Header  |  1993-06-04  |  1.8 KB  |  63 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  GetVersion.c
  3.  
  4.     AUTHOR: Andrew_Gilmartin@Brown.Edu
  5.     MODIFIED: 93-06-03
  6.  
  7. ******************************************************************************/
  8.  
  9. #include <TCLHeaders>
  10. #include "GetVersion.h"
  11.  
  12.  
  13. #define HiNibble( _byte ) ( (_byte) >> 4 )
  14. #define LoNibble( _byte ) ( (_byte) & 0x0F )
  15.  
  16.  
  17.  
  18. /******************************************************************************
  19.  GetVersion
  20.  
  21.     Copy the values in the 'vers' resource id to the version structure.
  22. ******************************************************************************/
  23.  
  24. void GetVersion( short id, VERSION* version )
  25. {
  26.     Handle resource;
  27.  
  28.         /* Get the resource */
  29.  
  30.     resource = GetResource( 'vers', id );
  31.     FailNILRes( resource );
  32.  
  33.         /*
  34.             These three values are distributed between two bytes. The first
  35.             byte has the major version number in BCD; it can have a max value
  36.             of 99. The minor and minuscule values are encoded in the second
  37.             byte in BCD; each can have a max value of 9.
  38.         */
  39.  
  40.     version->Major = HiNibble( (*resource)[0] ) * 10 + LoNibble( (*resource)[0] );
  41.     version->Minor = HiNibble( (*resource)[1] );
  42.     version->Minuscule = LoNibble( (*resource)[1] );
  43.     
  44.     version->Stage = (*resource)[2];    
  45.     version->Release = HiNibble( (*resource)[3] ) * 10 + LoNibble( (*resource)[3] );
  46.     
  47.     version->Region = *(short*) ((*resource) + 4);
  48.  
  49.         /*
  50.             The long and short description strings are concatinated in resource.
  51.             Thus the long description's start is dependent upon the short
  52.             description's length.
  53.         */
  54.  
  55.     CopyPString( (StringPtr) (*resource) + 6, version->ShortDescription );
  56.     CopyPString( (StringPtr) (*resource) + (7 + version->ShortDescription[0] ), 
  57.         version->LongDescription );
  58.  
  59.         /* Done with the resource */
  60.     
  61.     ReleaseResource( resource );
  62.  
  63. } /* GetVersion */