ExpertPinReadImpl.mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
Christophe Cuenod, May 25, 1989 12:54:37 pm PDT
Reads an Expert .pinlist file and retrieve the pin info
DIRECTORY
FS USING [StreamOpen],
IO USING [Backup, BreakProc, EndOf, GetChar, GetInt, GetLineRope, GetTokenRope, RIS, STREAM],
Rope USING [Equal, ROPE],
ExpertPinRead,
SymTab USING [Create, Fetch, Ref, Store];
ExpertPinReadImpl: CEDAR PROGRAM
IMPORTS FS, IO, Rope, SymTab
EXPORTS ExpertPinRead
~ BEGIN
ROPE: TYPE = Rope.ROPE;
PinTable: TYPE = ExpertPinRead.PinTable;
PinInfoList: TYPE = ExpertPinRead.PinInfoList;
PinInfo: TYPE = ExpertPinRead.PinInfo;
Private procedures
TokenProc1: IO.BreakProc ~ { -- Takes any character different from SP for the name
IF char = ' THEN RETURN [sepr];
RETURN [other];
};
ProcessEachLine: PROC [pinTable: PinTable, line: ROPE] ~ {
c: CHAR;
pinInfoList: PinInfoList;
pinInfo: PinInfo;
in: IO.STREAMIO.RIS[line];
key: ROPEIO.GetTokenRope[in, TokenProc1].token;
[] ← IO.GetTokenRope[in, TokenProc1]; --Skips two token
[] ← IO.GetTokenRope[in, TokenProc1];
pinInfo.refDes ← IO.GetTokenRope[in, TokenProc1].token;
IF Rope.Equal[pinInfo.refDes, "?"] THEN { -- Symbol not yet placed
pinInfo.refDes ← NIL;
[] ← IO.GetTokenRope[in, TokenProc1];
pinInfo.pinNumber ← 0;
}
ELSE {
pinInfo.pinNumber ← IO.GetInt[in];
};
[] ← IO.GetChar[in]; -- Skips one character
c ← IO.GetChar[in];
IO.Backup[in, c];
IF c = ' THEN { -- Tests the presence of a symbol pin mame
pinInfo.symbolPinName ← NIL
}
ELSE {
pinInfo.symbolPinName ← IO.GetTokenRope[in, TokenProc1].token;
};
[] ← IO.GetTokenRope[in, TokenProc1];
pinInfo.pageNumber ← IO.GetInt[in];
Possible to land here if the pin name has a wrong character (ie a space) ...
pinInfoList ← NIL;
IF SymTab.Fetch[pinTable, key].found THEN {
pinInfoList ← NARROW[SymTab.Fetch[pinTable, key].val];
};
pinInfoList ← CONS[pinInfo, pinInfoList];
[] ← SymTab.Store[pinTable, key, pinInfoList];
};
Public Procedures
ReadPinFile: PUBLIC PROC [file: ROPE] RETURNS [pinTable: PinTable] ~ {
line, spareLine: ROPE;
exit: BOOLEANFALSE;
in: IO.STREAMFS.StreamOpen[file];
pinTable ← SymTab.Create[];
Skip the begining of the file and position at the first pin line
WHILE NOT Rope.Equal[IO.GetTokenRope[in].token, "wattage"] DO
ENDLOOP;
WHILE IO.GetLineRope[in] # NIL DO
ENDLOOP;
line ← IO.GetLineRope[in];
WHILE NOT IO.EndOf[in] AND line # NIL DO
spareLine ← IO.GetLineRope[in];
ProcessEachLine[pinTable, line];
line ← spareLine;
ENDLOOP;
};
END.