Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!rutgers!bellcore!faline!ulysses!ucbvax!CITHEX.CALTECH.EDU!carl From: carl@CITHEX.CALTECH.EDU (Carl J Lydick) Newsgroups: comp.os.vms Subject: Re: TPU Range (In)equality Message-ID: <870920181935.079@CitHex.Caltech.Edu> Date: Sun, 20-Sep-87 23:48:17 EDT Article-I.D.: CitHex.870920181935.079 Posted: Sun Sep 20 23:48:17 1987 Date-Received: Tue, 22-Sep-87 01:23:22 EDT References: <870917081437.01q@Mipl3.JPL.Nasa.Gov> Sender: daemon@ucbvax.BERKELEY.EDU Organization: The ARPA Internet Lines: 75 > My goal is to find a target string if if it exists in the current > line. To do so, I set up the following TPU code: > ; target := 'xyz'; ! In real life this is variable ; pat1 := target | LINE_END; ; pat2 := LINE_END; ; target_range := search (pat1, FORWARD, EXACT); ; eol_range := search (pat2, FORWARD, EXACT); ; ; if target_range = eol_range then ; message ("String not found"); ; else ; message ("Target found"); ; endif; > What I can't figure out is why the only response that I can get from that > code is "String not found" when the two ranges are distinctly different. > I've also tried setting "pat1 := '' & (target | LINE_END);", that doesn't > do what I want either. That's odd; when I run the same code fragment, the only response I ever get is: "Target found"; perhaps it's because I'm left-handed. > My question is: What constitutes (in)equality of ranges? How should I set > up my patterns to find what I am looking for and take two different actions > on the basis of what is found? In answer to the question of what constitutes (in)equality of ranges, as near as I can tell no two ranges can ever be equal. This might even make sense in a warped fashion, since it is possible to have two ranges referring to the same text, have the same video attributes, etc. However, you can delete one of the markers without deleting the other if they were created independently. For example: m0:=mark(none); m1:=mark(none); r0:=create_range(m0,m1,reverse); r1:=create_range(m0,m1,reverse); delete(r1); results in one reverse video range, while m0:=mark(none); m1:=mark(none); r0:=create_range(m0,m1,reverse); r1:=r0; delete(r1); results in none. You might expect r0 and r1 to be considered unequal in the first example, but in the second example, we find that even if two ranges are equivalent to the extent that whatever you do to one happens to both, they're still not considered equal. At any rate, the definition of ranges isn't pinned down nearly well enough in the orange manuals for me to figure what equality might mean. Now, in response to your question about how to force TPU to act like a halfway reasonable editor and let you know whether a given pattern occurs on the current line, the following does what you say you want done; it's not elegant, but neither is TPU, at least in its current incarnation. target := 'xyz'; ! In real life this is variable pat1 := target; ! Don't force match to be on same line pat2 := LINE_END; eol_range := search (pat2, FORWARD, EXACT); target_range := search (pat1, FORWARD, EXACT); ! First check to make sure the target was found someplace; then make ! sure the end of the match is not beyond the current line, by ! comparing the endpoints of both ranges. if (target_range <> 0) then if end_of(eol_range) >= end_of(target_range) then message ("Target found"); else target_range := eol_range; message ("String not found!"); endif; else target_range := eol_range; message ("String not found!"); endif;