DIRECTORY MessageWindow USING [Append, Blink], Rope USING [ROPE], RuntimeError USING [UNCAUGHT], TiogaAccess USING [CopyNode, Create, DoneWith, EndOf, FromFile, FromSelection, Get, PeekRope, Put, Reader, TiogaChar, WriteFile, Writer, WriteSelection], TiogaOps USING [CallWithLocks, Ref]; TiogaAccessExample: CEDAR PROGRAM IMPORTS MessageWindow, RuntimeError, TiogaAccess, TiogaOps ~ BEGIN ROPE: TYPE ~ Rope.ROPE; SaveSelection: PROC [fileName: ROPE] ~ { out: TiogaAccess.Writer ¬ TiogaAccess.Create[]; in: TiogaAccess.Reader ¬ TiogaAccess.FromSelection[]; UNTIL TiogaAccess.EndOf[in] DO DO tiogaChar: TiogaAccess.TiogaChar ¬ TiogaAccess.Get[in]; TiogaAccess.Put[out, tiogaChar]; IF tiogaChar.endOfNode THEN EXIT; ENDLOOP; ENDLOOP; TiogaAccess.DoneWith[in]; TiogaAccess.WriteFile[out, fileName]; }; GetSelection: PROC ~ { out: TiogaAccess.Writer ¬ TiogaAccess.Create[]; selection: TiogaAccess.Reader ¬ TiogaAccess.FromSelection[]; fileName: ROPE ¬ TiogaAccess.PeekRope[selection]; in: TiogaAccess.Reader ¬ TiogaAccess.FromFile[fileName]; TiogaAccess.DoneWith[selection]; IF NOT TiogaAccess.EndOf[in] THEN [] ¬ TiogaAccess.Get[in]; UNTIL TiogaAccess.EndOf[in] DO [] ¬ TiogaAccess.CopyNode[out, in] ENDLOOP; TiogaAccess.DoneWith[in]; TiogaAccess.WriteSelection[out]; }; ReverseSelection: PROC ~ { buffer: LIST OF TiogaAccess.TiogaChar; out: TiogaAccess.Writer ¬ TiogaAccess.Create[]; in: TiogaAccess.Reader ¬ TiogaAccess.FromSelection[]; UNTIL TiogaAccess.EndOf[in] DO tiogaChar: TiogaAccess.TiogaChar; DO tiogaChar ¬ TiogaAccess.Get[in]; IF tiogaChar.endOfNode THEN EXIT; buffer ¬ CONS[tiogaChar, buffer]; ENDLOOP; UNTIL buffer = NIL DO t: LIST OF TiogaAccess.TiogaChar ¬ buffer; buffer ¬ t.rest; t.rest ¬ NIL; TiogaAccess.Put[out, t.first]; ENDLOOP; TiogaAccess.Put[out, tiogaChar]; ENDLOOP; TiogaAccess.DoneWith[in]; TiogaAccess.WriteSelection[out]; }; LockedReverseSelection: PROC ~ { action: PROC [ref: TiogaOps.Ref] ~ {ReverseSelection[]}; TiogaOps.CallWithLocks[action ! RuntimeError.UNCAUGHT => { MessageWindow.Append["Unknown error in ReverseSelection", TRUE]; MessageWindow.Blink[]; CONTINUE }]; }; END. CreateButton S ¬ TiogaAccessExample.SaveSelection["Save"] CreateButton G ¬ TiogaAccessExample.GetSelection[] CreateButton R ¬ TiogaAccessExample.ReverseSelection[] CreateButton L ¬ TiogaAccessExample.LockedReverseSelection[] CreateButton P ¬ TiogaAccess.GetPosition[TiogaAccess.FromSelection[]] CreateButton s ¬ &s ¬ TiogaAccess.FromSelection[] CreateButton t ¬ TiogaAccess.WriteSelection[&w] ¬ &w ¬ TiogaAccess.Create[] ¬ TiogaAccess.Put[&w, [charSet: 0, char: 'n, looks: ALL[FALSE], format: $default, comment: FALSE, endOfNode: FALSE, deltaLevel: 0, propList: NIL]] ¬ TiogaAccess.Put[&w, [charSet: 0, char: '\n, looks: ALL[FALSE], format: $default, comment: FALSE, endOfNode: TRUE, deltaLevel: 0, propList: NIL]] ¬ &w ¬ TiogaAccess.WriteFile[&w, "Save"]  TiogaAccessExample.mesa Copyright Σ 1984, 1991, Xerox Corporation. All rights reserved. Michael Plass, March 25, 1985 5:10:28 pm PST Could catch FS.Error here for bad name or missing file. Discard root; failure to do this will cause the WriteSelection to fail. Κv•NewlineDelimiter –(cedarcode) style™™Jšœ Οeœ4™@J™,Icode˜—šΟk ˜ Kšœžœ˜$Kšœžœžœ˜Kšœ žœžœ˜Kšœ žœˆ˜™šœ žœ˜$K˜——šœž ˜!Kšžœ3˜:Kšœž˜K˜šžœžœžœ˜K˜—šΟn œžœ žœ˜(Kšœ/˜/Kšœ5˜5šžœž˜šž˜Kšœ7˜7Kšœ ˜ Kšžœžœžœ˜!Kšžœ˜—Kšžœ˜—Kšœ˜Kšœ%˜%Kšœ˜K˜—šŸ œžœ˜Kšœ/˜/Kšœ<˜