{ This item is the property of SofTech Microsystems, Inc., } { and it may be used, copied or distrubuted only as permitted } { in a written license from that company. } { This is an unpublished work copyright 1977,1978,1979 by The } { Regents of the University of California and 1980, 1981, } { 1982, 1983 by SofTech Microsystems, Inc. } {$C Copr (c) 1977,78,79 Regents,UC and 1980,81,82,83 SMS } (*{$I #17:head.text}*) unit error_handler; { Passed the error number, error_handler passes back the string in msg (an empty string means no message available). This unit may need changes when system.syntax is modified. } interface procedure putsyntax(var msg:string; errnum:integer); implementation procedure putsyntax; const eol = 13; dle = 16; maxchar = 128; VAR msglength,D0,D1,D2,BLK,PTR,COLON: INTEGER; T,C:PACKED ARRAY [0..2] OF CHAR; BUF:PACKED ARRAY [0..1023] OF CHAR; F: FILE; PROCEDURE PUTNUM; BEGIN msg := ''; END; BEGIN (* putsyntax *) reset(F,'*SYSTEM.SYNTAX'); { This code assumes that system.syntax remains unchanged. This hard- wired index allows both the editor and the compiler to do only one disk read to get to the text of the error message } IF (errnum < 0) or (errnum > 409) or (IORESULT<>0) THEN PUTNUM ELSE BEGIN IF ERRNUM<=101 THEN BLK:=2 ELSE IF ERRNUM<=125 THEN BLK:=4 ELSE IF ERRNUM<=150 THEN BLK:=6 ELSE IF ERRNUM<=183 THEN BLK:=8 ELSE IF ERRNUM<=259 THEN BLK:=10 ELSE BLK:=12; if BLOCKREAD(F,BUF,2,BLK)<>2 THEN PUTNUM ELSE BEGIN IF BUF[0]=CHR(DLE) THEN PTR:=2 ELSE PTR:=0; D0:=ERRNUM DIV 100; (* convert error number to characters *) D1:=(ERRNUM-D0*100) DIV 10; D2:=ERRNUM MOD 10; T[0]:=CHR(D0+ORD('0')); T[1]:=CHR(D1+ORD('0')); T[2]:=CHR(D2+ORD('0')); REPEAT FILLCHAR(C,3,'0'); COLON:=SCAN(3,=':',BUF[PTR]); MOVELEFT(BUF[PTR],C[3-COLON],COLON); COLON:=COLON+PTR; PTR:=SCAN(MAXCHAR,=CHR(EOL),BUF[PTR])+PTR+3 UNTIL (T=C) OR (BUF[PTR-2]=CHR(0)); IF T<>C THEN PUTNUM ELSE BEGIN if (ptr-colon)-4 < 80 then msglength := (ptr-colon) - 4 else msglength := 80; msg[0] := chr(msglength); MOVELEFT(BUF[COLON+1],MSG[1],msglength); END END END(* if ioresult<>0 *); END(* putsyntax *); end.