SpiceCDCmds.mesa
Copyright Ó 1987, 1988 by Xerox Corporation. All rights reserved.
Christian Le Cocq April 4, 1988 4:25:27 pm PDT
LeCocq, July 23, 1987 2:48:49 pm PDT
DIRECTORY
CedarProcess,
CD,
CDCells,
CDOps,
CDSequencer,
CDSequencerExtras,
Core,
CoreOps,
FS,
IO,
Rope,
Rsh,
SinixOps,
Sisyph,
TerminalIO,
SpiceOps;
SpiceCDCmds: CEDAR MONITOR
IMPORTS CedarProcess, CDCells, CDOps, CDSequencerExtras, CoreOps, IO, FS, Rope, Rsh, SinixOps, Sisyph, SpiceOps, TerminalIO
~ BEGIN
ROPE: TYPE = Rope.ROPE;
stop: BOOLFALSE;
cmd: ROPE ← "/usr/datools/spice ";
host: ROPE ← "tregonsee";
SIGTERM: CHAR = VAL[15]; -- Unix signal to terminate a process.
debug: BOOLEANFALSE;
Command Procs
ExtractSelectedObjAndSpiceIt: PROC [comm: CDSequencer.Command] = {
msg: Rope.ROPE;
selected: CD.Instance;
multiple: BOOL;
stdStr, errStr: IO.STREAM;
cellType: Core.CellType;
cellName: Rope.ROPE;
[selected, multiple] ← CDOps.SelectedInstance[comm.design];
IF ~IsSingleSelectedAndCell[selected, multiple] THEN RETURN;
cellType ← NARROW [SinixOps.ExtractCDInstance[selected, comm.design, Sisyph.mode].result];
cellName ← CoreOps.GetCellTypeName[cellType];
TerminalIO.PutRopes["SpiceOps on ", cellName, " ."];
[stdStr, errStr, msg] ← Rsh.RemoteShell[host, cmd, TRUE];
IF stdStr#NIL THEN {
ENABLE ABORTED => {
IO.PutChar[errStr, SIGTERM];
IO.Flush[errStr];
IO.Close[errStr];
IO.Close[stdStr];
TerminalIO.PutRopes["SpiceOps Failure : ", msg, "\n"];
GOTO Failed
};
convData: SpiceOps.ConvData ← SpiceOps.CreateConvData[stdStr, stdStr];
convData.rootCell ← cellType;
IF msg#NIL THEN ERROR ABORTED;
IF debug THEN [] ← CedarProcess.Fork[action: WatchErrors, data: stdStr]
ELSE [] ← CedarProcess.Fork[ReadOutput, convData, [inheritProperties: TRUE]];
[] ← CedarProcess.Fork[action: WatchErrors, data: errStr];
SpiceOps.WriteSpiceDeck[cellType, convData];
IO.Flush[stdStr];
IO.Close[stdStr];
TerminalIO.PutRope["."];
};
EXITS Failed => {};
};
ReadOutput: PROC [data: REF] RETURNS [result: REFNIL] ~ {
line: Rope.ROPENIL;
convData: SpiceOps.ConvData ← NARROW[data];
stdStr: IO.STREAM ← convData.inS;
fileName: Rope.ROPE ← Rope.Cat[CoreOps.GetCellTypeName[convData.rootCell], ".spo"];
file: IO.STREAM ← FS.StreamOpen[fileName, create];
WHILE NOT IO.EndOf[stdStr] DO
c: CHARIO.GetChar[stdStr];
IF c = '\l THEN {
IO.PutRope[file, line];
IO.PutChar[file, '\n];
line ← NIL;
}
ELSE line ← Rope.Concat[line, Rope.FromChar[c]];
ENDLOOP;
IF line#NIL THEN IO.PutRope[file, line];
IO.Close[file];
convData.inS ← FS.StreamOpen[fileName];
TerminalIO.PutRopes[".finished, ", fileName, " created.\n"];
SpiceOps.DisplaySpiceListing[convData];
};
WatchErrors: PROC [data: REF] RETURNS [results: REFNIL] ~ {
line: Rope.ROPENIL;
errStr: IO.STREAMNARROW[data];
WHILE NOT IO.EndOf[errStr] DO
c: CHARIO.GetChar[errStr ! IO.EndOfStream => {
IF line#NIL THEN TerminalIO.PutRopes[line, "\n"];
GOTO CleanExit
}];
IF c = '\l THEN {
TerminalIO.PutRopes[line, "\n"];
line ← NIL;
}
ELSE line ← Rope.Concat[line, Rope.FromChar[c]];
ENDLOOP;
EXITS
CleanExit => NULL;
};
IsSingleSelectedAndCell: PROC [selected: CD.Instance, multiple: BOOL] RETURNS [BOOL] = {
IF ~IsSingleSelected[selected, multiple] THEN RETURN [FALSE];
IF ~CDCells.IsCell[selected.ob] THEN {
TerminalIO.PutRope["\n** Selected instance is not a cell—can't do it.\n"];
RETURN[FALSE];
};
RETURN[TRUE];
};
IsSingleSelected: PROC [selected: CD.Instance, multiple: BOOL] RETURNS [BOOL] = {
IF selected=NIL THEN {
TerminalIO.PutRope["\n** No current selection--can't do it.\n"];
RETURN[FALSE];
};
IF multiple THEN {
TerminalIO.PutRope["\n** Multiple instances selected--can't do it.\n"];
RETURN[FALSE];
};
RETURN[TRUE];
};
LoadModelFile: PROC [fileName: Rope.ROPE] ~ {
file: IO.STREAMFS.StreamOpen[fileName];
SpiceOps.ReadModels[file];
};
Initialization
CDSequencerExtras.RegisterCommand[key: $Spice, proc: ExtractSelectedObjAndSpiceIt, queue: doQueue];
LoadModelFile["MODELS.DAT"];
END.