PDPrinterClientImpl.mesa
Michael Plass, November 18, 1983 4:51 pm
Last Edited by: Pier, November 22, 1983 2:52 pm
DIRECTORY Environment, Rope, IO, FileIO, MessageWindow, PDInterpBasic, PDPrinterRpcControl, PDPrinter, MesaRPC;
PDPrinterClientImpl: CEDAR PROGRAM
IMPORTS IO, FileIO, MessageWindow, PDPrinterRpcControl, PDPrinter, MesaRPC
~ BEGIN
mess: CARDINAL ← 0;
ReportStatus: PROC [status: PDInterpBasic.Status] ~ {
s: IO.STREAMIO.CreateOutputStreamToRope[];
s.Put[IO.refAny[NEW[PDInterpBasic.Status ← status]]];
s.PutRope[", "];
MessageWindow.Append[IO.GetOutputStreamRope[s], mess MOD 4 = 0];
mess ← mess + 1;
s.Close[];
};
Print: PUBLIC PROC [file: Rope.ROPE] ~ TRUSTED {
requestorName: LONG STRING = "Melba.auto"L;
interfaceName: MesaRPC.InterfaceName ← [instance: requestorName];
stream: IO.STREAM ← FileIO.Open[file
! FileIO.OpenFailed => TRUSTED {
s: IO.STREAMIO.CreateOutputStreamToRope[];
s.PutRope["Unable to open PD file: "];
s.Put[IO.refAny[NEW[FileIO.OpenFailure ← why]]];
s.Put[IO.rope[fileName]];
MessageWindow.Append[IO.GetOutputStreamRope[s], TRUE];
MessageWindow.Blink[];
GOTO Quit;
}
];
response: PDPrinter.Response ← [nextWordIndex: 0, status: betweenPages, currentPage: 0];
dataBlock: PDPrinter.DataBlock;
oldStatus: PDInterpBasic.Status ← transmissionComplete;
PDPrinterRpcControl.ImportInterface[interfaceName
! MesaRPC.ImportFailed => {
s: IO.STREAMIO.CreateOutputStreamToRope[];
s.PutRope["Unable to access PDInterpControl: "];
s.Put[IO.refAny[NEW[MesaRPC.ImportFailure ← why]]];
MessageWindow.Append[IO.GetOutputStreamRope[s], TRUE];
MessageWindow.Blink[];
GOTO Quit;
}
];
BEGIN ENABLE UNWIND => {PDPrinterRpcControl.UnimportInterface[]; IO.Close[stream]};
WHILE response.nextWordIndex >= 0 DO
byteIndex: INT ← response.nextWordIndex*2;
bytesRead: INT ← 0;
bytesPerBlock: INT = PDPrinter.maxBlockSize*Environment.bytesPerWord;
stream.SetIndex[byteIndex];
bytesRead ← stream.UnsafeGetBlock[[@(dataBlock.buffer), 0, bytesPerBlock]];
dataBlock.wordIndex ← response.nextWordIndex;
dataBlock.wordCount ← bytesRead/Environment.bytesPerWord;
response ← PDPrinter.TransmitBlock[dataBlock];
IF response.status # oldStatus THEN {
ReportStatus[response.status];
oldStatus ← response.status;
};
ENDLOOP;
END;
PDPrinterRpcControl.UnimportInterface[];
IO.Close[stream];
EXITS Quit => NULL;
};
END.