<> <> <> <> 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: BOOL _ TRUE; firstTime: BOOL _ TRUE; 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; }.