ErrorLogButtonImpl.mesa
Copyright Ó 1990, 1991 by Xerox Corporation. All rights reserved.
Bill Jackson (bj), March 22, 1990 9:19 pm PST
DIRECTORY
Basics USING [ Comparison ],
Buttons USING [ Button, ButtonProc, Create ],
FileViewerOps USING [ AttachErrorLog, ShowLog, RemoveErrorLog ],
PFS USING [FileSearch, PathFromRope],
PFSNames USING [Component, ComponentRope, Directory, PATH, ShortName],
RedBlackTree USING [ Compare, Create, DuplicateKey, EachNode, EnumerateIncreasing, GetKey, Insert, Lookup, Table ],
Rope USING [ Compare, Concat, Equal, FindBackward, ROPE, Substr ],
ViewerClasses USING [ Column, Viewer ],
ViewerOps USING [ EnumerateViewers, EnumProc ];
ErrorLogButtonImpl: CEDAR MONITOR
IMPORTS Buttons, FileViewerOps, PFS, PFSNames, RedBlackTree, Rope, ViewerOps ~ {
ROPE: TYPE ~ Rope.ROPE;
GetKey: RedBlackTree.GetKey ~ {
viewers: LIST OF ViewerClasses.Viewer ~ NARROW[data];
key: ROPE ~ viewers.first.name;
RETURN[key];
};
Compare: RedBlackTree.Compare ~ {
key1: ROPE ~ NARROW[k];
key2: ROPE ~ NARROW[GetKey[data]];
comparison: Basics.Comparison ~ key1.Compare[key2, FALSE];
RETURN[comparison];
};
ListAllViewers: PROC RETURNS [ all: RedBlackTree.Table ] ~ {
enum: ViewerOps.EnumProc ~ {
ENABLE {
UNWIND => { NULL };
RedBlackTree.DuplicateKey => {
others: LIST OF ViewerClasses.Viewer ¬ NARROW[all.Lookup[v.name]];
others ¬ CONS[v, others];
GOTO Next;
};
};
list: LIST OF ViewerClasses.Viewer ~ LIST[v];
all.Insert[list, v.name];
EXITS
Next => { NULL };
};
all ¬ RedBlackTree.Create[GetKey, Compare];
ViewerOps.EnumerateViewers[enum];
};
Class: TYPE ~ { none, c, cedar, cm, command, config, cr, df, errlog, h, jam, mesa, require, style, threeC4, tioga };
FileType: PROC [ viewer: ViewerClasses.Viewer ] RETURNS [ class: Class ¬ $none ] ~ {
label: ROPE ~ viewer.name;
dotSpot: INT32 ~ label.FindBackward["."];
suffix: ROPE ~ label.Substr[dotSpot.SUCC];
class ¬ SELECT TRUE FROM
( suffix.Equal["c", FALSE] ) => $c,
( suffix.Equal["cedar", FALSE] ) => $cedar,
( suffix.Equal["cm", FALSE] ) => $cm,
( suffix.Equal["command", FALSE] ) => $command,
( suffix.Equal["config", FALSE] ) => $config,
( suffix.Equal["cr", FALSE] ) => $cr,
( suffix.Equal["df", FALSE] ) => $df,
( suffix.Equal["errlog", FALSE] ) => $errlog,
( suffix.Equal["h", FALSE] ) => $h,
( suffix.Equal["jam", FALSE] ) => $jam,
( suffix.Equal["mesa", FALSE] ) => $mesa,
( suffix.Equal["require", FALSE] ) => $require,
( suffix.Equal["style", FALSE] ) => $style,
( suffix.Equal["threeC4", FALSE] ) => $threeC4,
( suffix.Equal["tioga", FALSE] ) => $tioga,
ENDCASE => $none;
};
RefreshErrorButtons: PROC ~ {
EachNode: RedBlackTree.EachNode ~ {
FOR tail: LIST OF ViewerClasses.Viewer ¬ NARROW[data], tail.rest WHILE ( tail # NIL ) DO
viewer: ViewerClasses.Viewer ~ tail.first;
label: ROPE ~ viewer.name;
column: ViewerClasses.Column ~ viewer.column;
iconic: BOOL ~ viewer.iconic;
class: Class ~ FileType[viewer];
SELECT class FROM
( $mesa ) => {
path: PFSNames.PATH ~ PFS.PathFromRope[label];
shortComp: PFSNames.Component ~ path.ShortName[];
short: ROPE ~ shortComp.ComponentRope[];
dotSpot: INT32 ~ short.FindBackward["."];
suffix: ROPE ~ short.Substr[dotSpot.SUCC];
basename: ROPE ~ short.Substr[len: dotSpot];
dir: PFSNames.PATH ~ path.Directory[];
errName: ROPE ~ basename.Concat[".errlog"];
errPath: PFSNames.PATH ~ PFS.PathFromRope[errName];
exists: BOOL ~ ( PFS.FileSearch[errPath, LIST[dir]] # NIL );
SELECT ( exists ) FROM
( TRUE ) => { FileViewerOps.AttachErrorLog[label] };
( FALSE ) => { FileViewerOps.RemoveErrorLog[label] };
ENDCASE => { ERROR };
};
( $errlog ) => {
path: PFSNames.PATH ~ PFS.PathFromRope[label];
destroyIt: BOOL ~ ( PFS.FileSearch[path, NIL] = NIL );
FileViewerOps.ShowLog[label, destroyIt];
};
ENDCASE => { NULL };
ENDLOOP;
};
all: RedBlackTree.Table ¬ ListAllViewers[];
all.EnumerateIncreasing[EachNode];
};
AnotherPush: Buttons.ButtonProc ~ { RefreshErrorButtons[] };
anotherButton: Buttons.Button ~ Buttons.Create[[name: "Errlog(s)"], AnotherPush];
}.