xfail scan-tree-dump-not throw in g++.dg/pr99966.C on hppa*64*-*-*
[official-gcc.git] / gcc / m2 / gm2-libs / SFIO.mod
blob27ced001e62e517ef8b2c443bae13ff23b9cc6ee
1 (* SFIO.mod provides a String interface to the opening routines of FIO.
3 Copyright (C) 2001-2024 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. *)
27 IMPLEMENTATION MODULE SFIO ;
29 FROM ASCII IMPORT nul ;
31 FROM DynamicStrings IMPORT string, Length, InitString, ConCatChar,
32 InitStringDB, InitStringCharStarDB,
33 InitStringCharDB, MultDB, DupDB, SliceDB ;
35 FROM FIO IMPORT exists, openToRead, openToWrite, openForRandom, WriteNBytes, ReadChar,
36 EOLN, EOF, IsNoError ;
39 #undef GM2_DEBUG_SFIO
40 #if defined(GM2_DEBUG_SFIO)
41 # define InitString(X) InitStringDB(X, __FILE__, __LINE__)
42 # define InitStringCharStar(X) InitStringCharStarDB(X, __FILE__, __LINE__)
43 # define InitStringChar(X) InitStringCharDB(X, __FILE__, __LINE__)
44 # define Mult(X,Y) MultDB(X, Y, __FILE__, __LINE__)
45 # define Dup(X) DupDB(X, __FILE__, __LINE__)
46 # define Slice(X,Y,Z) SliceDB(X, Y, Z, __FILE__, __LINE__)
47 #endif
52 Exists - returns TRUE if a file named, fname exists for reading.
55 PROCEDURE Exists (fname: String) : BOOLEAN ;
56 BEGIN
57 RETURN exists (string (fname), Length (fname))
58 END Exists ;
62 OpenToRead - attempts to open a file, fname, for reading and
63 it returns this file.
64 The success of this operation can be checked by
65 calling IsNoError.
68 PROCEDURE OpenToRead (fname: String) : File ;
69 BEGIN
70 RETURN openToRead (string (fname), Length (fname))
71 END OpenToRead ;
75 OpenToWrite - attempts to open a file, fname, for write and
76 it returns this file.
77 The success of this operation can be checked by
78 calling IsNoError.
81 PROCEDURE OpenToWrite (fname: String) : File ;
82 BEGIN
83 RETURN openToWrite (string (fname), Length (fname))
84 END OpenToWrite ;
88 OpenForRandom - attempts to open a file, fname, for random access
89 read or write and it returns this file.
90 The success of this operation can be checked by
91 calling IsNoError.
92 towrite, determines whether the file should be
93 opened for writing or reading.
94 if towrite is TRUE or whether the previous file should
95 be left alone, allowing this descriptor to seek
96 and modify an existing file.
99 PROCEDURE OpenForRandom (fname: String; towrite, newfile: BOOLEAN) : File ;
100 BEGIN
101 RETURN openForRandom (string (fname), Length (fname), towrite, newfile)
102 END OpenForRandom ;
106 WriteS - writes a string, s, to, file. It returns the String, s.
109 PROCEDURE WriteS (file: File; s: String) : String ;
111 nBytes: CARDINAL ;
112 BEGIN
113 IF s#NIL
114 THEN
115 nBytes := WriteNBytes(file, Length(s), string(s))
116 END ;
117 RETURN( s )
118 END WriteS ;
122 ReadS - reads and returns a string from, file.
123 It stops reading the string at the end of line or end of file.
124 It consumes the newline at the end of line but does not place
125 this into the returned string.
128 PROCEDURE ReadS (file: File) : String ;
130 s: String ;
131 BEGIN
132 s := InitString ('') ;
133 WHILE (NOT EOLN (file)) AND (NOT EOF (file)) AND IsNoError (file) DO
134 s := ConCatChar (s, ReadChar (file))
135 END ;
136 IF EOLN (file)
137 THEN
138 (* consume nl *)
139 IF ReadChar (file) = nul
140 THEN
142 END ;
143 RETURN s
144 END ReadS ;
147 END SFIO.