[comp.sys.mac.programmer] Getting _Launch trap file name

andyb@hasvcr.UUCP (Andy Babinszki) (08/01/89)

I want to fire up a particular desk accessory every time a programme is 
launched.  I have no trouble installing a patch to the launch trap, 
however, I cannot isolate the name of the application to be launched ( needed
by the DA ).  When I pass control to the original launch trap, everything
works as it should.  According to Inside Macintosh V.II p. 60, A0 contains
all the launch parameters.  0(A0) is a pointer to a PASCAL string which is
the name of the file to be launched.  ( ie. the string is preceeded by a 
length byte )  If that is so then the following code should be able to
copy the app name into curAppName without problems, as far as I can see.
But the catch is that it doesn't.  I'd appreciate it if anyone could tell
me what I'm doing wrong.


 Note:   I tried to LEA NoAppName,A0
         instead of the actual (A0), and that worked as it should.


Thankyou,

Andy Babinszki

...!ubc-cs!van-bc!hasvcr!andyb


The actual patch code:

    MOVEM.L     D0-D7/A0-A6,-(SP)       ; Save registers

    Move.L      0(A0),-(SP)             ; save pointer to app name

    Pea     -4(A5)
    _InitGraf
    _InitResources
    _InitFonts
    _InitWindows
    _TEInit
    Clr.L       -(SP)
    _InitDialogs
    _InitCursor
    
    Move.L      (SP)+,A0            ; get pointer to app name
    Clr.L       D0
    Move.B      (A0),D0             ; get length byte
    Add.L       #1,D0
    Cmp.B       #64,D0              ; names > 64 chars are illegal
    Bgt.S       OutAHere            ; if D0 - 64 > 0 => namelen > 64
    LEA         CurAppName, A1
    _BlockMove
    
    Clr.W       -(SP)
    Pea         DAName
    _OpenDeskAcc
    
    Move.W      (SP)+,D0                ; dump the return value
    
OutAHere:

    MOVEM.L     (SP)+,D0-D7/A0-A6       ; Restore registers
    
    Move.L      OldTrap,-(SP)           ; the REAL _Launch trap
    RTS

OldTrap     DC.L    0
InstallFlag DC.W    0
DAName      DC.B    $C,00,'SomeDeskAcc'
grafPtr     DC.L    0
CurAppName  DCB.B   64,0
NoAppName   DC.B    $F,00,'No Application' 

EndPatch    DC.B    0

    End