supermario/bin/MPW-3.2.3/Examples/HyperXExamples/Reduce.a
2019-06-29 22:17:03 +08:00

90 lines
1.8 KiB
Plaintext

*
* Reduce - XFCN to compress runs of spaces and tabs to a space
* - Fully MPW 3.0 compatible
*
* Copyright © 1988 Apple Computer, Inc.
* All rights reserved.
*
* Sample HyperTalk line:
*
* put reduce(field 1) into field 1 -- reduce tabs & spaces
*
*
CASE OBJ
INCLUDE 'Traps.a'
INCLUDE 'HyperXCmd.a'
LOCALS EQU 0 ; Local storage will be on A6 stack frame, which
h EQU LOCALS-4 ; always counts backwards, so values negative.
LOCALSIZE EQU h
; PROCEDURE EntryPoint(paramPtr: XCmdPtr);
ENTRYPOINT MAIN EXPORT ; build script uses ENTRYPOINT as main segment name.
WITH XCmdBlock
; Set up the stack frame for local variables.
LINK A6,#LOCALSIZE
MOVEM.L A3/A4,-(SP)
; Get pointer to XCmdBlock
MOVE.L 8(A6),A4 ; get paramPtr
CLR.L returnValue(A4) ; initialize return to empty
MOVE.W paramCount(A4),D0
CMP.W #1,D0 ; only XFCN parameter is input string
BNE.S Done
; The heart and soul of the XFCN goes here.
tab EQU 9
space EQU 32
MOVE.L params(A4),A0 ; A0 = paramPtr->params[0]
_MoveHHi
MOVE.L params(A4),A0
_GetHandleSize ; How big is the original string?
_NewHandle ; Make room for a copy.
TST.W D0 ; Check error code
BNE.S Done ; Quit if no room
MOVE.L A0,A3 ; Save handle for return
MOVE.L params(A4),A0
MOVE.L (A0),A0 ; Get pointers to parse strings.
MOVE.L (A3),A1
Loop
MOVE.B (A0)+,D0
CMP.B #space,D0
BEQ.S InnerLoop
CMP.B #tab,D0
BNE.S GotChar
InnerLoop
MOVE.B (A0)+,D0
CMP.B #space,D0
BEQ.S InnerLoop
CMP.B #tab,D0
BEQ.S InnerLoop
MOVE.B #space,(A1)+
GotChar
MOVE.B D0,(A1)+
BNE.S Loop
MOVE.L A3,returnValue(A4)
Done ; Return to HyperCard.
MOVEM.L (SP)+,A3/A4
UNLK A6
MOVE.L (SP)+,A0 ; return address
ADDQ.L #4,SP ; clean off input parameter
JMP (A0)
ENDWITH
ENDMAIN
END