kka059@Mipl3.JPL.Nasa.GOV (09/17/87)
If anyone has mastered (at least more than I have) the arcane world of TPU variables, I have a question for you... 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. 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? As usual, please reply directly to me and I will summarize to the net. +----------------------------+------------------------------------------+ | Kurt Andersen | Jet Propulsion Laboratory | | MIPL Applications | Mail Stop 168-427 | | Programmer | 4800 Oak Grove Drive | | Office: 169-425 | Pasadena, Calif. 91109 | +----------------------------+-------------------------+----------------+ | NETWORKS: | "The time has | | SPAN: Mipl3::KKA059 (5.153) | come," the | | ARPA Internet: KKA059@Mipl3.Jpl.Nasa.Gov | walrus said, | | Internet Address: [128.149.1.28] | | | ARPAnet->SPAN: KKA059%Mipl3@Su-Star.Stanford.Edu | "to speak of | | or: KKA059%Mipl3.Span@Jpl-Vlsi.Arpa | many things: | | Ma Bell (R.I.P.): (818) 354-1672 | of patterns | +------------------------------+-----------------------+ and ranges, | | (Apologies to the author) -> | and variables, of TPU and things..." | +------------------------------+----------------------------------------+
carl@CITHEX.CALTECH.EDU (Carl J Lydick) (09/21/87)
> 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;