(1 / 1)
Date: October 26, 1987 19:45
From: KIM::SHEPPERD
To: @sys$mail:engineer,SHEPPERD
Occasionally I've been asked how to make TPU search for \n's in a file. TPU
can do it, but it is a bit messy. I've needed to do it from time to time too,
so I figured out a way to make it less messy and built it into the section
file. This new procedure allows you to use all the features of TPU's pattern
matching expressions, so I'll briefly point out the functions:
ANY(string) !matches any character in the string
ARB(int) !matches an arbitray string of int characters
LINE_BEGIN !matches beginning of line
LINE_END !matches end of line
MATCH(string) !matches all chars up to and including string
NOTANY(string) !matches any character NOT in the string
REMAIN !matches all characters to end of line
SCAN(string) !Matches the longest string of chars that does
not contain any of the chars in string
SCANL(string) !same as SCAN but will cross record boundaries
SPAN(string) !matches the longest string of chars that only
contains the chars in string
ANCHOR !search without moving off current position
(advanced uses)
The pattern operators (which have equal precedence) are:
| !alternation (logical or)
& !concatenation (logical and)
Strings must be enclosed in either single quotes ('string') or double
quotes ("string"). Parentheses may be used around subexpressions.
No other operators are allowed. Some examples:
"abc" !find string 'abc'
'a' & 'b' & 'c' !find string where a before b before c ("abc")
LINE_BEGIN & 'fred' !find string where "FRED" is first thing on line
LINE_BEGIN & " " !find line beginning with a tab
^ there's a tab character here
')};' & LINE_END !find line where ")};" is the last thing on it
LINE_BEGIN & ANY("0123456789") !find line beginning with any number
SPAN('0123456789') & '$' !find a local symbol
"Oh goody, how do I use this spiffy thing", you ask? You have two choices. You
may type GOLD/PF3, enter the search pattern and terminate it with another PF3 or
you may open a buffer (GOLD/B to some empty buffer), enter your search pattern
in that buffer, go back to the buffer you want to search through, type GOLD/PF3
=buffer_name terminating with another PF3. If TPU liked your expression, it'll
search the buffer as always with PF3 finding the next occurance just as before.
If TPU didn't like your expression, you'll get various nasty messages. If you
use the buffer method then, of course, you can edit the buffer to fix your
problem (or change what you want to seach on). Typing GOLD/PF3/PF3 will prompt
for a "Search string (RE): " to which you can type a search expression or
the =buffer_name and terminate it with a carriage return, KP4 or KP5. You may
also notice that some extra stuff was inserted in your search string buffer
the first time you use it, please don't change the extra stuff or you'll find
your search string will always fail.
If you're really intrested, here's a big example of a complex search sequence
(stolen from a TPU procedure to find the next word, the variable edt$x_word has
been defined as a string of the characters that may delimt a word):
! Redefine the forward word skipper:
!
! don't move off current character position
(
anchor
&
! if on eol,then match that
(
(line_end)
|
!leading spaces,on a word delimiter
(span(' ') & (any(edt$x_word) | edt$x_empty) ) )
|
!no leading spaces, if on a word delimiter, move to second grp non-delimiter char
( span(edt$x_word) !skip all the leading delimiters
& scan(edt$x_word) !skip all the non-delimiters
& span(edt$x_word) ) !and skip all the next delimiters
|
!no leading spaces, on a real word, go to next word
(scan(edt$x_word) & span(edt$x_word))
|
!no leading spaces,on a last real word of line, match rest of line
REMAIN
)
&
! after matching, skip over trailing spaces if any
! except if match occurred at the eol. In this case,don't skip over blanks
(line_begin|span(' ') | edt$x_empty)
;
! End of forward word skipper
Oct 26, 1987