diff options
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/m2/gm2-libs-iso/LongIO.mod | 2 | ||||
-rw-r--r-- | gcc/m2/gm2-libs-iso/LongWholeIO.mod | 3 | ||||
-rw-r--r-- | gcc/m2/gm2-libs-iso/RealIO.mod | 2 | ||||
-rw-r--r-- | gcc/m2/gm2-libs-iso/ShortWholeIO.mod | 3 | ||||
-rw-r--r-- | gcc/m2/gm2-libs-iso/TextIO.mod | 38 | ||||
-rw-r--r-- | gcc/m2/gm2-libs-iso/TextUtil.def | 56 | ||||
-rw-r--r-- | gcc/m2/gm2-libs-iso/TextUtil.mod | 42 | ||||
-rw-r--r-- | gcc/m2/gm2-libs-iso/WholeIO.mod | 5 | ||||
-rw-r--r-- | gcc/testsuite/gm2/isolib/run/pass/testreadint.mod | 89 |
9 files changed, 202 insertions, 38 deletions
diff --git a/gcc/m2/gm2-libs-iso/LongIO.mod b/gcc/m2/gm2-libs-iso/LongIO.mod index dd62e32cb4e..40a2a601b63 100644 --- a/gcc/m2/gm2-libs-iso/LongIO.mod +++ b/gcc/m2/gm2-libs-iso/LongIO.mod @@ -30,6 +30,7 @@ FROM DynamicStrings IMPORT String, char, KillString, Length, InitString, ConCatC FROM LongConv IMPORT ScanReal ; FROM StringChan IMPORT writeString, writeFieldWidth ; FROM ldtoa IMPORT strtold ; +FROM TextUtil IMPORT SkipSpaces ; (* The text form of a signed fixed-point real number is @@ -55,6 +56,7 @@ VAR s : String ; error : BOOLEAN ; BEGIN + SkipSpaces (cid) ; ReadChar(cid, ch) ; nextState := ScanReal ; REPEAT diff --git a/gcc/m2/gm2-libs-iso/LongWholeIO.mod b/gcc/m2/gm2-libs-iso/LongWholeIO.mod index 825d290f606..252026cd3fe 100644 --- a/gcc/m2/gm2-libs-iso/LongWholeIO.mod +++ b/gcc/m2/gm2-libs-iso/LongWholeIO.mod @@ -33,6 +33,7 @@ FROM StringConvert IMPORT LongIntegerToString, LongCardinalToString ; FROM WholeConv IMPORT ScanInt, ScanCard ; FROM StringChan IMPORT writeString ; FROM IOConsts IMPORT ReadResults ; +FROM TextUtil IMPORT SkipSpaces ; (* Input and output of whole numbers in decimal text form @@ -63,6 +64,7 @@ VAR ch : CHAR ; negative : BOOLEAN ; BEGIN + SkipSpaces (cid) ; ReadChar(cid, ch) ; negative := FALSE ; c := 0 ; @@ -133,6 +135,7 @@ VAR ch : CHAR ; c : LONGCARD ; BEGIN + SkipSpaces (cid) ; ReadChar(cid, ch) ; c := 0 ; nextState := ScanCard ; diff --git a/gcc/m2/gm2-libs-iso/RealIO.mod b/gcc/m2/gm2-libs-iso/RealIO.mod index cf94487550d..ec2cc5b5fe5 100644 --- a/gcc/m2/gm2-libs-iso/RealIO.mod +++ b/gcc/m2/gm2-libs-iso/RealIO.mod @@ -30,6 +30,7 @@ FROM DynamicStrings IMPORT String, char, KillString, Length, InitString, ConCatC FROM RealConv IMPORT ScanReal ; FROM StringChan IMPORT writeString, writeFieldWidth ; FROM dtoa IMPORT strtod ; +FROM TextUtil IMPORT SkipSpaces ; (* The text form of a signed fixed-point real number is @@ -55,6 +56,7 @@ VAR s : String ; error : BOOLEAN ; BEGIN + SkipSpaces (cid) ; ReadChar(cid, ch) ; nextState := ScanReal ; REPEAT diff --git a/gcc/m2/gm2-libs-iso/ShortWholeIO.mod b/gcc/m2/gm2-libs-iso/ShortWholeIO.mod index ca2cd90934f..ac244fa3610 100644 --- a/gcc/m2/gm2-libs-iso/ShortWholeIO.mod +++ b/gcc/m2/gm2-libs-iso/ShortWholeIO.mod @@ -33,6 +33,7 @@ FROM StringConvert IMPORT IntegerToString, CardinalToString ; FROM WholeConv IMPORT ScanInt, ScanCard ; FROM StringChan IMPORT writeString ; FROM IOConsts IMPORT ReadResults ; +FROM TextUtil IMPORT SkipSpaces ; (* Input and output of whole numbers in decimal text form @@ -63,6 +64,7 @@ VAR ch : CHAR ; negative : BOOLEAN ; BEGIN + SkipSpaces (cid) ; ReadChar(cid, ch) ; negative := FALSE ; c := 0 ; @@ -133,6 +135,7 @@ VAR ch : CHAR ; c : SHORTCARD ; BEGIN + SkipSpaces (cid) ; ReadChar(cid, ch) ; c := 0 ; nextState := ScanCard ; diff --git a/gcc/m2/gm2-libs-iso/TextIO.mod b/gcc/m2/gm2-libs-iso/TextIO.mod index 75998300bed..a6ca17edecb 100644 --- a/gcc/m2/gm2-libs-iso/TextIO.mod +++ b/gcc/m2/gm2-libs-iso/TextIO.mod @@ -31,28 +31,13 @@ IMPORT IOChan, IOConsts, CharClass, ASCII ; FROM SYSTEM IMPORT ADR ; FROM FIO IMPORT FlushOutErr ; FROM libc IMPORT printf ; +FROM TextUtil IMPORT SkipSpaces, EofOrEoln, CharAvailable ; CONST DebugState = FALSE ; - (* The following procedures do not read past line marks *) - -PROCEDURE CharAvailable (cid: IOChan.ChanId) : BOOLEAN ; -BEGIN - RETURN( (IOChan.ReadResult (cid) = IOConsts.notKnown) OR - (IOChan.ReadResult (cid) = IOConsts.allRight) ) -END CharAvailable ; - - -PROCEDURE EofOrEoln (cid: IOChan.ChanId) : BOOLEAN ; -BEGIN - RETURN( (IOChan.ReadResult (cid) = IOConsts.endOfLine) OR - (IOChan.ReadResult (cid) = IOConsts.endOfInput) ) -END EofOrEoln ; - - (* DumpState *) @@ -176,27 +161,6 @@ BEGIN END ReadString ; -(* - SkipSpaces - skips any spaces. -*) - -PROCEDURE SkipSpaces (cid: IOChan.ChanId) ; -VAR - ch : CHAR ; - res: IOConsts.ReadResults ; -BEGIN - WHILE CharAvailable (cid) DO - IOChan.Look(cid, ch, res) ; - IF (res=IOConsts.allRight) AND CharClass.IsWhiteSpace (ch) - THEN - IOChan.Skip (cid) - ELSE - RETURN - END - END -END SkipSpaces ; - - PROCEDURE ReadToken (cid: IOChan.ChanId; VAR s: ARRAY OF CHAR); (* Skips leading spaces, and then removes characters from the input stream cid before the next space or line mark, diff --git a/gcc/m2/gm2-libs-iso/TextUtil.def b/gcc/m2/gm2-libs-iso/TextUtil.def new file mode 100644 index 00000000000..45272e9154e --- /dev/null +++ b/gcc/m2/gm2-libs-iso/TextUtil.def @@ -0,0 +1,56 @@ +(* TextUtil.def provides simple text manipulation routines. + +Copyright (C) 2023 Free Software Foundation, Inc. +Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>. + +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 +<http://www.gnu.org/licenses/>. *) + +DEFINITION MODULE TextUtil ; + +(* + Title : TextUtil + Author : Gaius Mulley + System : GNU Modula-2 + Date : Tue May 16 18:22:44 2023 + Revision : $Version$ + Description: provides text manmipulation routines. +*) + +IMPORT IOChan ; + + +(* + SkipSpaces - skips any spaces. +*) + +PROCEDURE SkipSpaces (cid: IOChan.ChanId) ; + + +(* The following procedures do not read past line marks. *) + +PROCEDURE CharAvailable (cid: IOChan.ChanId) : BOOLEAN ; + + +PROCEDURE EofOrEoln (cid: IOChan.ChanId) : BOOLEAN ; + + +END TextUtil. diff --git a/gcc/m2/gm2-libs-iso/TextUtil.mod b/gcc/m2/gm2-libs-iso/TextUtil.mod new file mode 100644 index 00000000000..6f6c02e68b1 --- /dev/null +++ b/gcc/m2/gm2-libs-iso/TextUtil.mod @@ -0,0 +1,42 @@ +IMPLEMENTATION MODULE TextUtil ; + +IMPORT IOChan, CharClass, IOConsts ; + +(* + SkipSpaces - skips any spaces. +*) + +PROCEDURE SkipSpaces (cid: IOChan.ChanId) ; +VAR + ch : CHAR ; + res: IOConsts.ReadResults ; +BEGIN + WHILE CharAvailable (cid) DO + IOChan.Look (cid, ch, res) ; + IF (res = IOConsts.allRight) AND CharClass.IsWhiteSpace (ch) + THEN + IOChan.Skip (cid) + ELSE + RETURN + END + END +END SkipSpaces ; + + +(* The following procedures do not read past line marks. *) + +PROCEDURE CharAvailable (cid: IOChan.ChanId) : BOOLEAN ; +BEGIN + RETURN( (IOChan.ReadResult (cid) = IOConsts.notKnown) OR + (IOChan.ReadResult (cid) = IOConsts.allRight) ) +END CharAvailable ; + + +PROCEDURE EofOrEoln (cid: IOChan.ChanId) : BOOLEAN ; +BEGIN + RETURN( (IOChan.ReadResult (cid) = IOConsts.endOfLine) OR + (IOChan.ReadResult (cid) = IOConsts.endOfInput) ) +END EofOrEoln ; + + +END TextUtil. diff --git a/gcc/m2/gm2-libs-iso/WholeIO.mod b/gcc/m2/gm2-libs-iso/WholeIO.mod index 9fc879e20a3..0bfe1a8fc0a 100644 --- a/gcc/m2/gm2-libs-iso/WholeIO.mod +++ b/gcc/m2/gm2-libs-iso/WholeIO.mod @@ -33,6 +33,7 @@ FROM StringConvert IMPORT IntegerToString, CardinalToString ; FROM WholeConv IMPORT ScanInt, ScanCard ; FROM StringChan IMPORT writeString ; FROM IOConsts IMPORT ReadResults ; +FROM TextUtil IMPORT SkipSpaces ; (* Input and output of whole numbers in decimal text form @@ -40,7 +41,7 @@ FROM IOConsts IMPORT ReadResults ; type IOConsts.ReadResults. *) -IMPORT IOChan; +IMPORT IOChan ; (* The text form of a signed whole number is ["+" | "-"], decimal digit, {decimal digit} @@ -63,6 +64,7 @@ VAR ch : CHAR ; negative : BOOLEAN ; BEGIN + SkipSpaces (cid) ; ReadChar(cid, ch) ; negative := FALSE ; c := 0 ; @@ -133,6 +135,7 @@ VAR ch : CHAR ; c : CARDINAL ; BEGIN + SkipSpaces (cid) ; ReadChar(cid, ch) ; c := 0 ; nextState := ScanCard ; diff --git a/gcc/testsuite/gm2/isolib/run/pass/testreadint.mod b/gcc/testsuite/gm2/isolib/run/pass/testreadint.mod new file mode 100644 index 00000000000..54073fdaf8b --- /dev/null +++ b/gcc/testsuite/gm2/isolib/run/pass/testreadint.mod @@ -0,0 +1,89 @@ +MODULE testreadint ; + +FROM ChanConsts IMPORT OpenResults, old, read, write ; +FROM IOChan IMPORT ChanId ; +FROM StdChans IMPORT StdOutChan ; +IMPORT StreamFile ; +FROM TextIO IMPORT SkipLine, WriteLn, WriteString ; +FROM WholeIO IMPORT ReadCard, ReadInt, WriteCard, WriteInt ; +FROM libc IMPORT printf, exit ; + + +CONST + TestFileName = "testdata" ; + + +PROCEDURE Assert (condition: BOOLEAN; name, result: ARRAY OF CHAR) ; +BEGIN + IF NOT condition + THEN + code := 1 ; + printf ("assert failed, procedure: %s failed to read number: %s\n", name, result) + END +END Assert ; + + +PROCEDURE StressReadInt ; +VAR + in, + out : ChanId ; + result: OpenResults ; + int : INTEGER ; + card : CARDINAL ; +BEGIN + (* Create a new file and use WriteCard to populate the file. *) + printf ("creating test file: %s\n", TestFileName) ; + + StreamFile.Open (out, TestFileName, write+old, result); + IF result = opened + THEN + WriteString (out, ' ') ; + WriteCard (out, 123, 3) ; + WriteLn (out) ; + WriteCard (out, 456, 3) ; + WriteLn (out) ; + StreamFile.Close (out) + ELSE + printf ("unable to create: %s\n", TestFileName) ; + exit (1) + END ; + + (* Now attempt to read the data using ReadCard. *) + printf ("reading test file using ReadCard: %s\n", TestFileName) ; + StreamFile.Open (in, TestFileName, read, result) ; + IF result = opened + THEN + ReadCard (in, card) ; + printf ("first cardinal: %d\n", card) ; + Assert (card = 123, "ReadCard", "123") ; + SkipLine (in) ; + ReadCard (in, card) ; + printf ("second cardinal: %d\n", card) ; + Assert (card = 456, "ReadCard", "456") ; + StreamFile.Close (in) + END ; + + (* Now attempt to read the data using ReadInt. *) + printf ("reading test file using ReadInt: %s\n", TestFileName) ; + StreamFile.Open (in, TestFileName, read, result) ; + IF result = opened + THEN + ReadInt (in, int) ; + printf ("first integer: %d\n", int) ; + Assert (int = 123, "ReadInt", "123") ; + SkipLine (in) ; + ReadInt (in, int) ; + printf ("second integer: %d\n", int) ; + Assert (int = 456, "ReadInt", "456") ; + StreamFile.Close (in) + END +END StressReadInt ; + + +VAR + code: INTEGER ; +BEGIN + code := 0 ; + StressReadInt ; + exit (code) +END testreadint. |