Last Edited by: Teitelman, May 11, 1983 2:52 pm
DIRECTORY
Icons USING [NewIconFromFile, IconFlavor],
Process USING [Ticks, Pause, SecondsToTicks, Detach],
RandomCard USING [Choose],
Rope USING [Cat, Find],
UserExec USING [DoIt],
ViewerClasses USING [Viewer],
ViewerEvents USING [EventProc, RegisterEventProc],
ViewerOps USING [PaintViewer],
ViewerTools USING [GetSelectedViewer]
;
DebugHack: CEDAR PROGRAM
IMPORTS RandomCard, Rope, ViewerEvents, UserExec, ViewerTools, ViewerOps, Icons, Process
= BEGIN
v: ViewerClasses.Viewer;
icon1, icon2, icon3, icon4, prev: Icons.IconFlavor;
delta0: Process.Ticks ← Process.SecondsToTicks[30];
delta1: Process.Ticks ← Process.SecondsToTicks[30];
delta2: Process.Ticks ← Process.SecondsToTicks[30];
delta3: Process.Ticks ← Process.SecondsToTicks[5];
min1: Process.Ticks ← Process.SecondsToTicks[1];
max1: Process.Ticks ← Process.SecondsToTicks[5]; -- how long to wait between movements.
min2: CARDINAL ← 2; -- how many movements before dormant
max2: CARDINAL ← 5;
min3: CARDINAL ← 2; -- number of movements (there are three positions)
max3: CARDINAL ← 10;
Selected: SIGNAL [moving: BOOL] = CODE;
IconOpened: SIGNAL = CODE;
WatchForClose: ViewerEvents.EventProc = {
IF Rope.Find[viewer.name, "Debug"] = 0 THEN TRUSTED {
v ← viewer;
Process.Detach[FORK DoIt[]];
};
};
DoIt: PROC [] = {
ENABLE {
Selected => {
InputFocus.SetInputFocus[NIL];
v.icon ← icon4;
ViewerOps.PaintViewer[v, all];
Process.Pause[delta3];
v.icon ← tool;
ViewerEvents.UnRegisterEventProc[proc: reg, event: close];
UserExec.DoIt[input: Rope.Cat[
"← SpecialCache.NameIt[\"",
v.name,
"\"]"], exec: NIL];
v.icon ← tool;
ViewerOps.PaintViewer[v, all];
CONTINUE;
};
IconOpened => {
v.icon ← tool;
CONTINUE;
};
};
-- Process.Pause[RandomCard.Choose[delta1, delta0 + delta1]]; first activity occurs between delta1 and delta1 + delta0 after user first closes debug tool
DO -- this loop twiddles the antenna between min2 and max2 times and waits a whle before doing it again. exit if viewer made iconic or destroyed, or if selected while moving.
ChangeIcon[];
FOR i: CARDINAL IN [0..RandomCard.Choose[min2, max2]) DO
Process.Pause[RandomCard.Choose[min1, max1]];
IF ViewerTools.GetSelectedViewer[] = v THEN SIGNAL Selected[TRUE];
IF v.destroyed OR NOT v.iconic THEN SIGNAL IconOpened;
MoveAntenna[RandomCard.Choose[min3, max3]];
ENDLOOP;
Process.Pause[RandomCard.Choose[delta2/2, delta2]];
IF ViewerTools.GetSelectedViewer[] = v THEN SIGNAL Selected[FALSE];
IF v.destroyed OR NOT v.iconic THEN SIGNAL IconOpened;
ENDLOOP;
};
MoveAntenna: PROC [n: CARDINAL] = {
FOR i: CARDINAL IN [0..n) DO
ChangeIcon[];
Process.Pause[-- RandomCard.Choose[1, 2]-- 1];
IF ViewerTools.GetSelectedViewer[] = v THEN SIGNAL Selected[TRUE];
IF v.destroyed OR NOT v.iconic THEN SIGNAL IconOpened;
ENDLOOP;
};
ChangeIcon: PROC = {
icon: Icons.IconFlavor = v.icon;
v.icon ← SELECT v.icon FROM
icon1 => icon2,
icon2 => IF prev = icon1 THEN icon3 ELSE icon1,
icon3 => icon2,
ENDCASE => icon1;
prev ← icon;
ViewerOps.PaintViewer[v, all];
};
Init: PROC = {
ENABLE ANY => CONTINUE;
icon1 ← Icons.NewIconFromFile["UserExec.icons", 4];
icon2 ← Icons.NewIconFromFile["UserExec.icons", 5];
icon3 ← Icons.NewIconFromFile["UserExec.icons", 6];
icon4 ← Icons.NewIconFromFile["UserExec.icons", 7];
[] ← ViewerEvents.RegisterEventProc[proc: WatchForClose, before: FALSE, event: close, filter: $Container];
};
Init[];
END. -- of DebugHack