-- Pupwatch: verbose log
-- DiskLog.mesa
-- Andrew Birrell September 24, 1982 11:57 am
DIRECTORY
Ascii USING[ CR, SP,TAB ],
FileIO USING[ Open ],
IO USING[ Close, Put, PutChar, PutRope, STREAM],
LookerDefs USING[],
Time USING[ Current ],
ViewerClasses USING[ Viewer ],
ViewerOps USING[ FindViewer, RestoreViewer ],
ViewerTools USING[ MakeNewTextViewer ];
DiskLog: PROGRAM
IMPORTS FileIO, IO, Time, ViewerOps, ViewerTools
EXPORTS LookerDefs =
BEGIN
lineLength: CARDINAL ← 0;
lineMaxlength: CARDINAL = 100;
firstChar: BOOLEAN ← TRUE;
DiskChar: PUBLIC PROC[c: CHARACTER] =
BEGIN
IF firstChar
THEN { firstChar ← FALSE; LogTime[] };
IF c = Ascii.CR
THEN { IO.PutChar[file, c]; lineLength ← 0 }
ELSE { IO.PutChar[file, c]; lineLength ← lineLength+1 };
END;
LogTime: PROC =
BEGIN
IO.PutRope[file, "Pupwatch.log written at "];
IO.Put[file, [time[Time.Current[]]] ];
END;
DiskMultiple: PUBLIC PROC[desc: LONG DESCRIPTOR FOR PACKED ARRAY OF CHARACTER] =
BEGIN
FOR i: CARDINAL IN [0..LENGTH[desc])
DO c: CHARACTER = desc[i];
IF c IN [40C..176C]
THEN DiskChar[c]
ELSE DiskChar['?];
ENDLOOP;
END;
DiskPos: PUBLIC PROC[pos: CARDINAL] =
BEGIN
THROUGH [lineLength..pos-1) DO IO.PutChar[file, Ascii.SP] ENDLOOP;
IO.PutChar[file, Ascii.TAB]; -- help alignment for variable width fonts --
lineLength ← MAX[lineLength, lineLength+pos];
END;
DiskCommit: PUBLIC PROC =
BEGIN
DiskChar[Ascii.CR]; DiskChar[Ascii.CR];
IO.Close[file];
BEGIN
v: ViewerClasses.Viewer = ViewerOps.FindViewer["Pupwatch.log"].viewer;
IF v = NIL
THEN [] ← ViewerTools.MakeNewTextViewer[
info: [name: "Pupwatch.log", file: "Pupwatch.log", iconic: FALSE] ]
ELSE ViewerOps.RestoreViewer[v];
END;
file ← FileIO.Open["Pupwatch.log", append];
firstChar ← TRUE;
END;
file: IO.STREAM ← FileIO.Open["Pupwatch.log", overwrite];
END.