<Cedar5.2>System>spErrors.mesa>> <> DIRECTORY FS USING [Error, StreamOpen], IO USING [CR, EndOf, GetChar, GetIndex, int, PutF, PutFR, rope, SetIndex, SP, STREAM, TAB], RefText USING [AppendChar, Fetch, Length, New], Rope USING [Concat, Fetch, Length, ROPE, Substr], RopeFrom USING [String], spGlobals USING [branchPtr, GetLineAndCptr, Handle, makeStringNB, MsgTextsWithLook, namePtr, next, nodePtr, PutMsgLine, WorkingDirectory]; spErrors: CEDAR PROGRAM IMPORTS FS, IO, RefText, Rope, RopeFrom, spGlobals EXPORTS spGlobals= BEGIN Handle: TYPE= spGlobals.Handle; ErrorSignal: PUBLIC SIGNAL[error: NAT, s: Rope.ROPE]= CODE; ErrWarnSummary: PUBLIC PROC[handle: Handle]= { IF handle.vars.errCount + handle.vars.warnCount > 0 THEN { handle.msgStream.PutF["\n\t"]; IF handle.vars.errCount > 0 THEN { spGlobals.MsgTextsWithLook[handle, "Total errors: ", 'b]; handle.msgStream.PutF["%d", IO.int[handle.vars.errCount]]; IF handle.vars.warnCount > 0 THEN handle.msgStream.PutF["; "] ELSE spGlobals.PutMsgLine[handle, ".\n"]; }; IF handle.vars.warnCount > 0 THEN { spGlobals.MsgTextsWithLook[handle, IF handle.vars.errCount > 0 THEN "tatal warnings: " ELSE "Total Warnings: ", 'b]; handle.msgStream.PutF["%d.\n", IO.int[handle.vars.warnCount]]; }; }; }; -- ErrWarnSummary printError: PROC[handle: Handle, err: NAT, warning: BOOL_ FALSE]= { OPEN handle.vars; errMsg: REF TEXT_ RefText.New[256]; tChar: CHAR; number: NAT_ 0; nonBlank: BOOL; <> IF thymeDotErrors=NIL AND ~triedOnce THEN {OPEN spGlobals; thymeDotErrors_ FS.StreamOpen[Rope.Concat[WorkingDirectory[handle], "Thyme.errors"] !FS.Error => { thymeDotErrors_ FS.StreamOpen["/Cherry/Thyme/Cedar5.2/Top/Thyme.errors" !FS.Error => { handle.msgStream.PutF[ "-- Thyme can't find the file \"thyme.errors\" on your working directory or the Thyme release directory. You'd need a copy of the file to get some hints about the errors.\n"]; thymeDotErrors_ NIL; triedOnce_ TRUE; CONTINUE; }; ]; CONTINUE; }; ]; IF thymeDotErrors # NIL THEN topOfMsgStream_ thymeDotErrors.GetIndex[]; }; <> <<(Current Cedar PutF doesn't seem to support %l.)>> <> <> <> handle.msgStream.PutF["\t\t"]; spGlobals.MsgTextsWithLook[handle, "g", 'm]; spGlobals.MsgTextsWithLook[handle, IF warning THEN " Warning " ELSE " Error ", 'b]; IF warning THEN warnCount_ warnCount + 1 ELSE errCount_ errCount + 1; <<>> <> IF thymeDotErrors # NIL THEN { thymeDotErrors.SetIndex[topOfMsgStream]; UNTIL number=err OR thymeDotErrors.EndOf[] DO errMsg.length _ 0; tChar_ IO.SP; nonBlank_ FALSE; <> UNTIL thymeDotErrors.EndOf[] DO tChar_ thymeDotErrors.GetChar[]; IF ~nonBlank THEN { IF tChar=IO.SP OR tChar=IO.TAB THEN LOOP ELSE nonBlank_ TRUE; }; IF tChar=IO.CR THEN EXIT; errMsg_ RefText.AppendChar[errMsg, tChar]; ENDLOOP; <> number_ 0; FOR index: INT IN [0..RefText.Length[errMsg]) DO tChar_ RefText.Fetch[errMsg, index]; IF tChar IN ['0..'9] THEN number_ number*10 + (tChar - '0) ELSE EXIT; ENDLOOP; <> ENDLOOP; }; IF thymeDotErrors=NIL OR number # err THEN handle.msgStream.PutF["%d.\n", IO.int[err]] ELSE handle.msgStream.PutF["%g.\n", IO.rope[RopeFrom.String[errMsg]]]; }; -- printError ErrorAtNB: PUBLIC PROC[handle: Handle, err: NAT, n: spGlobals.nodePtr, b: spGlobals.branchPtr]= { handle.msgStream.PutF["%g", IO.rope[ spGlobals.makeStringNB[handle, n, b, FALSE]]]; <> printError[handle, err]; }; -- ErrorAtNB ErrorStrings: PUBLIC PROC[handle: Handle, err: NAT, s1, s2: Rope.ROPE]= { errLine: Rope.ROPE_ IF s2= NIL THEN IO.PutFR["%g", IO.rope[s1]] ELSE IO.PutFR["%g at %g", IO.rope[s1], IO.rope[s2]]; handle.msgStream.PutF["%g", IO.rope[errLine]]; printError[handle, err]; }; -- ErrorStrings error: PUBLIC PROC[handle: Handle, err: NAT, skip, warning: BOOL_ FALSE]= { cptr, lastPos: INT; line: Rope.ROPE; [line, cptr]_ spGlobals.GetLineAndCptr[handle]; cptr_ MAX[0, cptr - 1]; lastPos_ MAX[0, line.Length[]-1]; IF line.Fetch[lastPos]=IO.CR AND lastPos > 0 THEN lastPos_ lastPos-1; <> <> <> <> <> <<];>> <<(Cedar5.2 doesn't seem to support PutF to change looks.)>> handle.msgStream.PutF["%g", IO.rope[line.Substr[0, cptr]]]; spGlobals.MsgTextsWithLook[handle, "8", 'm]; handle.msgStream.PutF["%g\n", IO.rope[line.Substr[cptr, lastPos-cptr+1]]]; printError[handle, err, warning]; IF skip THEN DO SELECT handle.vars.item FROM semi, eof, rightC, leftC => EXIT; ENDCASE; spGlobals.next[handle]; ENDLOOP; }; -- error error2: PUBLIC PROC[handle: Handle, err: NAT, n: spGlobals.namePtr]= { errLine: Rope.ROPE; errLine_ IO.PutFR["%g", IO.rope[n.name]]; handle.msgStream.PutF["%g", IO.rope[errLine]]; printError[handle, err]; }; -- error2 END. <> <<>> <> <> <>