home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Otherware
/
Otherware_1_SB_Development.iso
/
mac
/
util
/
diskfile
/
macwrite.sit
/
launch.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-27
|
3KB
|
106 lines
/* Program to launch MacWrite II
Sak Wathanasin
Linotype Ltd
R & D Dept
Bath Road
Cheltenham
Glos. GL53 7LR
UK
(+44) 242 222 333 x206
This program and source code is in the public domain.
Most of it was, in any case, shamelessly copied from Apple Tech Note 126
and whose authors I gratefully acknowledge.
NB. You can change it to launch other applications by changing the "fCre"
resource with ResEdit & also the BNDL, FREF, ICN and signature resources
(it's easiest to copy these from the appl. that created the files you
want to launch).
*/
#define NULLSTR (StringPtr)"\p"
#define nil 0L
#define FILE(pb) (((pb).ioFlAttrib & 0x10) == 0x00)
typedef struct LaunchStruct {
StringPtr pfName; /* pointer to the name of launchee */
short int param;
} *pLaunchStruct;
OSErr LaunchIt(pLnch) /* < 0 means error */
pLaunchStruct pLnch;
{
asm{
/* pops pointer into A0, calls Launch,
result in D0
*/
MOVE.L pLnch,A0
_Launch
}
}
main()
{ /* DoLaunch */
struct LaunchStruct myLaunch;
HFileInfo myPB;
OSErr err=noErr;
short index;
OSType fdCreator; /* Finder Creator */
Handle fCreatorH;
Boolean fndLaunchee = FALSE;
Str255 subsNameStr;
/* Std initializations */
MoreMasters ();
InitGraf ((Ptr)&thePort);
InitFonts();
FlushEvents(everyEvent, 0);
InitWindows();
TEInit();
InitDialogs(nil);
InitCursor();
/* read creator signature from our private resource */
if ((fCreatorH = GetResource('fCre', 1)) == nil) {
ExitToShell(); /* just give up */
}
BlockMove(*fCreatorH, &fdCreator, 4);
ReleaseResource(fCreatorH);
DisposHandle(fCreatorH);
/*Look for the launchee in the current folder;
the Finder puts us in the right WD before it calls us */
GetVol((StringPtr)subsNameStr, &myPB.ioVRefNum); /* this will probably be a WD id */
myPB.ioNamePtr = (StringPtr)subsNameStr;
index = 1;
do {
myPB.ioFDirIndex= index++;
myPB.ioDirID = 0;
err = PBGetCatInfo((CInfoPBPtr) &myPB,false);
}
while (err == noErr && !(FILE(myPB) &&
myPB.ioFlFndrInfo.fdType == 'APPL' &&
(fndLaunchee = (myPB.ioFlFndrInfo.fdCreator == fdCreator))));
if (!fndLaunchee) {
StopAlert(1001, nil);
ExitToShell();
}
/*Set up the launch parameters
TN 126 says to set up a WD, but the Finder has already done this for us */
myLaunch.pfName = myPB.ioNamePtr; /*pointer to our fileName*/
myLaunch.param = 0; /*we don't want alternate screen
or sound buffers*/
err = LaunchIt(&myLaunch); /* call _Launch */
/* Launch will not return unless there is a problem */
if (err < 0)
{
DebugStr("\plaunch failed");
StopAlert(1001, nil);
}
} /*DoLaunch*/