File: [Cherry]<Thyme>Cedar5.1>System>spErrors.mesa
Last Edited by: SChen, August 18, 1984 4:49:12 pm PDT
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;
try to open Thyme.errors once
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[];
};
set leading word (Warning or Error) and increment errCount if it's an error.
(Current Cedar PutF doesn't seem to support %l.)
handle.msgStream.PutF["\t%l8%l ", IO.rope["m"], IO.rope["M"]];
handle.msgStream.PutF[IF warning THEN "%lWarning%l " ELSE "%lError%l ",
IO.rope["b"], IO.rope["B"]];
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;
search for the right line in the whole file.
IF thymeDotErrors #
NIL
THEN {
thymeDotErrors.SetIndex[topOfMsgStream];
UNTIL number=err
OR thymeDotErrors.EndOf[]
DO
errMsg.length ← 0;
tChar← IO.SP;
nonBlank← FALSE;
get a line of error message from thyme.errors, skipping leading blanks.
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;
parse the number, if any
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;
loop if number # err and not eof
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]]];
proc name not right. will be makeRopeNB or something better ...
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;
handle.msgStream.PutF["%g%l38%l%g\n",
IO.rope[line.Substr[0, cptr]],
IO.rope["m"],
IO.rope["M"],
IO.rope[line.Substr[cptr, lastPos-cptr]],
];
(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.
CHANGE LOG
Wilhelm, March 30, 1982 8:36 AM
Barth, 7-May-82 10:50:38 PDT
Chen, June 11, 1984 7:13:37 pm PDT, cedarized.