RosemaryVectorImpl.mesa
Copyright © 1985, 1986 by Xerox Corporation. All rights reserved.
Barth, February 2, 1987 3:09:58 pm PST
DIRECTORY FS, IO, Ports, Rope, RosemaryVector;
RosemaryVectorImpl: CEDAR PROGRAM
IMPORTS FS, IO, Ports, Rope
EXPORTS RosemaryVector = BEGIN OPEN RosemaryVector;
OpenVectorFile: PUBLIC PROC [fileName: Rope.ROPE, port: Ports.Port, read: BOOLTRUE] RETURNS [vectorFile: VectorFile] = {
vectorFile ← NEW [VectorFileRec];
vectorFile.port ← port;
vectorFile.stream ← FS.StreamOpen[fileName, IF read THEN $read ELSE $create];
};
CloseVectorFile: PUBLIC PROC [vectorFile: VectorFile] = {
IO.Close[vectorFile.stream];
};
WriteVector: PUBLIC PROC [vectorFile: VectorFile, neverSayExpect: BOOLFALSE] = {
WriteDrive: PROC [d: Ports.Drive] = {
IO.PutRope[vectorFile.stream, Ports.driveNames[IF neverSayExpect AND d=expect THEN none ELSE d]];
IO.PutRope[vectorFile.stream, " "];
};
WriteLevel: PROC [l: Ports.Level] = {
IO.PutRope[vectorFile.stream, Ports.levelNames[l]];
IO.PutRope[vectorFile.stream, " "];
};
WriteBool: PROC [b: BOOL] = {
IO.PutRope[vectorFile.stream, IF b THEN "T " ELSE "F "];
};
WritePort: PROC [p: Ports.Port] = {
IF p.levelType=composite THEN FOR i: NAT IN [0..p.size) DO
WritePort[p[i]];
ENDLOOP
ELSE {
IO.PutRope[vectorFile.stream, Ports.driveTypeNames[p.driveType]];
IO.PutRope[vectorFile.stream, " "];
SELECT p.driveType FROM
aggregate => WriteDrive[p.d];
seperate => FOR i: NAT IN [0..p.ds.size) DO
WriteDrive[p.ds[i]];
ENDLOOP;
ENDCASE => ERROR;
SELECT p.levelType FROM
l => WriteLevel[p.l];
ls => FOR i: NAT IN [0..p.ls.size) DO
WriteLevel[p.ls[i]];
ENDLOOP;
b => WriteBool[p.b];
bs => FOR i: NAT IN [0..p.bs.size) DO
WriteBool[p.bs[i]];
ENDLOOP;
c => IO.PutF[vectorFile.stream, "%g ", IO.card[p.c]];
lc => IO.PutF[vectorFile.stream, "%g ", IO.card[p.lc]];
q => FOR i: NAT IN [0..4) DO
IO.PutF[vectorFile.stream, "%g ", IO.card[p.q[i]]];
ENDLOOP;
ENDCASE => ERROR;
};
};
WritePort[vectorFile.port];
};
ReadVector: PUBLIC PROC [vectorFile: VectorFile] = {
ReadDrive: PROC RETURNS [d: Ports.Drive] = {
name: Rope.ROPEIO.GetID[vectorFile.stream];
d ← Ports.FindDrive[name];
};
ReadLevel: PROC RETURNS [l: Ports.Level] = {
name: Rope.ROPEIO.GetID[vectorFile.stream];
l ← Ports.FindLevel[name];
};
ReadBool: PROC RETURNS [b: BOOL] = {
name: Rope.ROPEIO.GetID[vectorFile.stream];
b ← SELECT TRUE FROM
Rope.Equal[name, "T"] => TRUE,
Rope.Equal[name, "F"] => FALSE,
ENDCASE => ERROR;
};
ReadPort: PROC [p: Ports.Port] = {
IF p.levelType=composite THEN FOR i: NAT IN [0..p.size) DO
ReadPort[p[i]];
ENDLOOP
ELSE {
name: Rope.ROPEIO.GetID[vectorFile.stream];
p.driveType ← Ports.FindDriveType[name];
SELECT p.driveType FROM
aggregate => p.d ← ReadDrive[];
seperate => FOR i: NAT IN [0..p.ds.size) DO
p.ds[i] ← ReadDrive[];
ENDLOOP;
ENDCASE => ERROR;
SELECT p.levelType FROM
l => p.l ← ReadLevel[];
ls => FOR i: NAT IN [0..p.ls.size) DO
p.ls[i] ← ReadLevel[];
ENDLOOP;
b => p.b ← ReadBool[];
bs => FOR i: NAT IN [0..p.bs.size) DO
p.bs[i] ← ReadBool[];
ENDLOOP;
c => p.c ← IO.GetCard[vectorFile.stream];
lc => p.lc ← IO.GetCard[vectorFile.stream];
q => FOR i: NAT IN [0..4) DO
p.q[i] ← IO.GetCard[vectorFile.stream];
ENDLOOP;
ENDCASE => ERROR;
};
};
ReadPort[vectorFile.port];
};
END.