| 1 |
(* Library module defined by the International Standard |
| 2 |
Information technology - programming languages |
| 3 |
BS ISO/IEC 10514-1:1996E Part 1: Modula-2, Base Language. |
| 4 |
|
| 5 |
Copyright ISO/IEC (International Organization for Standardization |
| 6 |
and International Electrotechnical Commission) 1996-2021. |
| 7 |
|
| 8 |
It may be freely copied for the purpose of implementation (see page |
| 9 |
707 of the Information technology - Programming languages Part 1: |
| 10 |
Modula-2, Base Language. BS ISO/IEC 10514-1:1996). *) |
| 11 |
|
| 12 |
DEFINITION MODULE TermFile; |
| 13 |
|
| 14 |
(* Access to the terminal device *) |
| 15 |
|
| 16 |
(* Channels opened by this module are connected to a single |
| 17 |
terminal device; typed characters are distributed between |
| 18 |
channels according to the sequence of read requests. |
| 19 |
*) |
| 20 |
|
| 21 |
IMPORT IOChan, ChanConsts; |
| 22 |
|
| 23 |
TYPE |
| 24 |
ChanId = IOChan.ChanId; |
| 25 |
FlagSet = ChanConsts.FlagSet; |
| 26 |
OpenResults = ChanConsts.OpenResults; |
| 27 |
|
| 28 |
(* Accepted singleton values of FlagSet *) |
| 29 |
|
| 30 |
CONST |
| 31 |
read = FlagSet{ChanConsts.readFlag}; |
| 32 |
(* input operations are requested/available *) |
| 33 |
write = FlagSet{ChanConsts.writeFlag}; |
| 34 |
(* output operations are requested/available *) |
| 35 |
text = FlagSet{ChanConsts.textFlag}; |
| 36 |
(* text operations are requested/available *) |
| 37 |
raw = FlagSet{ChanConsts.rawFlag}; |
| 38 |
(* raw operations are requested/available *) |
| 39 |
echo = FlagSet{ChanConsts.echoFlag}; |
| 40 |
(* echoing by interactive device on reading of |
| 41 |
characters from input stream requested/applies |
| 42 |
*) |
| 43 |
|
| 44 |
PROCEDURE Open (VAR cid: ChanId; flagset: FlagSet; VAR res: OpenResults); |
| 45 |
(* Attempts to obtain and open a channel connected to |
| 46 |
the terminal. Without the raw flag, text is implied. |
| 47 |
Without the echo flag, line mode is requested, |
| 48 |
otherwise single character mode is requested. |
| 49 |
If successful, assigns to cid the identity of |
| 50 |
the opened channel, and assigns the value opened to res. |
| 51 |
If a channel cannot be opened as required, the value of |
| 52 |
res indicates the reason, and cid identifies the |
| 53 |
invalid channel. |
| 54 |
*) |
| 55 |
|
| 56 |
PROCEDURE IsTermFile (cid: ChanId): BOOLEAN; |
| 57 |
(* Tests if the channel identified by cid is open to |
| 58 |
the terminal. *) |
| 59 |
|
| 60 |
PROCEDURE Close (VAR cid: ChanId); |
| 61 |
(* If the channel identified by cid is not open to the terminal, |
| 62 |
the exception wrongDevice is raised; otherwise closes the |
| 63 |
channel and assigns the value identifying the invalid channel |
| 64 |
to cid. |
| 65 |
*) |
| 66 |
|
| 67 |
END TermFile. |
| 68 |
|