TiogaFileOpsImpl.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
written by Bill Paxton, June 1982
last written by Paxton. September 22, 1982 1:19 pm
Last Edited by: Maxwell, January 6, 1983 11:48 am
Rick Beach, March 28, 1985 10:02:14 am PST
Michael Plass, March 27, 1985 5:06:37 pm PST
Doug Wyatt, September 2, 1986 5:37:02 pm PDT
DIRECTORY
Atom USING [MakeAtom],
PutGet USING [ToFile],
Rope USING [IsEmpty, ROPE],
TextEdit USING [AddLooks, ChangeFormat, ChangeStyle],
TextLooks USING [Looks, noLooks],
TextNode USING [LastChild, NewTextNode, Node, NodeBody, Root],
TiogaFileOps;
TiogaFileOpsImpl: CEDAR PROGRAM
IMPORTS Atom, PutGet, Rope, TextEdit, TextNode
EXPORTS TiogaFileOps
= BEGIN OPEN TiogaFileOps;
Node: TYPE = TextNode.Node; -- points to a Tioga node
NodeBody: PUBLIC TYPE = TextNode.NodeBody;
CreateRoot: PUBLIC PROC RETURNS [root: Node] = {
root ← TextNode.NewTextNode[];
root.last ← TRUE };
InsertNode: PUBLIC PROC [x: Node, child: BOOLFALSE] RETURNS [new: Node] = {
-- 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: Node, prevLast: Node ← NIL] RETURNS [new: Node] = {
-- 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: Node, txt: Rope.ROPE] = { x.rope ← txt; x.runs ← NIL };
AddLooks: PUBLIC PROC [x: Node, start, len: INT, look: CHAR ['a..'z], root: Node ← 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: Node, format: Rope.ROPE] = {
name: ATOMIF format.IsEmpty THEN NIL ELSE Atom.MakeAtom[format];
TextEdit.ChangeFormat[x, name] };
SetStyle: PUBLIC PROC [x: Node, style: Rope.ROPE] = { TextEdit.ChangeStyle[x, style] };
Store: PUBLIC PROC [x: Node, filename: Rope.ROPE] = { [] ← PutGet.ToFile[filename, x] };
END.