DIRECTORY Rope USING [ROPE], TextLooks USING [Looks], TextNode USING [RefTextNode], TextFindPrivate USING [FinderRecord]; TextFind: CEDAR DEFINITIONS = BEGIN RefTextNode: TYPE = TextNode.RefTextNode; ROPE: TYPE = Rope.ROPE; CR: CHAR = '\n; MalformedPattern: ERROR [ec: PatternErrorCode]; PatternErrorCode: TYPE = { toobig, -- pattern too long endquote, -- pattern ends with ' endtilda, -- pattern ends with ~ boundary, -- pattern has | inside rather than at beginning or end missingNameEnd, -- pattern has < without matching > unmatchedNameEnd -- pattern has > without previous < }; Finder: TYPE = REF FinderRec; FinderRec: TYPE = TextFindPrivate.FinderRecord; Create: PROC [pattern: RefTextNode, literal, word, ignoreLooks, ignoreCase, addBounds: BOOL _ FALSE, patternStart: INT _ 0, patternLen: INT _ LAST[INT]] RETURNS [finder: Finder]; CreateFromRope: PROC [pattern: ROPE, literal, word, ignoreCase, addBounds: BOOL _ FALSE, patternStart: INT _ 0, patternLen: INT _ LAST[INT]] RETURNS [finder: Finder]; NameLoc: PROC [finder: Finder, name: ROPE] RETURNS [at, atEnd: INT]; NameLooks: PROC [finder: Finder, name: ROPE] RETURNS [looks: TextLooks.Looks]; Try: PROC [finder: Finder, text: RefTextNode, start: INT _ 0, len: INT _ LAST[INT], looksExact: BOOL _ FALSE, interrupt: REF BOOL _ NIL] RETURNS [found: BOOL, at, atEnd, before, after: INT]; TryBackwards: PROC [finder: Finder, text: RefTextNode, start: INT _ 0, len: INT _ LAST[INT], looksExact: BOOL _ FALSE, interrupt: REF BOOL _ NIL] RETURNS [found: BOOL, at, atEnd, before, after: INT]; SearchRope: PROC [finder: Finder, rope: ROPE, start: INT _ 0, len: INT _ LAST[INT], interrupt: REF BOOL _ NIL] RETURNS [found: BOOL, at, atEnd, before, after: INT]; SearchRopeBackwards: PROC [finder: Finder, rope: ROPE, start: INT _ 0, len: INT _ LAST[INT], interrupt: REF BOOL _ NIL] RETURNS [found: BOOL, at, atEnd, before, after: INT]; Find: PROC [pattern, text: RefTextNode, literal, word, ignoreLooks, ignoreCase, looksExact, addBounds: BOOL _ FALSE, patternStart: INT _ 0, patternLen: INT _ LAST[INT], textStart: INT _ 0, textLen: INT _ LAST[INT], interrupt: REF BOOL _ NIL] RETURNS [found: BOOL, at, atEnd, before, after: INT]; BackwardsFind: PROC [pattern, text: RefTextNode, literal, word, ignoreLooks, ignoreCase, looksExact, addBounds: BOOL _ FALSE, patternStart: INT _ 0, patternLen: INT _ LAST[INT], textStart: INT _ 0, textLen: INT _ LAST[INT], interrupt: REF BOOL _ NIL] RETURNS [found: BOOL, at, atEnd, before, after: INT]; END. TextFind.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. derived from EditorFind.Mesa of Laurel 6 written by Bill Paxton, May 1981 last edit by Paxton, December 30, 1982 10:33 am Doug Wyatt, March 2, 1985 5:16:38 pm PST Michael Plass, March 21, 1985 2:40:46 pm PST This module provides a "Find" operation for text nodes The pattern is given as a substring of a text node The text to be searched is also a substring of a text node The search can be in either direction within the substring If a match character in the pattern has looks, the looks of the matching character(s) in the text will include those looks. For example, if the pattern includes a * with looks x and y, the characters matching the * will have looks x and y too. The matching characters may have other looks too. creates a record containing a "compiled" version of the pattern if literal is true, each character in pattern is taken literally if word flag is true, pattern only matches if no adjacent letters or digits if ignoreLooks is true, then ignore the looks of the pattern characters if ignoreCase is false, then alpha chars in pattern must match case otherwise, they can match either upper or lower if addBounds is true, add |'s to both ends of pattern name is the name of a subpattern value is where that subpattern matched last time name is the name of a subpattern value are looks that name had in the pattern searches text for first match in [start..start+len) i.e., searches up from start until reaches start+len if finds a match, returns with found = true, at = beginning of match or location corresponding to { in pattern atEnd = end of match or location corresponding to } in pattern after = end of entire match, which may be > atEnd if used } in pattern before = start of entire match, which may be < at if used { in pattern if looksExact is true, then match by equality, else by subset if interrupt^ becomes true, will stop searching searches text for last match in [start..start+len) i.e., searches down from start+len until reaches start Ê~˜codešœ ™ Kšœ Ïmœ1™™>KšœF™FKšœF™FKšœ=™=Kšœ/™/K˜—š¡ œžœ-žœ žœžœžœžœžœžœžœžœžœ žœžœ˜Éšœ2™2Kšœ6™6K˜——š¡ œžœžœ žœ žœžœžœžœžœžœžœ žœžœ˜¥K˜—š¡œžœžœ žœ žœžœžœžœžœžœžœ žœžœ˜®K˜—K˜š$¡œžœ^žœžœžœžœžœžœžœžœžœžœžœžœžœžœ žœžœ˜«K˜—š$¡ œžœ^žœžœžœžœžœžœžœžœžœžœžœžœžœžœ žœžœ˜´K˜—Kšžœ˜——…— äf