home *** CD-ROM | disk | FTP | other *** search
- (*
-
- This program was written to display compile errors
- in TDI/Modula-2 programs. You can use this program
- instead of the TDI's Editor.
-
- Loosely based on a program by Bob Hawkins.
-
- Use with TDI/Modula-2 V3.00
-
- Created: 3/29/87 by Richie Bielak
-
- Modified:
-
- Copyright (c) 1987 by Richie Bielak.
-
- This program may be freely copied, but please leave
- my name in.....Thanks....Richie
- *)
- MODULE M2Error;
-
- FROM GetFileNames IMPORT ProcessCommandLine;
- FROM FastTextIO IMPORT OpenFF, CloseFF, FastFile, ReadLine, EofFF,
- SkipLines;
- FROM InOut IMPORT WriteString, WriteLn, Write, OpenOutputFile,
- WriteCard, CloseOutput, Done, Read, EOL;
- FROM GetError IMPORT GetErrString;
-
- VAR
- GotFiles : BOOLEAN;
- inFileName, outFileName, errorFileName : ARRAY [0..80] OF CHAR;
- inFile, errorFile : FastFile;
- PromptAfterError : BOOLEAN;
-
- (* +++++++++++++++++++++++++++++++++++++++++ *)
- PROCEDURE GiveDirections ();
- BEGIN
- WriteString ("Usage: M2ERROR <infile> {<outfile>}"); WriteLn;
- WriteString (" <outfile> optional"); WriteLn;
- WriteString (" Use with V3.00 of TDI"); WriteLn;
- WriteString (" -- by Richie Bielak, April 1987 --"); WriteLn;
- END GiveDirections;
-
- (* ++++++++++++++++++++++++++++++++++++++++++ *)
- (* This procedure opens all files and returns *)
- (* if all files were opened successfully. *)
- PROCEDURE OpenFiles (in, out, error : ARRAY OF CHAR) : BOOLEAN;
- VAR
- succ : BOOLEAN;
- BEGIN
- OpenFF (inFile, in, succ);
- IF NOT succ THEN
- WriteString ("Can't open input file-->"); WriteString (in); WriteLn;
- RETURN FALSE (* Get out of here *)
- END;
- OpenFF (errorFile, error, succ);
- IF NOT succ THEN
- CloseFF (inFile); (* Close the file already opened *)
- WriteString ("Can't open error file-->"); WriteString (error); WriteLn;
- RETURN FALSE(* Get out of here *)
- END;
- IF out[0] <> 0C THEN
- OpenOutputFile (out);
- IF NOT Done THEN
- CloseFF (inFile); (* Close the files already opened *)
- CloseFF (errorFile);
- WriteString ("Can't open output file"); WriteLn;
- RETURN FALSE
- END;
- END;
- RETURN TRUE
- END OpenFiles;
-
- (* +++++++++++++++++++++++++++++++++++++++ *)
- PROCEDURE CloseFiles ();
- BEGIN
- CloseOutput ();
- CloseFF (inFile);
- CloseFF (errorFile);
- END CloseFiles;
-
- (* +++++++++++++++++++++++++++++++++++++++ *)
- (* The format of the error line is this: *)
- (* <line no> <column> <error code> *)
- PROCEDURE GetErrorNumber (ErrorLine : ARRAY OF CHAR;
- VAR line, col, err : CARDINAL);
- VAR
- i : CARDINAL;
-
- PROCEDURE MakeNumber (VAR pos, number : CARDINAL);
- TYPE CharSet = SET OF CHAR;
- BEGIN
- number := 0;
- WHILE ErrorLine [pos] IN CharSet {"0".."9"} DO
- number := number * 10 + ORD (ErrorLine[pos]) - ORD ("0");
- INC (pos);
- END
- END MakeNumber;
-
- BEGIN
- i := 0;
- MakeNumber (i, line); INC (i); (* Skip past the space *)
- MakeNumber (i, col); INC (i);
- MakeNumber (i, err)
- END GetErrorNumber;
-
- (* +++++++++++++++++++++++++++++++++++++++ *)
- PROCEDURE GetSourceLine (lineNo, CurLine : CARDINAL;
- VAR outline : ARRAY OF CHAR);
- BEGIN
- (* Skip some lines *)
- SkipLines (inFile, lineNo - CurLine - 1);
- (* Now read the source line *)
- IF NOT EofFF (inFile) THEN
- ReadLine (inFile, outline);
- END
- END GetSourceLine;
-
- (* +++++++++++++++++++++++++++++++++++++++ *)
- PROCEDURE DisplayError (col, err : CARDINAL);
- VAR
- i : CARDINAL;
- errstr : ARRAY [0..100] OF CHAR;
- BEGIN
- (* First set up a string of blanks *)
- (* Bump the "col" by the length of the "Line 34: " string *)
- col := col + 11;
- FOR i := 0 TO col-1 DO errstr[i] := " " END;
- errstr[col-1] := "|"; errstr[col] := 0C;
- WriteString (errstr); WriteLn;
- (* Get the error string and print it *)
- GetErrString (err, errstr);
- WriteString (" "); WriteString (errstr); WriteLn;
- END DisplayError;
-
- (* +++++++++++++++++++++++++++++++++++++++ *)
- PROCEDURE PromptUser (VAR quit : BOOLEAN);
- VAR ch : CHAR;
- BEGIN
- quit := FALSE;
- WriteLn;
- WriteString ("Type RETURN to continue, or Q to quit: ");
- REPEAT
- Read (ch);
- IF CAP(ch) = "Q" THEN quit := TRUE END;
- UNTIL ch = EOL;
- END PromptUser;
-
- (* +++++++++++++++++++++++++++++++++++++++ *)
- PROCEDURE PrintErrors ();
- TYPE
- line = ARRAY [0..100] OF CHAR;
- VAR
- SourceLine, ErrorLine : line;
- OldLineNo, Column, ErrorCode, LineNo : CARDINAL;
- Quit : BOOLEAN;
- BEGIN
- (* First print some heading *)
- WriteString ("-- Module -->");
- WriteString (inFileName); WriteLn;
- ReadLine (errorFile, ErrorLine);
- WriteString ("-- Number of errors --> ");
- WriteString (ErrorLine); WriteLn; WriteLn;
- (* Now read the input file and print the *)
- (* offending lines. *)
-
- OldLineNo := 0;
- LOOP
- ReadLine (errorFile, ErrorLine);
- (* If no more errors, then exit *)
- IF EofFF (errorFile) THEN EXIT END;
- GetErrorNumber (ErrorLine, LineNo, Column, ErrorCode);
- (* If this is a new line number, skip through the source *)
- IF LineNo <> OldLineNo THEN
- (* All errors for this line displayed, prompt the user *)
- (* But don't do it the first time through. *)
- IF PromptAfterError AND (OldLineNo <> 0) THEN
- PromptUser (Quit);
- IF Quit THEN EXIT END;
- END;
- GetSourceLine (LineNo, OldLineNo, SourceLine);
- IF EofFF (inFile) THEN EXIT END;
- WriteLn; WriteString ("Line "); WriteCard (LineNo,4);
- WriteString(": "); WriteString (SourceLine); WriteLn;
- OldLineNo := LineNo;
- END;
- DisplayError (Column, ErrorCode);
- END; (* LOOP *)
- END PrintErrors;
-
- BEGIN
- (* First process the command line *)
- ProcessCommandLine (inFileName, outFileName, errorFileName, GotFiles);
-
- IF GotFiles THEN
- (* Open files *)
- IF OpenFiles (inFileName, outFileName, errorFileName) THEN
- (* If no output file was specified, errors are *)
- (* displayed on the screen, and we prompt after *)
- (* erroneus line. *)
- PromptAfterError := (outFileName[0] = 0C);
- (* Print errors *)
- PrintErrors ();
- (* Close files *)
- CloseFiles ();
- END
- ELSE
- GiveDirections ();
- END;
- END M2Error.
-