ThymeErrors.mesa
Copyright (C) 1985 by Xerox Corporation. All rights reserved.
Last Edited by:
Barth, July 8, 1988 1:20:06 pm PDT
Christian LeCocq January 23, 1987 4:21:28 pm PST
Pradeep Sindhu March 19, 1986 9:49:32 pm PST
Sweetsun Chen, September 18, 1985 9:17:35 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, FromRefText, Length, ROPE, Substr],
ThymeGlobals USING [branchPtr, EchoInput, GetLineAndCptr, Handle, MakeStringNB, MsgTextsWithLook, namePtr, Next, nodePtr, PutMsgLine, WorkingDirectory];
ThymeErrors:
CEDAR
PROGRAM
IMPORTS
FS,
IO,
RefText,
Rope,
ThymeGlobals
= BEGIN
Handle: TYPE = ThymeGlobals.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 {
ThymeGlobals.MsgTextsWithLook[handle, "Total errors: ", 'b];
handle.msgStream.PutF["%d", IO.int[handle.vars.errCount]];
IF handle.vars.warnCount > 0 THEN handle.msgStream.PutF["; "]
ELSE ThymeGlobals.PutMsgLine[handle, ".\n"];
};
IF handle.vars.warnCount > 0
THEN {
ThymeGlobals.MsgTextsWithLook[handle, IF handle.vars.errCount > 0 THEN "total 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 ThymeGlobals;
thymeDotErrors ←
FS.StreamOpen[Rope.Concat[WorkingDirectory[handle], "Thyme.errors"]
!
FS.Error => {
thymeDotErrors ←
FS.StreamOpen["/DATools/DATools7.0/Thyme/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 need the file to find out what the Error is.\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"];
ThymeGlobals.MsgTextsWithLook[handle, "g", 'm];
ThymeGlobals.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[Rope.FromRefText[errMsg]]];
}; -- PrintError
ErrorAtNB:
PUBLIC
PROC[handle: Handle, err:
NAT,
n: ThymeGlobals.nodePtr, b: ThymeGlobals.branchPtr]= {
handle.msgStream.PutF["%g",
IO.rope[ ThymeGlobals.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;
noEcho: BOOL ← NOT ThymeGlobals.EchoInput[handle];
[line, cptr]← ThymeGlobals.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[IF noEcho THEN "\n%g" ELSE "%g", IO.rope[line.Substr[0, cptr]]];
ThymeGlobals.MsgTextsWithLook[handle, "8", 'm];
handle.msgStream.PutF["%g\n", IO.rope[line.Substr[cptr, lastPos-cptr+1]]];
PrintError[handle, err, warning];
IF
NOT ThymeGlobals.EchoInput[handle]
THEN handle.msgStream.PutF["\t\tat [%g] in %g.\n",
IO.int[handle.vars.inStream.GetIndex[] - line.Length[] + cptr - 1],
IO.rope[handle.vars.fileNameStack[handle.vars.fileStackTop]]
];
IF skip
THEN
DO
SELECT handle.vars.item
FROM
semi, eof, rightC, leftC => EXIT;
ENDCASE;
ThymeGlobals.Next[handle];
ENDLOOP;
}; -- Error
Error2:
PUBLIC
PROC[handle: Handle, err:
NAT, n: ThymeGlobals.namePtr]= {
errLine: Rope.ROPE ← 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.
Chen, July 22, 1985 8:03:18 pm PDT, => Cedar6.0.