<> <> <> 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.STREAM _ IO.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.STREAM _ IO.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.STREAM _ IO.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.