Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!hplabs!hpda!hpcuhb!hpcllla!hpclisp!hpclscu!shankar From: shankar@hpclscu.HP.COM (Shankar Unni) Newsgroups: comp.sys.hp Subject: Re: Traps Message-ID: <1340014@hpclscu.HP.COM> Date: 25 Apr 88 20:52:20 GMT References: <4654@cup.portal.com> Organization: HP NSG/ISD Computer Language Lab Lines: 91 > / hpclscu:comp.sys.hp / Mike_W_Ryan@cup.portal.com / 5:11 pm Apr 20, 1988 / > Does anyone know of how to utilize control Y traps in PASCAL3000? Althogh Control-Y traps on the classic 3000's are a *little* tricky, unless you want to exit immediately on receipt of the Control-Y. This is because control-Y's on the classic 3000's push a variable number of items on the stack before calling the user's trap handler. The technique that we use goes as follows: we write a little onion-skin routine in SPL, whose PLabel is passed to XContrap for calling on receipt of the signal. The onionskin then calls the regular Pascal routine for doing the real thing on receipt of the control-Y. Specifically: SPL Onionskin: PROCEDURE AltCntlY; BEGIN PROCEDURE RealCntlY; OPTION EXTERNAL; INTRINSIC ResetControl; RealCntlY; << Call the real handler >> ResetControl; << Re-arm the control-y trap >> ASSEMBLE (ADDM *+2; XEQ 0); << This is why the onionskin is needed >> END; Pascal routine: PROCEDURE RealCntlY; (* the real thing *) BEGIN (* whatever you want to do on receipt of a control-Y *) END; Arming the trap (I assume you want to do it from the Pascal Outer Block): PROGRAM Whatever; ... VAR OldPLabel : -32768..32767; PROCEDURE XCONTRAP; INTRINSIC; PROCEDURE AltCntlY; EXTERNAL SPL; ... BEGIN (* outer block *) ... XConTrap (WAddress (AltCntlY), OldPLabel); (* arms the trap handler *) ... END. (* outer block *) If you just want to, say, print a message and exit on receipt of a Control-Y, then you can bypass the SPL onionskin, and pass the WAddress of the Pascal Handler directly to XContrap. > > While I am at it.. does anyone know if PASCAL on the SPECTRUM systems > (commercial) will support control Y traps? Absolutely. And here, fortunately, the Onionskin in SPL is not necessary. The calling convention is absolutely straightforward: Pascal trap handler: PROCEDURE RealCntlY; (* declarations *) PROCEDURE ResetControl; INTRINSIC; BEGIN (* RealCntlY *) (* whatever you do on receipt of a cntl-y *) ResetControl; (* re-arm the trap *) END; (* RealCntlY *) Outer block: PROGRAM Whatever; VAR OldPLabel : Integer; (* <<<< NOTE: 32-bit integer required!! *) ... PROCEDURE XContrap; INTRINSIC; PROCEDURE RealCntlY; EXTERNAL; (* or forward, or whatever ... *) ... BEGIN (* outer block *) ... XContrap (WAddress (RealCntlY), OldPLabel); (* arm the trap *) ... END. (* outer block *) > ---------- Shankar