DIRECTORY TreeFind, TextFind, TiogaNode, TiogaNodeOps, TextEdit, NameSymbolTable, Rope; TreeFindImpl: CEDAR PROGRAM IMPORTS TextFind, TiogaNodeOps, TextEdit EXPORTS TreeFind = BEGIN OPEN TreeFind, TiogaNode; Try: PUBLIC PROC [finder: Finder, first: Ref, start: Offset _ 0, last: Ref _ NIL, lastLen: Offset _ MaxLen, looksExact: BOOLEAN _ FALSE, commentControl: CommentControl _ includeComments, checkType: BOOLEAN _ FALSE, type: 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: RefTextNode, at, atEnd, before, after: Offset] = TRUSTED { node: Ref; found _ FALSE; IF (node _ first)=NIL THEN RETURN; DO -- test new node each time through the loop IF checkType AND node.format # type THEN NULL ELSE IF checkStyle AND styleProc[node] # style THEN NULL ELSE IF TiogaNodeOps.IsText[node] THEN BEGIN n: TiogaNode.RefTextNode = TiogaNodeOps.NarrowToTextNode[node]; 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 n=last THEN lastLen-start ELSE MaxLen,looksExact,interrupt] ELSE { found _ TRUE; at _ before _ 0; atEnd _ after _ TextEdit.Size[n] }; END; IF found THEN { where _ n; RETURN }; END; start _ 0; IF node=last THEN RETURN; IF (node _ TiogaNodeOps.StepForwardNode[node])=NIL THEN RETURN; ENDLOOP }; TryBackwards: PUBLIC PROC [finder: TextFind.Finder, first: Ref, len: Offset _ MaxLen, last: Ref _ NIL, lastStart: Offset _ 0, looksExact: BOOLEAN _ FALSE, commentControl: CommentControl _ includeComments, checkType: BOOLEAN _ FALSE, type: 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: RefTextNode, at, atEnd, before, after: Offset] = TRUSTED { node, parent: Ref; found _ FALSE; IF (node _ first)=NIL THEN RETURN; DO -- test new node each time through the loop IF checkType AND node.format # type THEN NULL ELSE IF checkStyle AND styleProc[node] # style THEN NULL ELSE IF TiogaNodeOps.IsText[node] THEN BEGIN n: TiogaNode.RefTextNode = TiogaNodeOps.NarrowToTextNode[node]; 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 n=last THEN lastStart ELSE 0,len,looksExact,interrupt] ELSE { found _ TRUE; at _ before _ 0; atEnd _ after _ TextEdit.Size[n] }; END; IF found THEN { where _ n; RETURN }; END; len _ MaxLen; IF node=last THEN RETURN; [node,parent] _ TiogaNodeOps.StepBackwardNode[node,parent]; IF node=NIL THEN RETURN; ENDLOOP }; Apply: PUBLIC PROC [finder: Finder, first: Ref, proc: ApplyProc, start: Offset _ 0, last: Ref _ NIL, lastLen: Offset _ MaxLen, looksExact: BOOLEAN _ FALSE, commentControl: CommentControl _ includeComments, checkType: BOOLEAN _ FALSE, type: TiogaNode.Name _ TiogaNode.nullName, checkStyle: BOOLEAN _ FALSE, style: NameSymbolTable.Name _ NameSymbolTable.nullName, styleProc: PROC [Ref] RETURNS [NameSymbolTable.Name] _ NIL] RETURNS [count: LONG INTEGER] = { where: RefTextNode; node: Ref; at, atEnd, before, after, from, delta: Offset; found, continue, bumpCount: BOOLEAN; count _ 0; node _ first; UNTIL node=NIL DO IF node=last AND start >= lastLen THEN RETURN; [found,where,at,atEnd,before,after] _ Try[finder,node,start,last,lastLen,looksExact,commentControl, checkType,type,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 where=last AND lastLen < MaxLen THEN lastLen _ lastLen+delta; IF finder # NIL THEN { node _ where; start _ from } ELSE { node _ TiogaNodeOps.StepForwardNode[node]; 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 Ê!˜Jšœ4™4Jšœ,™,Jšœ'™'Jšœ*™*J˜šÏk ˜ J˜ J˜ J˜ J˜ J˜ J˜J˜J˜—šœœ˜Jšœ!˜(Jšœ ˜J˜—Jšœœ˜J˜šÏnœœœ0˜@Jšœ œ(œœ˜GJ˜1Jšœ œœ,˜FJšœ œœ9˜TJšœ œœœ˜;Jšœ œœœ˜Jšœ œ:œ˜ZJ˜ Jšœœ˜Jšœœœœ˜"šœÏc+˜.Jšœ œœ˜-Jš œœ œœ˜8šœœœ˜,J˜?šœœ˜J˜J˜šœœœœ˜šœ œ˜˜˜Jšœœœ˜>———šœ œ˜J˜J˜#—Jšœ˜——Jšœœœ˜$Jšœ˜—Jšœ™J˜ Jšœ œœ˜Jšœ-œœœ˜?Jšœ˜ J˜——šž œœœ&˜?Jšœ"œ˜=Jšœ œœ3˜NJšœ œœ,˜FJšœ œœ9˜TJšœ œœœ˜;Jšœ œœœ˜Jšœ œ:œ˜ZJ˜Jšœœ˜Jšœœœœ˜"šœŸ+˜.Jšœ œœ˜-Jš œœ œœ˜8šœœœ˜,J˜?šœœ˜J˜J˜šœœœœ˜šœ œ˜˜?Jšœœ œ˜9——šœ œ˜J˜J˜#—Jšœ˜——Jšœœœ˜$Jšœ˜—Jšœ™J˜ Jšœ œœ˜J˜;Jšœœœœ˜Jšœ˜ J˜——šžœœœA˜SJšœ œ(œœ˜GJ˜1Jšœ œœ,˜FJšœ œœ9˜TJšœ œœœ˜;Jšœ œœ˜!J˜J˜ J˜.Jšœœ˜$J˜šœœ˜Jšœ œœœ˜.˜%˜=J˜+——Jšœœœ˜J˜DJšœ œ˜"Jšœ œœ˜Jšœ œœ˜@Jšœ œœ˜3Jšœ:˜>Jšœ˜ J˜——Jšœ˜J˜—…—þù