1987-05-13 14:36:45 +00:00
|
|
|
#
|
1988-02-19 15:54:01 +00:00
|
|
|
(*
|
|
|
|
(c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands.
|
|
|
|
See the copyright notice in the ACK home directory, in the file "Copyright".
|
|
|
|
*)
|
|
|
|
|
1987-08-19 18:07:01 +00:00
|
|
|
(*$R-*)
|
1987-05-13 14:36:45 +00:00
|
|
|
IMPLEMENTATION MODULE Terminal;
|
1988-02-19 15:54:01 +00:00
|
|
|
(*
|
|
|
|
Module: Input/Output to/from terminals
|
|
|
|
Author: Ceriel J.H. Jacobs
|
1994-06-24 14:02:31 +00:00
|
|
|
Version: $Id$
|
1988-02-19 15:54:01 +00:00
|
|
|
|
|
|
|
Implementation for Unix.
|
1987-05-13 14:36:45 +00:00
|
|
|
*)
|
1991-03-05 13:47:08 +00:00
|
|
|
FROM SYSTEM IMPORT ADR;
|
|
|
|
#ifdef __USG
|
|
|
|
FROM Unix IMPORT read, write, open, fcntl;
|
|
|
|
#else
|
|
|
|
FROM Unix IMPORT read, write, open, ioctl;
|
|
|
|
#endif
|
2017-10-28 21:20:39 +00:00
|
|
|
VAR fildes, fdout: INTEGER;
|
1987-05-13 14:36:45 +00:00
|
|
|
unreadch: CHAR;
|
|
|
|
unread: BOOLEAN;
|
|
|
|
tty: ARRAY[0..8] OF CHAR;
|
|
|
|
|
|
|
|
PROCEDURE Read(VAR ch: CHAR);
|
|
|
|
BEGIN
|
|
|
|
IF unread THEN
|
|
|
|
ch := unreadch;
|
|
|
|
unread := FALSE
|
|
|
|
ELSE
|
1991-03-05 13:47:08 +00:00
|
|
|
IF read(fildes, ADR(ch), 1) < 0 THEN
|
1987-05-13 14:36:45 +00:00
|
|
|
;
|
|
|
|
END;
|
|
|
|
END;
|
|
|
|
unreadch := ch;
|
|
|
|
END Read;
|
|
|
|
|
|
|
|
PROCEDURE BusyRead(VAR ch: CHAR);
|
|
|
|
VAR l: INTEGER;
|
|
|
|
BEGIN
|
|
|
|
IF unread THEN
|
|
|
|
ch := unreadch;
|
|
|
|
unread := FALSE
|
|
|
|
ELSE
|
|
|
|
#ifdef __USG
|
1991-03-05 13:47:08 +00:00
|
|
|
l := fcntl(fildes, (*FGETFL*) 3, 0);
|
|
|
|
IF fcntl(fildes,
|
1987-05-13 14:36:45 +00:00
|
|
|
(* FSETFL *) 4,
|
|
|
|
l + (*ONDELAY*) 2) < 0 THEN
|
|
|
|
;
|
|
|
|
END;
|
1991-03-05 13:47:08 +00:00
|
|
|
IF read(fildes, ADR(ch), 1) = 0 THEN
|
1987-05-13 14:36:45 +00:00
|
|
|
ch := 0C;
|
|
|
|
ELSE
|
|
|
|
unreadch := ch;
|
|
|
|
END;
|
1991-03-05 13:47:08 +00:00
|
|
|
IF fcntl(fildes, (*FSETFL*)4, l) < 0 THEN
|
1987-05-13 14:36:45 +00:00
|
|
|
;
|
|
|
|
END;
|
|
|
|
#else
|
|
|
|
#ifdef __BSD4_2
|
1991-03-05 13:47:08 +00:00
|
|
|
IF ioctl(fildes, INTEGER(ORD('f')*256+127+4*65536+40000000H), ADR(l)) < 0 THEN
|
1987-05-13 14:36:45 +00:00
|
|
|
#else
|
1991-03-05 13:47:08 +00:00
|
|
|
IF ioctl(fildes, INTEGER(ORD('f')*256+127), ADR(l)) < 0 THEN
|
1987-05-13 14:36:45 +00:00
|
|
|
#endif
|
|
|
|
;
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF l = 0 THEN
|
|
|
|
ch := 0C;
|
|
|
|
ELSE
|
1991-03-05 13:47:08 +00:00
|
|
|
IF read(fildes, ADR(ch), 1) < 0 THEN
|
1987-05-13 14:36:45 +00:00
|
|
|
;
|
|
|
|
END;
|
|
|
|
unreadch := ch;
|
|
|
|
END;
|
|
|
|
#endif
|
|
|
|
END;
|
|
|
|
END BusyRead;
|
|
|
|
|
|
|
|
PROCEDURE ReadAgain;
|
|
|
|
BEGIN
|
|
|
|
unread := TRUE;
|
|
|
|
END ReadAgain;
|
|
|
|
|
|
|
|
PROCEDURE Write(ch: CHAR);
|
|
|
|
BEGIN
|
2017-10-28 21:20:39 +00:00
|
|
|
IF write(fdout, ADR(ch), 1) < 0 THEN
|
1987-05-13 14:36:45 +00:00
|
|
|
;
|
|
|
|
END;
|
|
|
|
END Write;
|
|
|
|
|
|
|
|
PROCEDURE WriteLn;
|
|
|
|
BEGIN
|
|
|
|
Write(12C);
|
|
|
|
END WriteLn;
|
|
|
|
|
|
|
|
PROCEDURE WriteString(s: ARRAY OF CHAR);
|
|
|
|
VAR i: CARDINAL;
|
|
|
|
BEGIN
|
|
|
|
i := 0;
|
|
|
|
WHILE (i <= HIGH(s)) & (s[i] # 0C) DO
|
|
|
|
Write(s[i]);
|
|
|
|
INC(i)
|
|
|
|
END
|
|
|
|
END WriteString;
|
|
|
|
|
|
|
|
BEGIN
|
2007-02-20 00:38:13 +00:00
|
|
|
(*
|
1987-05-13 14:36:45 +00:00
|
|
|
tty := "/dev/tty";
|
1991-03-05 13:47:08 +00:00
|
|
|
fildes := open(ADR(tty), 2);
|
1987-05-13 14:36:45 +00:00
|
|
|
unread := FALSE;
|
2007-02-20 00:38:13 +00:00
|
|
|
*)
|
|
|
|
(* dtrg: changed so that instead of opening /dev/tty, fd 0 is always used. *)
|
|
|
|
tty := "stdio";
|
|
|
|
fildes := 0;
|
2017-10-28 21:20:39 +00:00
|
|
|
fdout := 1;
|
2007-02-20 00:38:13 +00:00
|
|
|
unread := FALSE;
|
1987-05-13 14:36:45 +00:00
|
|
|
END Terminal.
|