CheckPD.mesa
Copyright (C) 1983, Xerox Corporation. All rights reserved.
Michael Plass, November 8, 1984 3:12:15 pm PST
DIRECTORY PDFileFormat, PDFileReader, Commander, IO, Rope;
CheckPD:
CEDAR PROGRAM
IMPORTS 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 ~
BOOLEAN ←
FALSE;
TypePDCommand: Commander.CommandProc ~ {
stream: IO.STREAM ← IO.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]];
};
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 => {
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[maskSamples.samples.fOrigin + maskSamples.samples.sMin],
IO.int[maskSamples.samples.fOrigin + maskSamples.samples.fMin],
IO.int[maskSamples.samples.sSize],
IO.int[maskSamples.samples.fSize]
];
};
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."];
};
CheckPDCommand: Commander.CommandProc ~ {
stream: IO.STREAM ← IO.RIS[cmd.commandLine];
name: Rope.ROPE ← stream.GetTokenRope[Break].token;
reader: PDFileReader.Handle ← PDFileReader.Open[name];
out: IO.STREAM ← cmd.out;
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];
};
documentEnd => EXIT;
ENDCASE => NULL;
};
ENDCASE => NULL;
ENDLOOP;
PDFileReader.Close[reader];
cmd.out.PutRope[" Done."];
};
Commander.Register["CheckPD", CheckPDCommand, "Check a PD file"];
Commander.Register["TypePD", TypePDCommand, "Type a PD file"];
END.