Source/SlimFunctions.c

/*
    9-30-92  ¥ Brigham Stevens
    --------------------------
 
    This is for sticking in test code that you want to run
    in response to menu commands.
*/
 
#include "MenuDispatch.h"
#include <Files.h>
 
 
pstrcat(s1, s2)
register char *s1, *s2;
{
    register char *p;
    register short len, i;
    
    if (*s1+*s2<=255) 
    {
        p = *s1 + s1 + 1;
        *s1 += (len = *s2++);
    }
    else 
    {
        *s1 = 255;
        p = s1 + 256 - (len = *s2++);
    }
    for (i=len; i; --i) *p++ = *s2++;
}
 
 
 
void DisplayStuff(DTPBPtr   dtp)
{
    Str255  msg = "\pFound It!\rName of Appl is: ";
    
    pstrcat(msg, dtp->ioNamePtr);
    
    Msg(msg);
}
 
 
void SlimFunction1()
{
    DTPBPtr dtp;
    WDPBPtr gvp;
    short   diskRefNum;
    short   dbRef;
    short   err;
    Str255  name;
    
    
    /*  Get the vRef of the disk with the desktop DB we want */
    gvp = NewPtrClear(sizeof(WDPBRec));
    if(!gvp) {
        ErrMsg("\pfail: getVolpb = NewPtrClear(sizeof(WDPBRec));");
        return; 
    }
    
    err = PBHGetVol(gvp,false);
    if(err) {
        ErrMsg("\perr = PBHGetVol(gvp,false);");
        return; 
    }
    diskRefNum = gvp->ioVRefNum;
    DisposePtr(gvp);
    
    dtp = NewPtrClear(sizeof(DTPBRec));
    if(!dtp) {
        ErrMsg("\pfail: dtp = NewPtrClear(sizeof(DTPBRec));");
        return;
    }
    
    /*  Get the ref num of the DB you want to munge */
    /*  either specify the name of the volume */
    /* or use a vRefNum */
    /* We are using the same volume as the application */
    
    dtp->ioNamePtr = name;
    dtp->ioVRefNum = diskRefNum;
    
    err = PBDTGetPath(dtp);
    if(err) {
        ErrMsgCode("\pfail: err = PBDTGetPath(dtp);",err);
        return;
    }
    
    dbRef = dtp->ioDTRefNum;
    DisposePtr(dtp);
 
    /* re-initialize our parameter block */
    /* this makes sure all fields start at ZERO */
    dtp = NewPtrClear(sizeof(DTPBRec));
    if(!dtp) {
        ErrMsg("\pfail: dtp = NewPtrClear(sizeof(DTPBRec)) [2];");
        return; 
    }
    
    /* Setup for the PBDTGetAPPL call */
    /* the GetCreator call just gets an OSType */
    
    dtp->ioNamePtr = name;
    dtp->ioDTRefNum = dbRef;
    dtp->ioIndex = 0;
    if(GetCreator(&dtp->ioFileCreator) == 1) {
        err = PBDTGetAPPL(dtp,false);
        if(err)
            if(err == afpItemNotFound)
                Msg("\pThe Creator you are seaking is unavailable.");
            else
                ErrMsgCode("\pfail: err = PBDTGetAPPL(dtp,false);",err);
        else 
            DisplayStuff(dtp);
    }
    
    DisposePtr(dtp);
}
 
void SlimFunction2()
{
    SysBeep(5);
}
 
 
void SlimFunction3()
{
    SysBeep(5);
}
 
 
void SlimFunction4()
{   
    SysBeep(5);
}
 
 
void ChooseSlim(short item)
{
    switch(item) {
        case SLIM_1 :   SlimFunction1();
                            break;
        case SLIM_2 :   SlimFunction2();
                            break;
        case SLIM_3 :   SlimFunction3();
                            break;
        case SLIM_4 :   SlimFunction4();
                            break;
        default:            break;
    }
}