Trailing-Edge
-
PDP-10 Archives
-
decuslib10-05
-
43,50337/23/search.mac
There are 3 other files named search.mac in the archive. Click here to see a list.
COMMENT * SIMULA specification;
OPTIONS(/E:QUICK,search);
INTEGER PROCEDURE search(master,config);
TEXT master,config;
COMMENT Starting at master.Pos, search looks for a subtext of master = config.
If such a subtext is found, SEARCH gives Pos of the first character, i e
master.Sub(search(master,config)-1,config.Length) is the subtext sought,
otherwise SEARCH returns master.Length+1.
;
!*;! MACRO-10 code !*;!
TITLE search
ENTRY search
SUBTTL SIMULA utility, Lars Enderin Nov 1975
;!*** Copyright 1975 by the Swedish Defence Research Institute. ***
;!*** Copying is allowed. ***
;! Last Edit: [125], 1976-06-21/LE
sall
search simmac,simmcr,simrpa
macinit
;! Local definitions ;!
master==XWAC1
s==master ;! Local copy
config==XWAC3
cfp==config
c1==cfp+1 ;! To hold first character of config
ls==s+1 ;! (Remaining) length of master
lc==XIAC ;! Length of config
xa==XWAC6 ;! Work ac, usually word address in master
sp==xa
xb==XWAC7 ;! Work ac
sp1==xb
ls1==XWAC10 ;! Work ac, remaining characters at start of initial
;! match in master
cfp1==XWAC11
search: PROC
IF ;! Top ac is not XWAC1
CAIN XTAC,XWAC1
GOTO FALSE
THEN ;! Save ac's
nn==0
repeat 4,<
EXCH XWAC1+nn,nn(XTAC)
nn==nn+1
>
FI
SAVE <cfp1,c1,sp,sp1,ls1,ls,lc>
STACK XTAC
LF lc,ZTVLNG(,config)
STACK XWAC1 ;! Place text descr in stack
HRRZ s,XPDP
STACK XWAC2
LF ls,ZTVLNG(s) ;! s.Length
JUMPE lc,L8 ;! config.Length=0
LF X1,ZTVCP(s)
SUBI ls,(X1) ;! rest(s).Length
SETO ls1, ;! remaining length-1 at match:=-1
CAIGE ls,(lc)
GOTO nomatch ;! if config too long to fit
;! Compute byte pointers for CONFIG and MASTER
LF sp,ZTVSP(,config)
IF ;! config starts at beginning of config.Main
JUMPN sp,FALSE
THEN ;! Convert directly to byte pointer
ADD cfp,ptab+1
ELSE ;! Compute via word and byte offsets
IDIVI sp,5
ADDI cfp,2(sp)
HLL cfp,ptab+1(sp+1)
FI
LF sp,ZTVSP(s) ;! startpos(s)-1
SETZ sp1,
ADDI sp,(X1) ;! + s.Pos-1
IF ;! Non-zero effective offset
JUMPE sp,FALSE
THEN
IDIVI sp,5 ;! sp1:=offset in first word
FI
ADD sp,(s) ;! Address of first word to consider
ADDI sp,2
HLL sp,ptab(sp1) ;! Create byte pointer for master
LDB c1,cfp ;! c1:=config.Getchar
L1():! SUBI ls,-1(lc)
LOOP ;! Through initial characters of master
SOJL ls,nomatch
ILDB sp
AS
CAIE (c1)
GOTO TRUE
SA
;! c1 matched a character of master here
;! Now check following characters if any
ADDI ls,-1(lc)
LI ls1,(ls) ;! Remember 1st match
L sp1,sp
LI x2,(lc)
L cfp1,cfp
LOOP ;! Matching characters from config and master
SOJLE X2,fullmatch
ILDB X1,cfp1
SOJL ls,nomatch
ILDB sp
AS
CAIN (X1)
GOTO TRUE
SA
LI ls,(ls1)
L sp,sp1
SETZ ls1,
GOTO L1
nomatch:SETO ls1,
fullmatch:
LF ,ZTVLNG(s)
SUBI 1(ls1)
SF ,ZTVCP(s)
L8():! LF XWAC1,ZTVCP(s)
SUB XPDP,[2,,2] ;! Remove text descr from stack
ADDI XWAC1,1
UNSTK XTAC
RESTORE
IF ;! Xtop is not XWAC1
CAIN XTAC,XWAC1
GOTO FALSE
THEN ;! Restore ac's
nn==4
repeat 4,<
nn==nn-1
EXCH XWAC1+nn,nn(XTAC)
>
FI
POPJ XPDP,
EPROC
ptab: POINT 7,2,-1
POINT 7,2,6
POINT 7,2,13
POINT 7,2,20
POINT 7,2,27
POINT 7,2,34 ;! [125]
END;