Trailing-Edge
-
PDP-10 Archives
-
decuslib20-03
-
decus/20-0078/libsim/change.sim
There is 1 other file named change.sim in the archive. Click here to see a list.
OPTIONS(/E/C/-Q/-A/-I/-D);
EXTERNAL TEXT PROCEDURE conc,from,upto;
EXTERNAL INTEGER PROCEDURE search;
COMMENT Change will change the subtext TOLD in MASTER - if
found when searching from MASTER.POS and on - to TNEW.
If TOLD.Length >= TNEW.Length then MASTER will denote
a subtext of the original MASTER text, otherwise MASTER will
denote a new text object.
Thus, if TOLD is NOTEXT, TNEW will be inserted before actual Pos.
If TNEW is NOTEXT, the TOLD part found after Pos will be deleted.
If MASTER is NOTEXT, no change will ever occur.
Changing all occurrencies of TOLD to TNEW may
be done with the following procedure:
! PROCEDURE edit(master,told,tnew);
! NAME master;
! TEXT master,told,tnew;
! BEGIN TEXT local;
! local:- master;
! WHILE local.More DO change(local,told,tnew);
! master:- local
! END of edit;
BOOLEAN PROCEDURE change(master,told,tnew); NAME master;
TEXT master,told,tnew;
BEGIN TEXT local; INTEGER p;
local:- master;
p:= search(local,told);
IF p <= local.Length THEN
BEGIN change:= TRUE;
IF told.Length >= tnew.Length THEN
BEGIN local.Sub(p,tnew.Length):= tnew;
IF told.Length > tnew.Length THEN
BEGIN
from(local,p+tnew.Length):= from(local,p+told.Length);
local:- local.Sub(1,local.Length-told.Length+tnew.Length)
END
END ELSE
local:- conc(upto(local,p),tnew,from(local,p+told.Length));
local.Setpos(p+tnew.Length); master:- local
END ELSE master.Setpos(0);
END of change;