GetPrintPropertiesProc: Commander.CommandProc ~ {
ENABLE {
CommanderOps.Failed => { msg ← errorMsg; GO TO Failed };
XNSPrint.Error => { msg ← Sensible[problem, explanation]; GO TO Failed };
};
argsProcessed: NAT ← 0;
argv: CommanderOps.ArgumentVector ← CommanderOps.Parse[cmd: cmd];
out: IO.STREAM ~ cmd.out;
CheckProperties:
PROC [arg:
ROPE] ~ {
service: ROPE;
properties: XNSPrint.Properties;
argsProcessed ← argsProcessed + 1;
Process.CheckForAbort[];
[service, properties] ← XNSPrint.GetPrinterProperties[arg];
IO.PutF[out, " Service: [%g]\n Staple: %g, TwoSided: %g\n Media: ",
IO.rope[service],
IO.bool[properties.staple],
IO.bool[properties.twoSided]
];
IF ( properties.media # NIL ) THEN DisplayMediaList[out, properties.media];
};
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: XNSPrint.Context;
context ← XNSPrint.GetDefaults[];
IF (context.printerName =
NIL)
THEN msg ← propusage
ELSE CheckProperties[context.printerName];
};
ENDCASE => { NULL };
EXITS
Failed => {result ← $Failure};
};
GetPrintStatusProc: Commander.CommandProc ~ {
ENABLE {
CommanderOps.Failed => { msg ← errorMsg; GO TO Failed };
XNSPrint.Error => { msg ← Sensible[problem, explanation]; GO TO Failed };
};
argsProcessed: NAT ← 0;
argv: CommanderOps.ArgumentVector ← CommanderOps.Parse[cmd: cmd];
out: IO.STREAM ~ cmd.out;
CheckPrinter:
PROC [arg:
ROPE] = {
service: ROPE;
status: XNSPrint.PrinterStatus;
argsProcessed ← argsProcessed + 1;
Process.CheckForAbort[];
[service, status] ← XNSPrint.GetPrinterStatus[arg];
IO.PutF[out, " Service: [%g]\n Spooler: %g, Formatter: %g, Printer: %g\n Media: ",
IO.rope[service],
IO.rope[PrintingAux.ExposeSpoolerStatus[status.spooler, 0]],
IO.rope[PrintingAux.ExposeFormatterStatus[status.formatter, 0]],
IO.rope[PrintingAux.ExposeMarkingEngineStatus[status.printer, 0]]
];
IF ( status.media # NIL ) THEN DisplayMediaList[out, status.media];
};
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: XNSPrint.Context;
context ← XNSPrint.GetDefaults[];
IF (context.printerName =
NIL)
THEN msg ← statususage
ELSE CheckPrinter[context.printerName];
};
ENDCASE => NULL;
EXITS
Failed => {result ← $Failure};
};
FaxMasterProc: Commander.CommandProc ~ {
ENABLE {
XNSPrint.Error => { msg ← Sensible[problem, explanation]; GO TO Failed };
};
context: XNSPrint.Context;
request: XNSPrint.PrintRequest;
ok: BOOL ← TRUE; fullFName, exp: ROPE ← NIL;
out: IO.STREAM ~ cmd.out;
name, phone, copies, host, oneSided, twoSided, first, last, pages: Args.Arg;
FixUpPhone:
PROC [in:
ROPE]
RETURNS [out:
ROPE ←
NIL] ~ {
out ← IO.PutFR["//%g//", IO.rope[in]];
};
IF Args.NArgs[cmd] = 0 THEN RETURN[$Failure, faxusage];
[name, phone, copies, host, oneSided, twoSided, first, last, pages] ← Args.ArgsGet[cmd,
"%s-t%s-c%i-h%s-1%b-2%b-f%i-l%i-p%i"
! Args.Error => {ok ← FALSE; CONTINUE}];
IF NOT ok THEN RETURN[$Failure, "Command syntax error."];
context ← XNSPrint.GetDefaults[];
IF copies.ok THEN context.copyCount ← copies.int;
IF host.ok THEN context.printerName ← host.rope;
IF phone.ok THEN context.message ← FixUpPhone[phone.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];
fullFName ← name.rope; -- FixUpFilename[name.rope, FALSE];
IO.PutF[out, " Sending %s to %s",
IO.rope[fullFName],
IO.rope[context.printerName]
];
Process.CheckForAbort[];
request ← XNSPrint.PrintFromFile[name.rope, context, AllDone];
IO.PutF[out, "\n Service: [%g]\n RequestID: %g\n",
IO.rope[request.distinguishedName],
IO.rope[PrintingAux.ExposeRequestID[request.requestID, 0]]
];
EXITS
Failed => {result ← $Failure};
};
SendMasterProc: Commander.CommandProc ~ {
ENABLE {
XNSPrint.Error => { msg ← Sensible[problem, explanation]; GO TO Failed };
};
context: XNSPrint.Context;
request: XNSPrint.PrintRequest;
ok: BOOL ← TRUE; fullFName, exp: ROPE ← NIL;
out: IO.STREAM ~ cmd.out;
name, copies, host, oneSided, twoSided, first, last, pages, colorCorr, grayBal, message, stapled: Args.Arg;
IF (
FALSE )
THEN {
[result, msg] ← GetPrintStatusProc[cmd];
IF ( result = $Failure ) THEN RETURN[$Failure, msg];
};
IF Args.NArgs[cmd] = 0 THEN RETURN[$Failure, sendusage];
[name, copies, host, oneSided, twoSided, first, last, pages, colorCorr, grayBal, message, stapled] ← Args.ArgsGet[cmd,
"%s-c%i-h%s-1%b-2%b-f%i-l%i-p%i-a%b-b%b-m%s-s%b"
! Args.Error => {ok ← FALSE; CONTINUE}];
IF NOT ok THEN RETURN[$Failure, "Command syntax error."];
context ← XNSPrint.GetDefaults[];
context.stapled ← FALSE;
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;
IF message.ok THEN context.message ← message.rope;
IF stapled.ok AND stapled.bool THEN context.stapled ← TRUE;
IF grayBal.ok THEN context.message ←
context.message.Concat["GrayBalanceThisMaster: TRUE\n"];
IF colorCorr.ok
THEN context.message ←
context.message.Concat["ColorCorrectThisMaster: TRUE\n"];
Note: colorCorr currently is a hack to be able to switch it on and off during research. Once it will work, the switch will disappear and servers will always perform color correction. Giordano Beretta November 4, 1988 10:08:19 am PST.
name.rope ← FileNames.ResolveRelativePath[name.rope];
fullFName ← name.rope; -- FixUpFilename[name.rope, FALSE];
IO.PutF[out, " Sending %s to %s",
IO.rope[fullFName],
IO.rope[context.printerName]
];
Process.CheckForAbort[];
request ← XNSPrint.PrintFromFile[name.rope, context, AllDone !
XNSPrint.Error => {
IF problem=serviceRetry
OR
(problem=service
AND Rope.Equal[s1: explanation, s2: "Spooling Queue Full"])
OR
(problem=connection
AND Rope.Equal[s1: explanation, s2: "communication failure"])
THEN {
Process.CheckForAbort[];
Process.Pause[Process.SecondsToTicks[5]];
IO.PutF[stream: out, format: " ... %lRETRY%l", v1: [rope["k"]], v2: [rope["K"]]];
RETRY;
}
}];
IO.PutF[out, "\n Service: [%g]\n RequestID: %g\n",
IO.rope[request.distinguishedName],
IO.rope[PrintingAux.ExposeRequestID[request.requestID, 0]]
];
EXITS
Failed => {result ← $Failure};
};