GetPrintPropertiesProc: Commander.CommandProc ~ {
argsProcessed: NAT ← 0;
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd: cmd, starExpand:
FALSE
! CommandTool.Failed => {msg ← errorMsg; GO TO failed}];
out: IO.STREAM ~ cmd.out;
CheckProperties:
PROC [arg:
ROPE] ~ {
service: CHName.Name;
status: Printing.PrinterProperties;
argsProcessed ← argsProcessed + 1;
Process.CheckForAbort[];
[service, status] ← XNSPrintRequestManager.GetPrinterProperties[arg];
DecodeProperties[out, service, status];
};
FOR i:
NAT
IN [1..argv.argc)
DO
printerName: ROPE ~ argv[i];
Process.CheckForAbort[];
IF (Rope.Length[printerName] = 0) THEN LOOP;
CheckProperties[printerName];
ENDLOOP;
SELECT argsProcessed
FROM
0 => {
context: XNSPrintRequestManager.Context;
context ← XNSPrintRequestManager.GetDefaults[];
IF (context.printerName =
NIL)
THEN msg ← propusage
ELSE CheckProperties[context.printerName];
};
ENDCASE => { NULL };
EXITS
failed => {result ← $Failure};
};
GetPrintStatusProc: Commander.CommandProc ~ {
argsProcessed: NAT ← 0;
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd: cmd, starExpand:
FALSE
! CommandTool.Failed => { msg ← errorMsg; GO TO failed; }];
out: IO.STREAM ~ cmd.out;
CheckPrinter:
PROC [arg:
ROPE] = {
service: CHName.Name;
status: Printing.PrinterStatus;
argsProcessed ← argsProcessed + 1;
Process.CheckForAbort[];
[service, status] ← XNSPrintRequestManager.GetPrinterStatus[arg];
DecodeStatus[out, service, status];
};
FOR i:
NAT
IN [1..argv.argc)
DO
printerName: ROPE ~ argv[i];
Process.CheckForAbort[];
IF (Rope.Length[printerName] = 0) THEN LOOP;
CheckPrinter[printerName];
ENDLOOP;
SELECT argsProcessed
FROM
0 => {
context: XNSPrintRequestManager.Context;
context ← XNSPrintRequestManager.GetDefaults[];
IF (context.printerName =
NIL)
THEN msg ← statususage
ELSE CheckPrinter[context.printerName];
};
ENDCASE => NULL;
EXITS
failed => {result ← $Failure};
};
SendMasterProc: Commander.CommandProc ~ {
context: XNSPrintRequestManager.Context;
request: XNSPrintRequestManager.PrintRequest;
ok: BOOL;
out: IO.STREAM ~ cmd.out;
name, copies, host, oneSided, twoSided, first, last, pages: Args.Arg;
PrintAFile:
PROC [name:
ROPE]
RETURNS [request: XNSPrintRequestManager.PrintRequest] ~ {
s: IO.STREAM;
Process.CheckForAbort[];
s ←
FS.StreamOpen[name
!
FS.Error =>
IF (error.group # $bug)
THEN { msg ← FSErrorMsg[error]; ERROR CommandTool.Failed[msg]; }
];
request ← XNSPrintRequestManager.PrintFromStream[s, context];
DecodeRequestID[out, request];
IF (s # NIL) THEN IO.Close[s];
};
IF Args.NArgs[cmd] = 0 THEN RETURN[$Failure, sendusage];
[ok, name, copies, host, oneSided, twoSided, first, last, pages] ← Args.ArgsGet[cmd, "%s-c%i-h%s-1%b-2%b-f%i-l%i-p%i"];
IF NOT ok THEN RETURN[$Failure, "Command syntax error."];
context ← XNSPrintRequestManager.GetDefaults[];
IF copies.ok THEN context.copyCount ← copies.int;
IF host.ok THEN context.printerName ← host.rope;
IF twoSided.ok AND twoSided.bool THEN context.twoSided ← TRUE;
IF oneSided.ok AND oneSided.bool THEN context.twoSided ← FALSE;
IF first.ok THEN context.pageFirst ← first.int;
IF last.ok THEN context.pageLast ← last.int;
IF pages.ok THEN context.pageLast ← context.pageFirst+pages.int;
name.rope ← FileNames.ResolveRelativePath[name.rope];
context.printObjectName ← FixUpFilename[name.rope, FALSE];
{
fullFName: ROPE;
attachedTo: ROPE;
keep: CARDINAL;
bytes: INT;
created: BasicTime.GMT;
[fullFName, attachedTo, keep, bytes, created] ← FS.FileInfo[name~name.rope, remoteCheck~FALSE];
context.printObjectCreateDate ← BasicTime.ToNSTime[created];
};
IO.PutF[out, " Sending %s to %s\n",
IO.rope[context.printObjectName],
IO.rope[context.printerName]
];
request ← PrintAFile[name.rope];
XNSPrintRequestManager.RegisterPrintRequest[request]; -- registered for later status requests!
request ← NIL;
};
Init:
PROC ~ {
Commander.Register[GetPrintProperties, GetPrintPropertiesProc, propdoc];
Commander.Register[GetPrintStatus, GetPrintStatusProc, statusdoc];
Commander.Register[SendIPMaster, SendMasterProc, senddoc];
};