perm filename SCANTO.MAC[SIM,SYS] blob sn#460215 filedate 1979-07-20 generic text, type T, neo UTF8
COMMENT * SIMULA specification;
OPTIONS(/E:QUICK,scanto);
TEXT PROCEDURE scanto(tt,c);
NAME tt; TEXT tt; CHARACTER c;
COMMENT Scans from tt.Pos until the next occurrence of
the character c.  Places tt.Pos after the character found.
The function value of scan is the text starting at the initial tt.Pos
and not including the character c found. If no character c is found,
tt.Pos will be = tt.Length+1, and scan denotes the rest of tt starting
at the initial tt.Pos.
;

!*;! MACRO-10 code !*;!

	TITLE	scanto
	ENTRY	scanto
	SUBTTL	SIMULA utility, Lars Enderin Nov 1975

;!*** Copyright 1975 by the Swedish Defence Research Institute. ***
;!*** Copying is allowed.					***

	sall
	search	simmac,simmcr,simrpa
	macinit

	;! Local definitions ;!

	tt==XWAC1
	t==tt
	c==XWAC3
	bp==X0
	l==XIAC
	c1==t+1


scanto:	PROC
	IF	;! Xtop is not XWAC1
		CAIN	XTAC,XWAC1
		GOTO	FALSE
	THEN	;! Rearrange ac's
		EXCH	XWAC1,(XTAC)
		EXCH	XWAC2,1(XTAC)
		EXCH	XWAC3,2(XTAC)
	FI
	ADDI	t,(t+1)	;! Address of text variable
	LF	X1,ZTVCP(t)	;! X1:=t.Pos-1
	LF	l,ZTVLNG(t)	;! l:=t.Length-X1
	SUBI	l,(X1)
	IF	;! NOT t.more
		JUMPG	l,FALSE
	THEN	;! Return NOTEXT, do not change tt.Pos
		SETZB	t,t+1
		GOTO	L9
	FI
	LF	,ZTVSP(t)
	ADDI	(X1)
	IDIVI	5
	ADD	(t)
	HRRZ
	ADD	bytep(X1)
	LOOP
		ILDB	c1,
		CAIN	c1,(c)
		GOTO	found
	AS
		SOJG	l,TRUE
	SA
found:	LF	X1,ZTVLNG(t)
	SUBI	X1,(l)		;! X1:=t.Length-l
	LF	,ZTVCP(t)	;! tt.Pos
	SF	X1,ZTVCP(t)	;! tt.Pos:=X1+1
	IF	;! Found
		JUMPLE	l,FALSE
	THEN	;! Adjust tt.Pos
		AOS	OFFSET(ZTVCP)(t)
	FI
	SUB	X1,		;! X1:=X1-t.Pos+1
	IF	;! X1 > 0
		JUMPLE	X1,FALSE
	THEN
		L	c,t		;! Save text var address
		MOVSI	t+1,(X1)	;! scan.Length:=X1;! scan.Pos:=1
		MOVSM	t		;! tt.Pos,,0
		ADD	t,(c)		;! +offset,,text obj addr
	ELSE
		SETZB	t,t+1	;! NOTEXT
	FI
L9():!
	IF	;! Xtop is not XWAC1
		CAIN	XTAC,XWAC1
		GOTO	FALSE
	THEN
		EXCH	XWAC3,2(XTAC)
		EXCH	XWAC2,1(XTAC)
		EXCH	XWAC1,(XTAC)
	FI
	RETURN
	EPROC

bytep:	POINT	7,2,-1
	POINT	7,2,6
	POINT	7,2,13
	POINT	7,2,20
	POINT	7,2,27
	LIT
	END;