CIFPrintImpl.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Christian Le Cocq, September 10, 1987 3:06:41 pm PDT
Pretty print of CIF files, but above all test of the CIF Parser.
DIRECTORY
CIFParser,
FS,
IO,
Rope;
CIFPrintImpl: CEDAR PROGRAM
IMPORTS CIFParser, FS, IO, Rope
EXPORTS Export
~ BEGIN
Print: PUBLIC PROC [cifName: Rope.ROPE] RETURNS [errMsg: Rope.ROPE] ~ {
Description of the procedure.
cifFile, printFile: IO.STREAM;
printReg: CIFParser.Registration;
cifFile ← FS.StreamOpen[Rope.Concat[cifName, ".cif"], read !
FS.Error => IF error.group#bug THEN {
errMsg ← error.explanation;
GOTO Exit;  
}
];
printFile ← FS.StreamOpen[Rope.Concat[cifName, ".cifPrint"], create !
FS.Error => IF error.group#bug THEN {
errMsg ← error.explanation;
GOTO Exit;  
}
];
printReg ← NEW[CIFParser.RegistrationRec ← [
defDelete: DefDelete,
defStart: DefStart,
defFinish: DefFinish,
polygon: Polygon,
box: Box,
roundFlash: RoundFlash,
wire: Wire,
layer: Layer,
call: Call,
userExtension: UserExtension,
comment: Comment,
data: printFile
]];
CIFParser.Parse[cifFile, printReg ! CIFParser.Error => errMsg ← IO.PutFR["%g @ %g\n", IO.rope[msg], IO.int[IO.GetIndex[cifFile]]]];
IO.PutF[printFile, "E ;\n"];
IO.Close[printFile];
EXITS Exit => {};
};
DefDelete: PROC[i: CARD, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "Define Delete #%d;\n", IO.card[i]];
};
DefStart: PROC[i, a, b: CARD, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "Define Start #%d with ratio %d/%d;\n", IO.card[i], IO.card[a], IO.card[b]];
};
DefFinish: PROC[data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "Define Finish;\n"];
};
Polygon: PROC[p: CIFParser.Path, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "Polygon "];
PrintPath[printFile, p];
IO.PutF[printFile, ";\n"];
};
Box: PROC[l, w: CARD, c, d: CIFParser.Point, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "Box length: %d, width: %w, center: [%d, %d]",
IO.card[l], IO.card[w], IO.int[c.x], IO.int[c.y]];
IF d#[1, 0] THEN IO.PutF[printFile, ", direction: [%d, %d]", IO.int[d.x], IO.int[d.y]];
IO.PutF[printFile, ";\n"]
};
RoundFlash: PROC[d: CARD, c: CIFParser.Point, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "Roundflash of diameter %d at [%d, %d];\n", IO.card[d], IO.int[c.x], IO.int[c.y]]
};
Wire: PROC[w: CARD, p: CIFParser.Path, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "Wire of width %d : ", IO.card[w]];
PrintPath[printFile, p];
IO.PutF[printFile, ";\n"];
};
Layer: PROC[n: Rope.ROPE, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "Layer name: %g;\n", IO.rope[n]]
};
Call: PROC[s: CARD, t: CIFParser.Transformation, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "Call symbol #%d with ", IO.card[s]];
PrintTransformation[printFile, t];
IO.PutF[printFile, ";\n"];
};
UserExtension: PROC[u: CARD, t: Rope.ROPE, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "%d %g;\n", IO.card[u], IO.rope[t]]
};
Comment: PROC[c: Rope.ROPE, data: REF ANY] ~ {
printFile: IO.STREAM ~ NARROW[data];
IO.PutF[printFile, "%g;\n", IO.rope[c]]
};
PrintPath: PROC [printFile: IO.STREAM, p: CIFParser.Path] ~ {
IO.PutF[printFile, "[%d, %d]", IO.int[p.first.x], IO.int[p.first.y]];
p ← p.rest;
UNTIL p=NIL DO
IO.PutF[printFile, ", [%d, %d]", IO.int[p.first.x], IO.int[p.first.y]];
p ← p.rest;
ENDLOOP;
};
PrintTransformation: PROC [printFile: IO.STREAM, t: CIFParser.Transformation] ~ {
UNTIL t=NIL DO
SELECT t.first.t FROM
translation => IO.PutF[printFile, "Translation of [%d, %d]", IO.int[t.first.p.x], IO.int[t.first.p.y]];
rotation  => IO.PutF[printFile, "Rotation to [%d, %d]", IO.int[t.first.p.x], IO.int[t.first.p.y]];
xSym  => IO.PutF[printFile, "Mirror along X"];
ySym  => IO.PutF[printFile, "Mirror along Y"];
ENDCASE => ERROR;
t ← t.rest;
ENDLOOP;
};
END.