CDSignalNamesImpl.mesa (part of Chipndale)
by Christian Jacobi November 7, 1983 5:39 pm
last edited Christian Jacobi December 14, 1983 12:11 pm
DIRECTORY
Atom,
CD,
CDApplications,
CDCommandOps,
CDOps,
CDProperties,
CDSequencer,
IO,
Rope,
RuntimeError USING [UNCAUGHT],
TerminalIO,
TokenIO;
CDSignalNamesImpl: CEDAR PROGRAM
IMPORTS Atom, CDCommandOps, CDOps, CDProperties, CDSequencer, IO, Rope, RuntimeError, TerminalIO =
BEGIN
specialRights: BOOLFALSE; -- gives the right to access exclusive properties
EnterSignalNameSP: PROC [comm: CDSequencer.Command] =
BEGIN
aptr: CD.ApplicationPtr ← CDCommandOps.TheApplication[comm, "read signal-name"];
IF aptr#NIL THEN {
name: Rope.ROPE;
TerminalIO.WriteRope[" onto "];
CDCommandOps.WriteInfo[aptr];
name ← TerminalIO.RequestRope[" type name: "];
--if name = nil, property will be removed
IF Rope.IsEmpty[name] THEN name←NIL;
CDProperties.PutPropOnApplication[onto: aptr, prop: $SignalName, val: name];
IF name#NIL THEN TerminalIO.WriteRope[" done\n"]
ELSE TerminalIO.WriteRope[" removed\n"];
}
END;
RemoveDollar: PROC [r: Rope.ROPE] RETURNS [Rope.ROPE] =
BEGIN
IF Rope.Length[r]>1 AND Rope.Fetch[r]='$ THEN r ← Rope.Substr[r, 1, Rope.Length[r]-1];
RETURN [r]
END;
detail: INT ← 0;
--XXX make public on next release; probably in CDCommandOps
WriteValue: PROC [x: REF] =
BEGIN
ENABLE RuntimeError.UNCAUGHT => GOTO err;
IF x=NIL THEN TerminalIO.WriteRope["NIL"]
ELSE
WITH x SELECT FROM
ip: REF INT => TerminalIO.WriteInt[ip^];
r: Rope.ROPE => TerminalIO.WriteRope[r];
a: ATOM => TerminalIO.WriteRope[Rope.Concat["$", Atom.GetPName[a]]];
ra: REF ATOM => TerminalIO.WriteRope[Rope.Concat["^$", Atom.GetPName[ra^]]];
d: CD.Design => TerminalIO.WriteRope[Rope.Concat["design ", (IF d.name=NIL THEN "no name" ELSE d.name)]];
ob: CD.ObPtr => TerminalIO.WriteRope[CDOps.Info[ob]];
ap: CD.ApplicationPtr => CDCommandOps.WriteInfo[ap];
ENDCASE =>
IF detail=0 THEN TerminalIO.WriteRope[IO.PutFR["(%b)", IO.int[LOOPHOLE[x]]]]
ELSE TerminalIO.WriteRope[IO.PutR[IO.refAny[x]]];
EXITS
err => TerminalIO.WriteRope["??"];
END;
RequestValue: PROC [default: REF] RETURNS [REF] =
BEGIN
n: CARDINAL𡤀
WHILE n=0 DO
n ← TerminalIO.RequestSelection["property value", LIST["leave it", "remove", "INT", "ROPE", "ATOM", "REF ANY"]];
SELECT n FROM
2 => {default ← NIL};
3 => {default ← NEW[INT←TerminalIO.RequestInt["int > "]]};
4 => {default ← TerminalIO.RequestRope["rope > "]};
5 => {default ← Atom.MakeAtom[RemoveDollar[TerminalIO.RequestRope["atom > "]]]};
6 => {
TerminalIO.WriteRope["(on crash: abort is ok)"];
default ← IO.GetRefAny[IO.RIS[TerminalIO.RequestRope["ref any > "]]]
};
ENDCASE --0, 1-- => {NULL};
ENDLOOP;
RETURN [default]
END;
EnterPropertySP: PROC [comm: CDSequencer.Command] =
BEGIN
aptr: CD.ApplicationPtr ← CDCommandOps.TheApplication[comm, "enter property"];
IF aptr#NIL THEN {
pType: CDProperties.PropertyProcs;
atom: ATOM;
value: REF;
name: Rope.ROPE ← RemoveDollar[TerminalIO.RequestRope["type property name: "]];
IF Rope.IsEmpty[name] THEN {
TerminalIO.WriteRope[" empty name; not done\n"];
RETURN
};
atom ← Atom.MakeAtom[name];
value ← CDProperties.GetPropFromApplication[aptr, atom];
TerminalIO.WriteRope[" old value: "];
WriteValue[value];
TerminalIO.WriteLn[];
pType ← CDProperties.FetchProcs[atom];
IF pType#NIL AND pType.exclusive THEN {
TerminalIO.WriteRope[" this property is used exclusively by the program; "];
IF ~specialRights THEN {
TerminalIO.WriteRope["interactive access is not possible\n"];
RETURN
}
};
value ← RequestValue[value];
CDProperties.PutPropOnApplication[onto: aptr, prop: atom, val: value];
TerminalIO.WriteRope[" done\n"];
}
END;
--move this procedure to CDProperties
ShowProperties: PROC [from: REF] =
BEGIN
WITH from SELECT FROM
a: CD.ApplicationPtr => ShowPropertyList[a.properties];
o: CD.ObPtr => ShowPropertyList[o.properties];
d: CD.Design => ShowPropertyList[d.properties];
t: CD.Technology => ShowPropertyList[t.properties];
--l: CD.LevelRef => ...;
--at: ATOM => ...;
ENDCASE => TerminalIO.WriteRope[" no showable CD properties"];
END;
ShowPropertyList: PROC [pl: CD.Properties] =
BEGIN
FOR list: CD.Properties ← pl, list.rest WHILE list#NIL DO
ShowProperty[list.first]
ENDLOOP
END;
ShowProperty: PROC [pp: Atom.DottedPair] =
BEGIN
TerminalIO.WriteRope[" name: "];
WriteValue[pp.key];
TerminalIO.WriteRope[" value: "];
WriteValue[pp.val];
TerminalIO.WriteLn[];
END;
ShowPropertiesSP: PROC [comm: CDSequencer.Command] =
BEGIN
aptr: CD.ApplicationPtr ← CDCommandOps.TheApplication[comm, "Show Properties"];
IF aptr#NIL THEN {
IF aptr.properties#NIL THEN {
TerminalIO.WriteRope[" --properties on instance\n"];
ShowPropertyList[aptr.properties];
};
IF aptr.ob.properties#NIL THEN {
TerminalIO.WriteRope[" --properties on object itself\n"];
ShowPropertyList[aptr.ob.properties];
};
TerminalIO.WriteRope[" --\n"];
}
END;
-- module initialization
Registration removed from this place, to port this module to commandlevel
IF NOT CDProperties.RegisterProperty[$SignalName] THEN ERROR;
IF NOT CDProperties.RegisterProperty[$InstanceName] THEN ERROR;
CDProperties.InstallProcs[prop: $SignalName, new:
CDProperties.PropertyProcsRec[
makeCopy: CDProperties.CopyVal,
internalWrite: CDProperties.RopePWrite,
internalRead: CDProperties.RopePRead
]];
CDProperties.InstallProcs[prop: $InstanceName, new:
CDProperties.PropertyProcsRec[
makeCopy: CDProperties.CopyVal,
internalWrite: CDProperties.RopePWrite,
internalRead: CDProperties.RopePRead
]];
CDSequencer.ImplementCommand[$EnterNameS, EnterSignalNameSP];
CDSequencer.ImplementCommand[$EnterNameP, EnterSignalNameSP];
CDSequencer.ImplementCommand[$EnterPropertyS, EnterPropertySP];
CDSequencer.ImplementCommand[$EnterPropertyP, EnterPropertySP];
CDSequencer.ImplementCommand[$ShowPropertiesP, ShowPropertiesSP,, doQueue];
CDSequencer.ImplementCommand[$ShowPropertiesS, ShowPropertiesSP,, doQueue];
END.