TestGestalt.c

/*
    File:       TestGestalt.c
 
    Contains:   
 
    Written by:     
 
    Copyright:  Copyright © 1999 by Apple Computer, Inc., All Rights Reserved.
 
                You may incorporate this Apple sample source code into your program(s) without
                restriction. This Apple sample source code has been provided "AS IS" and the
                responsibility for its operation is yours. You are not permitted to redistribute
                this Apple sample source code as "Apple sample source code" after having made
                changes. If you're going to re-distribute the source, we require that you make
                it clear in the source that the code was descended from Apple sample source
                code, but that you've made changes.
 
    Change History (most recent first):
                7/23/1999   Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
                
 
*/
#ifndef __CTYPE__
#include <CType.h>
#endif
 
#ifndef __OSUTILS__
#include <OSUtils.h>
#endif
 
#ifndef __STDIO__
#include <StdIO.h>
#endif
 
#ifndef __GESTALTEQU__
#include <GestaltEqu.h>
#endif
 
#ifndef __TYPES__
#include <Types.h>
#endif
 
#include <Traps.h>
 
#define TRUE            0xFF
#define FALSE           0
 
Boolean TrapAvailable(short theTrap);
 
// check to see if a given trap is implemented. We follow IM VI-3-8.
Boolean TrapAvailable(short theTrap)
{
    TrapType theTrapType;
    short numToolboxTraps;
    
    if ((theTrap & 0x0800) > 0)
        theTrapType = ToolTrap;
    else
        theTrapType = OSTrap;
 
    if (theTrapType == ToolTrap)
    {
        theTrap = theTrap & 0x07ff;
        if (NGetTrapAddress(_InitGraf, ToolTrap) == NGetTrapAddress(0xaa6e, ToolTrap))
            numToolboxTraps = 0x0200;
        else
            numToolboxTraps = 0x0400;
        if (theTrap >= numToolboxTraps)
            theTrap = _Unimplemented;
    };
 
    return (NGetTrapAddress(theTrap, theTrapType) != NGetTrapAddress(_Unimplemented, ToolTrap));
}
 
 
void main()
{
OSErr       err;
long        feature;
 
if (TrapAvailable(_Gestalt)) {
    err = Gestalt(gestaltQuickdrawVersion, &feature);
    if (!err) {
        if ((feature & 0x0f00) == 0x0000)
            printf ("We have Original QuickDraw version 0.%x\n", (feature & 0x00ff));
        else if ((feature & 0x0f00) == 0x0100)
            printf ("We have 8 Bit QuickDraw version 1.%x\n", (feature & 0x00ff));
        else if ((feature & 0x0f00) == 0x0200)
            printf ("We have 32 Bit QuickDraw version 2.%x\n", (feature & 0x00ff));
        else
            printf ("We don't have QD\n");
        }
    else 
        printf ("Gestalt err = %i\n",err);
    }
else
    printf ("No Gestalt\n");
}