DIRECTORY TiogaOpsDefs, EditSpan, MessageWindow, NameSymbolTable, NodeStyle, Rope, RunReader, TiogaDocument, TiogaDocumentPrivate, TiogaInput, TiogaInputOps, TiogaLocks, TiogaMesaOps, TiogaOps, TiogaProfile, TiogaRefresh, TiogaScrolling, TiogaSelection, TextEdit, TextFind, TextFindPrivate, TiogaLooks, TiogaLooksSupport, TiogaNode, TiogaNodeOps, TiogaOps, TiogaExtraOps, TiogaMenuOps, TreeFind; TiogaOps2Impl: CEDAR PROGRAM IMPORTS MessageWindow, NameSymbolTable, NodeStyle, Rope, RunReader, TiogaDocumentPrivate, TiogaInput, TiogaInputOps, TiogaOps, TiogaProfile, TiogaRefresh, TiogaScrolling, TiogaSelection, TextEdit, TextFind, TiogaLooksSupport, TiogaNodeOps, TreeFind EXPORTS TiogaOpsDefs, TiogaOps, TiogaMenuOps = BEGIN OPEN TiogaOps, TiogaMenuOps, TiogaOpsDefs; Ref: TYPE = REF NodeBody; -- points to a Tioga node NodeBody: PUBLIC TYPE = TiogaNode.Body; Finder: TYPE = REF FinderRec; FinderRec: PUBLIC TYPE = TextFindPrivate.FinderRecord; LooksRope: PROC [looks: TiogaLooks.Looks] RETURNS [r: ROPE] = { FOR c: CHAR IN TiogaLooks.Look DO IF looks[c] THEN r _ Rope.Concat[r, Rope.FromChar[c]]; ENDLOOP }; RopeToLooks: PROC [r: ROPE] RETURNS [looks: TiogaLooks.Looks] = { Set: PROC [c: CHAR] RETURNS [quit: BOOL _ FALSE] = { looks[c] _ TRUE }; [] _ Rope.Map[base: r, action: Set]; }; CreateGeneralPattern: PUBLIC PROC [ target: Ref, -- node from which to get the pattern text: BOOL _ TRUE, -- if true, match target text looks: BOOL _ FALSE, -- if true, match target looks format: BOOL _ FALSE, -- if true, match target format style: BOOL _ FALSE, -- if true, match target style comment: BOOL _ FALSE, -- if true, match target comment property case: BOOL _ TRUE, -- if true, match case literal: BOOL _ FALSE, -- if true, treat target literally rather than as a pattern word: BOOL _ FALSE, -- if true, match words only subset: BOOL _ TRUE, -- if true, use subset for looks test, else use equality addBounds: BOOL _ FALSE] -- if true, add |'s to both ends of pattern RETURNS [pattern: Pattern] = { txt: TiogaNode.RefTextNode = TiogaNodeOps.NarrowToTextNode[target]; patternTxt: TiogaNode.RefTextNode _ txt; pattern _ NEW[PatternRec]; IF looks AND ~text THEN { -- make a phony search pattern and get the looks size: Offset = TextEdit.Size[txt]; lks: TiogaLooks.Looks = IF size=0 THEN TiogaLooks.noLooks ELSE TextEdit.FetchLooks[txt,0]; pattern.searchLooks _ LooksRope[lks]; FOR i: Offset IN [1..size) DO IF TextEdit.FetchLooks[txt,i]#lks THEN { OPEN MessageWindow; Append["Search pattern does not have uniform looks.",TRUE]; Append[" Using looks from first char."]; EXIT }; ENDLOOP; literal _ FALSE; patternTxt _ TextEdit.FromRope["#*"]; TextEdit.SetLooks[NIL, patternTxt, lks] }; pattern.text _ text; pattern.looks _ looks; pattern.word _ word; pattern.looksExact _ ~subset; pattern.commentControl _ IF ~comment OR txt=NIL THEN includeComments ELSE IF txt.comment THEN commentsOnly ELSE excludeComments; pattern.checkFormat _ format; pattern.format _ IF target=NIL OR target.format=TiogaNode.nullName THEN NIL ELSE NameSymbolTable.RopeFromName[target.format]; pattern.checkStyle _ style; pattern.style _ IF ~style THEN NIL ELSE NameSymbolTable.RopeFromName[NodeStyle.StyleNameForNode[target]]; IF text OR looks THEN TRUSTED { -- create a description of the pattern pattern.finder _ LOOPHOLE[ TreeFind.Create[patternTxt, literal, word, ~looks, ~case, addBounds]]}; }; CreateSimplePattern: PUBLIC PROC [ target: ROPE, -- node from which to get the pattern case: BOOL _ TRUE, -- if true, match case literal: BOOL _ FALSE, -- if true, treat target literally rather than as a pattern word: BOOL _ FALSE, -- if true, match words only addBounds: BOOL _ FALSE] -- if true, add |'s to both ends of pattern RETURNS [pattern: Pattern] = { pattern _ NEW[PatternRec]; pattern.text _ TRUE; pattern.looks _ FALSE; pattern.word _ word; pattern.commentControl _ includeComments; pattern.checkFormat _ FALSE; pattern.format _ NIL; pattern.checkStyle _ FALSE; pattern.style _ NIL; TRUSTED {pattern.finder _ LOOPHOLE[TreeFind.CreateFromRope[target, literal, word, ~case, addBounds]]}; }; FindCC: PROC [cc: CommentControl] RETURNS [TreeFind.CommentControl] = INLINE { RETURN [SELECT cc FROM includeComments => includeComments, excludeComments => excludeComments, commentsOnly => commentsOnly, ENDCASE => ERROR] }; SelectionSearch: PUBLIC PROC [ pattern: Pattern, whichDir: SearchDir _ forwards, interrupt: REF BOOL _ NIL, startBoundaryNode, endBoundaryNode: Ref _ NIL, startBoundaryOffset: Offset _ 0, endBoundaryOffset: Offset _ LAST[Offset]] RETURNS [found: BOOL] = { pSel: TiogaDocument.Selection = TiogaSelection.pSel; Found: PROC [tSel: TiogaDocument.Selection] = { tSel.viewer _ pSel.viewer; tSel.data _ pSel.data; TiogaOps.RememberCurrentPosition[pSel.viewer]; TiogaSelection.SetSelLooks[tSel]; TiogaSelection.MakeSelection[new: tSel]; TiogaInput.CloseEvent[]; TiogaRefresh.ScrollToEndOfSel[tSel.viewer, FALSE] }; Locations: PROC RETURNS [start, end: TiogaNode.Location] = { start _ pSel.start.pos; end _ pSel.end.pos }; found _ DoSearch[pattern, whichDir, interrupt, Found, Locations, startBoundaryNode, endBoundaryNode, startBoundaryOffset, endBoundaryOffset] }; DocLoc: PROC [loc: Location] RETURNS [TiogaNode.Location] = INLINE { RETURN [[loc.node, loc.where]] }; MyLoc: PROC [loc: TiogaNode.Location] RETURNS [Location] = INLINE { RETURN [[loc.node, loc.where]] }; NodeSearch: PUBLIC PROC [ pattern: Pattern, whichDir: SearchDir _ forwards, startLoc, endLoc: Location, interrupt: REF BOOL _ NIL, startBoundaryNode, endBoundaryNode: Ref _ NIL, startBoundaryOffset: Offset _ 0, endBoundaryOffset: Offset _ LAST[Offset]] RETURNS [found: BOOL, start, end: Location] = { Found: PROC [tSel: TiogaDocument.Selection] = { start _ MyLoc[tSel.start.pos]; end _ MyLoc[tSel.end.pos] }; Locations: PROC RETURNS [start, end: TiogaNode.Location] = { start _ DocLoc[startLoc]; end _ DocLoc[endLoc] }; found _ DoSearch[pattern, whichDir, interrupt, Found, Locations, startBoundaryNode, endBoundaryNode, startBoundaryOffset, endBoundaryOffset] }; DoSearch: PROC [ pattern: Pattern, whichDir: SearchDir _ forwards, interrupt: REF BOOL _ NIL, foundProc: PROC [tSel: TiogaDocument.Selection], locationProc: PROC RETURNS [start, end: TiogaNode.Location], startBoundaryNode, endBoundaryNode: Ref _ NIL, startBoundaryOffset: Offset _ 0, endBoundaryOffset: Offset _ LAST[Offset]] RETURNS [found: BOOL] = { at, atEnd, offset: TiogaNode.Offset; first: TiogaNode.Ref; where: TiogaNode.RefTextNode; startLoc, endLoc: TiogaNode.Location; DoLookForPattern: PROC [ root: TiogaNode.RefBranchNode, tSel: TiogaDocument.Selection] = { Forwards: PROC = TRUSTED { IF (offset _ endLoc.where+1) >= TextEdit.Size[TiogaNodeOps.NarrowToTextNode[first _ endLoc.node]] THEN { first _ TiogaNodeOps.StepForward[first]; offset _ 0 }; [found,where,at,atEnd,,] _ TreeFind.Try[finder: LOOPHOLE[pattern.finder], first: first, start: offset, last: endBoundaryNode, lastLen: endBoundaryOffset, interrupt: interrupt, looksExact: pattern.looksExact, checkFormat: pattern.checkFormat, format: NameSymbolTable.MakeNameFromRope[pattern.format], commentControl: FindCC[pattern.commentControl], checkStyle: pattern.checkStyle, style: NameSymbolTable.MakeNameFromRope[pattern.style], styleProc: NodeStyle.StyleNameForNode] }; Backwards: PROC = TRUSTED { IF (offset _ startLoc.where)=0 THEN { first _ TiogaNode.StepBackward[startLoc.node]; offset _ TreeFind.MaxLen } ELSE first _ startLoc.node; [found,where,at,atEnd,,] _ TreeFind.TryBackwards[finder: LOOPHOLE[pattern.finder], first: first, len: offset, last: startBoundaryNode, lastStart: startBoundaryOffset, interrupt: interrupt, looksExact: pattern.looksExact, checkFormat: pattern.checkFormat, format: NameSymbolTable.MakeNameFromRope[pattern.format], commentControl: FindCC[pattern.commentControl], checkStyle: pattern.checkStyle, style: NameSymbolTable.MakeNameFromRope[pattern.style], styleProc: NodeStyle.StyleNameForNode] }; [startLoc, endLoc] _ locationProc[]; IF interrupt#NIL THEN interrupt^ _ FALSE; SELECT whichDir FROM forwards => Forwards[]; backwards => Backwards[]; anywhere => { Forwards[]; IF found THEN whichDir _ forwards ELSE { whichDir _ backwards; Backwards[] }}; ENDCASE => ERROR; IF ~found OR where=NIL THEN RETURN; IF pattern.looks AND ~pattern.text AND ~pattern.word THEN [at,atEnd] _ Extend[whichDir=forwards, pattern.looksExact, RopeToLooks[pattern.searchLooks], where, at, atEnd]; tSel.start.pos _ [where,at]; tSel.end.pos _ [where,MAX[0,atEnd-1]]; tSel.granularity _ IF ~pattern.looks AND ~pattern.text THEN node ELSE IF pattern.word THEN word ELSE char; tSel.insertion _ IF TiogaProfile.selectionCaret=before THEN before ELSE after; foundProc[tSel]; }; TiogaInputOps.CallWithLocks[DoLookForPattern, read] }; Extend: PROC [forward, looksExact: BOOLEAN, searchLooks: TiogaLooks.Looks, where: TiogaNode.RefTextNode, at, atEnd: TiogaNode.Offset, last: TiogaNode.Ref _ NIL, lastLen: TiogaNode.Offset _ TiogaNode.MaxLen] RETURNS [newAt, newAtEnd: TiogaNode.Offset] = { runrdr: RunReader.Ref _ RunReader.GetRunReader[]; { -- for EXITS looks: TiogaLooks.Looks; runLen: TiogaNode.Offset; runs: TiogaLooks.Runs _ where.runs; IF forward THEN { -- extend toward end of node size: TiogaNode.Offset _ TextEdit.Size[where]; IF atEnd=size OR size=0 THEN GOTO Done; lastLen _ IF where=last THEN MIN[size,lastLen] ELSE size; RunReader.SetPosition[runrdr,runs,atEnd]; WHILE atEnd < lastLen DO IF runs=NIL THEN { runLen _ size-atEnd; looks _ TiogaLooks.noLooks } ELSE [runLen,looks] _ RunReader.Get[runrdr]; IF ~looksExact THEN looks _ TiogaLooksSupport.LooksAND[looks,searchLooks]; IF searchLooks # looks THEN EXIT; atEnd _ atEnd+runLen; ENDLOOP; RunReader.FreeRunReader[runrdr]; RETURN [at,MIN[atEnd,lastLen]] }; IF at=0 THEN GOTO Done; RunReader.SetPosition[runrdr,runs,at]; WHILE at > 0 DO IF runs=NIL THEN { runLen _ at; looks _ TiogaLooks.noLooks } ELSE [runLen,looks] _ RunReader.Backwards[runrdr]; IF ~looksExact THEN looks _ TiogaLooksSupport.LooksAND[looks,searchLooks]; IF searchLooks # looks THEN EXIT; at _ at-runLen; ENDLOOP; RunReader.FreeRunReader[runrdr]; RETURN [at,atEnd]; EXITS Done => { RunReader.FreeRunReader[runrdr]; RETURN }}}; SelectMatchingBrackets: PUBLIC PROC [before, after: CHAR] RETURNS [found: BOOL] = { found _ TiogaInputOps.DoSelectMatchingBrackets[before, after] }; NextPlaceholder: PUBLIC PROC [dir: Dir _ forward, gotoend: BOOL, startBoundaryNode, endBoundaryNode: Ref _ NIL, startBoundaryOffset: Offset _ 0, endBoundaryOffset: Offset _ LAST[Offset]] RETURNS [found, wenttoend: BOOL] = { [found, wenttoend] _ TiogaInputOps.DoFindPlaceholders[ dir=forward, gotoend, startBoundaryNode, endBoundaryNode, startBoundaryOffset, endBoundaryOffset] }; NextViewer: PUBLIC PROC [dir: Dir _ forward] RETURNS [found: BOOL] = { found _ TiogaInputOps.DoNextViewer[dir=forward] }; SearchWhere: PROC [whichDir: SearchDir] RETURNS [TiogaSelection.FindWhere] = INLINE { RETURN [SELECT whichDir FROM forwards => forwards, backwards => backwards, anywhere => anywhere, ENDCASE => ERROR] }; Position: PUBLIC PROC [viewer: Viewer] = { TiogaSelection.Position[viewer] }; Normalize: PUBLIC PROC [viewer: Viewer] = { [] _ TiogaInput.Normalize[] }; PrevPlace: PUBLIC PROC [viewer: Viewer] = { TiogaDocumentPrivate.JumpToPrevious[viewer] }; Reselect: PUBLIC PROC [viewer: Viewer] = { TiogaDocumentPrivate.Reselect[viewer] }; Save: PUBLIC PROC [viewer: Viewer] = { TiogaDocumentPrivate.Save[viewer] }; Load: PUBLIC PROC [viewer: Viewer, fileName: ROPE _ NIL, fileNameProcViewer: Viewer _ NIL] = { [] _ TiogaDocumentPrivate.DoLoadFile[ viewer, fileName, FALSE, fileNameProcViewer] }; Open: PUBLIC PROC [fileName: ROPE _ NIL, fileNameProcViewer: Viewer _ NIL] RETURNS [Viewer] = { RETURN [TiogaDocumentPrivate.DoOpenFile[fileName, fileNameProcViewer]] }; CloseAndOpen: PUBLIC PROC [ viewer: Viewer, fileName: ROPE _ NIL, fileNameProcViewer: Viewer _ NIL] RETURNS [Viewer] = { RETURN [TiogaDocumentPrivate.DoLoadFile[ viewer, fileName, TRUE, fileNameProcViewer]] }; LoadImpl: PUBLIC PROC [viewer: Viewer, fileName: ROPE _ NIL] = { [] _ TiogaDocumentPrivate.DoLoadImplFile[viewer, fileName] }; OpenImpl: PUBLIC PROC [fileName: ROPE _ NIL] RETURNS [Viewer] = { RETURN [TiogaDocumentPrivate.DoOpenImplFile[fileName]] }; CloseAndOpenImpl: PUBLIC PROC [viewer: Viewer, fileName: ROPE _ NIL] RETURNS [Viewer] = { RETURN [TiogaDocumentPrivate.DoCloseAndOpenImplFile[viewer, fileName]] }; LoadPreviousFile: PUBLIC PROC [parent: Viewer] = { TiogaDocumentPrivate.LoadPreviousFile[parent] }; OpenPreviousFile: PUBLIC PROC [parent: Viewer] = { TiogaDocumentPrivate.OpenPreviousFile[parent] }; CloseAndOpenPreviousFile: PUBLIC PROC [parent: Viewer] = { TiogaDocumentPrivate.CloseAndOpenPreviousFile[parent] }; DefaultMenus: PUBLIC PROC [viewer: Viewer, paint: BOOL _ FALSE] = { TiogaDocumentPrivate.DefaultMenus[viewer, paint] }; Store: PUBLIC PROC [viewer: Viewer, fileName: ROPE _ NIL] = { TiogaDocumentPrivate.DoStoreFile[viewer, fileName] }; New: PUBLIC PROC RETURNS [Viewer] = { RETURN [TiogaDocumentPrivate.DoNewViewer[]] }; Empty: PUBLIC PROC [viewer: Viewer] = { TiogaDocumentPrivate.EmptyViewer[viewer] }; CloseAndNewViewer: PUBLIC PROC [viewer: Viewer] RETURNS [Viewer] = { RETURN [TiogaDocumentPrivate.DoCloseAndNewViewer[viewer]] }; Reset: PUBLIC PROC [viewer: Viewer] = { TiogaDocumentPrivate.Reset[viewer] }; Jump: PUBLIC PROC [viewer: Viewer, loc: Location] = { DocLoc: PROC [loc: Location] RETURNS [TiogaNode.Location] = INLINE { RETURN [[loc.node, loc.where]] }; [] _ TiogaScrolling.ScrollToPosition[viewer, DocLoc[loc]] }; FirstLevelOnly: PUBLIC PROC [viewer: Viewer] = { [] _ TiogaInput.FirstLevelOnly[viewer] }; MoreLevels: PUBLIC PROC [viewer: Viewer] = { [] _ TiogaInput.MoreLevels[viewer] }; FewerLevels: PUBLIC PROC [viewer: Viewer] = { [] _ TiogaInput.FewerLevels[viewer] }; AllLevels: PUBLIC PROC [viewer: Viewer] = { [] _ TiogaInput.AllLevels[viewer] }; END. θTiogaOps2Impl.Mesa written by Bill Paxton. June 1982 last written by Paxton. December 30, 1982 11:13 am Last Edited by: Maxwell, January 6, 1983 11:48 am Search Places menu commands Files and text viewers Levels menu commands ΚQ˜Jšœ™Jšœ!™!Jšœ2™2J™1šΟk ˜ Jšœ ˜ J˜ J˜J˜J˜ J˜J˜ J˜J˜J˜ J˜J˜ J˜ J˜ Jšœ ˜ J˜ J˜J˜J˜ J˜ J˜J˜ J˜J˜ J˜ J˜ J˜J˜ J˜ J˜—Jšœ ˜š˜J˜J˜J˜ J˜J˜ J˜J˜ J˜J˜ Jšœ ˜ J˜ J˜J˜J˜ J˜ J˜J˜ Jšœ˜—Jšœ'˜.Jšœœ&˜0J˜Jšœœœ Οc˜3Jšœ œœ˜'Iprocšœœœ ˜Kšœ œœ ˜6J˜Jšž™˜šΟn œœœœ˜?šœœœ˜!Kšœ œ&˜6Kš˜—K˜K˜—šŸ œœœœ˜AKšŸœœœœœœœ˜GK˜$K˜K˜—šŸœœœ˜#Jšœ ž%˜2Jšœœœž˜0Jšœœœž˜3Jšœœœž˜5Jšœœœž˜3Jšœ œœž)˜@Jšœœœž˜)Jšœ œœž;˜RJšœœœž˜0Jšœœœž8˜MJšœ œœž+˜DJšœ˜JšœC˜CJšœ(˜(Jšœ œ ˜šœœœž0˜JJšœ"˜"Jšœœœœ˜ZJšœ%˜%šœ œ ˜šœ œ˜(Jšœ˜Jšœ5œ˜;Jšœ)˜)Jšœ˜—Jšœ˜—Jšœ œ˜Jšœ%˜%Jšœœ˜*—Jšœ˜Jšœ˜Jšœ˜Jšœ˜š œœ œœœ˜DJšœœ œœ˜;—Jšœ˜š œœœœ"œœ˜PJšœ,˜,—Jšœ˜šœœœ˜"JšœB˜F—š œœœ œž&˜Fšœœ˜JšœG˜G——J˜J˜—šŸœœœ˜"Jšœœž%˜3Jšœœœž˜)Jšœ œœž;˜RJšœœœž˜0Jšœ œœž+˜DJšœ˜Jšœ œ ˜Jšœœ˜Jšœœ˜Jšœ˜Jšœ)˜)Jšœœ˜Jšœœ˜Jšœœ˜Jšœœ˜JšœœD˜fJ˜J˜—šŸœœœœ˜Nšœœ˜Kšœ#˜#Kšœ#˜#Kšœ˜Kšœœ˜K˜——šŸœœœ˜Kšœ=œœœ˜LKšœ*œ˜.Kšœ=œ ˜JJšœ œ˜J˜4šœœ$˜/Jšœ˜Jšœ˜Jšœ.˜.J˜!Jšœ(˜(Jšœ˜Jšœ+œ˜4—šœ œœ%˜