DIRECTORY Process USING [Detach], Rope USING [Concat, Equal, ROPE], TEditDocumentsCache, TEditDocumentPrivate, TEditInput USING [FreeTree], TEditProfile USING [unsavedDocumentCacheSize], TextNode USING [pZone, Ref]; TEditDocumentsCacheImpl: CEDAR MONITOR IMPORTS Process, Rope, TEditDocumentsCache, TEditInput, TEditProfile, TextNode EXPORTS TEditDocumentsCache, TEditDocumentPrivate = BEGIN OPEN TEditDocumentsCache, TEditDocumentPrivate; list: LIST OF UnsavedDocumentInfo; UnsavedDocumentInfo: TYPE = REF UnsavedDocumentInfoRec; UnsavedDocumentInfoRec: TYPE = RECORD [fileName: ROPE, root: TextNode.Ref]; GetList: PUBLIC ENTRY PROC RETURNS [rope: ROPE] = { FOR l: LIST OF UnsavedDocumentInfo _ list, l.rest UNTIL l=NIL DO rope _ Rope.Concat[rope, Rope.Concat["\n", l.first.fileName]]; ENDLOOP }; RecordUnsavedDocument: PUBLIC ENTRY PROC [fileName: ROPE, root: TextNode.Ref] = { ENABLE UNWIND => NULL; Size: PROC RETURNS [size: INTEGER] = { size _ 0; IF list=NIL THEN RETURN; FOR l: LIST OF UnsavedDocumentInfo _ list, l.rest UNTIL l=NIL DO size _ size+1; ENDLOOP }; info: UnsavedDocumentInfo; oldRoot: TextNode.Ref; IF (oldRoot _ SearchList[fileName]) # NIL THEN -- discard previous entry, if any TEditInput.FreeTree[oldRoot]; info _ TextNode.pZone.NEW[UnsavedDocumentInfoRec _ [fileName, root]]; list _ TextNode.pZone.CONS[info, list]; WHILE Size[] > MAX[TEditProfile.unsavedDocumentCacheSize, 0] DO DiscardOldest[]; ENDLOOP; TRUSTED {Process.Detach[FORK Update[]] }}; FindUnsavedDocument: PUBLIC ENTRY PROC [fileName: ROPE] RETURNS [root: TextNode.Ref] = { ENABLE UNWIND => NULL; IF (root _ SearchList[fileName]) # NIL THEN TRUSTED {Process.Detach[FORK Update[]] }}; DiscardOldest: PROC = { IF list=NIL THEN RETURN; FOR l: LIST OF UnsavedDocumentInfo _ list, l.rest DO IF l.rest # NIL THEN LOOP; -- spin until get to the oldest entry TEditInput.FreeTree[SearchList[l.first.fileName]]; RETURN; ENDLOOP }; SearchList: PROC [fileName: ROPE] RETURNS [root: TextNode.Ref] = { -- if find, then remove prev: LIST OF UnsavedDocumentInfo; IF list=NIL THEN RETURN [NIL]; IF Rope.Equal[list.first.fileName, fileName, FALSE] THEN { root _ list.first.root; list _ list.rest; RETURN }; prev _ list; FOR l: LIST OF UnsavedDocumentInfo _ list.rest, l.rest UNTIL l=NIL DO IF Rope.Equal[l.first.fileName, fileName, FALSE] THEN { root _ l.first.root; prev.rest _ l.rest; RETURN }; prev _ l; ENDLOOP; RETURN [NIL] }; END. ²TEditDocumentsCacheImpl.mesa; Edited by Paxton on October 20, 1982 8:39 am Last Edited by: Maxwell, January 6, 1983 11:10 am Last Edited by: Plass, March 16, 1983 11:59 am Ê’˜JšÏcJ™JJšÏk1™1J™.šž ˜ Jšœžœ ˜Jšœžœžœ˜!Jšœ˜J˜Jšœ žœ ˜Jšœ žœ˜.Jšœ žœ˜J˜—Jšœž ˜&J˜JšžœG˜NJšžœ*žœ˜3J˜Jšžœžœ+˜5J˜Jšœžœžœ˜"J˜Jšœžœžœ˜7Jšœžœžœ žœ˜KJ˜š Ïnœžœžœžœžœžœ˜3š žœžœžœ$žœžœž˜@Jšœ>˜>Jšžœ˜ ——J˜šŸœžœ žœ˜QJšžœžœžœ˜šŸœžœžœžœ˜&J˜ Jšžœžœžœžœ˜š žœžœžœ$žœžœž˜@Jšœ˜Jšžœ˜ ——Jšœ˜Jšœ˜šžœ$žœžœ!˜PJ˜—Jšœžœ,˜EJšœžœ ˜'Jšžœ žœ+žœžœ˜YJšžœžœ˜*—J˜šŸœžœ žœ˜7Jšžœ˜ Jšžœžœžœ˜Jš žœ!žœžœžœžœ˜V—J˜šŸ œžœ˜Jšžœžœžœžœ˜šžœžœžœ$ž˜4Jš žœ žœžœžœ%˜@J˜2Jšžœ˜Jšžœ˜ ——J˜š Ÿ œžœ žœžœ˜ZJšœžœžœ˜"Jš žœžœžœžœžœ˜šžœ+žœžœ˜:J˜J˜Jšžœ˜ —J˜ š žœžœžœ)žœžœž˜Ešžœ(žœžœ˜7J˜Jšœ˜Jšžœ˜ —J˜ Jšžœ˜—šžœžœ˜J˜——J˜Jšžœ˜J˜—…— t ¸