1 (* FileSystem.def provides a PIM [234] FileSystem module.
3 Copyright (C) 2004-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)
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 FileSystem ;
29 (* Use this module sparingly, FIO or the ISO file modules have a
30 much cleaner interface. *)
32 FROM SYSTEM IMPORT WORD, BYTE, ADDRESS ;
34 FROM DynamicStrings IMPORT String ;
36 EXPORT QUALIFIED File, Response, Flag, FlagSet,
38 Create, Close, Lookup, Rename, Delete,
39 SetRead, SetWrite, SetModify, SetOpen,
40 Doio, SetPos, GetPos, Length, Reset,
42 ReadWord, ReadChar, ReadByte, ReadNBytes,
43 WriteWord, WriteChar, WriteByte, WriteNBytes ;
59 read, (* read access mode *)
60 write, (* write access mode *)
62 truncate, (* truncate file when closed *)
63 again, (* reread the last character *)
64 temporary, (* file is temporary *)
65 opened (* file has been opened *)
68 FlagSet = SET OF Flag;
70 Response = (done, notdone, notsupported, callerror,
71 unknownfile, paramerror, toomanyfiles,
74 Command = (create, close, lookup, rename, delete,
75 setread, setwrite, setmodify, setopen,
76 doio, setpos, getpos, length) ;
80 Create - creates a temporary file. To make the file perminant
81 the file must be renamed.
84 PROCEDURE Create (VAR f: File) ;
88 Close - closes an open file.
91 PROCEDURE Close (f: File) ;
95 Lookup - looks for a file, filename. If the file is found
96 then, f, is opened. If it is not found and, newFile,
97 is TRUE then a new file is created and attached to, f.
98 If, newFile, is FALSE and no file was found then f.res
102 PROCEDURE Lookup (VAR f: File; filename: ARRAY OF CHAR; newFile: BOOLEAN) ;
106 Rename - rename a file and change a temporary file to a permanent
107 file. f.res is set appropriately.
110 PROCEDURE Rename (VAR f: File; newname: ARRAY OF CHAR) ;
114 Delete - deletes a file, name, and sets the f.res field.
115 f.res is set appropriately.
118 PROCEDURE Delete (name: ARRAY OF CHAR; VAR f: File) ;
122 ReadWord - reads a WORD, w, from file, f.
123 f.res is set appropriately.
126 PROCEDURE ReadWord (VAR f: File; VAR w: WORD) ;
130 WriteWord - writes one word to a file, f.
131 f.res is set appropriately.
134 PROCEDURE WriteWord (VAR f: File; w: WORD) ;
138 ReadChar - reads one character from a file, f.
141 PROCEDURE ReadChar (VAR f: File; VAR ch: CHAR) ;
145 WriteChar - writes a character, ch, to a file, f.
146 f.res is set appropriately.
149 PROCEDURE WriteChar (VAR f: File; ch: CHAR) ;
153 ReadByte - reads a BYTE, b, from file, f.
154 f.res is set appropriately.
157 PROCEDURE ReadByte (VAR f: File; VAR b: BYTE) ;
161 WriteByte - writes one BYTE, b, to a file, f.
162 f.res is set appropriately.
165 PROCEDURE WriteByte (VAR f: File; b: BYTE) ;
169 ReadNBytes - reads a sequence of bytes from a file, f.
172 PROCEDURE ReadNBytes (VAR f: File; a: ADDRESS; amount: CARDINAL;
173 VAR actuallyRead: CARDINAL) ;
177 WriteNBytes - writes a sequence of bytes to file, f.
180 PROCEDURE WriteNBytes (VAR f: File; a: ADDRESS; amount: CARDINAL;
181 VAR actuallyWritten: CARDINAL) ;
185 Again - returns the last character read to the internal buffer
186 so that it can be read again.
189 PROCEDURE Again (VAR f: File) ;
193 SetRead - puts the file, f, into the read state.
194 The file position is unchanged.
197 PROCEDURE SetRead (VAR f: File) ;
201 SetWrite - puts the file, f, into the write state.
202 The file position is unchanged.
205 PROCEDURE SetWrite (VAR f: File) ;
209 SetModify - puts the file, f, into the modify state.
210 The file position is unchanged but the file can be
214 PROCEDURE SetModify (VAR f: File) ;
218 SetOpen - places a file, f, into the open state. The file may
219 have been in the read/write/modify state before and
220 in which case the previous buffer contents are flushed
221 and the file state is reset to open. The position is
225 PROCEDURE SetOpen (VAR f: File) ;
229 Reset - places a file, f, into the open state and reset the
230 position to the start of the file.
233 PROCEDURE Reset (VAR f: File) ;
237 SetPos - lseek to a position within a file.
240 PROCEDURE SetPos (VAR f: File; high, low: CARDINAL) ;
244 GetPos - return the position within a file.
247 PROCEDURE GetPos (VAR f: File; VAR high, low: CARDINAL) ;
251 Length - returns the length of file, in, high, and, low.
254 PROCEDURE Length (VAR f: File; VAR high, low: CARDINAL) ;
258 Doio - effectively flushes a file in write mode, rereads the
259 current buffer from disk if in read mode and writes
260 and rereads the buffer if in modify mode.
263 PROCEDURE Doio (VAR f: File) ;
267 FileNameChar - checks to see whether the character, ch, is
268 legal in a filename. nul is returned if the
269 character was illegal.
272 PROCEDURE FileNameChar (ch: CHAR) ;