EngineLogImpl.mesa
Copyright (C) Xerox Corporation 1982, 1983, 1984, 1985, 1986. All rights reserved.
Last edited by Strickberger 22-Nov-85 18:18:44
Tim Diebert: December 2, 1986 1:27:00 pm PST
DIRECTORY
BasicTime USING [Now],
EngineLog USING [EngineType, Object],
FS USING [Error, FileInfo, StreamOpen],
IO USING [Close, EndOfStream, Error, GetChar, GetLength, PutText, STREAM],
PrincOpsUtils USING [LongCopy],
Rope USING[ROPE];
EngineLogImpl: CEDAR PROGRAM
IMPORTS BasicTime, FS, IO, PrincOpsUtils
EXPORTS EngineLog = BEGIN
Types
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Constants:
logFileName: ROPE = "PrintEngine.log";
Variables:
localPointer: REF EngineLog.Object ← NIL;
PUBLIC PROCEDUREs:
ForceOut: PUBLIC PROCEDURE = BEGIN
words: NATSIZE[EngineLog.Object];
s: STREAM; text: REF TEXTNEW[TEXT[words]];
TRUSTED BEGIN
ENABLE FS.Error, IO.Error, IO.EndOfStream => GOTO Out;
s ← FS.StreamOpen[fileName: logFileName, accessOptions: create, keep: 2];
PrincOpsUtils.LongCopy[from: LOOPHOLE[localPointer], nwords: words,
to: (LOOPHOLE[text, LONG POINTER] + SIZE[TEXT[0]])];
IO.PutText[s, text];
IO.Close[s];
EXITS Out => {IF s # NIL THEN IO.Close[s]};
END;
END;
Map: PUBLIC PROCEDURE [engineType: EngineLog.EngineType, version: CARDINAL]
RETURNS [pointer: REF EngineLog.Object] = BEGIN
words: NATSELECT engineType FROM
raven => SIZE[EngineLog.Object],
banshee => SIZE[EngineLog.Object],
ENDCASE => 1;
file: ROPENIL; s: STREAM; text: REF TEXTNEW[TEXT[words]]; length: INT;
localPointer ← pointer ← SELECT engineType FROM
raven => NEW[EngineLog.Object ← [raven, BasicTime.Now[], ALL [0]]],
banshee => NEW[EngineLog.Object ← [banshee, BasicTime.Now[], ALL [0]]],
ENDCASE => NIL;
file ← FS.FileInfo[logFileName ! FS.Error => CONTINUE].fullFName;
IF file # NIL
THEN TRUSTED BEGIN
ENABLE FS.Error, IO.Error, IO.EndOfStream => GOTO Out;
s ← FS.StreamOpen[fileName: logFileName, accessOptions: read];
IF (length ← IO.GetLength[s]) = words*2 THEN GOTO Out;
FOR i: INT IN [0 .. length) DO
text[i] ← IO.GetChar[s];
ENDLOOP;
IO.Close[s];
EXITS Out => {IF s # NIL THEN IO.Close[s]; RETURN [NIL]};
END
ELSE BEGIN
ENABLE FS.Error, IO.Error => GOTO Out;
s ← FS.StreamOpen[fileName: logFileName, accessOptions: create, keep: 2];
IO.Close[s];
EXITS Out => {IF s # NIL THEN IO.Close[s]; RETURN [NIL]};
END;
END; -- Map
END.
LOG
When / Who / What
Strickberger / 11-Aug-85 22:43:59 / Created for Euclid.
Strickberger / 22-Nov-85 18:18:44 / Specify session on OpenByName. REJECT other errors.