From: CSBVAX::MRGATE!@KL.SRI.Com,@wiscvm.wisc.edu:MSIEWEKE@GTRI01.BITNET@SMTP 22-SEP-1987 07:12 To: EVERHART Subj: tpu searching on same line Received: from wiscvm.wisc.edu by KL.SRI.COM with TCP; Mon 21 Sep 87 14:10:39-PDT Received: from GTRI01.BITNET by wiscvm.wisc.edu ; Mon, 21 Sep 87 16:15:40 CDT Received: by GTRI01 (Mailer X1.23b) id 9566; Mon, 21 Sep 87 17:11:10 EDT Date: Mon, 21 Sep 87 16:50:31 EDT From: Mike Sieweke Subject: tpu searching on same line To: INFO-VAX@KL.SRI.COM > 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. This is almost correct. You don't want to compare the ranges returned by search. You want to compare the _beginning_ of the ranges. ; if beginning_of(target_range) = beginning_of(eol_range) then If target is found, target_range will start with target. If target is not found, target_range will begin with line_end. (Only true if using incremental search. See below.) Another little tidbit: pat1:=''&(target|line_end) is the correct way to do this. TPU has 2 methods of searching: incremental and seek. The default method is seek. Prepending ''& to the beginning of your pattern forces incremental search. In seek mode, TPU takes the first part of your pattern and searches the whole file for it. If the first part is not found, TPU backs up and searches for the next part. Thus in your code, if "target" existed beyond the current line, search would return a range containing "target" wherever it existed. It would _not_ stop at line_end since it has to fail searching for "target" before it searches for line_end. In incremental search mode, TPU searches like you would expect: compare the current position to the _whole_ pattern, then move if not found. Seek mode is the faster one. But in your case you only want to look at the current line, and speed is not quite as important. Hope this helps... Mike Sieweke Georgia Tech Research Institute Atlanta, Georgia