| 1 |
(* RTfio.mod implement default FIO based methods. |
| 2 |
|
| 3 |
Copyright (C) 2008-2025 Free Software Foundation, Inc. |
| 4 |
Contributed by Gaius Mulley <[email protected]>. |
| 5 |
|
| 6 |
This file is part of GNU Modula-2. |
| 7 |
|
| 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. |
| 12 |
|
| 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. |
| 17 |
|
| 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. |
| 21 |
|
| 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/>. *) |
| 26 |
|
| 27 |
IMPLEMENTATION MODULE RTfio ; |
| 28 |
|
| 29 |
FROM RTio IMPORT GetFile ; |
| 30 |
FROM errno IMPORT geterrno ; |
| 31 |
|
| 32 |
FROM FIO IMPORT File, ReadChar, UnReadChar, WriteChar, ReadNBytes, |
| 33 |
WriteNBytes, IsActive, |
| 34 |
WriteLine, EOF, WasEOLN, IsNoError ; |
| 35 |
|
| 36 |
|
| 37 |
(* |
| 38 |
doreadchar - returns a CHAR from the file associated with, g. |
| 39 |
*) |
| 40 |
|
| 41 |
PROCEDURE doreadchar (g: GenDevIF; d: DeviceTablePtr) : CHAR ; |
| 42 |
VAR |
| 43 |
f: File ; |
| 44 |
BEGIN |
| 45 |
WITH d^ DO |
| 46 |
f := GetFile(cid) ; |
| 47 |
RETURN( ReadChar(f) ) |
| 48 |
END |
| 49 |
END doreadchar ; |
| 50 |
|
| 51 |
|
| 52 |
(* |
| 53 |
dounreadchar - pushes a CHAR back onto the file associated with, g. |
| 54 |
*) |
| 55 |
|
| 56 |
PROCEDURE dounreadchar (g: GenDevIF; d: DeviceTablePtr; ch: CHAR) : CHAR ; |
| 57 |
VAR |
| 58 |
f: File ; |
| 59 |
BEGIN |
| 60 |
WITH d^ DO |
| 61 |
f := GetFile(cid) ; |
| 62 |
UnReadChar(f, ch) ; |
| 63 |
RETURN( ch ) |
| 64 |
END |
| 65 |
END dounreadchar ; |
| 66 |
|
| 67 |
|
| 68 |
(* |
| 69 |
dogeterrno - returns the errno relating to the generic device. |
| 70 |
*) |
| 71 |
|
| 72 |
PROCEDURE dogeterrno (g: GenDevIF; d: DeviceTablePtr) : INTEGER ; |
| 73 |
BEGIN |
| 74 |
RETURN geterrno() |
| 75 |
END dogeterrno ; |
| 76 |
|
| 77 |
|
| 78 |
(* |
| 79 |
dorbytes - reads upto, max, bytes setting, actual, and |
| 80 |
returning FALSE if an error (not due to eof) |
| 81 |
occurred. |
| 82 |
*) |
| 83 |
|
| 84 |
PROCEDURE dorbytes (g: GenDevIF; d: DeviceTablePtr; |
| 85 |
to: ADDRESS; |
| 86 |
max: CARDINAL; |
| 87 |
VAR actual: CARDINAL) : BOOLEAN ; |
| 88 |
VAR |
| 89 |
f: File ; |
| 90 |
BEGIN |
| 91 |
WITH d^ DO |
| 92 |
f := GetFile(cid) ; |
| 93 |
actual := ReadNBytes(f, max, to) ; |
| 94 |
RETURN( IsNoError(f) ) |
| 95 |
END |
| 96 |
END dorbytes ; |
| 97 |
|
| 98 |
|
| 99 |
(* |
| 100 |
dowbytes - |
| 101 |
*) |
| 102 |
|
| 103 |
PROCEDURE dowbytes (g: GenDevIF; d: DeviceTablePtr; |
| 104 |
from: ADDRESS; |
| 105 |
nBytes: CARDINAL; |
| 106 |
VAR actual: CARDINAL) : BOOLEAN ; |
| 107 |
VAR |
| 108 |
f: File ; |
| 109 |
BEGIN |
| 110 |
WITH d^ DO |
| 111 |
f := GetFile(cid) ; |
| 112 |
actual := WriteNBytes(f, nBytes, from) ; |
| 113 |
RETURN( IsNoError(f) ) |
| 114 |
END |
| 115 |
END dowbytes ; |
| 116 |
|
| 117 |
|
| 118 |
(* |
| 119 |
dowriteln - attempt to write an end of line marker to the |
| 120 |
file and returns TRUE if successful. |
| 121 |
*) |
| 122 |
|
| 123 |
PROCEDURE dowriteln (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; |
| 124 |
VAR |
| 125 |
f: File ; |
| 126 |
BEGIN |
| 127 |
f := GetFile(d^.cid) ; |
| 128 |
WriteLine(f) ; |
| 129 |
RETURN( IsNoError(f) ) |
| 130 |
END dowriteln ; |
| 131 |
|
| 132 |
|
| 133 |
(* |
| 134 |
iseof - returns TRUE if end of file has been seen. |
| 135 |
*) |
| 136 |
|
| 137 |
PROCEDURE iseof (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; |
| 138 |
VAR |
| 139 |
f: File ; |
| 140 |
BEGIN |
| 141 |
WITH d^ DO |
| 142 |
f := GetFile(cid) ; |
| 143 |
RETURN( EOF(f) ) |
| 144 |
END |
| 145 |
END iseof ; |
| 146 |
|
| 147 |
|
| 148 |
(* |
| 149 |
iseoln - returns TRUE if end of line is seen. |
| 150 |
*) |
| 151 |
|
| 152 |
PROCEDURE iseoln (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; |
| 153 |
VAR |
| 154 |
f: File ; |
| 155 |
BEGIN |
| 156 |
WITH d^ DO |
| 157 |
f := GetFile(cid) ; |
| 158 |
RETURN( WasEOLN(f) ) |
| 159 |
END |
| 160 |
END iseoln ; |
| 161 |
|
| 162 |
|
| 163 |
(* |
| 164 |
iserror - returns TRUE if an error was seen on the device. |
| 165 |
*) |
| 166 |
|
| 167 |
PROCEDURE iserror (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; |
| 168 |
VAR |
| 169 |
f: File ; |
| 170 |
BEGIN |
| 171 |
WITH d^ DO |
| 172 |
f := GetFile(cid) ; |
| 173 |
RETURN( IsActive(f) AND (NOT IsNoError(f)) ) |
| 174 |
END |
| 175 |
END iserror ; |
| 176 |
|
| 177 |
|
| 178 |
END RTfio. |