GetPrintPropertiesImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Russ Atkinson, April 2, 1985 4:22:08 pm PST
Bill Jackson (bj) October 9, 1986 5:49:50 am PDT
Demers, June 6, 1986 3:09:39 pm PDT
DIRECTORY
CHNameP2V0 USING [Name],
CHLookUp USING [AddressFromRope],
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Failed, Parse],
CrRPC USING [CreateClientHandle, DestroyClientHandle, Handle],
Endian USING [BYTE, FWORD, HWORD],
PrintingP4V3 USING [GetPrinterProperties, PrinterProperties],
PrintingP4V3Aux USING [ExposePrinterProperties],
IO USING [PutFR, PutRope, STREAM],
Process USING [CheckForAbort],
Rope USING [Concat, Fetch, Length, ROPE],
UserProfile USING [Token],
XNS USING [Address];
GetPrintPropertiesImpl:
CEDAR
PROGRAM
IMPORTS CHLookUp, CrRPC, Commander, CommandTool, IO, PrintingP4V3, PrintingP4V3Aux, Process, Rope, UserProfile ~ {
Copied Types
BYTE: TYPE ~ Endian.BYTE;
FWORD: TYPE ~ Endian.FWORD;
Handle: TYPE ~ CrRPC.Handle;
HWORD: TYPE ~ Endian.HWORD;
ROPE: TYPE = Rope.ROPE;
PrinterProperties: TYPE ~ PrintingP4V3.PrinterProperties;
STREAM: TYPE = IO.STREAM;
Constants
GetPrintProperties: ROPE = "///Commands/GetPrintProperties";
doc: ROPE = "{Printer}*\nFind out the properties of an XNS based printer.\nSwitches: <none yet>";
usage: ROPE = Rope.Concat["Usage: GetPrintProperties ", doc];
Procs
DecodeStatus:
PROC [out:
STREAM, status: PrinterProperties] ~ {
msg: ROPE ← IO.PutFR["%g arguments seen.", [integer[1]] ];
msg ← Rope.Concat[PrintingP4V3Aux.ExposePrinterProperties[status, 0], "\n"];
IO.PutRope[out, msg];
};
GetPrinterProperties:
PROC [destRope:
ROPE]
RETURNS [answer: PrinterProperties] ~ {
addr: XNS.Address;
h: Handle;
service: CHNameP2V0.Name;
[addr, service] ← CHLookUp.AddressFromRope[destRope];
h ← CrRPC.CreateClientHandle[class~$SPP, remote~addr];
answer ← PrintingP4V3.GetPrinterProperties[h];
CrRPC.DestroyClientHandle[h];
};
GetPrintPropertiesProc: Commander.CommandProc ~ {
out: STREAM ~ cmd.out;
switches: PACKED ARRAY CHAR['a..'z] OF BOOL ← ALL[FALSE];
ProcessSwitches:
PROC [arg:
ROPE] ~ {
sense: BOOL ← TRUE;
FOR index:
INT
IN [0..Rope.Length[arg])
DO
char: CHAR ← Rope.Fetch[arg, index];
SELECT char
FROM
'- => LOOP;
'~ => {sense ← NOT sense; LOOP};
IN ['a..'z] => switches[char] ← sense;
IN ['A..'Z] => switches[char + ('a-'A)] ← sense;
ENDCASE;
sense ← TRUE;
ENDLOOP;
};
ProcessArgument:
PROC [arg:
ROPE] ~ {
status: PrinterProperties;
argsProcessed ← argsProcessed + 1;
Process.CheckForAbort[];
To process an argument,
get the status from the printer,
and generate some sensible textual output.
status ← GetPrinterProperties[arg];
DecodeStatus[out, status];
};
argsProcessed: NAT ← 0;
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd: cmd, starExpand:
FALSE
! CommandTool.Failed => {msg ← errorMsg; GO TO failed}];
ProcessSwitches[UserProfile.Token["GetPrintProperties.DefaultSwitches"]];
FOR i:
NAT
IN [1..argv.argc)
DO
arg: ROPE ~ argv[i];
Process.CheckForAbort[];
IF (Rope.Length[arg] = 0) THEN LOOP;
IF (Rope.Fetch[arg, 0] = '-)
THEN {
ProcessSwitches[arg];
LOOP;
};
ProcessArgument[arg];
ENDLOOP;
SELECT argsProcessed
FROM
0 => { msg ← usage };
ENDCASE => { NULL };
EXITS
failed => {result ← $Failure};
};
Init:
PROC ~ {
Commander.Register[key: GetPrintProperties, proc: GetPrintPropertiesProc, doc: doc, clientData: NIL, interpreted: TRUE];
};
}...