RepHacks.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Louis Monier October 10, 1988 8:42:51 pm PDT
DIRECTORY
CD, CDRepetitions, CDCommandOps, CDDirectory, CDOps, CDSequencer, IO, Rope, TerminalIO;
RepHacks: CEDAR PROGRAM
IMPORTS CDRepetitions, CDCommandOps, CDDirectory, CDOps, IO, Rope, TerminalIO
~
BEGIN
hackMenu: ATOM ← $SpecialMenu; -- where DAUserHacks commands are forcefully registered
ROPE: TYPE = Rope.ROPE;
Reps Checker
Signals whether a cell contains (recursively) a CD repetition
CheckReps:
PROC [comm: CDSequencer.Command] ~ {
EachObject:
PROC [me:
CD.Object, data:
REF←
NIL]
RETURNS [quit:
BOOL←
FALSE] ~ {
IF ~CDRepetitions.IsRepetition[me] THEN RETURN;
TerminalIO.PutF["Yep!\n"];
quit ← TRUE;
};
inst: CD.Instance; multiple: BOOL;
[inst, multiple] ← CDOps.SelectedInstance[comm.design];
IF multiple THEN {TerminalIO.PutF["Multiple Selections\n"]; RETURN};
IF ~CDDirectory.EnumerateObject[ob: inst.ob, proc: EachObject] THEN TerminalIO.PutF["Nope!\n"];
};
Sanitizer
Makes all cell names acceptable to almost any brain-damaged aging software
nameMagicCounter: NAT ← 0;
NewName:
PROC []
RETURNS [name:
ROPE] ~ {
-- Generates a new name on every call
nameMagicCounter ← nameMagicCounter+1;
name ← IO.PutFR["NEWCELLN%g", IO.int[nameMagicCounter]];
};
IsLowerC: PROC [c: CHAR] RETURNS [BOOL] ~ {RETURN [c IN ['a..'z]]};
IsUpperC: PROC [c: CHAR] RETURNS [BOOL] ~ {RETURN [c IN ['A..'Z]]};
IsLetter: PROC [c: CHAR] RETURNS [BOOL] ~ {RETURN [(c IN ['A..'Z]) OR (c IN ['a..'z])]};
IsDigit: PROC [c: CHAR] RETURNS [BOOL] ~ {RETURN [(c IN ['0..'9])]};
Sanitize:
PROC [old:
CHAR]
RETURNS [new:
CHAR] ~ {
-- Replaces funny characters by x's
new ←
SELECT
TRUE
FROM
IsLowerC[old] => old+('A-'a),
IsUpperC[old] => old,
IsDigit[old] => old,
ENDCASE => 'X;
};
SanitizeName:
PROC [name:
ROPE]
RETURNS [simpler:
ROPE] ~ {
IF Rope.IsEmpty[name] OR Rope.Length[name]>16 THEN RETURN[NewName[]];
simpler ← Rope.Translate[base: name, translator: Sanitize];
IF IsDigit[Rope.Fetch[simpler, 0]] THEN simpler ← Rope.Cat["X", simpler];
IF Rope.Length[simpler]>16
THEN
TerminalIO.PutF["%g has more than 16 characters\n", IO.rope[simpler]];
};
SanitizeDesign:
PROC [comm: CDSequencer.Command] ~ {
EachObject:
PROC [name:
ROPE, ob:
CD.Object]
RETURNS [quit:
BOOL←
FALSE] ~ {
safe: NAT ← 0;
newName: ROPE ← SanitizeName[name];
IF Rope.Equal[name, newName] THEN RETURN;
TerminalIO.PutF["%g -> %g\n", IO.rope[name], IO.rope[newName]];
IF CDDirectory.Rename[design: comm.design, object: ob, newName: newName, fiddle: FALSE, fiddleFirst: FALSE, removeFirst: FALSE].done THEN RETURN;
DO
newName ← NewName[]; -- it failed for some reason: try again!
TerminalIO.PutF["%g -> %g, another try\n", IO.rope[name], IO.rope[newName]];
IF CDDirectory.Rename[design: comm.design, object: ob, newName: newName, fiddle:
FALSE, fiddleFirst:
FALSE, removeFirst:
FALSE].done
THEN
EXIT;
-- something is very screwed up here!
safe ← safe+1;
IF safe>100 THEN ERROR;
ENDLOOP;
};
TerminalIO.PutF["Sanitizing the name of all cells in the directory\n"];
[] ← CDDirectory.Enumerate[design: comm.design, action: EachObject];
TerminalIO.PutF["Yep, that's what it takes to interface to the real world!\n"];
};
Depth Checker
Counts the maximum number of levels of hierarchy (CIF limitation in a few places)
CheckDepth: PROC [comm: CDSequencer.Command] ~ {
EachObject: PROC [me: CD.Object, data: REF←NIL] RETURNS [quit: BOOL←FALSE] ~ {
d: NAT ← NARROW[data, REF NAT]^+1;
IF d>maxDepth THEN maxDepth ← d;
IF me.class.composed THEN [] ← CDDirectory.EnumerateObject[ob: me, proc: EachObject, data: NEW[NAT ← d], recurse: FALSE];
};
inst: CD.Instance; multiple: BOOL;
depth, maxDepth: NAT ← 0;
[inst, multiple] ← CDOps.SelectedInstance[comm.design];
IF multiple THEN {TerminalIO.PutF["Multiple Selections\n"]; RETURN};
[] ← CDDirectory.EnumerateObject[ob: inst.ob, proc: EachObject, data: NEW[NAT ← depth], recurse: FALSE];
TerminalIO.PutF["\n Max Depth for this cell is %g\n", IO.int[maxDepth]];
};
Initializations
CDCommandOps.RegisterWithMenu[hackMenu, "Check for reps", "Check if contains a CD repetition", $RepHacksCheckReps, CheckReps];
CDCommandOps.RegisterWithMenu[hackMenu, "Sanitize cell names", "Makes all cell names acceptable to almost any brain-damaged aging software", $RepHacksSanitize, SanitizeDesign];
CDCommandOps.RegisterWithMenu[hackMenu, "Measure Depth", "Reports the maximum number of levels of hierarchy", $RepHacksCheckDepth, CheckDepth];
END.