home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / util / diskfile / macwrite.sit / launch.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  3KB  |  106 lines

  1. /*    Program to launch MacWrite II
  2.     
  3.     Sak Wathanasin
  4.     Linotype Ltd
  5.     R & D Dept
  6.     Bath Road
  7.     Cheltenham
  8.     Glos. GL53 7LR
  9.     UK
  10.     (+44) 242 222 333 x206
  11.     
  12.     This program and source code is in the public domain.
  13.     Most of it was, in any case, shamelessly copied from Apple Tech Note 126
  14.     and whose authors I gratefully acknowledge.
  15.     
  16.     NB. You can change it to launch other applications by changing the "fCre"
  17.         resource with ResEdit & also the BNDL, FREF, ICN and signature resources
  18.         (it's easiest to copy these from the appl. that created the files you
  19.         want to launch).
  20. */
  21. #define    NULLSTR    (StringPtr)"\p"
  22. #define    nil    0L
  23. #define FILE(pb)    (((pb).ioFlAttrib & 0x10) == 0x00)
  24.  
  25. typedef struct LaunchStruct {
  26.     StringPtr    pfName;         /* pointer to the name of launchee */
  27.     short int    param;
  28. } *pLaunchStruct;
  29.  
  30. OSErr LaunchIt(pLnch) /* < 0 means error */
  31. pLaunchStruct  pLnch;
  32. {
  33.     asm{
  34.         /* pops pointer into A0, calls Launch,
  35.            result in D0
  36.         */
  37.       MOVE.L  pLnch,A0
  38.       _Launch
  39.     }
  40. }
  41.  
  42. main()
  43. {  /* DoLaunch */
  44.     struct        LaunchStruct    myLaunch;
  45.     HFileInfo    myPB;
  46.     OSErr        err=noErr;
  47.     short        index;
  48.     OSType        fdCreator;        /* Finder Creator */
  49.     Handle        fCreatorH;
  50.     Boolean        fndLaunchee = FALSE;
  51.     Str255        subsNameStr;
  52.  
  53.     /* Std initializations */
  54.     MoreMasters ();
  55.     InitGraf ((Ptr)&thePort);
  56.     InitFonts();
  57.     FlushEvents(everyEvent, 0);
  58.     InitWindows();
  59.     TEInit();
  60.     InitDialogs(nil);
  61.     InitCursor();
  62.  
  63.     /* read creator signature from our private resource */
  64.     if ((fCreatorH = GetResource('fCre', 1)) == nil) {
  65.         ExitToShell(); /* just give up */
  66.     }
  67.     BlockMove(*fCreatorH, &fdCreator, 4);
  68.     ReleaseResource(fCreatorH);
  69.     DisposHandle(fCreatorH);
  70.     
  71.     /*Look for the launchee in the current folder;
  72.       the Finder puts us in the right WD before it calls us */
  73.     
  74.     GetVol((StringPtr)subsNameStr, &myPB.ioVRefNum);        /* this will probably be a WD id */
  75.     myPB.ioNamePtr = (StringPtr)subsNameStr;
  76.     index = 1;
  77.     do {
  78.         myPB.ioFDirIndex= index++;
  79.         myPB.ioDirID = 0;
  80.         err = PBGetCatInfo((CInfoPBPtr) &myPB,false);
  81.     }
  82.     while (err == noErr && !(FILE(myPB) &&
  83.                                 myPB.ioFlFndrInfo.fdType == 'APPL' &&
  84.                                 (fndLaunchee = (myPB.ioFlFndrInfo.fdCreator == fdCreator))));
  85.     if (!fndLaunchee) {
  86.         StopAlert(1001, nil);
  87.         ExitToShell();
  88.     }
  89.     
  90.     /*Set up the launch parameters
  91.       TN 126 says to set up a WD, but the Finder has already done this for us */
  92.       
  93.     myLaunch.pfName = myPB.ioNamePtr;    /*pointer to our fileName*/
  94.     myLaunch.param = 0;            /*we don't want alternate screen
  95.                                     or sound buffers*/
  96.     err = LaunchIt(&myLaunch);        /* call _Launch            */
  97.     
  98.     /* Launch will not return unless there is a problem */
  99.     if (err < 0)
  100.     {
  101.         DebugStr("\plaunch failed");
  102.         StopAlert(1001, nil);
  103.     }
  104. } /*DoLaunch*/
  105.  
  106.