--File SIFControl.mesa
--
Device independent Output module for CIF 2.0 Parser
-- Written by Martin Newell, August 1980.
--
Last updated: June 5, 1981 2:55 PM

DIRECTORY

CIFOutputDefs: FROM "CIFOutputDefs" USING [OutputSymbolName,
OutputNamedPoint],
IcarusInputDefs: FROM "IcarusInputDefs",
IntDefs: FROM "IntDefs" USING [IDefineStart, IDefineEnd, IComment, ILayer,
IBox, ICallSymbol, IEnd],
IODefs: FROM "IODefs" USING [SP, WriteChar, WriteDecimal],
ParserErrorDefs: FROM "ParserErrorDefs" USING [Report],
ParserTypeDefs: FROM "ParserTypeDefs" USING [TList, AllocateTList, AppendTList, FreeTList],
SifGutsDefs: FROM "SifGutsDefs" USING [Point, IcToCif],
SifOutputDefs: FROM "SifOutputDefs";

SIFControl: PROGRAM
IMPORTS CIFOutputDefs, IntDefs, IODefs, ParserErrorDefs, ParserTypeDefs, SifGutsDefs
EXPORTS IcarusInputDefs, SifOutputDefs =

BEGIN OPEN CIFOutputDefs, IntDefs, IODefs, ParserErrorDefs, ParserTypeDefs, SifGutsDefs;

ParseIcarus: PUBLIC PROCEDURE [fileName: STRING, mul,div: LONG INTEGER, StartDefNumber: INTEGER] RETURNS [ok: BOOLEAN, nDefs: INTEGER] =
BEGIN
error: BOOLEAN;
NComs ← 0;
NComs100 ← 100;
[error,nDefs] ← IcToCif[fileName, mul, div, StartDefNumber];
RETURN[~error, nDefs];
END;

PutDefStart: PUBLIC PROCEDURE [num: INTEGER, xScale,yScale:LONG INTEGER, name: STRING] =
BEGIN
Count[];
IDefineStart[num, xScale,yScale];
IF name.length#0 THEN OutputSymbolName[name];
END;

PutDefFinish: PUBLIC PROCEDURE =
BEGIN
Count[];
IDefineEnd[];
END;

PutComment: PUBLIC PROCEDURE[s: STRING] =
BEGIN
Count[];
IComment[s];
END;

PutLayer: PUBLIC PROCEDURE[l: STRING] =
BEGIN
Count[];
ILayer[l];
END;

PutBox: PUBLIC PROCEDURE [len,wid: LONG INTEGER, center: Point, angle: Point] =
BEGIN
Count[];
IBox[len, wid, [center.x,center.y], angle.x, angle.y];
END;

PutCall: PUBLIC PROCEDURE [def: INTEGER, mirx,miry: BOOLEAN, rot:Point, trans:Point] =
BEGIN
list: ParserTypeDefs.TList ← AllocateTList[];
Count[];
IF mirx THEN AppendTList[list, [Mirror[X]]];
IF miry THEN AppendTList[list, [Mirror[Y]]];

IF rot.x<0 OR rot.y#0 THEN AppendTList[list, [Rotate[rot.x,rot.y]]];

IF trans.x#0 OR trans.y#0 THEN AppendTList[list, [Translate[trans.x,trans.y]]];

ICallSymbol[def, list];
FreeTList[list];
END;

PutName: PUBLIC PROCEDURE [x,y: LONG INTEGER, s: STRING] =
BEGIN
Count[];
OutputNamedPoint[s, x,y];
END;

PutEnd: PUBLIC PROCEDURE =
BEGIN
Count[];
IEnd[];
END;

PutError: PUBLIC PROCEDURE[msg: STRING] =
BEGIN
Report[msg, Advisory];
END;

Count: PROCEDURE =
BEGIN
NComs100 ← NComs100 - 1;
IF NComs100=0 THEN
{NComs ← NComs+100;
NComs100 ← 100;
WriteDecimal[NComs]; WriteChar[SP];
};
END;
NComs: INTEGER;
NComs100: INTEGER;


END.