-- File: DJExtUtils.mesa
-- utility routines used by the disjoint circuit extractor
-- Written by Martin Newell/Dan Fitzpatrick July 1981
-- Last edited: August 25, 1981 4:35 PM

DIRECTORY


DJExtUtilsDefs: FROM "DJExtUtilsDefs",
IODefs: FROM "IODefs" USING [WriteString, WriteLine, WriteChar],
Real: FROM "Real" USING [Fix, WriteReal],
SegmentDefs: FROM "SegmentDefs" USING [Write, Append, OldFileOnly, FileNameError, FileError, NewFile, DestroyFile],
StreamDefs: FROM "StreamDefs" USING [StreamHandle, NewByteStream],
String: FROM "String" USING [AppendLongDecimal];

DJExtUtils: PROGRAM
IMPORTS IODefs, Real, SegmentDefs, StreamDefs, String
EXPORTS DJExtUtilsDefs =
BEGIN
OPEN IODefs, Real, SegmentDefs, StreamDefs, String;

Create
: PUBLIC PROCEDURE [fileName:STRING] RETURNS[StreamHandle] =
BEGIN
out:StreamHandle;
DeleteFile[fileName];
out ← NewByteStream[fileName,Write+Append];
out.reset[out];
RETURN[out];
END;

Close
: PUBLIC PROCEDURE [file: StreamHandle] =
BEGIN
file.destroy[file];
END;

DeleteFile: PUBLIC PROCEDURE [s:STRING] =
BEGIN
ENABLE BEGIN
FileNameError => CONTINUE;
FileError => BEGIN
WriteString[s];
WriteLine[": can’t delete"];
CONTINUE;
END;
END;
DestroyFile[NewFile[s,Write,OldFileOnly]];
END;

Trace: PUBLIC PROCEDURE [str:STRING, n1:LONG UNSPECIFIED, n2:LONG UNSPECIFIED ← 0] =
BEGIN
WriteString[str];
WriteString[": "];
WriteLongDecimal[n1];
IF n2 # 0 THEN {
WriteString[" "];
WriteLongDecimal[n2];
};
WriteLine[""];
END;

Error: PUBLIC PROCEDURE [x,y: REAL, str:STRING] =
BEGIN
WriteCIFUnits[x];
WriteString[" "];
WriteCIFUnits[y];
WriteString[" "];
WriteLine[str];
END;

WriteLongDecimal: PUBLIC PROCEDURE [n:LONG UNSPECIFIED] =
BEGIN
str: STRING ← [50];
AppendLongDecimal[str,n];
WriteString[str];
END;

WriteCIFUnits: PUBLIC PROCEDURE [r:REAL] =
BEGIN
WriteLongDecimal[Fix[r]];
END;

WriteFloat: PUBLIC PROCEDURE [r:REAL] =
BEGIN
WriteReal[WriteChar,r];
END;

END.