File: BackConn212.mesa
Christophe Cuenod June 25, 1987 4:50:19 pm PDT

Enables to generate easily 21 pins Burndy connector parts for EXPERT.
Requires 2 input files: Filename.left, Filename.right and generates a file Filename.part (to be transformed by the NewPart program).
Each file has to be 106 lines long exactly. Each line has to content either NC or PinName PinType (I, O, D, ...) and SwapNumber. (i.e. K5 D 5)
The pads stacks are:
- all the pins  stack 33
DIRECTORY
Commander USING [CommandProc, Register],
Convert USING [Error, IntFromRope],
Rope USING [ROPE, Equal, Cat],
FS USING [Error, StreamOpen],
IO USING [ card, Close, EndOfStream, GetTokenRope, int, Put, PutF, PutRope, RIS, rope, STREAM];
Backconn212: CEDAR PROGRAM
IMPORTS IO, Commander, Convert, Rope, FS =
BEGIN
ROPE: TYPE = Rope.ROPE;
LineRep: TYPE = RECORD[
name: ROPE,
type: INTEGER,
swap: INTEGER
];
Line: TYPE = REF LineRep;
ConnRep: TYPE = ARRAY[0..212) OF Line;
Conn: TYPE = REF ConnRep;
BadFile: SIGNAL [];
GetLine: PROC [in: IO.STREAM, display: IO.STREAM, i: CARD, file: ROPE] RETURNS [line: Line] ~ {
temp1, temp2: ROPE;
line ← NEW[LineRep];
line.name ← IO.GetTokenRope[in ! IO.EndOfStream => CONTINUE].token;
IF NOT Rope.Equal[line.name, "NC", FALSE] THEN {
temp1 ← IO.GetTokenRope[in ! IO.EndOfStream => CONTINUE].token;
temp2 ← IO.GetTokenRope[in ! IO.EndOfStream => CONTINUE].token;
IF line.name = NIL OR temp1 = NIL OR temp2 = NIL THEN {
IO.PutF[display, "File %g is too short: line %g is missing or incomplete.\n",
IO.rope[file], IO.card[i+1]];
SIGNAL BadFile[];
};
SELECT TRUE FROM
Rope.Equal[temp1, "I", FALSE]  => {
line.type ← 1;
};
Rope.Equal[temp1, "O", FALSE] => {
line.type ← 2;
};
Rope.Equal[temp1, "D", FALSE] => {
line.type ← 3;
};
ENDCASE => {
IO.PutF[display, "In file %g the second word on line %g has to be I, O or D instead of %g\n", IO.rope[file], IO.card[i+1], IO.rope[temp1]];
SIGNAL BadFile[];
};
line.swap ← Convert.IntFromRope[temp2 ! Convert.Error =>{
IO.PutF[display, "In file %g the third word on line %g has to be numeric instead of %g\n", IO.rope[file], IO.card[i+1], IO.rope[temp2]];
SIGNAL BadFile[];
}];
};
};
InsertPin: PROC [i: INT, conn: Conn, out: IO.STREAM] ~ {
x, y: INT;
SELECT i FROM
IN [0..53) => {
x ← i*25;
y ← ((i MOD 2)* 235);
};
IN [53..106) => {
x ← (i-53)*25;
y ← -307-(((i+1) MOD 2)* 235);
};
IN [106..159) => {
x ← (i-106)*25+1600;
y ← ((i MOD 2)* 235);
};
IN [159..212) => {
x ← (i-159)*25+1600;
y ← -307-(((i+1) MOD 2)* 235);
};
ENDCASE;
IO.PutF[out, "%g %g ", IO.int[x], IO.int[y]];
IF Rope.Equal[conn[i].name, "NC", FALSE] THEN IO.PutF[out, "NC 1 0 256 0 33\n"]
ELSE {
IO.PutF[out, "%g %g 0 1 %g 33\n", IO.rope[conn[i].name], IO.int[conn[i].swap], IO.int[conn[i].type]];
};
};
Backconn212Proc: Commander.CommandProc = BEGIN
i: CARD;
in: IO.STREAM;
out: IO.STREAM;
fault: BOOLEANFALSE;
stream: IO.STREAMIO.RIS[cmd.commandLine];
conn: Conn ← NEW[ConnRep];
fileName: ROPE;
fileName ← IO.GetTokenRope[stream ! IO.EndOfStream => CONTINUE].token;
Reading Input files:
Top side :
in ← FS.StreamOpen[Rope.Cat[fileName,".left"] ! FS.Error => {
fault ← TRUE;
IO.PutF[cmd.out, "The File %g is missing\n", IO.rope[Rope.Cat[fileName,".left"]]];
CONTINUE;
}];
IF NOT fault THEN {
FOR i IN [0..106) DO
conn[i] ← GetLine[in, cmd.out, i, Rope.Cat[fileName,".left"] ! BadFile => {
fault ← TRUE;
CONTINUE;
}];
IF fault THEN EXIT;
ENDLOOP;
};
Bottom side :
in ← FS.StreamOpen[Rope.Cat[fileName,".right"] ! FS.Error => {
fault ← TRUE;
IO.PutF[cmd.out, "The File %g is missing\n", IO.rope[Rope.Cat[fileName,".right"]]];
CONTINUE;
}];
IF NOT fault THEN {
FOR i IN [0..106) DO
conn[i+106] ← GetLine[in, cmd.out, i, Rope.Cat[fileName,".right"] ! BadFile => {
fault ← TRUE;
CONTINUE;
}];
IF fault THEN EXIT;
ENDLOOP;
};
IF NOT fault THEN {
Writing output file
out ← FS.StreamOpen[Rope.Cat[fileName,".part"],$create];
IO.Put[out, IO.rope[Rope.Cat["4096 2048 -100 -100 1500 1500 700 -100 ",
fileName, " PARC-", fileName, " U\n"]]];
FOR i IN [0..106) DO
InsertPin[i, conn, out];
ENDLOOP;
FOR i IN [0..106) DO
InsertPin[i+106, conn, out];
ENDLOOP;
IO.Close[out];
cmd.out.PutRope[Rope.Cat["File ", fileName,".part Written\n"]];
};
END;
Commander.Register[
key: "Backconn212", proc: Backconn212Proc, doc: "Transform the 2 input files: Filename.left, Filename.right into Filename.part (to be used by the NewPart program)."];
END.