DIRECTORY
BasicTime USING [FromNSTime, GMT],
DFUtilities USING [DirectoryItem, FileItem, ParseFromStream, ProcessItemProc, SyntaxError],
FS USING [ComponentPositions, Copy, Error, ExpandName, StreamOpen],
IO USING [card, Close, Flush, GetTokenRope, PutChar, PutF, PutF1, PutFR, PutRope, rope, STREAM, time, TokenProc],
PrintingP4V3 USING [Attribute, InterpressMasterStatus, Option, PrintAttributes, PrintOptions, RequestID],
Rope USING [Cat, ROPE, Substr],
SystemNames USING [ReleaseName],
XNSPSCommander USING [CommandProc, Confirm, GetArg, GetNumber, RegisterCommand],
XNSPSMessages USING [LogMessage],
XNSPSPrint USING [GetMargins, SetMargins],
XNSPSSpooler USING [EnumerateQueue]
;
~
BEGIN
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
SetPrinterParams: XNSPSCommander.CommandProc =
BEGIN
CommandProc: TYPE = PROC [in, out: STREAM];
sMargin, fMargin, newsMargin, newfMargin: CARDINAL;
IO.PutRope[out, " \nGetting current parameters ... "];
[sMargin, fMargin] ← XNSPSPrint.GetMargins[];
IO.PutF[out, " Current Parameters: sMargin: %g, fMargin: %g \n",
IO.card[sMargin], IO.card[fMargin]];
newsMargin ← XNSPSCommander.GetNumber[in: in, out: out, default: sMargin,
prompt: "\nNew sMargin: ", help: NIL];
IF newsMargin
NOT
IN [1..30]
THEN {
IO.PutRope[out, " must be in [1..30] \n"];
RETURN;
};
newfMargin ← XNSPSCommander.GetNumber[in: in, out: out, default: fMargin,
prompt: "\nNew fMargin: ", help: NIL];
IF newfMargin
NOT
IN [10..43]
THEN {
IO.PutRope[out, " must be in [10..43]\n"];
RETURN;
};
IO.PutRope[out, " You sure? "];
IF XNSPSCommander.Confirm[in: in, out: out]
THEN {
XNSPSPrint.SetMargins[newsMargin, newfMargin];
[sMargin, fMargin] ← XNSPSPrint.GetMargins[];
XNSPSMessages.LogMessage[
IO.PutFR["Setting margins to: sMargin: %g, fMargin: %g",
IO.card[sMargin], IO.card[fMargin]]];
};
IO.PutRope[out, "\n"];
END;
InstallFonts: XNSPSCommander.CommandProc =
BEGIN
CommandProc: TYPE = PROC [in, out: STREAM];
errorRope: ROPE ← NIL;
BEGIN
-- for exit
ENABLE {UNWIND => NULL; FS.Error => {errorRope ← error.explanation; GOTO Error}};
HelpFontClass:
PROC [] =
BEGIN
IO.PutRope[out, "Specify font type (ie. XC1-2-2 or PressFonts)\n"];
END;
HelpDFName:
PROC [] =
BEGIN
IO.PutRope[out,
"Specify df file name (ie. [Fonts]<CedarFonts>Top>XC1-2-2-CD-Splines.df)\n"];
END;
ProcessItem: DFUtilities.ProcessItemProc =
BEGIN
[item: REF ANY] RETURNS [stop: BOOL ← FALSE];
WITH item
SELECT
FROM
dir: REF DFUtilities.DirectoryItem => {root ← dir.path1};
file:
REF DFUtilities.FileItem => {
fullFName, toName: ROPE; cp: FS.ComponentPositions;
[fullFName, ] ← FS.ExpandName[name: file.name, wDir: root]; -- glue it together
[toName, cp] ← FS.ExpandName[name: file.name, wDir: localDir]; -- glue it together
toName ← Rope.Substr[base: toName, start: 0, len: cp.ver.start-1]; -- strip off version
toName ← FS.Copy[from: fullFName, to: toName, setKeep: TRUE, keep: 1,
attach: FALSE]; -- don't attach it
IO.PutF[out, "Copied %g => %g\n", IO.rope[fullFName], IO.rope[toName]];
IO.Flush[out];
};
ENDCASE => NULL;
END;
root, remoteName, localDir, fontType: ROPE ← NIL;
df: STREAM;
fontType ← XNSPSCommander.GetArg[in: in, out: out, prompt: "\nFont type: ",
default: "XC1-2-2", help: HelpFontClass];
IF fontType = NIL THEN GOTO Abort;
localDir ← Rope.Cat["///", SystemNames.ReleaseName[], "/Fonts/Xerox/", fontType, "/"];
remoteName ← XNSPSCommander.GetArg[in: in, out: out, prompt: "\nDF file name: ",
default: "[Fonts]<CedarFonts>Top>XC1-2-2-CD-Splines.df", help: HelpDFName];
IF remoteName = NIL THEN GOTO Abort;
IO.PutRope[out, "\nFetching ...\n"];
df ← FS.StreamOpen[remoteName, read
! FS.Error => {errorRope ← error.explanation; GOTO Error}];
DFUtilities.ParseFromStream[df, ProcessItem
! DFUtilities.SyntaxError => {errorRope ← reason; GOTO Error}];
IO.Close[df];
EXITS
Error => IO.PutF1[out, "\nError: %g while fetching fonts\n", IO.rope[errorRope]];
Abort => IO.PutRope[out, "\nAborted\n"];
END;
END;
Login: XNSPSCommander.CommandProc =
BEGIN
CommandProc: TYPE = PROC [in, out: STREAM];
name, password: ROPE ← NIL;
IO.PutRope[out, "\nName: "];
name ← IO.GetTokenRope[stream: in, breakProc: IO.TokenProc].token;
IO.PutF1[out, " %g Password: ", IO.rope[name]];
password ← IO.GetTokenRope[stream: in, breakProc: IO.TokenProc].token;
IO.PutRope[out, "\nDone"];
END;
ListFonts: XNSPSCommander.CommandProc =
BEGIN
CommandProc: TYPE = PROC [in, out: STREAM];
END;
ListQueue: XNSPSCommander.CommandProc =
BEGIN
Proc:
PROC [id: PrintingP4V3.RequestID,
status: PrintingP4V3.InterpressMasterStatus,
printAttributes: PrintingP4V3.PrintAttributes,
printOptions: PrintingP4V3.PrintOptions]
RETURNS [continue:
BOOL] =
TRUSTED {
md: MACHINE DEPENDENT RECORD [lo, hi: CARDINAL];
md.lo ← id[4]; md.hi ← id[3];
IO.PutF[out, "ID: %g\tStatus: %g\n",
IO.card[
LOOPHOLE[md]],
IO.rope[(
SELECT status
FROM
pending => "pending", inProgress => "in progress",
completed => "completed",
completedWithWarning => "completed with warnings",
unknown => "unknown", rejected => "rejected", aborted => "aborted",
canceled => "canceled", held => "held", ENDCASE => NIL)]
];
IO.PutRope[out, "Print Attributes:\n"];
IF printAttributes
# NIL THEN
FOR i:
CARDINAL
IN [0 .. printAttributes.length)
DO
option: PrintingP4V3.Attribute ← printAttributes.body[i];
WITH option: option
SELECT
FROM
printObjectName => {IO.PutF1[out, " name: %g\n", IO.rope[option.printObjectName]]};
printObjectCreateDate => {
time: BasicTime.GMT ← BasicTime.FromNSTime[option.printObjectCreateDate];
IO.PutF1[out, " createTime: %g\n", IO.time[time]]};
senderName => {IO.PutF1[out, " name: %g\n", IO.rope[option.senderName]]};
ENDCASE => NULL;
ENDLOOP;
IO.PutRope[out, "Print Options:\n"];
IF printOptions #
NIL
THEN
FOR i:
CARDINAL
IN [0 .. printOptions.length)
DO
option: PrintingP4V3.Option ← printOptions.body[i];
WITH option: option
SELECT
FROM
printObjectSize => IO.PutF1[out, " size: %g\n", IO.card[option.printObjectSize]];
recipientName => IO.PutF1[out, " recipientName: %g\n", IO.rope[option.recipientName]];
message => IO.PutF1[out, " message: %g\n", IO.rope[option.message]];
copyCount => IO.PutF1[out, " copies: %g\n", IO.card[option.copyCount]];
ENDCASE => NULL;
ENDLOOP;
IO.Flush[out];
};
IO.PutChar[out, '\n];
XNSPSSpooler.EnumerateQueue[Proc];
IO.PutChar[out, '\n];
END;
Init:
PROC [] =
BEGIN
XNSPSCommander.RegisterCommand[[SetPrinterParams, "Set Printer Parmeters"]];
XNSPSCommander.RegisterCommand[[InstallFonts, "Install Fonts"]];
XNSPSCommander.RegisterCommand[[Login, "Login"]];
XNSPSCommander.RegisterCommand[[ListFonts, "List Fonts"]];
XNSPSCommander.RegisterCommand[[ListQueue, "List Queue"]];
END;
Init[];