DIRECTORY Environment, Inline, PDInterpBasic, PDFileFormat, PDInterpBitmap, PDInterpReader, PDInterpSysCalls, Mopcodes, Heap, PDPrinter, PDPrinterRpcControl, MesaRPC, OthelloDefs, Process; PDInterpReaderImpl: MONITOR IMPORTS Inline, PDInterpBitmap, PDInterpSysCalls, Heap, PDPrinterRpcControl, MesaRPC, OthelloDefs, Process EXPORTS PDInterpReader, PDPrinter = BEGIN OPEN PDInterpReader; bitsPerWord: NAT = Environment.bitsPerWord; zone: UNCOUNTED ZONE = Heap.systemZone; currentHandle: Handle _ NIL; NewClient: CONDITION; BufferSpaceAvailable: CONDITION; NewDataAvailable: CONDITION; TransmitBlock: PUBLIC ENTRY PROC [dataBlock: PDPrinter.DataBlock] RETURNS [response: PDPrinter.Response] = { ENABLE UNWIND => NULL; IF currentHandle = NIL THEN { dataPtr: LONG POINTER _ @(dataBlock.buffer); herald: LONG POINTER TO PDFileFormat.Herald _ dataPtr; private: Private _ zone.NEW[PrivateRep]; PDInterpSysCalls.SetDisplayLights[105]; OthelloDefs.WriteLine["New client request"]; IF dataBlock.wordIndex # 0 THEN RETURN[[nextWordIndex: -1, status: serverAbort, currentPage: 0]]; currentHandle _ zone.NEW[Rep _ [ herald: herald^, image: [0,FALSE,FALSE,FALSE,black,0,0,0,0], bandNumber: 0, sMinBand: 0, sSizeBand: 0, colorType: none, colorTileLoadAddress: -1, priority: 0, loadWords: 0, private: private, index: 0, page: 0, pass: 0, status: betweenPages, warningCount: 0 ]]; IF dataBlock.wordCount < SIZE[PDFileFormat.Herald] THEN currentHandle.status _ unexpectedEOF ELSE CheckHerald[currentHandle]; IF currentHandle.status # betweenPages THEN { errorStatus: PDInterpBasic.Status _ currentHandle.status; zone.FREE[@private]; zone.FREE[@currentHandle]; RETURN[[nextWordIndex: -1, status: errorStatus, currentPage: 0]]; }; currentHandle.index _ SIZE[PDFileFormat.Herald]; currentHandle.sSizeBand _ herald.bandSSize; {ENABLE UNWIND => { zone.FREE[@private]; zone.FREE[@currentHandle]; }; AllocateSpace[currentHandle]; }; NOTIFY NewClient; RETURN[[nextWordIndex: currentHandle.index, status: currentHandle.status, currentPage: 0]]; } ELSE { private: Private _ currentHandle.private; BufferEndIndex: PROC RETURNS [INT] = { wordsPassedBy: INT = private.bufferWordPointer-private.bufferOriginPointer; wordsToEndOfBuffer: INT = private.bufferWordsAllocated-wordsPassedBy; RETURN [currentHandle.index + wordsToEndOfBuffer]; }; oldEndIndex: INT = currentHandle.index + private.bufferWordCount; IF dataBlock.wordIndex # oldEndIndex THEN { RETURN[[ nextWordIndex: oldEndIndex, status: currentHandle.status, currentPage: currentHandle.page ]]; }; WHILE BufferEndIndex[] < dataBlock.wordIndex + dataBlock.wordCount DO WAIT BufferSpaceAvailable; ENDLOOP; BlockTransfer[source: @(dataBlock.buffer), count: dataBlock.wordCount, dest: private.bufferWordPointer+private.bufferWordCount]; private.bufferWordCount _ private.bufferWordCount + dataBlock.wordCount; NOTIFY NewDataAvailable; RETURN[[ nextWordIndex: IF currentHandle.status = transmissionComplete THEN -1 ELSE oldEndIndex + dataBlock.wordCount, status: currentHandle.status, currentPage: currentHandle.page ]]; }; }; CheckHerald: INTERNAL PROC [handle: Handle] = { IF handle.herald.maxLoadWord > 100000 THEN handle.status _ unreasonableLoadSize; IF NOT (handle.herald.copies IN [1..200]) THEN handle.status _ unreasonableNumberOfCopies; IF NOT (handle.herald.imageSSize IN [80..32767]) OR NOT (handle.herald.imageFSize IN [80..32767]) THEN handle.status _ unreasonableImageSize; IF NOT (handle.herald.bandSSize IN [8..32767]) THEN handle.status _ unreasonableBandSSize; IF NOT (handle.herald.sResolution IN [10..10000]) OR NOT (handle.herald.fResolution IN [10..10000]) THEN handle.status _ unreasonableResolution; IF handle.herald.version # PDFileFormat.versionValue THEN handle.status _ wrongFormatVersion; IF handle.herald.password # PDFileFormat.passwordValue THEN handle.status _ invalidPassword; }; AllocateSpace: INTERNAL PROC [handle: Handle] = { ENABLE UNWIND => NULL; private: Private _ handle.private; bufferWords: INT _ (Inline.LongMult[handle.herald.bandSSize, (handle.herald.imageFSize+bitsPerWord-1)/bitsPerWord]+100)*2; private.loadPointer _ PDInterpSysCalls.AllocateSpace[handle.herald.maxLoadWord+bufferWords]; private.loadWordsAllocated _ handle.herald.maxLoadWord; private.bufferWordPointer _ private.bufferOriginPointer _ private.loadPointer + private.loadWordsAllocated; private.bufferWordsAllocated _ bufferWords; private.bufferWordCount _ 0; }; Open: PUBLIC ENTRY PROC RETURNS [handle: Handle] = { ENABLE UNWIND => NULL; interfaceName: MesaRPC.InterfaceName _ [instance: "Melba.auto"L]; PDInterpSysCalls.SetDisplayLights[100]; OthelloDefs.WriteLine["Exporting PD server"]; PDPrinterRpcControl.ExportInterface[interfaceName: interfaceName, user: "Melba.auto"L, password: MesaRPC.MakeKey ["6VIVW621"L] ]; PDInterpSysCalls.SetDisplayLights[101]; OthelloDefs.WriteLine["Soliciting client"]; WHILE currentHandle = NIL DO WAIT NewClient; ENDLOOP; PDInterpSysCalls.SetDisplayLights[107]; OthelloDefs.WriteLine["Got a client"]; handle _ currentHandle; }; WaitForClientToFindOutWeAreDone: ENTRY PROC = { WAIT NewDataAvailable; }; Close: PUBLIC ENTRY PROC [handle: Handle] RETURNS [Handle _ NIL] = { ENABLE UNWIND => NULL; private: Private _ handle.private; PDInterpSysCalls.SetDisplayLights[108]; OthelloDefs.WriteLine["Finishing with client"]; IF handle # currentHandle THEN ERROR; PDPrinterRpcControl.UnexportInterface[]; currentHandle _ NIL; IF private.loadPointer # NIL THEN PDInterpSysCalls.FreeSpace[private.loadPointer]; zone.FREE[@private]; zone.FREE[@handle]; PDInterpSysCalls.SetDisplayLights[109]; OthelloDefs.WriteLine["Finished"]; }; ColorTileFromLoad: PUBLIC PROC [handle: Handle, colorTileLoadAddress: INT, scratchPointer: LONG POINTER, scratchWords: INT] RETURNS [PDInterpBitmap.Tile] = { private: Private = handle.private; tile: LONG POINTER TO PDFileFormat.Tile = private.loadPointer + colorTileLoadAddress; words: INT = Inline.LongMult[tile.sSize, (tile.fSize+(bitsPerWord-1))/bitsPerWord]; bitmap: PDInterpBitmap.BitmapDesc_ PDInterpBitmap.Reshape[ tile + SIZE[PDFileFormat.Tile], words, [tile.sMin, tile.fMin, tile.sSize, tile.fSize] ]; RETURN [PDInterpBitmap.CreateTile[ rectangle: [tile.sMin, tile.fMin, tile.sSize, tile.fSize], phase: tile.phase, rasterPointer: tile + SIZE[PDFileFormat.Tile], scratchPointer: scratchPointer, scratchWords: scratchWords ]]; }; BlockTransfer: PROC [source: LONG POINTER, count: CARDINAL, dest: LONG POINTER] = MACHINE CODE {Mopcodes.zBLTL}; LongBlockTransfer: PROC [source: LONG POINTER, count: INT, dest: LONG POINTER] = { WHILE count > LAST[CARDINAL] DO BlockTransfer[source, LAST[CARDINAL], dest]; source _ source + LAST[CARDINAL]; dest _ dest + LAST[CARDINAL]; count _ count - LAST[CARDINAL]; ENDLOOP; BlockTransfer[source, count, dest]; }; Private: TYPE = LONG POINTER TO PrivateRep; PrivateRep: PUBLIC TYPE = RECORD [ loadPointer: LONG POINTER _ NIL, loadWordsAllocated: INT _ 0, bufferOriginPointer: LONG POINTER _ NIL, bufferWordsAllocated: INT _ 0, bufferWordPointer: LONG POINTER _ NIL, bufferWordCount: INT _ 0 ]; FillBuffer: ENTRY PROC [handle: Handle, wordsNeeded: INT] RETURNS [wordsRemovedFromFront: INT] = { wordsRemovedFromFront _ InternalFillBuffer[handle, wordsNeeded]; }; InternalFillBuffer: INTERNAL PROC [handle: Handle, wordsNeeded: INT] RETURNS [wordsRemovedFromFront: INT] = { private: Private _ handle.private; wordsRemovedFromFront _ (private.bufferWordPointer-private.bufferOriginPointer); LongBlockTransfer[source: private.bufferWordPointer, count: private.bufferWordCount, dest: private.bufferOriginPointer]; private.bufferWordPointer _ private.bufferOriginPointer; NOTIFY BufferSpaceAvailable; WHILE private.bufferWordCount < wordsNeeded DO WAIT NewDataAvailable; ENDLOOP; }; BlockDescription: TYPE = RECORD [pointer: LONG POINTER, words: CARDINAL]; ReadLocate: ENTRY PROC [handle: Handle, words: INT] RETURNS [blockDescription: BlockDescription] = { private: Private _ handle.private; IF private.bufferWordCount < words THEN [] _ InternalFillBuffer[handle, words]; blockDescription.pointer _ private.bufferWordPointer; blockDescription.words _ MIN[private.bufferWordCount, words]; private.bufferWordPointer _ private.bufferWordPointer + blockDescription.words; private.bufferWordCount _ private.bufferWordCount - blockDescription.words; handle.index _ handle.index + blockDescription.words; }; ReadBlock: ENTRY PROC [handle: Handle, dest: LONG POINTER, words: INT] = { private: Private _ handle.private; WHILE words > 0 DO inBuffer: INT _ MIN[private.bufferWordCount, words]; BlockTransfer[source: private.bufferWordPointer, count: inBuffer, dest: dest]; private.bufferWordPointer _ private.bufferWordPointer + inBuffer; private.bufferWordCount _ private.bufferWordCount - inBuffer; handle.index _ handle.index + inBuffer; dest _ dest + inBuffer; words _ words - inBuffer; IF words > 0 THEN [] _ InternalFillBuffer[handle, MIN[words, PDPrinter.maxBlockSize]]; ENDLOOP; }; CheckBB: PROC [handle: Handle, sMin, fMin, sSize, fSize: CARDINAL, errorWordCount: INT] = { IF LONG[sMin] + sSize > handle.herald.imageSSize OR LONG[fMin] + fSize > handle.herald.imageFSize OR fMin < handle.image.fMinPage OR fMin + fSize > handle.image.fMinPage + handle.image.fSizePage THEN RaisePDError[handle, objectOutOfBounds, errorWordCount]; IF sMin + sSize <= handle.sMinBand OR sMin >= handle.sMinBand+handle.sSizeBand THEN { RaisePDWarning[handle, objectOutOfBand, errorWordCount]; }; }; Get: PUBLIC PROC [handle: Handle] RETURNS [CommandBuffer] = { private: Private _ handle.private; command: PDFileFormat.Command; BadLoadReference: PROC [dataWords: INT] = { RaisePDError[handle, badLoadReference, SIZE[PDFileFormat.Command]+dataWords]; }; IF handle.priority = LAST[INT] THEN { ans: CommandBuffer.stateChange; ans.loadChangeStart _ ans.loadChangeLength _ 0; handle.sMinBand _ handle.sMinBand + handle.sSizeBand; handle.bandNumber _ handle.bandNumber + 1; handle.priority _ 0; handle.colorType _ ink; ans.whatChanged _ bandChange; IF handle.bandNumber = handle.image.nBands THEN { ans.whatChanged _ imageEnd; handle.colorType _ none; handle.status _ betweenPages; }; RETURN [ans]; }; ReadBlock[handle, @command, SIZE[PDFileFormat.Command]]; WITH command SELECT FROM imagingCommand: PDFileFormat.Command.imaging => { IF handle.colorType = none THEN { RaisePDError[handle, missingStartImage, SIZE[PDFileFormat.Command]]; ERROR }; SELECT imagingCommand.com FROM maskSamplesRef => { ans: CommandBuffer.maskSamples; maskSamplesRef: PDFileFormat.MaskSamplesRef; loadAddress: Environment.LongNumber; samples: LONG POINTER TO PDFileFormat.SampleArray; words: INT; ReadBlock[handle, @maskSamplesRef, SIZE[PDFileFormat.MaskSamplesRef]]; loadAddress.highbits _ imagingCommand.addrHighBits; loadAddress.lowbits _ maskSamplesRef.addrLowBits; ans.loadAddress _ loadAddress.li; IF ans.loadAddress < 0 OR ans.loadAddress + SIZE[PDFileFormat.SampleArray] > handle.loadWords THEN BadLoadReference[SIZE[PDFileFormat.MaskSamplesRef]]; samples _ private.loadPointer + loadAddress.li; words _ Inline.LongMult[samples.sSize, (samples.fSize+(bitsPerWord-1))/bitsPerWord]; IF ans.loadAddress + SIZE[PDFileFormat.SampleArray] + words > handle.loadWords THEN BadLoadReference[SIZE[PDFileFormat.MaskSamplesRef]]; CheckBB[handle, maskSamplesRef.sMin, maskSamplesRef.fMin, samples.sSize, samples.fSize, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.MaskSamplesRef]]; ans.samples _ [sOrigin: maskSamplesRef.sMin, fOrigin: maskSamplesRef.fMin, sMin: 0, fMin: 0, sSize: samples.sSize, fSize: samples.fSize, pointer: samples+SIZE[PDFileFormat.SampleArray], rast: (samples.fSize+(bitsPerWord-1))/bitsPerWord, lines: samples.sSize]; RETURN [ans] }; maskRunGroupRef => { ans: CommandBuffer.maskRunGroup; maskRunGroupRef: PDFileFormat.MaskRunGroupRef; loadAddress: Environment.LongNumber; runGroup: LONG POINTER TO PDFileFormat.RunGroup; run: LONG POINTER TO PDFileFormat.Run; s: CARDINAL _ 0; runCount: CARDINAL _ 0; words: INT _ 0; fSize: CARDINAL _ 0; ReadBlock[handle, @maskRunGroupRef, SIZE[PDFileFormat.MaskRunGroupRef]]; loadAddress.highbits _ imagingCommand.addrHighBits; loadAddress.lowbits _ maskRunGroupRef.addrLowBits; ans.loadAddress _ loadAddress.li; IF ans.loadAddress < 0 OR ans.loadAddress + SIZE[PDFileFormat.RunGroup] > handle.loadWords THEN BadLoadReference[SIZE[PDFileFormat.MaskRunGroupRef]]; runGroup _ private.loadPointer + loadAddress.li; ans.pointer _ run _ private.loadPointer + loadAddress.li + SIZE[PDFileFormat.RunGroup]; WHILE s < runGroup.sSize DO IF INT[run-private.loadPointer] >= handle.loadWords THEN BadLoadReference[SIZE[PDFileFormat.MaskRunGroupRef]]; IF run.fSize > fSize THEN fSize _ run.fSize; IF run.lastRun THEN s _ s + 1; run _ run + SIZE[PDFileFormat.Run]; ENDLOOP; ans.runCount _ runCount; CheckBB[handle, maskRunGroupRef.sMin, maskRunGroupRef.fMin, runGroup.sSize, fSize, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.MaskRunGroupRef]]; ans.sMin _ maskRunGroupRef.sMin; ans.fMin _ ans.fOffset _ maskRunGroupRef.fMin; ans.sSize _ runGroup.sSize; ans.fSize _ fSize; RETURN [ans] }; maskRectangle => { ans: CommandBuffer.maskRectangle; maskRectangle: PDFileFormat.MaskRectangle; ReadBlock[handle, @maskRectangle, SIZE[PDFileFormat.MaskRectangle]]; CheckBB[handle, maskRectangle.sMin, maskRectangle.fMin, maskRectangle.sSize, maskRectangle.fSize, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.MaskRectangle]]; ans.sMin _ maskRectangle.sMin; ans.fMin _ maskRectangle.fMin; ans.sSize _ maskRectangle.sSize; ans.fSize _ maskRectangle.fSize; RETURN [ans] }; maskTrapezoid => { ans: CommandBuffer.maskTrapezoid; maskTrapezoid: PDFileFormat.MaskTrapezoid; fMin, fMax: INT; ReadBlock[handle, @maskTrapezoid, SIZE[PDFileFormat.MaskTrapezoid]]; fMin _ MIN[maskTrapezoid.fMin, maskTrapezoid.fMinLast]; fMax _ MAX[LONG[maskTrapezoid.fMin] + maskTrapezoid.fSize, LONG[maskTrapezoid.fMinLast] + maskTrapezoid.fSizeLast]; CheckBB[handle, maskTrapezoid.sMin, fMin, maskTrapezoid.sSize, fMax-fMin, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.MaskTrapezoid]]; ans.sMin _ maskTrapezoid.sMin; ans.fMin _ maskTrapezoid.fMin; ans.fMinLast _ maskTrapezoid.fMinLast; ans.sSize _ maskTrapezoid.sSize; ans.fSize _ maskTrapezoid.fSize; ans.fSizeLast _ maskTrapezoid.fSizeLast; RETURN [ans] }; maskRunGroup => { ans: CommandBuffer.maskRunGroup; maskRunGroup: PDFileFormat.MaskRunGroup; runGroup: PDFileFormat.RunGroup; s: CARDINAL _ 0; runCount: INT _ 0; words: INT _ 0; fMin: CARDINAL _ LAST[CARDINAL]; fMax: CARDINAL _ FIRST[CARDINAL]; run: LONG POINTER TO PDFileFormat.Run; ReadBlock[handle, @maskRunGroup, SIZE[PDFileFormat.MaskRunGroup]]; ReadBlock[handle, @runGroup, SIZE[PDFileFormat.RunGroup]]; run _ private.bufferWordPointer; WHILE s < runGroup.sSize DO IF (runCount+1)*SIZE[PDFileFormat.Run] > private.bufferWordCount THEN { run _ run - FillBuffer[handle, (runCount+1)*SIZE[PDFileFormat.Run]]; IF (runCount+1)*SIZE[PDFileFormat.Run] > private.bufferWordCount THEN RaisePDError[handle, runGroupTooLong, SIZE[PDFileFormat.MaskRunGroup] + SIZE[PDFileFormat.RunGroup]]; }; IF run.fMin < fMin THEN fMin _ run.fMin; IF LONG[run.fMin] + run.fSize > fMax THEN fMax _ LONG[run.fMin] + run.fSize; IF run.lastRun THEN s _ s + 1; runCount _ runCount + 1; run _ run + SIZE[PDFileFormat.Run]; ENDLOOP; ans.runCount _ runCount; ans.loadAddress _ -1; IF runCount = 0 THEN { ans.pointer _ NIL; RaisePDWarning[handle, emptyRunGroup, SIZE[PDFileFormat.MaskRunGroup]+SIZE[PDFileFormat.RunGroup]]; fMin _ fMax; } ELSE { [[ans.pointer, ----]] _ ReadLocate[handle, runCount*SIZE[PDFileFormat.Run]]; CheckBB[handle, maskRunGroup.sMin, fMin, runGroup.sSize, fMax-fMin, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.MaskRunGroupRef]] }; ans.sMin _ maskRunGroup.sMin; ans.fMin _ fMin; ans.fOffset _ 0; ans.sSize _ runGroup.sSize; ans.fSize _ fMax; RETURN [ans]; }; maskSamples => { ans: CommandBuffer.maskSamples; maskSamples: PDFileFormat.MaskSamples; samples: PDFileFormat.SampleArray; ReadBlock[handle, @maskSamples, SIZE[PDFileFormat.MaskSamples]]; ReadBlock[handle, @samples, SIZE[PDFileFormat.SampleArray]]; CheckBB[handle, maskSamples.sMin, maskSamples.fMin, samples.sSize, samples.fSize, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.MaskSamples]+SIZE[PDFileFormat.SampleArray]]; ans.loadAddress _ -1; {raster: BlockDescription _ ReadLocate[ handle, Inline.LongMult[samples.sSize, (samples.fSize+(bitsPerWord-1))/bitsPerWord] ]; ans.samples _ PDInterpBitmap.Reshape[ raster.pointer, raster.words, [maskSamples.sMin, maskSamples.fMin, samples.sSize, samples.fSize] ! PDInterpBitmap.InsufficientSpace => { RaisePDError[handle, bitmapTooBig, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.MaskSamples]+SIZE[PDFileFormat.SampleArray]]; ERROR } ]; }; RETURN [ans]; }; colorSamples => { ans: CommandBuffer.colorSamples; colorSamples: PDFileFormat.ColorSamples; samples: PDFileFormat.SampleArray; ReadBlock[handle, @colorSamples, SIZE[PDFileFormat.ColorSamples]]; ReadBlock[handle, @samples, SIZE[PDFileFormat.SampleArray]]; CheckBB[handle, colorSamples.sMin, colorSamples.fMin, samples.sSize, samples.fSize, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.ColorSamples]+SIZE[PDFileFormat.SampleArray]]; {raster: BlockDescription _ ReadLocate[ handle, Inline.LongMult[samples.sSize, (samples.fSize+(bitsPerWord-1))/bitsPerWord] ]; ans.samples _ PDInterpBitmap.Reshape[ raster.pointer, raster.words, [colorSamples.sMin, colorSamples.fMin, samples.sSize, samples.fSize] ! PDInterpBitmap.InsufficientSpace => { RaisePDError[handle, bitmapTooBig, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.MaskSamples]+SIZE[PDFileFormat.SampleArray]]; ERROR } ]; }; RETURN [ans]; }; ENDCASE => { RaisePDError[handle, unrecognisedImagingCommand, SIZE[PDFileFormat.Command]]; ERROR}; }; controlCommand: PDFileFormat.Command.control => { ans: CommandBuffer.stateChange; ans.loadChangeStart _ ans.loadChangeLength _ 0; IF handle.colorType = none THEN SELECT controlCommand.com FROM startImage, deviceCommand, storeLoad, endDocument => NULL; ENDCASE => { RaisePDError[handle, missingStartImage, SIZE[PDFileFormat.Command]]; ERROR }; SELECT controlCommand.com FROM startImage => { startImage: PDFileFormat.StartImage; ReadBlock[handle, @startImage, SIZE[PDFileFormat.StartImage]]; IF startImage.filler # 0 THEN { RaisePDWarning[handle, nonZeroFill, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.StartImage]]; }; IF (LONG[startImage.passBands]+startImage.nBands)*handle.sSizeBand >= handle.herald.imageSSize+handle.sSizeBand OR LONG[startImage.fMinPage]+startImage.fSizePage > handle.herald.imageFSize THEN { RaisePDWarning[handle, imageBoundsExceedPageBounds, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.StartImage]]; }; IF handle.colorType # none AND handle.bandNumber < handle.image.nBands THEN RaisePDWarning[handle, tooFewBands, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.StartImage]]; handle.image _ startImage; ans.whatChanged _ imageStart; handle.priority _ 0; handle.colorType _ ink; handle.bandNumber _ 0; handle.sMinBand _ startImage.passBands*handle.sSizeBand; IF NOT startImage.strip THEN {handle.pass _ handle.pass + 1}; IF startImage.feed THEN {handle.page _ handle.page + 1; handle.pass _ 1}; handle.status _ constructingImage; RETURN [ans] }; setPriority => { priorityLow: PDFileFormat.Priority; priority: Environment.LongNumber; ReadBlock[handle, @priorityLow, SIZE[PDFileFormat.Priority]]; priority.highbits _ controlCommand.rest; priority.lowbits _ priorityLow; handle.priority _ priority.li; ans.whatChanged _ priorityChange; RETURN [ans] }; setColorInk => { handle.colorType _ ink; ans.whatChanged _ colorChange; RETURN [ans] }; setColorClear => { handle.colorType _ clear; ans.whatChanged _ colorChange; RETURN [ans] }; setColorTile => { setColorTile: PDFileFormat.SetColorTile; ReadBlock[handle, @setColorTile, SIZE[PDFileFormat.SetColorTile]]; handle.colorTileLoadAddress _ setColorTile.addr; SELECT controlCommand.rest FROM 0 => handle.colorType _ opaqueTile; 1 => handle.colorType _ transparentTile; ENDCASE => { handle.colorType _ opaqueTile; RaisePDWarning[handle, unknownColorTileFlag, SIZE[PDFileFormat.Command]]; }; ans.whatChanged _ colorChange; RETURN [ans]; }; endBand => { handle.priority _ LAST[INT]; ans.whatChanged _ priorityChange; RETURN [ans]; }; endDocument => { ans.whatChanged _ documentEnd; handle.status _ transmissionComplete; WaitForClientToFindOutWeAreDone[]; RETURN [ans]; }; storeLoad => { storeLoad: PDFileFormat.StoreLoad; loadWordsAllocated: LONG CARDINAL _ private.loadWordsAllocated; ReadBlock[handle, @storeLoad, SIZE[PDFileFormat.StoreLoad]]; IF storeLoad.firstAddress > loadWordsAllocated OR storeLoad.firstAddress + storeLoad.wordCount > loadWordsAllocated OR storeLoad.firstAddress + storeLoad.wordCount > handle.herald.maxLoadWord THEN {RaisePDError[handle, loadOutOfBounds, SIZE[PDFileFormat.Command]+SIZE[PDFileFormat.StoreLoad]]; ERROR}; ReadBlock[handle, private.loadPointer+storeLoad.firstAddress, storeLoad.wordCount]; ans.whatChanged _ loadChange; ans.loadChangeStart _ storeLoad.firstAddress; ans.loadChangeLength _ storeLoad.wordCount; handle.loadWords _ MAX[handle.loadWords, ans.loadChangeStart + ans.loadChangeLength]; handle.colorTileLoadAddress _ -1; RETURN [ans]; }; deviceCommand => { deviceCommand: CommandBuffer.deviceCommand; wordCount: CARDINAL; block: BlockDescription; ReadBlock[handle, @wordCount, SIZE[CARDINAL]]; block _ ReadLocate[handle, wordCount]; IF block.words < wordCount THEN RaisePDError[handle, unexpectedEOF, block.words+SIZE[CARDINAL]]; deviceCommand.deviceCommandPointer _ block.pointer; deviceCommand.deviceCommandWords _ block.words; RETURN [deviceCommand]; }; ENDCASE => {RaisePDError[handle, unrecognisedControlCommand, SIZE[PDFileFormat.Command]]; ERROR}; }; ENDCASE => {RaisePDError[handle, unrecognisedCommandType, SIZE[PDFileFormat.Command]]; ERROR}; }; Error: PUBLIC ERROR [handle: Handle, code: PDInterpBasic.PDErrorCode, wordIndex, wordCount: INT] = CODE; Warning: PUBLIC SIGNAL [handle: Handle, code: PDInterpBasic.PDWarningCode, wordIndex, wordCount: INT] = CODE; RaisePDError: PROC [handle: Handle, code: PDInterpBasic.PDErrorCode, words: INT] = { handle.status _ code; ERROR Error[handle, code, handle.index-words, words]; }; RaisePDWarning: PROC [handle: Handle, code: PDInterpBasic.PDWarningCode, words: INT] = { handle.warningCount _ handle.warningCount + 1; handle.status _ code; SIGNAL Warning[handle, code, handle.index-words, words]; }; END. PDInterpReaderImpl.mesa Michael Plass, December 2, 1983 5:11 pm Last Edited by: Pier, November 22, 1983 2:45 pm Last Edited by: Lamming, December 9, 1983 1:27 pm IF dataBlock.wordCount=0 THEN { -- used to time interpretter OthelloDefs.WriteLine["Cranking up interp"]; NOTIFY NewDataAvailable; Process.Pause[Process.MsecToTicks[1000]]; }; The buffer variables satisfy the invariants (bufferWordPointer + i)^ = InputFileWord[handle.index+i], i IN [0..bufferWordCount) handle.index+bufferWordCount <= inputFileSizeInWords bufferWordPointer-bufferOriginPointer >= 0 bufferWordCount + (bufferWordPointer-bufferOriginPointer) <= bufferWordsAllocated where InputFileWord[k] stands for the kth word of the input file. The buffer storage may get re-used with the next ReadLocate or ReadBlock; Κ˜Jšœ™J™'J™/J™1unitšΟk ˜ Jšœ²˜²—šΟnœ˜Jšœc˜jJšœ˜!Jšœœœ˜—˜Jšœ œ˜+šœ œœ˜'J˜—J˜—Jšœœ˜Jšœ  œ˜Jšœ œ˜ Jšœ œ˜J˜šž œœœœ!˜AJšœ#˜*Jšœœœ˜šœœœ˜Jšœ œœ˜,Jšœœœœ˜6Jšœœ ˜(Jšœ'˜'Jšœ,˜,Jšœœœ;˜ašœœ˜ Jšœ˜Jšœ œœœ˜+Jšœ˜Jšœ ˜ Jšœ ˜ Jšœ˜Jšœ˜Jšœ ˜ Jšœ ˜ Jšœ˜Jšœ ˜ Jšœ˜Jšœ˜J˜Jšœ˜Jšœ˜—Jšœœœ%˜\Jšœ˜ šœ%œ˜-Jšœ9˜9Jšœœ ˜Jšœœ˜Jšœ;˜AJšœ˜—Jšœœ˜0Jšœ+˜+šœ˜šœ˜ Jšœœ ˜Jšœœ˜Jšœ˜—Jšœ˜J˜—Jšœ ˜JšœU˜[Jšœ˜—šœ˜Jšœ)˜)šžœœœœ˜&Jšœœ9˜KJšœœ.˜EJšœœ˜2Jšœ˜—Jšœ œ1˜Ašœ#œ˜+šœ˜Jšœ˜Jšœ˜Jšœ˜Jšœ˜—Jšœ˜—šœ>˜EJšœ˜Jšœ˜—Jšœ€˜€JšœH˜HJšœ˜šœ<™˜@Jšœ9˜=Jšœ ˜"šœ*œ˜2Jšœ8˜8Jšœ˜—Jšœ˜J˜—šžœœœœ˜=Jšœ"˜"Jšœ˜šžœœ œ˜+Jšœ'œ"˜MJšœ˜—šœœœœ˜%Jšœ˜Jšœ/˜/Jšœ5˜5Jšœ*˜*Jšœ˜Jšœ˜Jšœ˜šœ)œ˜1Jšœ˜Jšœ˜Jšœ˜Jšœ˜—Jšœ˜ Jšœ˜—Jšœœ˜8šœ œ˜šžœ#˜1šœœ˜!Jšœ(œ˜DJš˜Jšœ˜—šœ˜šžœ˜Jšœ˜Jšœ,˜,J˜$Jšœ œœœ˜2Jšœœ˜ Jšœ#œ˜FJšœ3˜3Jšœ1˜1Jšœ!˜!Jš œœœ.œœ˜—Jšœ/˜/JšœT˜TJšœœ6œœ˜ˆJšœXœœ˜–Jšœšœe˜ƒJšœ˜ Jšœ˜—šžœ˜Jšœ ˜ Jšœ.˜.J˜$Jšœ œœœ˜0Jšœœœœ˜&Jšœœ˜Jšœ œ˜Jšœœ˜Jšœœ˜Jšœ$œ ˜HJšœ3˜3Jšœ2˜2Jšœ!˜!Jš œœœ+œœ ˜•Jšœ0˜0Jšœ;œ˜Wšœ˜Jšœœ.œœ ˜nJšœœ˜,Jšœ œ ˜Jšœ œ˜#Jšœ˜—Jšœ˜JšœSœœ ˜’Jšœ ˜ Jšœ.˜.Jšœ˜Jšœ˜Jšœ˜ Jšœ˜—šž œ˜Jšœ!˜!Jšœ*˜*Jšœ"œ˜DJšœbœœ˜ŸJšœ˜Jšœ˜Jšœ ˜ Jšœ ˜ Jšœ˜ Jšœ˜—šž œ˜Jšœ!˜!Jšœ*˜*Jšœ œ˜Jšœ"œ˜DJšœœ-˜7Jšœœœ,œ4˜sJšœJœœ˜‡Jšœ˜Jšœ˜Jšœ&˜&Jšœ ˜ Jšœ ˜ Jšœ(˜(Jšœ˜ Jšœ˜—šž œ˜Jšœœ ˜ Jšœ(˜(Jšœ ˜ Jšœœ˜Jšœ œ˜Jšœœ˜Jšœœœœ˜ Jšœœœœ˜!Jšœœœœ˜&Jšœ!œ˜BJšœœ˜:Jšœ ˜ šœ˜šœœ-œ˜GJšœ,œ˜DJš œœ-œ'œœ˜«Jšœ˜—Jšœœ˜(Jšœœœœ˜LJšœ œ ˜Jšœ˜Jšœ œ˜#Jšœ˜—Jšœ˜Jšœ˜šœœ˜Jšœœ˜Jšœ&œœ˜cJšœ ˜ Jšœ˜—šœ˜JšœΟcœ!œ˜LJšœDœœ˜‚Jšœ˜—Jšœ˜Jšœ˜J˜Jšœ˜Jšœ˜Jšœ˜ Jšœ˜—šž œ˜Jšœ˜Jšœ&˜&Jšœ"˜"Jšœ œ˜@Jšœœ˜Jšœ5œ˜:šœ˜ Jšœ(œ˜DJš˜Jšœ˜——šœ˜šž œ˜Jšœ$˜$Jšœœ˜>šœœ˜Jšœ$œœ˜^Jšœ˜—Jšœœg˜ošœœFœ˜SJšœ4œœ˜nJšœ˜—šœœ)˜KJšœ$œœ˜^—Jšœ˜Jšœ˜Jšœ˜J˜Jšœ˜Jšœ8˜8Jšœœœ!˜=Jšœœ2˜IJ˜"Jšœ˜ Jšœ˜—šž œ˜Jšœ#˜#Jšœ!˜!Jšœ œ˜=Jšœ(˜(Jšœ˜Jšœ˜Jšœ!˜!Jšœ˜ Jšœ˜—šž œ˜J˜Jšœ˜Jšœ˜ Jšœ˜—šž œ˜J˜Jšœ˜Jšœ˜ Jšœ˜—šž œ˜Jšœ(˜(Jšœ!œ˜BJšœ0˜0šœ˜J˜#Jšœ(˜(šœ˜ J˜Jšœ-œ˜IJšœ˜——Jšœ˜Jšœ˜ Jšœ˜—šžœ˜ Jšœœœ˜Jšœ!˜!Jšœ˜ Jšœ˜—šž œ˜Jšœ˜J˜%J˜"Jšœ˜ Jšœ˜—šž œ˜Jšœ"˜"Jšœœœ˜?Jšœœ˜