DIRECTORY
BasicTime USING [GMT, MonthOfYear, Now, Unpack, Unpacked],
Convert USING [AppendCard],
IO,
PrintingP4V3 USING [RequestID],
RefText USING [AppendChar, AppendRope, ObtainScratch, ReleaseScratch],
Rope USING [FromRefText, ROPE],
XNSPSMessages;
~
BEGIN
OPEN PrintingP4V3;
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
LogMessage:
PUBLIC
ENTRY
PROC [message:
ROPE, request: RequestID ←
ALL[0]] = {
InternalLogMessage[message, request];
};
MsgList: TYPE ~ REF MsgListRep;
MsgListRep:
TYPE ~
RECORD [
next: MsgList ← NIL,
msg: ROPE ← NIL];
msgHead: MsgList ← NIL;
msgTail: MsgList ← NIL;
msgCnt: CARDINAL ← 0;
serverStream: IO.STREAM ← NIL;
RegisterTTY: PUBLIC ENTRY PROC [stream: IO.STREAM] = {serverStream ← stream};
InternalLogMessage:
INTERNAL
PROC [message:
ROPE, request: RequestID ←
ALL[0]] = {
md: MACHINE DEPENDENT RECORD [lo, hi: CARDINAL];
scratch: REF TEXT ~ RefText.ObtainScratch[100];
text: REF TEXT ← scratch;
msg: ROPE ← NIL;
IF msgHead =
NIL
THEN msgHead ← msgTail ← NEW[MsgListRep]
ELSE {msgTail.next ← NEW[MsgListRep]; msgTail ← msgTail.next};
text ← TimeToRefText[BasicTime.Now[], text];
text ← RefText.AppendChar[text, ' ];
IF request #
ALL[0]
THEN {
md.lo ← request[4]; md.hi ← request[3];
text ← RefText.AppendChar[text, 'R];
text ← RefText.AppendChar[text, '#];
text ← Convert.AppendCard[to: text, from: LOOPHOLE[md]];
text ← RefText.AppendChar[text, ' ];
};
text ← RefText.AppendChar[text, '\t];
text ← RefText.AppendRope[text, message];
text ← RefText.AppendChar[text, '\n];
msg ← Rope.FromRefText[text];
msgTail.msg ← msg; msgCnt ← msgCnt + 1;
IF serverStream # NIL THEN {IO.PutRope[serverStream, msg]; IO.Flush[serverStream]};
IF msgCnt > 150
THEN
BEGIN
IF msgHead.next = NIL THEN {msgCnt ← 1; RETURN};
msgCnt ← msgCnt - 1;
msgHead ← msgHead.next;
END;
RefText.ReleaseScratch[scratch];
};
monthName:
ARRAY BasicTime.MonthOfYear
OF Rope.
ROPE ~ ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"];
TimeToRefText:
PROC [time: BasicTime.
GMT, text:
REF
TEXT]
RETURNS [t:
REF
TEXT] =
BEGIN
unpacked: BasicTime.Unpacked ← BasicTime.Unpack[time];
stream: IO.STREAM ← IO.TOS[text];
IO.PutF[stream, "%2g-%g-%02g ", IO.int[unpacked.day], IO.rope[monthName[unpacked.month]], IO.int[unpacked.year MOD 100]];
IO.PutF[stream, "%2g:%02g:%02g", IO.int[unpacked.hour], IO.int[unpacked.minute], IO.int[unpacked.second]];
t ← IO.TextFromTOS[stream];
END;
EnumerateMessages:
PUBLIC
PROC [action:
PROC[message:
ROPE]
RETURNS [continue:
BOOLEAN]] =
BEGIN
myTail: MsgList ← msgHead;
DO
IF myTail = NIL THEN RETURN;
IF NOT action[myTail.msg] THEN RETURN;
myTail ← myTail.next;
ENDLOOP;
END;