[comp.sys.mac.programmer] help with sublaunching

aib@j.cc.purdue.edu (coleman) (05/01/89)

a
HELP !!

  I am having major problems with sublaunching. Everytime I try it,
  I get a system beep, but it exits from there without returning
  an error code. This was copied mostly from tech note # 126. Any 
  help would be greatly appreciated.
  
  Source is as follows :
  
  
typedef struct LaunchStruct {
	char		*pfName; 		/* pointer to the name of launchee */
	short int	param;
	char		LC[2]; 			/*extended parameters:*/
	long int	extBlockLen;		/*number of bytes in extension == 6*/
	short int	fFlags; 		/*Finder file info flags (see below)*/
	long int	launchFlags;		/*bit 31,30==1 for sublaunch, others reserved*/
} *pLaunchStruct;

pascal OSErr LaunchIt( pLnch) /* < 0 means error */
pLaunchStruct pLnch ;
{
	asm {
	 MOVE.L  (A7)+,A0
	  _Launch
	  MOVE.W  D0,(A7)  ; since it MAY return */
	}
}

OSErr DoLaunch(line)
char	*line ;
{
	struct LaunchStruct	myLaunch;
	OSErr			err;

		/*Set up the launch parameters*/
		myLaunch.pfName = line;	/*pointer to our fileName*/
		myLaunch.param = 0;		/*we don't want alternate screen
		myLaunch.LC[0] = 'L'; myLaunch.LC[1] = 'C';
		myLaunch.extBlockLen = 6;		/*length of param. block past
							  this long word*/
		/*copy flags; set bit 6 of low byte to 1 for RO access:*/
		/* gmc myLaunch.fFlags = 32;*/	/*from _GetCatInfo*/

		myLaunch.launchFlags = 0xC0000000;	/*set BOTH hi bits for a sublaunch	*/
		err = LaunchIt(&myLaunch);		/* call _Launch			*/
		if (err)
		{ printf("error = %d", err) ; }
}

ech@pegasus.ATT.COM (Edward C Horvath) (05/04/89)

From article <9410@j.cc.purdue.edu>, by aib@j.cc.purdue.edu (coleman):
> HELP !!

>   I am having major problems with sublaunching...

> pascal OSErr LaunchIt( pLnch) /* < 0 means error */
> pLaunchStruct pLnch ;
> {
> 	asm {
> 	 MOVE.L  (A7)+,A0
> 	  _Launch
> 	  MOVE.W  D0,(A7)  ; since it MAY return */
> 	}
> }

Depending on how your C compiler works -- I assume this is LSC from the
asm{...} -- you have either one or two longwords on the stack on top of
the address of the launch parameters, namely the return address, and
perhaps the old value of A6.  There is also no need for the pascal
keyword, since d0 is where _Launch leaves its result code, and where a
C caller expects to find it.  LSC also lets you access parameters
symbolically.  Thus, the following:

OSErr LaunchIt (pLnch)
	pLaunchStruct (pLnch);
{
	asm {
		move.l	pLnch,a0
		_Launch
	}
}

That's it.  In fact, if you have the LaunchStruct, you can embed the
trap right in your other routine:

	LaunchStruct Lnch;
	OSErr rslt;
...
	/* set up Lnch */
	asm {
		lea	Lnch,a0
		_Launch
		move.w	d0,rslt
	}

=Ned Horvath=

brecher@well.UUCP (Steve Brecher) (05/04/89)

In article <9410@j.cc.purdue.edu>, aib@j.cc.purdue.edu (coleman) writes:

>   I am having major problems with sublaunching. Everytime I try it,
>   I get a system beep, but it exits from there without returning
>   an error code. This was copied mostly from tech note # 126. Any 
>   help would be greatly appreciated.
>   
>   Source is as follows :
> 
> ...
> 
> pascal OSErr LaunchIt( pLnch) /* < 0 means error */
> pLaunchStruct pLnch ;
> {
>       asm {
>        MOVE.L  (A7)+,A0
>         _Launch
>         MOVE.W  D0,(A7)  ; since it MAY return */
>       }
> }
> 
> ...

In technote 126 LaunchIt is declared as an inline routine; that means the
compiler will generate the code at the place where LaunchIt is called. The
MPC C syntax = { <hex code } is not the same as other Cs' Asm directive. Your
compiler may not support inline functions.  The code you have doesn't work as
a real subroutine (C function).  To make LaunchIt into a callable function:

pascal OSErr LaunchIt(pLnch)
 pLaunchStruct pLnch ;
 {
        asm {
         MOVE.L  (A7)+,A1    ; pop return address
     Move.L  (A7)+,A0    ; pop struct pointer
          _Launch
          MOVE.W  D0,(A7)  ; since it MAY return */
     Jmp     (A1)        ; return to caller
        }
 }

(I didn't examine the rest of your code.)
-- 

brecher@well.UUCP (Steve Brecher)