TSExtrasImpl.mesa
Michael Plass, May 2, 1983 9:47 am
Last Edited by: Beach, October 18, 1983 11:04 am
DIRECTORY
FileIO,
NameSymbolTable,
NodeProps,
NodeStyle,
PressPrinter,
Rope,
TEditDocument,
TextNode,
TSExtras,
TSJaMPageBuilder,
TSObject,
TSOutput,
TSOutputPress,
TSTranslate,
TSViewer,
ViewerClasses,
UserCredentials,
UserProfile;
TSExtrasImpl: MONITOR
IMPORTS FileIO, 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.ROPENIL,
copies: INT ← 1,
messageProc: PROC [Rope.ROPE] ← NIL
] = {ENABLE UNWIND => NULL;
node: TextNode.Ref ← NARROW[viewer.data, TEditDocument.TEditDocumentData].text;
outputHandle: TSOutput.Handle ← TSOutputPress.CreateWithCursor[
stream: FileIO.Open["temp.press$", overwrite],
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 server = NIL THEN server ← UserProfile.Token["Hardcopy.PressPrinter", ""];
[galley, style] ← TSTranslate.TreeToVlist[node];
[] ← TSJaMPageBuilder.RunPageBuilder[
galley: galley,
style: style,
output: outputHandle,
abortCheckProc: isAborted,
documentName: nameForSeparatorPage
];
outputHandle.Close[];
[] ← PressPrinter.SendPressFile[
fileName: "temp.press$",
server: server,
progressProc: progressProc,
copies: copies,
userName: UserCredentials.GetUserCredentials[].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;
outputHandle: TSOutput.Handle ← TSOutputPress.CreateWithCursor[
stream: FileIO.Open["temp.press$", overwrite],
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 server = NIL THEN server ← UserProfile.Token["Hardcopy.PressPrinter", ""];
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: nameForSeparatorPage];
outputHandle.Close[];
[] ← PressPrinter.SendPressFile[
fileName: "temp.press$",
server: server,
progressProc: progressProc,
copies: copies,
userName: UserCredentials.GetUserCredentials[].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: 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];
};
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