<> <> <> <> <> <> <> <<>> DIRECTORY Atom USING [MakeAtom], PutGet USING [ToFile], Rope USING [IsEmpty, ROPE], TextEdit USING [AddLooks, ChangeFormat, ChangeStyle], TextLooks USING [Looks, noLooks], TextNode USING [Body, LastChild, NewTextNode, Ref, Root], TiogaFileOps; TiogaFileOpsImpl: CEDAR PROGRAM IMPORTS Atom, PutGet, Rope, TextEdit, TextNode EXPORTS TiogaFileOps = BEGIN OPEN TiogaFileOps; Ref: TYPE = REF NodeBody; -- points to a Tioga node NodeBody: PUBLIC TYPE = TextNode.Body; CreateRoot: PUBLIC PROC RETURNS [root: Ref] = { root _ TextNode.NewTextNode[]; root.last _ TRUE }; InsertNode: PUBLIC PROC [x: Ref, child: BOOL _ FALSE] RETURNS [new: Ref] = { <<-- if ~child then new is sibling of x>> <<-- else new is first child of x>> new _ TextNode.NewTextNode[]; IF child THEN { IF x.child # NIL THEN { new.next _ x.child; new.last _ FALSE } ELSE { new.next _ x; new.last _ TRUE }; x.child _ new } ELSE { new.next _ x.next; new.last _ x.last; x.next _ new; x.last _ FALSE }}; InsertAsLastChild: PUBLIC PROC [x: Ref, prevLast: Ref _ NIL] RETURNS [new: Ref] = { <<-- prevLast is optional accelerator>> IF prevLast=NIL OR ~prevLast.last OR prevLast.next # x THEN prevLast _ TextNode.LastChild[x]; new _ IF prevLast=NIL THEN InsertNode[x, TRUE] ELSE InsertNode[prevLast, FALSE] }; SetContents: PUBLIC PROC [x: Ref, txt: Rope.ROPE] = { x.rope _ txt; x.runs _ NIL }; AddLooks: PUBLIC PROC [x: Ref, start, len: INT, look: CHAR ['a..'z], root: Ref _ NIL] = { looks: TextLooks.Looks _ TextLooks.noLooks; looks[look] _ TRUE; IF root = NIL THEN root _ TextNode.Root[x]; TextEdit.AddLooks[root, x, looks, start, len] }; SetFormat: PUBLIC PROC [x: Ref, format: Rope.ROPE] = { name: ATOM _ IF format.IsEmpty THEN NIL ELSE Atom.MakeAtom[format]; TextEdit.ChangeFormat[x, name] }; SetStyle: PUBLIC PROC [x: Ref, style: Rope.ROPE] = { TextEdit.ChangeStyle[x, style] }; Store: PUBLIC PROC [x: Ref, filename: Rope.ROPE] = { [] _ PutGet.ToFile[filename, x] }; END.