| 1 |
(* RTgenif.mod implement a generic device interface mechanism used by RTgen. |
| 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 RTgenif ; |
| 28 |
|
| 29 |
FROM Storage IMPORT ALLOCATE, DEALLOCATE ; |
| 30 |
|
| 31 |
TYPE |
| 32 |
GenDevIF = POINTER TO RECORD |
| 33 |
did : DeviceId ; |
| 34 |
dorc : readchar ; |
| 35 |
dourc : unreadchar ; |
| 36 |
dogeterrno: geterrno ; |
| 37 |
dorbytes : readbytes ; |
| 38 |
dowbytes : writebytes ; |
| 39 |
dowrln : writeln; |
| 40 |
doeof : iseof ; |
| 41 |
doeoln : iseoln ; |
| 42 |
doerror : iserror ; |
| 43 |
END ; |
| 44 |
|
| 45 |
|
| 46 |
(* |
| 47 |
InitGenDev - initializes a generic device. |
| 48 |
*) |
| 49 |
|
| 50 |
PROCEDURE InitGenDevIF (d : DeviceId; |
| 51 |
rc : readchar; |
| 52 |
urc : unreadchar; |
| 53 |
geterr: geterrno; |
| 54 |
rbytes: readbytes; |
| 55 |
wbytes: writebytes; |
| 56 |
wl : writeln; |
| 57 |
eof : iseof; |
| 58 |
eoln : iseoln; |
| 59 |
iserr : iserror) : GenDevIF ; |
| 60 |
VAR |
| 61 |
g: GenDevIF ; |
| 62 |
BEGIN |
| 63 |
NEW(g) ; |
| 64 |
WITH g^ DO |
| 65 |
did := d ; |
| 66 |
dorc := rc ; |
| 67 |
dourc := urc ; |
| 68 |
dogeterrno := geterr ; |
| 69 |
dorbytes := rbytes ; |
| 70 |
dowbytes := wbytes ; |
| 71 |
dowrln := wl ; |
| 72 |
doeof := eof ; |
| 73 |
doeoln := eoln ; |
| 74 |
doerror := iserr |
| 75 |
END ; |
| 76 |
RETURN( g ) |
| 77 |
END InitGenDevIF ; |
| 78 |
|
| 79 |
|
| 80 |
(* |
| 81 |
getDID - returns the device id belonging to this generic interface. |
| 82 |
*) |
| 83 |
|
| 84 |
PROCEDURE getDID (g: GenDevIF) : DeviceId ; |
| 85 |
BEGIN |
| 86 |
RETURN( g^.did ) |
| 87 |
END getDID ; |
| 88 |
|
| 89 |
|
| 90 |
(* |
| 91 |
doReadChar - returns the next character from the generic device. |
| 92 |
*) |
| 93 |
|
| 94 |
PROCEDURE doReadChar (g: GenDevIF; d: DeviceTablePtr) : CHAR ; |
| 95 |
BEGIN |
| 96 |
RETURN( g^.dorc(g, d) ) |
| 97 |
END doReadChar ; |
| 98 |
|
| 99 |
|
| 100 |
(* |
| 101 |
doUnReadChar - pushes back a character to the generic device. |
| 102 |
*) |
| 103 |
|
| 104 |
PROCEDURE doUnReadChar (g: GenDevIF; d: DeviceTablePtr; ch: CHAR) : CHAR ; |
| 105 |
BEGIN |
| 106 |
RETURN( g^.dourc(g, d, ch) ) |
| 107 |
END doUnReadChar ; |
| 108 |
|
| 109 |
|
| 110 |
(* |
| 111 |
doGetErrno - returns the errno relating to the generic device. |
| 112 |
*) |
| 113 |
|
| 114 |
PROCEDURE doGetErrno (g: GenDevIF; d: DeviceTablePtr) : INTEGER ; |
| 115 |
BEGIN |
| 116 |
RETURN( g^.dogeterrno(g, d) ) |
| 117 |
END doGetErrno ; |
| 118 |
|
| 119 |
|
| 120 |
(* |
| 121 |
doRBytes - attempts to read, n, bytes from the generic device. |
| 122 |
It set the actual amount read and returns a boolean |
| 123 |
to determine whether an error occurred. |
| 124 |
*) |
| 125 |
|
| 126 |
PROCEDURE doRBytes (g: GenDevIF; d: DeviceTablePtr; |
| 127 |
to: ADDRESS; max: CARDINAL; |
| 128 |
VAR actual: CARDINAL) : BOOLEAN ; |
| 129 |
BEGIN |
| 130 |
RETURN( g^.dorbytes(g, d, to, max, actual) ) |
| 131 |
END doRBytes ; |
| 132 |
|
| 133 |
|
| 134 |
(* |
| 135 |
doWBytes - attempts to write, n, bytes to the generic device. |
| 136 |
It sets the actual amount written and returns a |
| 137 |
boolean to determine whether an error occurred. |
| 138 |
*) |
| 139 |
|
| 140 |
PROCEDURE doWBytes (g: GenDevIF; d: DeviceTablePtr; |
| 141 |
from: ADDRESS; max: CARDINAL; |
| 142 |
VAR actual: CARDINAL) : BOOLEAN ; |
| 143 |
BEGIN |
| 144 |
RETURN( g^.dowbytes(g, d, from, max, actual) ) |
| 145 |
END doWBytes ; |
| 146 |
|
| 147 |
|
| 148 |
(* |
| 149 |
doWrLn - writes an end of line marker and returns |
| 150 |
TRUE if successful. |
| 151 |
*) |
| 152 |
|
| 153 |
PROCEDURE doWrLn (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; |
| 154 |
BEGIN |
| 155 |
RETURN( g^.dowrln(g, d) ) |
| 156 |
END doWrLn ; |
| 157 |
|
| 158 |
|
| 159 |
(* |
| 160 |
isEOF - returns true if the end of file was reached. |
| 161 |
*) |
| 162 |
|
| 163 |
PROCEDURE isEOF (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; |
| 164 |
BEGIN |
| 165 |
RETURN( g^.doeof(g, d) ) |
| 166 |
END isEOF ; |
| 167 |
|
| 168 |
|
| 169 |
(* |
| 170 |
isEOLN - returns true if the end of line was reached. |
| 171 |
*) |
| 172 |
|
| 173 |
PROCEDURE isEOLN (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; |
| 174 |
BEGIN |
| 175 |
RETURN( g^.doeoln(g, d) ) |
| 176 |
END isEOLN ; |
| 177 |
|
| 178 |
|
| 179 |
(* |
| 180 |
isError - returns true if an error was seen in the device. |
| 181 |
*) |
| 182 |
|
| 183 |
PROCEDURE isError (g: GenDevIF; d: DeviceTablePtr) : BOOLEAN ; |
| 184 |
BEGIN |
| 185 |
RETURN( g^.doerror(g, d) ) |
| 186 |
END isError ; |
| 187 |
|
| 188 |
|
| 189 |
(* |
| 190 |
KillGenDevIF - deallocates a generic device. |
| 191 |
*) |
| 192 |
|
| 193 |
PROCEDURE KillGenDevIF (g: GenDevIF) : GenDevIF ; |
| 194 |
BEGIN |
| 195 |
DISPOSE(g) ; |
| 196 |
RETURN( NIL ) |
| 197 |
END KillGenDevIF ; |
| 198 |
|
| 199 |
|
| 200 |
END RTgenif. |