ReadCifImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
by Jim Gasbarro March 12, 1985 12:38:00 pm PST
Ripped off from: MPCControl.Mesa
Last Edited by: Gasbarro, January 16, 1987 3:29:21 pm PST
McCreight, April 14, 1986 3:29:33 pm PST
DIRECTORY
CD, CDIO, CDSequencer, CDMenus, Commander, CommandTool, IntDefs, IO, IODefs, LayerFileDefs, MPCDefs, MPCParserDefs, OutputDefs, ParserDefs, ParserErrorDefs, ParserInputDefs, ReadCif, Rope, TerminalIO;
ReadCifImpl:
CEDAR
PROGRAM
IMPORTS
CDIO, CDSequencer, CDMenus, Commander, CommandTool, IntDefs, IO, IODefs, OutputDefs, ParserDefs, ParserErrorDefs, ParserInputDefs, ReadCif, Rope, TerminalIO
BEGIN
designName: PUBLIC Rope.ROPE;
cifUnitsPerLambda:
PUBLIC
CARDINAL;
ReadCifCDMenu:
PROC [comm: CDSequencer.Command] ~ {
fname: Rope.ROPE;
TerminalIO.WriteRope["Cif file name?\n"];
fname ← TerminalIO.RequestRope[">> "];
ReadFile[fname, comm.design];
};
ReadCifCmdTool: Commander.CommandProc = {
ENABLE TerminalIO.UserAbort => {GOTO abort};
argv: CommandTool.ArgumentVector ← CommandTool.Parse[cmd: cmd
! CommandTool.Failed => {msg ← errorMsg; GO TO failed}];
fname: Rope.ROPE;
FOR i:
NAT
IN [1..argv.argc)
DO
fname ← argv[i];
IF Rope.Length[fname] = 0 THEN LOOP ELSE EXIT;
ENDLOOP;
ReadFile[fname];
EXITS
failed => {result ← $Failure};
abort => {result ← $Failure; msg ← "aborted"};
ReadFile:
PROC [fname: Rope.
ROPE, into:
CD.Design ←
NIL] = {
ENABLE TerminalIO.UserAbort => {GOTO abort};
ok: BOOLEAN ← TRUE;
aborted: BOOLEAN ← FALSE;
errorSummary: ARRAY ParserErrorDefs.ErrorType OF CARDINAL ← ALL[0];
fname ← CDIO.MakeName[base: fname, ext: "cif", wDir: NIL, modifier: NIL];
IF ~OutputDefs.FinishOutput[] THEN GO TO failed; --make sure we cleaned up
IF ~ParserDefs.InitParser[] OR ~ParserInputDefs.InFromFile[fname] THEN GO TO failed;
IF ~IntDefs.InitInterpreter[] THEN GO TO failed;
ReadCif.design ← into;
ReadCif.designName ← fname;
TerminalIO.WriteRope["How many CIF units per lambda? (1 CIF unit = 0.01 microns)\n"];
ReadCif.cifUnitsPerLambda ← TerminalIO.RequestInt[">> "];
Main loop to convert CIF file
BEGIN
ENABLE
ParserErrorDefs.ParserAbort =>
BEGIN aborted ← TRUE; IODefs.WriteLine["---Parser aborted---"]; CONTINUE; END;
nStatements: INT ← 0;
DO
SELECT ParserDefs.ParseStatement[]
FROM
End => BEGIN nStatements ← nStatements + 1; EXIT; END;
SemanticError, SyntaxError =>
IF ParserInputDefs.EndOfFile[] THEN aborted ← TRUE;
ENDCASE;
nStatements ← nStatements + 1;
IF nStatements
MOD 100 = 0
THEN
IODefs.PostIt[IO.PutFR["CIF File: %g, Statement: %g...", IO.rope[fname], IO.int[nStatements]]];
IF ParserInputDefs.EndOfFile[]
THEN
BEGIN
IODefs.WriteLine[
"Unexpected end of input file, Probably missing End command"];
aborted ← TRUE;
END;
ENDLOOP;
END; --End of Enable clause
errorSummary ← ParserErrorDefs.ErrorSummary[];
[] ← ParserDefs.FinishParser[];
ok ← ~aborted
AND
(errorSummary[Fatal] + errorSummary[FatalSyntax] + errorSummary[
FatalSemantic] + errorSummary[FatalInternal]) = 0;
IF ok THEN IntDefs.Instantiate[];
[] ← IntDefs.FinishInterpreter[];
[] ← OutputDefs.FinishOutput[];
EXITS
failed => {};
abort => {};
};
doc: Rope.ROPE = "Chipndale command to read Cif format design files";
Commander.Register[key: "///Commands/ReadCif", proc: ReadCifCmdTool, doc: doc];
CDSequencer.ImplementCommand[key: $ReadCif, proc: ReadCifCDMenu, queue: doQueue];
CDMenus.CreateEntry[menu: $ProgramMenu, entry: "ReadCif", key: $ReadCif];
END.