DIRECTORY Rope USING [ROPE], TextFind USING [Finder], TextNode USING [Ref, RefTextNode]; TreeFind: CEDAR DEFINITIONS = BEGIN Ref: TYPE = TextNode.Ref; RefTextNode: TYPE = TextNode.RefTextNode; ROPE: TYPE = Rope.ROPE; Finder: TYPE = TextFind.Finder; Create: PROC [pattern: RefTextNode, literal, word, ignoreLooks, ignoreCase, addBounds: BOOL _ FALSE, patternStart: INT _ 0, patternLen: INT _ LAST[INT]] RETURNS [Finder]; CreateFromRope: PROC [pattern: ROPE, literal, word, ignoreCase, addBounds: BOOL _ FALSE, patternStart: INT _ 0, patternLen: INT _ LAST[INT]] RETURNS [Finder]; CommentControl: TYPE = { includeComments, excludeComments, commentsOnly }; Try: PROC [finder: Finder, first: Ref, start: INT _ 0, last: Ref _ NIL, lastLen: INT _ LAST[INT], looksExact: BOOL _ FALSE, commentControl: CommentControl _ includeComments, checkFormat: BOOL _ FALSE, format: ATOM _ NIL, checkStyle: BOOL _ FALSE, style: ATOM _ NIL, styleProc: PROC [Ref] RETURNS [ATOM] _ NIL, interrupt: REF BOOL _ NIL ] RETURNS [found: BOOL, where: RefTextNode, at, atEnd, before, after: INT]; TryBackwards: PROC [ finder: Finder, first: Ref, len: INT _ LAST[INT], last: Ref _ NIL, lastStart: INT _ 0, looksExact: BOOL _ FALSE, commentControl: CommentControl _ includeComments, checkFormat: BOOL _ FALSE, format: ATOM _ NIL, checkStyle: BOOL _ FALSE, style: ATOM _ NIL, styleProc: PROC [Ref] RETURNS [ATOM] _ NIL, interrupt: REF BOOL _ NIL ] RETURNS [found: BOOL, where: RefTextNode, at, atEnd, before, after: INT]; Apply: PROC [ finder: Finder, first: Ref, proc: ApplyProc, start: INT _ 0, last: Ref _ NIL, lastLen: INT _ LAST[INT], looksExact: BOOL _ FALSE, commentControl: CommentControl _ includeComments, checkFormat: BOOL _ FALSE, format: ATOM _ NIL, checkStyle: BOOL _ FALSE, style: ATOM _ NIL, styleProc: PROC [Ref] RETURNS [ATOM] _ NIL ] RETURNS [count: LONG INTEGER]; ApplyProc: TYPE = PROC [where: RefTextNode, at, atEnd, before, after: INT] RETURNS [continue, bumpCount: BOOL, from, delta: INT]; END. bTreeFind.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. written by Bill Paxton, June 1981 last edit by Bill Paxton, December 30, 1982 10:30 am Doug Wyatt, March 2, 1985 5:25:56 pm PST Michael Plass, March 21, 1985 2:55:53 pm PST Rick Beach, March 27, 1985 1:00:13 pm PST This module provides a "Find" operation for text in trees The pattern matching is done by TextFind.Mesa This module simply walks the tree (forward or backwards) applying the text creates a record containing a "compiled" version of the pattern see TextFind.Mesa for more info about patterns 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 if 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 searches first node beginning at start continues until finds a match or reaches last node seaches lastLen chars in last node; seaches to end of other nodes 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 commentControl allows restriction of search to comments/noncomments if checkFormat is true, then only match in nodes with given format if checkStyle is true, then only match in nodes with given style styleProc is supplied so called can determine style for nodes if just interested in format/style, can pass finder=NIL if interrupt^ becomes true, will stop searching searches first node from start=0 to end=len continues back through tree until finds a match or reaches last node searches from lastStart in last node; searches from 0 in other nodes finds a span of text and calls proc arg's are results from Try if continue is true, Apply will Try again starting at "from" in "where" delta tells change in length caused by the action Apply does the following with delta IF where=last AND lastLen < LAST[INT] THEN lastLen _ lastLen+delta if bumpCount is true, Apply will increment its result counter Κ˜codešœ ™ Kšœ Οmœ1™™>KšœF™FKšœF™FKšœ=™=KšœC™CKšœB™Bšœ@™@Kšœ=™=—Kšœ7™7Kšœ/™/K˜——š6  œžœ$žœžœžœžœ žœžœžœAžœžœ žœžœžœžœ žœžœ žœžœžœžœ žœžœžœžœ žœ0žœ˜₯šœ+™+KšœD™DKšœD™DK˜——šH œžœžœ žœžœžœžœ žœžœ žœžœžœžœ žœžœžœ1žœ žœžœžœžœžœžœ žœžœžœžœžœžœ žœžœžœžœžœ žœžœ˜ιKšœ#™#K˜—š  œžœžœ0žœžœžœžœ˜šœ™KšœG™Gšœ1™1Kšœ#™#Kšœžœžœ™B—Kšœ=™=—K˜——K™Kšžœ˜—…—Ξ4