-- TiogaFileOpsImpl.mesa
-- 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
DIRECTORY
TiogaFileOps,
NameSymbolTable,
PutGet,
TextEdit,
TiogaLooks,
TiogaNode,
Rope;
TiogaFileOpsImpl:
CEDAR PROGRAM
IMPORTS NameSymbolTable, PutGet, Rope, TextEdit, TiogaNode
EXPORTS TiogaFileOps =
BEGIN
OPEN TiogaFileOps;
Ref: TYPE = REF NodeBody; -- points to a Tioga node
NodeBody: PUBLIC TYPE = TiogaNode.Node.item.text;
CreateRoot:
PUBLIC
PROC
RETURNS [root: Ref] = {
root ← TiogaNode.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 ← TiogaNode.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 ← TiogaNode.NarrowToTextNode[TiogaNode.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: TiogaLooks.Looks ← TiogaLooks.noLooks;
looks[look] ← TRUE;
IF root = NIL THEN root ← TiogaNode.NarrowToTextNode[TiogaNode.Root[x]];
TextEdit.AddLooks[root, x, looks, start, len] };
SetFormat:
PUBLIC
PROC [x: Ref, format: Rope.
ROPE] =
TRUSTED {
name: TiogaNode.TypeName ← NameSymbolTable.MakeName[
LOOPHOLE[Rope.Flatten[format]]];
TextEdit.ChangeType[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.