TSExtrasImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Michael Plass, April 25, 1985 12:40:38 pm PST
Rick Beach, April 28, 1985 12:46:31 pm PDT
DIRECTORY
Atom USING [GetPName],
CommandTool USING [DoCommand],
FS USING [GetName, OpenFileFromStream, StreamOpen],
IO USING [STREAM],
NodeProps USING [GetProp, PutProp],
NodeStyle USING [Ref],
NodeStyleOps USING [Create, defaultStyleName],
PressPrinter USING [Abort, CurrentStateMessage, Handle, ProgressProc, SendPressFile],
Rope USING [Cat, Concat, Equal, Length, ROPE],
TEditDocument USING [TEditDocumentData],
TextNode USING [LastChild, NarrowToTextNode, NewTextNode, Ref],
TSExtras USING [NodeProc],
TSJaMPageBuilder USING [RunPageBuilder],
TSObject USING [ItemList],
TSOutput USING [Close, Handle],
TSOutputPress USING [CreateWithCursor],
TSTranslate USING [ProgressProc, TreeToVlist],
TSViewer USING [],
UserCredentials USING [Get],
UserProfile USING [Token],
ViewerClasses USING [Viewer];
TSExtrasImpl: CEDAR MONITOR
IMPORTS CommandTool, FS, Atom, NodeProps, NodeStyleOps, PressPrinter, Rope, TextNode, TSJaMPageBuilder, TSOutput, TSOutputPress, TSTranslate, UserCredentials, UserProfile EXPORTS TSExtras
= BEGIN
PrintTiogaViewer: PUBLIC ENTRY PROCEDURE [
viewer: ViewerClasses.Viewer,
nameForSeparatorPage: Rope.ROPE,
aborted: REF BOOLEAN,
server: Rope.ROPENIL,
copies: INT ← 1,
messageProc: PROC [Rope.ROPE] ← NIL
] = {ENABLE UNWIND => NULL;
node: TextNode.Ref ← NARROW[viewer.data, TEditDocument.TEditDocumentData].text;
stream: IO.STREAMFS.StreamOpen["temp.press$", $create];
fullName: Rope.ROPEFS.GetName[FS.OpenFileFromStream[stream]].fullFName;
outputHandle: TSOutput.Handle ← TSOutputPress.CreateWithCursor[
stream: stream,
documentName: nameForSeparatorPage,
cursorObject: NIL
];
galley: TSObject.ItemList;
style: NodeStyle.Ref;
isAborted: PROC RETURNS [BOOLEAN] = {RETURN[IF aborted = NIL THEN FALSE ELSE aborted^]};
progressProc: PressPrinter.ProgressProc = TRUSTED {
IF messageProc # NIL THEN messageProc[handle.CurrentStateMessage[]];
IF aborted # NIL AND aborted^ THEN handle.Abort[];
};
IF Rope.Length[server] = 0 THEN server ← UserProfile.Token["Hardcopy.PressPrinter", "Clover"];
[galley, style] ← TSTranslate.TreeToVlist[node];
[] ← TSJaMPageBuilder.RunPageBuilder[
galley: galley,
style: style,
output: outputHandle,
abortCheckProc: isAborted,
documentName: nameForSeparatorPage
];
outputHandle.Close[];
IF server.Equal["*"] THEN {
[] ← CommandTool.DoCommand[Rope.Concat["ShowPress ", fullName], NIL];
}
ELSE [] ← PressPrinter.SendPressFile[
fileName: fullName,
server: server,
progressProc: progressProc,
copies: copies,
userName: UserCredentials.Get[].name
];
};
PrintSuppliedNodes: PUBLIC ENTRY PROCEDURE [
nodeProc: TSExtras.NodeProc,
nameForSeparatorPage: Rope.ROPE,
aborted: REF BOOLEAN,
server: Rope.ROPENIL,
copies: INT ← 1,
messageProc: PROC [Rope.ROPE] ← NIL] = {
ENABLE UNWIND => NULL;
stream: IO.STREAMFS.StreamOpen["temp.press$", $create];
fullName: Rope.ROPEFS.GetName[FS.OpenFileFromStream[stream]].fullFName;
outputHandle: TSOutput.Handle ← TSOutputPress.CreateWithCursor[
stream: stream,
documentName: nameForSeparatorPage,
cursorObject: NIL
];
root: TextNode.Ref;
node: TextNode.Ref;
prevLast: TextNode.Ref ← NIL;
prop: REF;
galley: TSObject.ItemList;
style: NodeStyle.Ref;
isAborted: PROC RETURNS [BOOLEAN] = {RETURN[IF aborted = NIL THEN FALSE ELSE aborted^]};
progressProc: PressPrinter.ProgressProc = TRUSTED {
IF messageProc # NIL THEN messageProc[handle.CurrentStateMessage[]];
IF aborted # NIL AND aborted^ THEN handle.Abort[];
};
InsertNode: PUBLIC PROC [x: Ref, child: BOOLFALSE] 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 }};
new -> node
x -> root
InsertNode: PROCEDURE [root, node: TextNode.Ref, child: BOOLFALSE] = {
-- if ~child then new is sibling of x
-- else new is first child of x
IF child THEN {
IF root.child # NIL THEN { node.next ← root.child; node.last ← FALSE }
ELSE { node.next ← root; node.last ← TRUE };
root.child ← node }
ELSE { node.next ← root.next; node.last ← root.last; root.next ← node; root.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.NarrowToTextNode[TextNode.LastChild[x]];
new ← IF prevLast=NIL THEN InsertNode[x, TRUE] ELSE InsertNode[prevLast, FALSE] };
InsertAsLastChild: PROCEDURE [root, node, prevLast: TextNode.Ref] = {
IF prevLast=NIL OR ~prevLast.last OR prevLast.next # root THEN
prevLast ← TextNode.NarrowToTextNode[TextNode.LastChild[root]];
IF prevLast=NIL THEN InsertNode[root, node, TRUE] ELSE InsertNode[prevLast, node, FALSE];
};
IF Rope.Length[server]=0 THEN server ← UserProfile.Token["Hardcopy.PressPrinter", "Clover"];
build a tree with the supplied nodes, each with the right style property
root ← TextNode.NewTextNode[];
root.last ← TRUE;
UNTIL (node ← nodeProc[]) = NIL DO
InsertAsLastChild[root, node, prevLast];
prevLast ← node;
put "styleName" Style in Prefix property
style ← NodeStyleOps.Create[];
prop ← NodeProps.GetProp[node, $Prefix];
IF prop # NIL THEN
NodeProps.PutProp[node, $Prefix, Rope.Cat[
NARROW[prop, Rope.ROPE],
" \"",
Atom.GetPName[NodeStyleOps.defaultStyleName],
"\" style"]];
ENDLOOP;
with the tree in hand, typeset it
stream ← NIL; -- gets closed elsewhere.
[galley, style] ← TSTranslate.TreeToVlist[root];
[] ← TSJaMPageBuilder.RunPageBuilder[
galley: galley,
style: style,
output: outputHandle,
abortCheckProc: isAborted,
documentName: nameForSeparatorPage];
outputHandle.Close[];
IF server.Equal["*"] THEN {
[] ← CommandTool.DoCommand[Rope.Concat["ShowPress ", fullName], NIL];
}
ELSE [] ← PressPrinter.SendPressFile[
fileName: fullName,
server: server,
progressProc: progressProc,
copies: copies,
userName: UserCredentials.Get[].name
];
};
DisplayTiogaViewer: PUBLIC ENTRY PROCEDURE [
viewer: ViewerClasses.Viewer,
nameOfDisplayViewer: Rope.ROPE,
aborted: REF BOOLEAN
] = {ENABLE UNWIND => NULL;
node: TextNode.Ref ← NARROW[viewer.data, TEditDocument.TEditDocumentData].text;
outputHandle: TSOutput.Handle ← TSOutput.CreateViewer[nameOfDisplayViewer];
galley: TSObject.ItemList;
style: NodeStyle.Ref;
isAborted: PROC RETURNS [BOOLEAN] = {RETURN[IF aborted = NIL THEN FALSE ELSE aborted^]};
[galley, style] ← TSTranslate.TreeToVlist[node];
[] ← TSJaMPageBuilder.RunPageBuilder[
galley: galley,
style: style,
output: outputHandle,
abortCheckProc: isAborted,
documentName: nameOfDisplayViewer
];
outputHandle.Close[];
};
DisplaySuppliedNodes: PUBLIC ENTRY PROCEDURE [
nodeProc: TSExtras.NodeProc,
nameOfDisplayViewer: Rope.ROPE,
aborted: REF BOOLEAN] = {
ENABLE UNWIND => NULL;
outputHandle: TSOutput.Handle ← TSOutput.CreateViewer[nameOfDisplayViewer];
root: TextNode.Ref;
node: TextNode.Ref;
prevLast: TextNode.Ref ← NIL;
prop: REF;
galley: TSObject.ItemList;
style: NodeStyle.Ref;
isAborted: PROC RETURNS [BOOLEAN] = {RETURN[IF aborted = NIL THEN FALSE ELSE aborted^]};
InsertNode: PROCEDURE [root, node: TextNode.Ref, child: BOOLFALSE] = {
-- if ~child then new is sibling of x
-- else new is first child of x
IF child THEN {
IF root.child # NIL THEN { node.next ← root.child; node.last ← FALSE }
ELSE { node.next ← root; node.last ← TRUE };
root.child ← node }
ELSE { node.next ← root.next; node.last ← root.last; root.next ← node; root.last ← FALSE };
};
InsertAsLastChild: PROCEDURE [root, node, prevLast: TextNode.Ref] = {
IF prevLast=NIL OR ~prevLast.last OR prevLast.next # root THEN
prevLast ← TextNode.NarrowToTextNode[TextNode.LastChild[root]];
IF prevLast=NIL THEN InsertNode[root, node, TRUE] ELSE InsertNode[prevLast, node, FALSE];
};
-- build a tree with the supplied nodes, each with the right style property
root ← TextNode.NewTextNode[];
root.last ← TRUE;
UNTIL (node ← nodeProc[]) = NIL DO
InsertAsLastChild[root, node, prevLast];
prevLast ← node;
-- put "styleName" Style in Prefix property
style ← NodeStyleOps.Create[];
prop ← NodeProps.GetProp[node, $Prefix];
IF prop # NIL THEN
NodeProps.PutProp[node, $Prefix, Rope.Cat[
NARROW[prop, Rope.ROPE],
" \"",
Atom.GetPName[NodeStyleOps.defaultStyleName],
"\" style"]];
ENDLOOP;
-- with the tree in hand, typeset it
[galley, style] ← TSTranslate.TreeToVlist[root];
[] ← TSJaMPageBuilder.RunPageBuilder[
galley: galley,
style: style,
output: outputHandle,
abortCheckProc: isAborted,
documentName: nameOfDisplayViewer];
outputHandle.Close[];
};
END.
Edited on May 16, 1983 3:47 pm, by Beach
Add PrintSuppliedNodes interface for printing Walnut message sets.
Edited on October 6, 1983 5:18 pm, by Beach
implement FormatTiogaViewer and FormatSuppliedNodes
Michael Plass, December 14, 1983 3:11 pm. Added check for empty server, * server.