1 (* RTgenif.mod implement a generic device interface mechanism used by RTgen.
3 Copyright (C) 2008-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 IMPLEMENTATION MODULE RTgenif
;
29 FROM Storage
IMPORT ALLOCATE
, DEALLOCATE
;
32 GenDevIF
= POINTER TO RECORD
36 dogeterrno
: geterrno
;
37 dorbytes
: readbytes
;
38 dowbytes
: writebytes
;
47 InitGenDev - initializes a generic device.
50 PROCEDURE InitGenDevIF (d
: DeviceId
;
59 iserr
: iserror
) : GenDevIF
;
68 dogeterrno
:= geterr
;
81 getDID - returns the device id belonging to this generic interface.
84 PROCEDURE getDID (g
: GenDevIF
) : DeviceId
;
91 doReadChar - returns the next character from the generic device.
94 PROCEDURE doReadChar (g
: GenDevIF
; d
: DeviceTablePtr
) : CHAR ;
96 RETURN( g^.
dorc(g
, d
) )
101 doUnReadChar - pushes back a character to the generic device.
104 PROCEDURE doUnReadChar (g
: GenDevIF
; d
: DeviceTablePtr
; ch
: CHAR) : CHAR ;
106 RETURN( g^.
dourc(g
, d
, ch
) )
111 doGetErrno - returns the errno relating to the generic device.
114 PROCEDURE doGetErrno (g
: GenDevIF
; d
: DeviceTablePtr
) : INTEGER ;
116 RETURN( g^.
dogeterrno(g
, d
) )
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.
126 PROCEDURE doRBytes (g
: GenDevIF
; d
: DeviceTablePtr
;
127 to
: ADDRESS
; max
: CARDINAL;
128 VAR actual
: CARDINAL) : BOOLEAN ;
130 RETURN( g^.
dorbytes(g
, d
, to
, max
, actual
) )
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.
140 PROCEDURE doWBytes (g
: GenDevIF
; d
: DeviceTablePtr
;
141 from
: ADDRESS
; max
: CARDINAL;
142 VAR actual
: CARDINAL) : BOOLEAN ;
144 RETURN( g^.
dowbytes(g
, d
, from
, max
, actual
) )
149 doWrLn - writes an end of line marker and returns
153 PROCEDURE doWrLn (g
: GenDevIF
; d
: DeviceTablePtr
) : BOOLEAN ;
155 RETURN( g^.
dowrln(g
, d
) )
160 isEOF - returns true if the end of file was reached.
163 PROCEDURE isEOF (g
: GenDevIF
; d
: DeviceTablePtr
) : BOOLEAN ;
165 RETURN( g^.
doeof(g
, d
) )
170 isEOLN - returns true if the end of line was reached.
173 PROCEDURE isEOLN (g
: GenDevIF
; d
: DeviceTablePtr
) : BOOLEAN ;
175 RETURN( g^.
doeoln(g
, d
) )
180 isError - returns true if an error was seen in the device.
183 PROCEDURE isError (g
: GenDevIF
; d
: DeviceTablePtr
) : BOOLEAN ;
185 RETURN( g^.
doerror(g
, d
) )
190 KillGenDevIF - deallocates a generic device.
193 PROCEDURE KillGenDevIF (g
: GenDevIF
) : GenDevIF
;