DiskLog.mesa: verbose log for Pupwatch
Copyright © 1985 by Xerox Corporation. All rights reserved.
Andrew Birrell October 26, 1983 3:02 pm
Russ Atkinson (RRA) March 13, 1985 1:06:52 pm PST
DIRECTORY
Ascii USING [CR, SP, TAB],
BasicTime USING [Now],
FS USING [Copy, Error, StreamOpen],
IO USING [Close, Put, PutChar, PutRope, STREAM],
LookerDefs USING [],
Rope USING [ROPE],
ViewerClasses USING [Viewer],
ViewerOps USING [FindViewer, RestoreViewer],
ViewerTools USING [MakeNewTextViewer];
DiskLog: PROGRAM
IMPORTS FS, IO, BasicTime, ViewerOps, ViewerTools
EXPORTS LookerDefs = {
lineLength: CARDINAL ← 0;
lineMaxlength: CARDINAL = 100;
firstChar: BOOLTRUE;
firstTime: BOOLTRUE;
DiskChar: PUBLIC PROC [c: CHAR] = {
IF firstChar THEN {
firstChar ← FALSE;
IF firstTime
THEN {
firstTime ← FALSE;
file ← FS.StreamOpen[logName, $create];
}
ELSE {
[] ← FS.Copy[from: logName, to: logName, keep: 1 ! FS.Error => CONTINUE];
file ← FS.StreamOpen[logName, $append];
};
LogTime[];
};
IF c = Ascii.CR
THEN { IO.PutChar[file, c]; lineLength ← 0 }
ELSE { IO.PutChar[file, c]; lineLength ← lineLength+1 };
};
LogTime: PROC = {
IO.PutRope[file, "Pupwatch.log written at "];
IO.Put[file, [time[BasicTime.Now[]]]];
};
DiskMultiple: PUBLIC PROC [desc: LONG DESCRIPTOR FOR PACKED ARRAY OF CHAR] = {
FOR i: CARDINAL IN [0..LENGTH[desc])
DO c: CHAR = desc[i];
IF c IN [40C..176C]
THEN DiskChar[c]
ELSE DiskChar['?];
ENDLOOP;
};
DiskPos: PUBLIC PROC [pos: CARDINAL] = {
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];
};
logName: Rope.ROPE = "Pupwatch.log";
DiskCommit: PUBLIC PROC = {
DiskChar[Ascii.CR]; DiskChar[Ascii.CR];
IO.Close[file];
{
v: ViewerClasses.Viewer = ViewerOps.FindViewer["Pupwatch.log"].viewer;
IF v = NIL
THEN [] ← ViewerTools.MakeNewTextViewer[
info: [name: logName, file: "Pupwatch.log", iconic: FALSE]]
ELSE ViewerOps.RestoreViewer[v];
};
firstChar ← TRUE;
};
file: IO.STREAM;
}.