Changed to call the isatty() syscall directly, rather than fiddling around with non-portable ioctls.
This commit is contained in:
parent
400c475c03
commit
f4e37e1319
|
@ -17,8 +17,7 @@ IMPLEMENTATION MODULE Streams;
|
||||||
FROM SYSTEM IMPORT BYTE, ADR;
|
FROM SYSTEM IMPORT BYTE, ADR;
|
||||||
FROM Epilogue IMPORT CallAtEnd;
|
FROM Epilogue IMPORT CallAtEnd;
|
||||||
FROM Storage IMPORT Allocate, Available;
|
FROM Storage IMPORT Allocate, Available;
|
||||||
FROM StripUnix IMPORT
|
IMPORT StripUnix;
|
||||||
open, close, lseek, read, write, creat, ioctl;
|
|
||||||
|
|
||||||
CONST BUFSIZ = 1024; (* tunable *)
|
CONST BUFSIZ = 1024; (* tunable *)
|
||||||
TYPE IOB = RECORD
|
TYPE IOB = RECORD
|
||||||
|
@ -82,17 +81,17 @@ IMPLEMENTATION MODULE Streams;
|
||||||
buf[HIGH(filename)+2] := BYTE(0C);
|
buf[HIGH(filename)+2] := BYTE(0C);
|
||||||
END;
|
END;
|
||||||
IF (mode = reading) THEN
|
IF (mode = reading) THEN
|
||||||
fd := open(ADR(stream^.buf), 0);
|
fd := StripUnix.open(ADR(stream^.buf), 0);
|
||||||
ELSE
|
ELSE
|
||||||
fd := -1;
|
fd := -1;
|
||||||
IF (mode = appending) THEN
|
IF (mode = appending) THEN
|
||||||
fd := open(ADR(stream^.buf), 1);
|
fd := StripUnix.open(ADR(stream^.buf), 1);
|
||||||
IF fd >= 0 THEN
|
IF fd >= 0 THEN
|
||||||
IF (lseek(fd, 0D , 2) < 0D) THEN ; END;
|
IF (StripUnix.lseek(fd, 0D , 2) < 0D) THEN ; END;
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
IF fd < 0 THEN
|
IF fd < 0 THEN
|
||||||
fd := creat(ADR(stream^.buf), 666B);
|
fd := StripUnix.creat(ADR(stream^.buf), 666B);
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
IF fd < 0 THEN
|
IF fd < 0 THEN
|
||||||
|
@ -153,7 +152,7 @@ IMPLEMENTATION MODULE Streams;
|
||||||
IF (cnt > 0) THEN
|
IF (cnt > 0) THEN
|
||||||
cnt1 := cnt;
|
cnt1 := cnt;
|
||||||
cnt := 0;
|
cnt := 0;
|
||||||
IF write(fildes, ADR(buf), cnt1) < 0 THEN END;
|
IF StripUnix.write(fildes, ADR(buf), cnt1) < 0 THEN END;
|
||||||
END;
|
END;
|
||||||
END;
|
END;
|
||||||
END FlushStream;
|
END FlushStream;
|
||||||
|
@ -165,7 +164,7 @@ IMPLEMENTATION MODULE Streams;
|
||||||
IF stream^.mode # reading THEN
|
IF stream^.mode # reading THEN
|
||||||
FlushStream(stream, result);
|
FlushStream(stream, result);
|
||||||
END;
|
END;
|
||||||
IF close(stream^.fildes) < 0 THEN ; END;
|
IF StripUnix.close(stream^.fildes) < 0 THEN ; END;
|
||||||
freestruct(stream);
|
freestruct(stream);
|
||||||
ELSE
|
ELSE
|
||||||
result := nostream;
|
result := nostream;
|
||||||
|
@ -212,7 +211,7 @@ IMPLEMENTATION MODULE Streams;
|
||||||
IF stream = InputStream THEN
|
IF stream = InputStream THEN
|
||||||
FlushLineBuffers();
|
FlushLineBuffers();
|
||||||
END;
|
END;
|
||||||
maxcnt := read(fildes, ADR(buf), bufferedcnt);
|
maxcnt := StripUnix.read(fildes, ADR(buf), bufferedcnt);
|
||||||
cnt := 1;
|
cnt := 1;
|
||||||
IF maxcnt <= 0 THEN
|
IF maxcnt <= 0 THEN
|
||||||
eof := TRUE;
|
eof := TRUE;
|
||||||
|
@ -335,7 +334,7 @@ IMPLEMENTATION MODULE Streams;
|
||||||
RETURN;
|
RETURN;
|
||||||
END;
|
END;
|
||||||
IF (s^.mode # reading) THEN FlushStream(s, result); END;
|
IF (s^.mode # reading) THEN FlushStream(s, result); END;
|
||||||
position := lseek(s^.fildes, 0D, 1);
|
position := StripUnix.lseek(s^.fildes, 0D, 1);
|
||||||
IF position < 0D THEN
|
IF position < 0D THEN
|
||||||
result := illegaloperation;
|
result := illegaloperation;
|
||||||
RETURN;
|
RETURN;
|
||||||
|
@ -360,7 +359,7 @@ IMPLEMENTATION MODULE Streams;
|
||||||
s^.eof := FALSE;
|
s^.eof := FALSE;
|
||||||
END;
|
END;
|
||||||
IF s^.mode = appending THEN
|
IF s^.mode = appending THEN
|
||||||
currpos := lseek(s^.fildes, 0D, 1);
|
currpos := StripUnix.lseek(s^.fildes, 0D, 1);
|
||||||
IF currpos < 0D THEN
|
IF currpos < 0D THEN
|
||||||
result := illegaloperation;
|
result := illegaloperation;
|
||||||
RETURN;
|
RETURN;
|
||||||
|
@ -370,7 +369,7 @@ IMPLEMENTATION MODULE Streams;
|
||||||
result := illegaloperation;
|
result := illegaloperation;
|
||||||
RETURN;
|
RETURN;
|
||||||
END;
|
END;
|
||||||
currpos := lseek(s^.fildes, position, 0);
|
currpos := StripUnix.lseek(s^.fildes, position, 0);
|
||||||
IF currpos < 0D THEN
|
IF currpos < 0D THEN
|
||||||
result := illegaloperation;
|
result := illegaloperation;
|
||||||
RETURN;
|
RETURN;
|
||||||
|
@ -379,21 +378,15 @@ IMPLEMENTATION MODULE Streams;
|
||||||
END SetPosition;
|
END SetPosition;
|
||||||
|
|
||||||
PROCEDURE isatty(stream: Stream; VAR result: StreamResult): BOOLEAN;
|
PROCEDURE isatty(stream: Stream; VAR result: StreamResult): BOOLEAN;
|
||||||
VAR buf: ARRAY[1..100] OF CHAR;
|
|
||||||
BEGIN
|
BEGIN
|
||||||
IF (stream = NIL) OR (stream^.kind = none) THEN
|
IF (stream = NIL) OR (stream^.kind = none) THEN
|
||||||
result := nostream;
|
result := nostream;
|
||||||
RETURN FALSE;
|
RETURN FALSE;
|
||||||
END;
|
END;
|
||||||
#ifdef __USG
|
IF (StripUnix.isatty(stream^.fildes) = 0) THEN
|
||||||
RETURN ioctl(stream^.fildes, INTEGER(ORD('T') * 256 + 1), ADR(buf)) >= 0;
|
RETURN FALSE;
|
||||||
#else
|
END;
|
||||||
#ifdef __BSD4_2
|
RETURN TRUE;
|
||||||
RETURN ioctl(stream^.fildes, INTEGER(ORD('t') * 256 + 8 + 6*65536 + 40000000H), ADR(buf)) >= 0;
|
|
||||||
#else
|
|
||||||
RETURN ioctl(stream^.fildes, INTEGER(ORD('t') * 256 + 8), ADR(buf)) >= 0;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
END isatty;
|
END isatty;
|
||||||
|
|
||||||
PROCEDURE InitStreams;
|
PROCEDURE InitStreams;
|
||||||
|
|
|
@ -21,6 +21,7 @@ DEFINITION MODULE StripUnix;
|
||||||
(* Sys5 *) PROCEDURE fcntl(fildes, request, arg: INTEGER) : INTEGER;
|
(* Sys5 *) PROCEDURE fcntl(fildes, request, arg: INTEGER) : INTEGER;
|
||||||
PROCEDURE getpid() : INTEGER;
|
PROCEDURE getpid() : INTEGER;
|
||||||
PROCEDURE ioctl(fildes, request: INTEGER; arg: ADDRESS) : INTEGER;
|
PROCEDURE ioctl(fildes, request: INTEGER; arg: ADDRESS) : INTEGER;
|
||||||
|
PROCEDURE isatty(fildes: INTEGER) : INTEGER;
|
||||||
PROCEDURE lseek(fildes: INTEGER; offset: LONGINT; whence: INTEGER) : LONGINT;
|
PROCEDURE lseek(fildes: INTEGER; offset: LONGINT; whence: INTEGER) : LONGINT;
|
||||||
PROCEDURE open(path: ADDRESS; oflag: INTEGER) : INTEGER;
|
PROCEDURE open(path: ADDRESS; oflag: INTEGER) : INTEGER;
|
||||||
PROCEDURE read(fildes: INTEGER;
|
PROCEDURE read(fildes: INTEGER;
|
||||||
|
|
|
@ -79,6 +79,7 @@ DEFINITION MODULE Unix;
|
||||||
PROCEDURE getgid() : INTEGER;
|
PROCEDURE getgid() : INTEGER;
|
||||||
PROCEDURE getegid() : INTEGER;
|
PROCEDURE getegid() : INTEGER;
|
||||||
PROCEDURE ioctl(fildes, request: INTEGER; arg: ADDRESS) : INTEGER;
|
PROCEDURE ioctl(fildes, request: INTEGER; arg: ADDRESS) : INTEGER;
|
||||||
|
PROCEDURE isatty(fildes: INTEGER) : INTEGER;
|
||||||
PROCEDURE stty(fildes: INTEGER; buf: ADDRESS) : INTEGER;
|
PROCEDURE stty(fildes: INTEGER; buf: ADDRESS) : INTEGER;
|
||||||
PROCEDURE gtty(fildes: INTEGER; buf: ADDRESS) : INTEGER;
|
PROCEDURE gtty(fildes: INTEGER; buf: ADDRESS) : INTEGER;
|
||||||
PROCEDURE kill(pid, sig: INTEGER) : INTEGER;
|
PROCEDURE kill(pid, sig: INTEGER) : INTEGER;
|
||||||
|
|
Loading…
Reference in a new issue