| 1 |
(* Terminal.mod provides a Logitech 3.0 compatible and PIM [234] compatible. |
| 2 |
|
| 3 |
Copyright (C) 2004-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 Terminal ; |
| 28 |
|
| 29 |
IMPORT Termbase ; |
| 30 |
FROM ASCII IMPORT nul, cr, tab, lf ; |
| 31 |
|
| 32 |
|
| 33 |
(* |
| 34 |
Read - reads a single character, ch, from the underlying Termbase |
| 35 |
module. |
| 36 |
*) |
| 37 |
|
| 38 |
PROCEDURE Read (VAR ch: CHAR) ; |
| 39 |
BEGIN |
| 40 |
Termbase.Read(ch) |
| 41 |
END Read ; |
| 42 |
|
| 43 |
|
| 44 |
(* |
| 45 |
ReadAgain - makes the last character readable again. |
| 46 |
*) |
| 47 |
|
| 48 |
PROCEDURE ReadAgain ; |
| 49 |
BEGIN |
| 50 |
END ReadAgain ; |
| 51 |
|
| 52 |
|
| 53 |
(* |
| 54 |
KeyPressed - returns TRUE if a character can be read without blocking |
| 55 |
the caller. |
| 56 |
*) |
| 57 |
|
| 58 |
PROCEDURE KeyPressed () : BOOLEAN ; |
| 59 |
BEGIN |
| 60 |
RETURN( Termbase.KeyPressed() ) |
| 61 |
END KeyPressed ; |
| 62 |
|
| 63 |
|
| 64 |
(* |
| 65 |
Write - writes a single character to the Termbase module. |
| 66 |
*) |
| 67 |
|
| 68 |
PROCEDURE Write (ch: CHAR) ; |
| 69 |
BEGIN |
| 70 |
Termbase.Write(ch) |
| 71 |
END Write ; |
| 72 |
|
| 73 |
|
| 74 |
(* |
| 75 |
ReadString - reads a sequence of characters. |
| 76 |
Tabs are expanded into 8 spaces and <cr> or <lf> terminates |
| 77 |
the string. |
| 78 |
*) |
| 79 |
|
| 80 |
PROCEDURE ReadString (VAR s: ARRAY OF CHAR) ; |
| 81 |
VAR |
| 82 |
t, h, i: CARDINAL ; |
| 83 |
BEGIN |
| 84 |
i := 0 ; |
| 85 |
h := HIGH(s) ; |
| 86 |
IF i<=h |
| 87 |
THEN |
| 88 |
REPEAT |
| 89 |
Read(s[i]) ; |
| 90 |
IF (s[i]=cr) OR (s[i]=lf) |
| 91 |
THEN |
| 92 |
s[i] := nul ; |
| 93 |
(* successful *) |
| 94 |
RETURN |
| 95 |
ELSIF s[i]=tab |
| 96 |
THEN |
| 97 |
t := 0 ; |
| 98 |
REPEAT |
| 99 |
s[i] := ' ' ; |
| 100 |
INC(i) ; |
| 101 |
IF i>h |
| 102 |
THEN |
| 103 |
RETURN |
| 104 |
END ; |
| 105 |
INC(t) |
| 106 |
UNTIL t=8 |
| 107 |
END ; |
| 108 |
INC(i) |
| 109 |
UNTIL i>h |
| 110 |
END |
| 111 |
END ReadString ; |
| 112 |
|
| 113 |
|
| 114 |
(* |
| 115 |
WriteString - writes out a string which is terminated by a <nul> |
| 116 |
character or the end of string HIGH(s). |
| 117 |
*) |
| 118 |
|
| 119 |
PROCEDURE WriteString (s: ARRAY OF CHAR) ; |
| 120 |
VAR |
| 121 |
i, h: CARDINAL ; |
| 122 |
BEGIN |
| 123 |
h := HIGH(s) ; |
| 124 |
i := 0 ; |
| 125 |
WHILE (i<=h) AND (s[i]#nul) DO |
| 126 |
Write(s[i]) ; |
| 127 |
INC(i) |
| 128 |
END |
| 129 |
END WriteString ; |
| 130 |
|
| 131 |
|
| 132 |
(* |
| 133 |
WriteLn - writes a lf character. |
| 134 |
*) |
| 135 |
|
| 136 |
PROCEDURE WriteLn ; |
| 137 |
BEGIN |
| 138 |
Write(lf) |
| 139 |
END WriteLn ; |
| 140 |
|
| 141 |
|
| 142 |
END Terminal. |