CheckPDImpl.mesa
Copyright Ó 1983, 1986, 1987, Xerox Corporation. All rights reserved.
Michael Plass, February 6, 1987 7:59:27 pm PST
DIRECTORY ImagerSample, PDFileFormat, PDFileReader, Commander, IO, Rope, SF;
CheckPDImpl: CEDAR PROGRAM
IMPORTS ImagerSample, PDFileReader, Commander, IO, Rope
~ BEGIN
Break: PROC [char: CHAR] RETURNS [IO.CharClass] = {
IF char = '← OR char = '; THEN RETURN [break];
IF char = ' OR char = '  OR char = ', OR char = '\n THEN RETURN [sepr];
RETURN [other];
};
BitTable: TYPE ~ REF BitTableRep;
BitTableRep: TYPE ~ ARRAY [0..10000) OF PACKED ARRAY [0..16) OF InitFalseBoolean;
InitFalseBoolean: TYPE ~ BOOLEANFALSE;
TypePDCommand: Commander.CommandProc ~ {
stream: IO.STREAMIO.RIS[cmd.commandLine];
name: Rope.ROPE ← stream.GetTokenRope[Break].token;
reader: PDFileReader.Handle ← PDFileReader.Open[name];
out: IO.STREAM ← cmd.out;
bitTable: BitTable ← NEW[BitTableRep];
AlreadyPrinted: PROC [loadAddress: INT] RETURNS [BOOLEAN] ~ {
IF loadAddress < 0 THEN RETURN [TRUE]
ELSE {
address: LONG CARDINAL ← loadAddress;
IF bitTable[address/16][address MOD 16] THEN RETURN [TRUE]
ELSE {bitTable[address/16][address MOD 16] ← TRUE; RETURN [FALSE]};
};
};
quiet: BOOLEAN ← Rope.Find[cmd.commandLine, "QUIET"] >= 0;
out.Put[IO.refAny[NEW[PDFileFormat.Herald ← reader.herald]]];
out.PutChar['\n];
DO
ref: REF ← PDFileReader.Get[reader];
WITH ref SELECT FROM
stateChange: PDFileReader.StateChange => {
SELECT stateChange.whatChanged FROM
imageStart => {
out.PutRope["StartImage "];
out.Put[IO.refAny[NEW[PDFileFormat.StartImage ← reader.image]]];
out.PutChar['\n];
};
imageEnd => out.PutRope["EndImage\n"];
priorityChange => out.PutF["Priority %g\n", IO.int[reader.priority]];
colorChange => {
out.PutF["Color Change %g addr %g", IO.refAny[NEW[PDFileReader.ColorType ← reader.colorType]], IO.int[reader.colorTileLoadAddress]];
IF quiet OR reader.colorTileLoadAddress < 0 OR AlreadyPrinted[reader.colorTileLoadAddress] THEN NULL
ELSE {
sampleMap: ImagerSample.SampleMap;
phase: CARDINAL;
min, size: SF.Vec;
[sampleMap, phase] ← PDFileReader.ColorTileFromLoad[reader, reader.colorTileLoadAddress];
min ← ImagerSample.GetBox[sampleMap].min;
size ← ImagerSample.GetSize[sampleMap];
out.PutF[" [sOrigin: %g, fOrigin: %g, sSize: %g, fSize: %g, phase: %g]\n",
IO.int[min.s], IO.int[min.f], IO.int[size.s], IO.int[size.f], IO.int[phase]];
};
};
bandChange => out.PutRope["New Band\n"];
loadChange => out.PutF["Load %g(%g)\n", IO.int[stateChange.loadChangeStart], IO.int[stateChange.loadChangeLength]];
documentEnd => EXIT;
ENDCASE => ERROR;
};
maskSamples: PDFileReader.MaskSamples => {
min: SF.Vec ~ ImagerSample.GetBox[maskSamples.samples].min;
size: SF.Vec ~ ImagerSample.GetSize[maskSamples.samples];
out.PutRope[" MaskSamples"];
IF maskSamples.loadAddress # -1 THEN {
out.PutF["Ref %g", IO.int[maskSamples.loadAddress]];
};
out.PutF[" [%g, %g, %g, %g]\n",
IO.int[min.s], IO.int[min.f], IO.int[size.s], IO.int[size.f]];
};
maskRunGroup: PDFileReader.MaskRunGroup => TRUSTED {
p: LONG POINTER TO PDFileFormat.Run ← maskRunGroup.pointer;
out.PutRope[" MaskRunGroup"];
IF maskRunGroup.loadAddress # -1 THEN {
out.PutF["Ref %g", IO.int[maskRunGroup.loadAddress]];
};
out.PutF[" [%g, %g, %g, %g] %g runs:\n",
IO.int[maskRunGroup.sMin],
IO.int[maskRunGroup.fMin],
IO.int[maskRunGroup.sSize],
IO.int[maskRunGroup.fSize],
IO.int[maskRunGroup.runCount]
];
IF quiet OR AlreadyPrinted[maskRunGroup.loadAddress] THEN NULL
ELSE {
FOR i: INT IN [0..maskRunGroup.runCount) DO
out.PutF[" %g(%g)", IO.int[p.fMin], IO.int[p.fSize]];
IF p.lastRun THEN out.PutChar['\n];
p ← p + SIZE[PDFileFormat.Run];
ENDLOOP;
};
};
ENDCASE => {
out.PutRope[" "];
out.Put[IO.refAny[ref]];
out.PutChar['\n];
};
ENDLOOP;
PDFileReader.Close[reader];
cmd.out.PutRope[" Done.\n"];
};
StatsRep: TYPE ~ RECORD [
priorityChange: INT ← 0,
colorChange: INT ← 0,
bandChange: INT ← 0,
loadChange: INT ← 0,
maskRectangle: INT ← 0,
maskTrapezoid: INT ← 0,
maskRunGroup: INT ← 0,
maskRunGroupRef: INT ← 0,
maskSamples: INT ← 0,
maskSamplesRef: INT ← 0,
colorSamples: INT ← 0,
deviceCommand: INT ← 0
];
CheckPDCommand: Commander.CommandProc ~ {
stream: IO.STREAMIO.RIS[cmd.commandLine];
name: Rope.ROPE ← stream.GetTokenRope[Break].token;
reader: PDFileReader.Handle ← PDFileReader.Open[name];
out: IO.STREAM ← cmd.out;
stats: REF StatsRep ← NEW[StatsRep ← []];
out.Put[IO.refAny[NEW[PDFileFormat.Herald ← reader.herald]]];
out.PutChar['\n];
DO
ref: REF ← PDFileReader.Get[handle: reader, scanning: TRUE];
WITH ref SELECT FROM
stateChange: PDFileReader.StateChange => {
SELECT stateChange.whatChanged FROM
imageStart => {
out.PutRope["StartImage "];
out.Put[IO.refAny[NEW[PDFileFormat.StartImage ← reader.image]]];
out.PutChar['\n];
stats^ ← [];
};
documentEnd => EXIT;
imageEnd => {
out.PutRope["EndImage "];
out.Put[IO.refAny[stats]];
out.PutRope["\n\n"];
};
priorityChange => {
stats.priorityChange ← stats.priorityChange + 1;
};
colorChange => {
stats.colorChange ← stats.colorChange + 1;
};
bandChange => {
stats.bandChange ← stats.bandChange + 1;
};
loadChange => {
stats.loadChange ← stats.loadChange + 1;
};
ENDCASE => NULL;
};
maskRectangle: PDFileReader.MaskRectangle => {
stats.maskRectangle ← stats.maskRectangle + 1;
};
maskTrapezoid: PDFileReader.MaskTrapezoid => {
stats.maskTrapezoid ← stats.maskTrapezoid + 1;
};
maskRunGroup: PDFileReader.MaskRunGroup => {
IF maskRunGroup.loadAddress >= 0
THEN stats.maskRunGroupRef ← stats.maskRunGroupRef + 1
ELSE stats.maskRunGroup ← stats.maskRunGroup + 1
};
maskSamples: PDFileReader.MaskSamples => {
IF maskSamples.loadAddress >= 0
THEN stats.maskSamplesRef ← stats.maskSamplesRef + 1
ELSE stats.maskSamples ← stats.maskSamples + 1
};
colorSamples: PDFileReader.ColorSamples => {
stats.colorSamples ← stats.colorSamples + 1;
};
deviceCommand: PDFileReader.DeviceCommand => {
stats.deviceCommand ← stats.deviceCommand + 1;
};
ENDCASE => NULL;
ENDLOOP;
PDFileReader.Close[reader];
cmd.out.PutRope[" Done.\n"];
};
Commander.Register["CheckPD", CheckPDCommand, "Check a PD file"];
Commander.Register["TypePD", TypePDCommand, "Type a PD file"];
END.