TSExtrasImpl.mesa
Michael Plass, December 14, 1983 5:21 pm
Last Edited by: Beach, May 7, 1984 4:21:44 pm PDT
DIRECTORY
CommandTool,
IO,
FS,
NameSymbolTable,
NodeProps,
NodeStyle,
PressPrinter,
Rope,
TEditDocument,
TextNode,
TSExtras,
TSJaMPageBuilder,
TSObject,
TSOutput,
TSOutputPress,
TSTranslate,
TSViewer,
ViewerClasses,
UserCredentials,
UserProfile;
TSExtrasImpl:
CEDAR MONITOR
IMPORTS CommandTool, FS, NameSymbolTable, NodeProps, NodeStyle, 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.ROPE ← NIL,
copies: INT ← 1,
messageProc: PROC [Rope.ROPE] ← NIL
] = {ENABLE UNWIND => NULL;
node: TextNode.Ref ← NARROW[viewer.data, TEditDocument.TEditDocumentData].text;
stream: IO.STREAM ← FS.StreamOpen["temp.press$", $create];
fullName: Rope.ROPE ← FS.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.ROPE ← NIL,
copies: INT ← 1,
messageProc: PROC [Rope.ROPE] ← NIL] = {
ENABLE UNWIND => NULL;
stream: IO.STREAM ← FS.StreamOpen["temp.press$", $create];
fullName: Rope.ROPE ← FS.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: 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 }};
new -> node
x -> root
InsertNode:
PROCEDURE [root, node: TextNode.Ref, child:
BOOL ←
FALSE] = {
-- 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 ← NodeStyle.Create[];
prop ← NodeProps.GetProp[node, $Prefix];
IF prop #
NIL
THEN
NodeProps.PutProp[node, $Prefix, Rope.Cat[
NARROW[prop, Rope.ROPE],
" \"",
NameSymbolTable.RopeFromName[style.GetStyleName[]],
"\" 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: 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 }};
new -> node
x -> root
InsertNode:
PROCEDURE [root, node: TextNode.Ref, child:
BOOL ←
FALSE] = {
-- 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];
};
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 ← NodeStyle.Create[];
prop ← NodeProps.GetProp[node, $Prefix];
IF prop #
NIL
THEN
NodeProps.PutProp[node, $Prefix, Rope.Cat[
NARROW[prop, Rope.ROPE],
" \"",
NameSymbolTable.RopeFromName[style.GetStyleName[]],
"\" 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.