DIRECTORY TreeFind, TextFind, TiogaNode, TiogaNodeOps, TiogaPathOps, TextEdit, NameSymbolTable, Rope; TreeFindImpl: CEDAR PROGRAM IMPORTS TextFind, TiogaNodeOps, TiogaPathOps EXPORTS TreeFind = BEGIN OPEN TreeFind, TiogaNode; Try: PUBLIC PROC [finder: Finder, first: Path, start: Offset _ 0, last: Path _ [NIL, NIL], lastLen: Offset _ MaxLen, looksExact: BOOLEAN _ FALSE, commentControl: CommentControl _ includeComments, checkFormat: BOOLEAN _ FALSE, format: TiogaNode.Name _ TiogaNode.nullName, checkStyle: BOOLEAN _ FALSE, style: NameSymbolTable.Name _ NameSymbolTable.nullName, styleProc: PROC [Ref] RETURNS [NameSymbolTable.Name] _ NIL, interrupt: REF BOOL _ NIL] RETURNS [found: BOOLEAN, where: Path, at, atEnd, before, after: Offset] = TRUSTED { p: Path _ first; found _ FALSE; DO -- test new node each time through the loop n: TiogaNode.RefTextNode; node: TiogaNode.Ref; lastOne: BOOL = TiogaPathOps.Equal[p, last]; IF (node _ p.node)=NIL THEN RETURN; IF checkFormat AND node.format # format THEN NULL ELSE IF checkStyle AND styleProc[node] # style THEN NULL ELSE IF (n _ TiogaNodeOps.NarrowToTextNode[node])#NIL THEN BEGIN IF (SELECT commentControl FROM excludeComments => ~n.comment, commentsOnly => n.comment, ENDCASE => TRUE) THEN BEGIN IF finder # NIL THEN [found,at,atEnd,before,after] _ TextFind.Try[finder,n,start, IF lastOne THEN lastLen-start ELSE MaxLen,looksExact,interrupt] ELSE { found _ TRUE; at _ before _ 0; atEnd _ after _ TiogaNodeOps.Size[n] }; END; IF found THEN { where _ p; RETURN }; END; start _ 0; IF lastOne THEN RETURN; p _ TiogaPathOps.StepForwardNode[p]; ENDLOOP }; TryBackwards: PUBLIC PROC [finder: TextFind.Finder, first: Path, len: Offset _ MaxLen, last: Path _ [NIL, NIL], lastStart: Offset _ 0, looksExact: BOOLEAN _ FALSE, commentControl: CommentControl _ includeComments, checkFormat: BOOLEAN _ FALSE, format: TiogaNode.Name _ TiogaNode.nullName, checkStyle: BOOLEAN _ FALSE, style: NameSymbolTable.Name _ NameSymbolTable.nullName, styleProc: PROC [Ref] RETURNS [NameSymbolTable.Name] _ NIL, interrupt: REF BOOL _ NIL] RETURNS [found: BOOLEAN, where: Path, at, atEnd, before, after: Offset] = TRUSTED { p, parent: Path; found _ FALSE; p _ first; DO -- test new node each time through the loop n: TiogaNode.RefTextNode; node: TiogaNode.Ref; lastOne: BOOL = TiogaPathOps.Equal[p, last]; IF (node _ p.node)=NIL THEN RETURN; IF checkFormat AND node.format # format THEN NULL ELSE IF checkStyle AND styleProc[node] # style THEN NULL ELSE IF (n _ TiogaNodeOps.NarrowToTextNode[node])#NIL THEN BEGIN IF (SELECT commentControl FROM excludeComments => ~n.comment, commentsOnly => n.comment, ENDCASE => TRUE) THEN BEGIN IF finder # NIL THEN [found,at,atEnd,before,after] _ TextFind.TryBackwards[finder,n, IF lastOne THEN lastStart ELSE 0,len,looksExact,interrupt] ELSE { found _ TRUE; at _ before _ 0; atEnd _ after _ TiogaNodeOps.Size[n] }; END; IF found THEN { where _ p; RETURN }; END; IF lastOne THEN RETURN; [p,parent] _ TiogaPathOps.StepBackwardNode[p,parent]; len _ MaxLen; ENDLOOP }; Apply: PUBLIC PROC [finder: Finder, first: Path, proc: ApplyProc, start: Offset _ 0, last: Path _ [NIL, NIL], lastLen: Offset _ MaxLen, looksExact: BOOLEAN _ FALSE, commentControl: CommentControl _ includeComments, checkFormat: BOOLEAN _ FALSE, format: TiogaNode.Name _ TiogaNode.nullName, checkStyle: BOOLEAN _ FALSE, style: NameSymbolTable.Name _ NameSymbolTable.nullName, styleProc: PROC [Ref] RETURNS [NameSymbolTable.Name] _ NIL] RETURNS [count: LONG INTEGER] = { where, p: Path; at, atEnd, before, after, from, delta: Offset; found, continue, bumpCount: BOOLEAN; count _ 0; p _ first; UNTIL p.node=NIL DO IF TiogaPathOps.Equal[p, last] AND start >= lastLen THEN RETURN; [found,where,at,atEnd,before,after] _ Try[finder,p,start,last,lastLen,looksExact,commentControl, checkFormat,format,checkStyle,style,styleProc]; IF ~found THEN RETURN; [continue,bumpCount,from,delta] _ proc[where,at,atEnd,before,after]; IF bumpCount THEN count _ count+1; IF ~continue THEN RETURN; IF TiogaPathOps.Equal[where, last] AND lastLen < MaxLen THEN lastLen _ lastLen+delta; IF finder # NIL THEN { p _ where; start _ from } ELSE { p _ TiogaPathOps.StepForwardNode[p]; start _ 0 }; ENDLOOP }; END. ÚTreeFindImpl.Mesa; written by Bill Paxton, June 1981 edited by McGregor, February 8, 1983 9:59 am edited by Paxton, June 9, 1983 10:44 am edited by Maxwell, January 5, 1983 3:51 pm go to next one go to next one �Êc˜Jšœ4™4Jšœ,™,Jšœ'™'Jšœ*™*J˜šÏk ˜ J˜ J˜ J˜ J˜ J˜ J˜ J˜J˜J˜—šœ�œ�˜Jš�œ%˜,Jš�œ ˜J˜—Jš�œ�œ˜J˜šÏnœ�œ�œ1˜AJš œ�œ�œ)�œ�œ˜OJ˜1Jšœ �œ�œ.˜JJšœ �œ�œ9˜TJšœ �œ�œ�œ˜;Jšœ �œ�œ�œ˜Jš�œ �œ3�œ˜SJšœ˜Jšœ�œ˜š�œÏc+˜.Jšœ�˜J˜Jšœ �œ˜,Jš�œ�œ�œ�œ˜#Jš�œ �œ�œ�˜1Jš �œ�œ �œ�œ�˜8š �œ�œ+�œ�œ�˜@š�œ�œ�˜J˜J˜š�œ�œ�œ�œ˜š�œ �œ�˜˜˜Jš�œ �œ�œ˜?———š�œ˜Jšœ�œ˜ J˜J˜'—Jš�œ˜——Jš�œ�œ�œ˜$Jš�œ˜—Jšœ™J˜ Jš�œ �œ�œ˜Jšœ$˜$Jš�œ˜ J˜——šž œ�œ�œ'˜@Jšœ$�œ�œ˜EJšœ �œ�œ3˜NJšœ �œ�œ.˜JJšœ �œ�œ9˜TJšœ �œ�œ�œ˜;Jšœ �œ�œ�œ˜Jš�œ �œ3�œ˜SJšœ˜Jšœ�œ˜Jšœ ˜ š�œŸ+˜.Jšœ�˜J˜Jšœ �œ˜,Jš�œ�œ�œ�œ˜#Jš�œ �œ�œ�˜1Jš �œ�œ �œ�œ�˜8š �œ�œ+�œ�œ�˜@š�œ�œ�˜J˜J˜š�œ�œ�œ�œ˜š�œ �œ�˜˜?Jš�œ �œ �œ˜:——š�œ˜Jšœ�œ˜ J˜J˜'—Jš�œ˜——Jš�œ�œ�œ˜$Jš�œ˜—Jšœ™Jš�œ �œ�œ˜Jšœ5˜5J˜ Jš�œ˜ J˜——šžœ�œ�œB˜TJš œ�œ�œ)�œ�œ˜OJ˜1Jšœ �œ�œ.˜JJšœ �œ�œ9˜TJšœ �œ�œ�œ˜;Jš�œ �œ�œ˜!Jšœ˜J˜.Jšœ�œ˜$Jšœ˜š�œ�œ�˜Jš�œ�œ�œ�œ˜@˜%˜:J˜/——Jš�œ�œ�œ˜J˜DJš�œ �œ˜"Jš�œ �œ�œ˜Jš�œ!�œ�œ˜UJš�œ �œ�œ˜0Jš�œ4˜8Jš�œ˜ J˜——Jš�œ˜J˜—…—~»