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
s : String ;
error : BOOLEAN ;
BEGIN
+ SkipSpaces (cid) ;
ReadChar(cid, ch) ;
nextState := ScanReal ;
REPEAT
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
ch : CHAR ;
negative : BOOLEAN ;
BEGIN
+ SkipSpaces (cid) ;
ReadChar(cid, ch) ;
negative := FALSE ;
c := 0 ;
ch : CHAR ;
c : LONGCARD ;
BEGIN
+ SkipSpaces (cid) ;
ReadChar(cid, ch) ;
c := 0 ;
nextState := ScanCard ;
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
s : String ;
error : BOOLEAN ;
BEGIN
+ SkipSpaces (cid) ;
ReadChar(cid, ch) ;
nextState := ScanReal ;
REPEAT
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
ch : CHAR ;
negative : BOOLEAN ;
BEGIN
+ SkipSpaces (cid) ;
ReadChar(cid, ch) ;
negative := FALSE ;
c := 0 ;
ch : CHAR ;
c : SHORTCARD ;
BEGIN
+ SkipSpaces (cid) ;
ReadChar(cid, ch) ;
c := 0 ;
nextState := ScanCard ;
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
*)
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,
--- /dev/null
+(* 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.
--- /dev/null
+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.
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
type IOConsts.ReadResults.
*)
-IMPORT IOChan;
+IMPORT IOChan ;
(* The text form of a signed whole number is
["+" | "-"], decimal digit, {decimal digit}
ch : CHAR ;
negative : BOOLEAN ;
BEGIN
+ SkipSpaces (cid) ;
ReadChar(cid, ch) ;
negative := FALSE ;
c := 0 ;
ch : CHAR ;
c : CARDINAL ;
BEGIN
+ SkipSpaces (cid) ;
ReadChar(cid, ch) ;
c := 0 ;
nextState := ScanCard ;
--- /dev/null
+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.
target_triplet = @target@
subdir = .
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/multi.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../config/override.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
- $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
- $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
AC_SUBST([am__untar])
]) # _AM_PROG_TAR
+m4_include([../libtool.m4])
+m4_include([../ltoptions.m4])
+m4_include([../ltsugar.m4])
+m4_include([../ltversion.m4])
+m4_include([../lt~obsolete.m4])
m4_include([../config/acx.m4])
m4_include([../config/depstand.m4])
m4_include([../config/lead-dot.m4])
m4_include([../config/multi.m4])
m4_include([../config/no-executables.m4])
m4_include([../config/override.m4])
-m4_include([../libtool.m4])
-m4_include([../ltoptions.m4])
-m4_include([../ltsugar.m4])
-m4_include([../ltversion.m4])
-m4_include([../lt~obsolete.m4])
target_triplet = @target@
subdir = libm2cor
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/multi.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../config/override.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
- $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
- $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am
SWholeIO.def SysClock.def \
SYSTEM.def TermFile.def \
TERMINATION.def TextIO.def \
+ TextUtil.def \
WholeConv.def WholeIO.def \
WholeStr.def wrapsock.def \
wraptime.def
SWholeIO.mod SysClock.mod \
SYSTEM.mod TermFile.mod \
TERMINATION.mod TextIO.mod \
+ TextUtil.mod \
WholeConv.mod WholeIO.mod \
WholeStr.mod
target_triplet = @target@
subdir = libm2iso
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/multi.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../config/override.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
- $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
- $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am
@BUILD_ISOLIB_TRUE@ Storage.lo StreamFile.lo StringChan.lo \
@BUILD_ISOLIB_TRUE@ Strings.lo SWholeIO.lo SysClock.lo \
@BUILD_ISOLIB_TRUE@ SYSTEM.lo TermFile.lo TERMINATION.lo \
-@BUILD_ISOLIB_TRUE@ TextIO.lo WholeConv.lo WholeIO.lo \
-@BUILD_ISOLIB_TRUE@ WholeStr.lo
+@BUILD_ISOLIB_TRUE@ TextIO.lo TextUtil.lo WholeConv.lo \
+@BUILD_ISOLIB_TRUE@ WholeIO.lo WholeStr.lo
@BUILD_ISOLIB_TRUE@am_libm2iso_la_OBJECTS = $(am__objects_1) \
@BUILD_ISOLIB_TRUE@ ErrnoCategory.lo wraptime.lo RTco.lo \
@BUILD_ISOLIB_TRUE@ libm2iso_la-wrapsock.lo
@BUILD_ISOLIB_TRUE@ SWholeIO.def SysClock.def \
@BUILD_ISOLIB_TRUE@ SYSTEM.def TermFile.def \
@BUILD_ISOLIB_TRUE@ TERMINATION.def TextIO.def \
+@BUILD_ISOLIB_TRUE@ TextUtil.def \
@BUILD_ISOLIB_TRUE@ WholeConv.def WholeIO.def \
@BUILD_ISOLIB_TRUE@ WholeStr.def wrapsock.def \
@BUILD_ISOLIB_TRUE@ wraptime.def
@BUILD_ISOLIB_TRUE@ SWholeIO.mod SysClock.mod \
@BUILD_ISOLIB_TRUE@ SYSTEM.mod TermFile.mod \
@BUILD_ISOLIB_TRUE@ TERMINATION.mod TextIO.mod \
+@BUILD_ISOLIB_TRUE@ TextUtil.mod \
@BUILD_ISOLIB_TRUE@ WholeConv.mod WholeIO.mod \
@BUILD_ISOLIB_TRUE@ WholeStr.mod
target_triplet = @target@
subdir = libm2log
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/multi.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../config/override.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
- $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
- $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am
target_triplet = @target@
subdir = libm2min
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/multi.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../config/override.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
- $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
- $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am
target_triplet = @target@
subdir = libm2pim
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
-am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
+am__aclocal_m4_deps = $(top_srcdir)/../libtool.m4 \
+ $(top_srcdir)/../ltoptions.m4 $(top_srcdir)/../ltsugar.m4 \
+ $(top_srcdir)/../ltversion.m4 $(top_srcdir)/../lt~obsolete.m4 \
+ $(top_srcdir)/../config/acx.m4 \
$(top_srcdir)/../config/depstand.m4 \
$(top_srcdir)/../config/lead-dot.m4 \
$(top_srcdir)/../config/multi.m4 \
$(top_srcdir)/../config/no-executables.m4 \
- $(top_srcdir)/../config/override.m4 \
- $(top_srcdir)/../libtool.m4 $(top_srcdir)/../ltoptions.m4 \
- $(top_srcdir)/../ltsugar.m4 $(top_srcdir)/../ltversion.m4 \
- $(top_srcdir)/../lt~obsolete.m4 $(top_srcdir)/configure.ac
+ $(top_srcdir)/../config/override.m4 $(top_srcdir)/configure.ac
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
DIST_COMMON = $(srcdir)/Makefile.am