(* Scan.mod Provides a primitive symbol fetching from input. Copyright (C) 2001-2024 Free Software Foundation, Inc. Contributed by Gaius Mulley . This file is part of GNU Modula-2. GNU Modula-2 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. GNU Modula-2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Under Section 7 of GPL version 3, you are granted additional permissions described in the GCC Runtime Library Exception, version 3.1, as published by the Free Software Foundation. You should have received a copy of the GNU General Public License and a copy of the GCC Runtime Library Exception along with this program; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see . *) IMPLEMENTATION MODULE Scan ; IMPORT StdIO ; FROM ASCII IMPORT nul, lf, cr, bs, del, bel ; FROM StdIO IMPORT Write ; FROM StrLib IMPORT StrEqual, StrLen, StrCopy ; FROM NumberIO IMPORT WriteCard, CardToStr ; FROM FIO IMPORT OpenToRead, IsNoError, Close, File, ReadChar ; FROM StrIO IMPORT WriteLn, WriteString ; FROM libc IMPORT exit ; CONST MaxLength = 255 ; (* Max Length of Source Line *) VAR FileName, CurrentString : ARRAY [0..MaxLength] OF CHAR ; CurrentLineNo : CARDINAL ; CurrentCursorPos : CARDINAL ; EOF : BOOLEAN ; LengthOfCurSym : CARDINAL ; f : File ; Opened : BOOLEAN ; HaltOnError : BOOLEAN ; AllowComments : BOOLEAN ; CommentLeader, CommentTrailer : ARRAY [0..MaxLength] OF CHAR ; TerminateOnEndOfLine: BOOLEAN ; InString : BOOLEAN ; PROCEDURE OpenSource (a: ARRAY OF CHAR) : BOOLEAN ; BEGIN StrCopy(a, FileName) ; f := OpenToRead(a) ; IF IsNoError(f) THEN StrCopy( '', CurrentString ) ; LengthOfCurSym := 0 ; CurrentCursorPos := 0 ; EOF := FALSE ; CurrentLineNo := 1 ; Opened := TRUE ELSE Opened := FALSE END ; RETURN( Opened ) END OpenSource ; PROCEDURE CloseSource ; BEGIN IF Opened THEN Close( f ) ; Opened := FALSE END END CloseSource ; (* IsStartOfComment - returns TRUE if we are looking at the start of a comment. *) PROCEDURE IsStartOfComment () : BOOLEAN ; VAR i, h: CARDINAL ; BEGIN IF AllowComments THEN i := 0 ; h := StrLen(CommentLeader) ; WHILE (i0 END DefineComments ; BEGIN InString := FALSE ; AllowComments := FALSE ; TerminateOnEndOfLine := FALSE ; StrCopy('' , CurrentString) ; LengthOfCurSym := 0 ; CurrentCursorPos := 0 ; EOF := FALSE ; CurrentLineNo := 1 ; Opened := FALSE ; HaltOnError := FALSE END Scan.