libstdc++: Include cstdarg in freestanding
[official-gcc.git] / gcc / m2 / gm2-libs / FIO.def
blobf4c201fe31d01a44ddb968cffedf1a0f4354ba2f
1 (* FIO.def provides a simple buffered file input/output library.
3 Copyright (C) 2001-2023 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 DEFINITION MODULE FIO ;
29 (* Provides a simple buffered file input/output library. *)
32 FROM SYSTEM IMPORT ADDRESS, BYTE ;
34 EXPORT QUALIFIED (* types *)
35 File,
36 (* procedures *)
37 OpenToRead, OpenToWrite, OpenForRandom, Close,
38 EOF, EOLN, WasEOLN, IsNoError, Exists, IsActive,
39 exists, openToRead, openToWrite, openForRandom,
40 SetPositionFromBeginning,
41 SetPositionFromEnd,
42 FindPosition,
43 ReadChar, ReadString,
44 WriteChar, WriteString, WriteLine,
45 WriteCardinal, ReadCardinal,
46 UnReadChar,
47 WriteNBytes, ReadNBytes,
48 FlushBuffer,
49 GetUnixFileDescriptor,
50 GetFileName, getFileName, getFileNameLength,
51 FlushOutErr,
52 (* variables *)
53 StdIn, StdOut, StdErr ;
55 TYPE
56 File = CARDINAL ;
58 (* the following variables are initialized to their UNIX equivalents *)
59 VAR
60 StdIn, StdOut, StdErr: File ;
65 IsNoError - returns a TRUE if no error has occured on file, f.
68 PROCEDURE IsNoError (f: File) : BOOLEAN ;
72 IsActive - returns TRUE if the file, f, is still active.
75 PROCEDURE IsActive (f: File) : BOOLEAN ;
79 Exists - returns TRUE if a file named, fname exists for reading.
82 PROCEDURE Exists (fname: ARRAY OF CHAR) : BOOLEAN ;
86 OpenToRead - attempts to open a file, fname, for reading and
87 it returns this file.
88 The success of this operation can be checked by
89 calling IsNoError.
92 PROCEDURE OpenToRead (fname: ARRAY OF CHAR) : File ;
96 OpenToWrite - attempts to open a file, fname, for write and
97 it returns this file.
98 The success of this operation can be checked by
99 calling IsNoError.
102 PROCEDURE OpenToWrite (fname: ARRAY OF CHAR) : File ;
106 OpenForRandom - attempts to open a file, fname, for random access
107 read or write and it returns this file.
108 The success of this operation can be checked by
109 calling IsNoError.
110 towrite, determines whether the file should be
111 opened for writing or reading.
112 newfile, determines whether a file should be
113 created if towrite is TRUE or whether the
114 previous file should be left alone,
115 allowing this descriptor to seek
116 and modify an existing file.
119 PROCEDURE OpenForRandom (fname: ARRAY OF CHAR;
120 towrite, newfile: BOOLEAN) : File ;
124 Close - close a file which has been previously opened using:
125 OpenToRead, OpenToWrite, OpenForRandom.
126 It is correct to close a file which has an error status.
129 PROCEDURE Close (f: File) ;
132 (* the following functions are functionally equivalent to the above
133 except they allow C style names.
136 PROCEDURE exists (fname: ADDRESS; flength: CARDINAL) : BOOLEAN ;
137 PROCEDURE openToRead (fname: ADDRESS; flength: CARDINAL) : File ;
138 PROCEDURE openToWrite (fname: ADDRESS; flength: CARDINAL) : File ;
139 PROCEDURE openForRandom (fname: ADDRESS; flength: CARDINAL;
140 towrite, newfile: BOOLEAN) : File ;
144 FlushBuffer - flush contents of the FIO file, f, to libc.
147 PROCEDURE FlushBuffer (f: File) ;
151 ReadNBytes - reads nBytes of a file into memory area, dest, returning
152 the number of bytes actually read.
153 This function will consume from the buffer and then
154 perform direct libc reads. It is ideal for large reads.
157 PROCEDURE ReadNBytes (f: File; nBytes: CARDINAL;
158 dest: ADDRESS) : CARDINAL ;
162 ReadAny - reads HIGH (a) + 1 bytes into, a. All input
163 is fully buffered, unlike ReadNBytes and thus is more
164 suited to small reads.
167 PROCEDURE ReadAny (f: File; VAR a: ARRAY OF BYTE) ;
171 WriteNBytes - writes nBytes from memory area src to a file
172 returning the number of bytes actually written.
173 This function will flush the buffer and then
174 write the nBytes using a direct write from libc.
175 It is ideal for large writes.
178 PROCEDURE WriteNBytes (f: File; nBytes: CARDINAL;
179 src: ADDRESS) : CARDINAL ;
183 WriteAny - writes HIGH (a) + 1 bytes onto, file, f. All output
184 is fully buffered, unlike WriteNBytes and thus is more
185 suited to small writes.
188 PROCEDURE WriteAny (f: File; VAR a: ARRAY OF BYTE) ;
192 WriteChar - writes a single character to file, f.
195 PROCEDURE WriteChar (f: File; ch: CHAR) ;
199 EOF - tests to see whether a file, f, has reached end of file.
202 PROCEDURE EOF (f: File) : BOOLEAN ;
206 EOLN - tests to see whether a file, f, is about to read a newline.
207 It does NOT consume the newline. It reads the next character
208 and then immediately unreads the character.
211 PROCEDURE EOLN (f: File) : BOOLEAN ;
215 WasEOLN - tests to see whether a file, f, has just read a newline
216 character.
219 PROCEDURE WasEOLN (f: File) : BOOLEAN ;
223 ReadChar - returns a character read from file, f.
224 Sensible to check with IsNoError or EOF after calling
225 this function.
228 PROCEDURE ReadChar (f: File) : CHAR ;
232 UnReadChar - replaces a character, ch, back into file, f.
233 This character must have been read by ReadChar
234 and it does not allow successive calls. It may
235 only be called if the previous read was successful,
236 end of file or end of line seen.
239 PROCEDURE UnReadChar (f: File ; ch: CHAR) ;
243 WriteLine - writes out a linefeed to file, f.
246 PROCEDURE WriteLine (f: File) ;
250 WriteString - writes a string to file, f.
253 PROCEDURE WriteString (f: File; a: ARRAY OF CHAR) ;
257 ReadString - reads a string from file, f, into string, a.
258 It terminates the string if HIGH is reached or
259 if a newline is seen or an error occurs.
262 PROCEDURE ReadString (f: File; VAR a: ARRAY OF CHAR) ;
266 WriteCardinal - writes a CARDINAL to file, f.
267 It writes the binary image of the CARDINAL.
268 to file, f.
271 PROCEDURE WriteCardinal (f: File; c: CARDINAL) ;
275 ReadCardinal - reads a CARDINAL from file, f.
276 It reads a bit image of a CARDINAL
277 from file, f.
280 PROCEDURE ReadCardinal (f: File) : CARDINAL ;
284 GetUnixFileDescriptor - returns the UNIX file descriptor of a file.
285 Useful when combining FIO.mod with select
286 (in Selective.def - but note the comments in
287 Selective about using read/write primatives)
290 PROCEDURE GetUnixFileDescriptor (f: File) : INTEGER ;
294 SetPositionFromBeginning - sets the position from the beginning
295 of the file.
298 PROCEDURE SetPositionFromBeginning (f: File; pos: LONGINT) ;
302 SetPositionFromEnd - sets the position from the end of the file.
305 PROCEDURE SetPositionFromEnd (f: File; pos: LONGINT) ;
309 FindPosition - returns the current absolute position in file, f.
312 PROCEDURE FindPosition (f: File) : LONGINT ;
316 GetFileName - assigns, a, with the filename associated with, f.
319 PROCEDURE GetFileName (f: File; VAR a: ARRAY OF CHAR) ;
323 getFileName - returns the address of the filename associated with, f.
326 PROCEDURE getFileName (f: File) : ADDRESS ;
330 getFileNameLength - returns the number of characters associated with
331 filename, f.
334 PROCEDURE getFileNameLength (f: File) : CARDINAL ;
338 FlushOutErr - flushes, StdOut, and, StdErr.
341 PROCEDURE FlushOutErr ;
344 END FIO.