1995-10-16 18:19:16 -04:00
|
|
|
;;; My comments:
|
|
|
|
;;; - We have a lot of NeXT-specific stuff. More importantly, what is the
|
|
|
|
;;; Linux, Solaris, and HP-UX specific stuff?
|
|
|
|
;;;
|
|
|
|
;;; - I would suggest totally flushing the ttychars vector from the interface
|
|
|
|
;;; in favor of individual slots in the TTY-INFO record. Keep the vec
|
|
|
|
;;; in the implementation, and define the TTY-INFO:EOL, etc. procs by
|
|
|
|
;;; hand as being indices into the vector. We could *also* expose the
|
|
|
|
;;; vector if we liked.
|
|
|
|
;;; -Olin
|
|
|
|
|
|
|
|
;;; Terminal Control for the Scheme Shell
|
|
|
|
;;; Copyright (c) 1995 by Brian D. Carlstrom.
|
|
|
|
;;; Rehacked by Olin 8/95.
|
|
|
|
|
|
|
|
(foreign-source
|
1995-10-31 22:52:02 -05:00
|
|
|
"#include <sys/types.h>"
|
|
|
|
""
|
1995-10-26 16:37:35 -04:00
|
|
|
"#include <unistd.h>"
|
1995-10-16 18:19:16 -04:00
|
|
|
"#include <termios.h>"
|
|
|
|
""
|
1995-10-22 08:34:53 -04:00
|
|
|
"/* Make sure foreign-function stubs interface to the C funs correctly: */"
|
|
|
|
"#include \"tty1.h\""
|
|
|
|
""
|
1995-10-16 18:19:16 -04:00
|
|
|
"extern int errno;"
|
|
|
|
""
|
|
|
|
"#define errno_or_false(x) (((x) == -1) ? ENTER_FIXNUM(errno) : SCHFALSE)"
|
|
|
|
"" )
|
|
|
|
|
|
|
|
|
|
|
|
;;; tty-info records
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; I have to fake out my record package so I can define my very own
|
|
|
|
;;; MAKE-TTY-INFO procedure. Ech. I oughta have a lower-level record macro
|
|
|
|
;;; for this kind of thing.
|
|
|
|
|
|
|
|
(define-record %tty-info
|
|
|
|
control-chars
|
|
|
|
input-flags
|
|
|
|
output-flags
|
|
|
|
control-flags
|
|
|
|
local-flags
|
|
|
|
input-speed
|
1995-10-31 19:19:30 -05:00
|
|
|
input-speed-code
|
1995-10-16 18:19:16 -04:00
|
|
|
output-speed
|
1995-10-31 19:19:30 -05:00
|
|
|
output-speed-code
|
1995-10-16 18:19:16 -04:00
|
|
|
min
|
|
|
|
time
|
1995-10-17 00:33:40 -04:00
|
|
|
((disclose info) '("tty-info")))
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define tty-info? %tty-info?)
|
1995-10-17 00:33:40 -04:00
|
|
|
(define type/tty-info type/%tty-info)
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define tty-info:control-chars %tty-info:control-chars)
|
|
|
|
(define tty-info:input-flags %tty-info:input-flags)
|
|
|
|
(define tty-info:output-flags %tty-info:output-flags)
|
|
|
|
(define tty-info:control-flags %tty-info:control-flags)
|
|
|
|
(define tty-info:local-flags %tty-info:local-flags)
|
|
|
|
(define tty-info:input-speed %tty-info:input-speed)
|
|
|
|
(define tty-info:output-speed %tty-info:output-speed)
|
|
|
|
(define tty-info:min %tty-info:min)
|
1995-10-17 00:33:40 -04:00
|
|
|
(define tty-info:time %tty-info:time)
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define set-tty-info:control-chars set-%tty-info:control-chars)
|
|
|
|
(define set-tty-info:input-flags set-%tty-info:input-flags)
|
|
|
|
(define set-tty-info:output-flags set-%tty-info:output-flags)
|
|
|
|
(define set-tty-info:control-flags set-%tty-info:control-flags)
|
|
|
|
(define set-tty-info:local-flags set-%tty-info:local-flags)
|
|
|
|
(define set-tty-info:min set-%tty-info:min)
|
1995-10-17 00:33:40 -04:00
|
|
|
(define set-tty-info:time set-%tty-info:time)
|
1995-10-16 18:19:16 -04:00
|
|
|
|
1995-10-31 19:19:30 -05:00
|
|
|
;;; Encode the speeds at assignment time.
|
|
|
|
(define (set-tty-info:input-speed info speed)
|
|
|
|
(set-%tty-info:input-speed-code info (encode-baud-rate speed))
|
|
|
|
(set-%tty-info:input-speed info speed))
|
|
|
|
|
|
|
|
(define (set-tty-info:output-speed info speed)
|
|
|
|
(set-%tty-info:output-speed-code info (encode-baud-rate speed))
|
|
|
|
(set-%tty-info:output-speed info speed))
|
|
|
|
|
|
|
|
|
1995-10-16 18:19:16 -04:00
|
|
|
(define (make-tty-info iflags oflags cflags lflags ispeed ospeed min time)
|
|
|
|
(make-%tty-info (make-string num-ttychars (ascii->char 0))
|
1995-10-31 19:19:30 -05:00
|
|
|
iflags oflags cflags lflags
|
|
|
|
ispeed (encode-baud-rate ispeed)
|
|
|
|
ospeed (encode-baud-rate ospeed)
|
|
|
|
min time))
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define (copy-tty-info info)
|
|
|
|
(make-%tty-info (string-copy (tty-info:control-chars info))
|
1995-10-31 19:19:30 -05:00
|
|
|
(tty-info:input-flags info)
|
|
|
|
(tty-info:output-flags info)
|
|
|
|
(tty-info:control-flags info)
|
|
|
|
(tty-info:local-flags info)
|
|
|
|
(tty-info:input-speed info)
|
|
|
|
(%tty-info:input-speed-code info)
|
|
|
|
(tty-info:output-speed info)
|
|
|
|
(%tty-info:output-speed-code info)
|
|
|
|
(tty-info:min info)
|
|
|
|
(tty-info:time info)))
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;; (tty-info fd/port)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; Retrieve tty-info bits from a tty.
|
|
|
|
|
|
|
|
(define (tty-info fdport)
|
|
|
|
(let ((control-chars (make-string num-ttychars)))
|
|
|
|
(receive (iflag-hi8 iflag-lo24 oflag-hi8 oflag-lo24
|
|
|
|
cflag-hi8 cflag-lo24 lflag-hi8 lflag-lo24
|
1995-10-31 19:19:30 -05:00
|
|
|
ispeed-code ospeed-code)
|
1996-09-11 21:43:53 -04:00
|
|
|
(sleazy-call/fdes fdport (lambda (fd) (%tty-info fd control-chars)))
|
1995-10-16 18:19:16 -04:00
|
|
|
(make-%tty-info control-chars
|
|
|
|
(bitwise-ior (arithmetic-shift iflag-hi8 24) iflag-lo24)
|
|
|
|
(bitwise-ior (arithmetic-shift oflag-hi8 24) oflag-lo24)
|
|
|
|
(bitwise-ior (arithmetic-shift cflag-hi8 24) cflag-lo24)
|
|
|
|
(bitwise-ior (arithmetic-shift lflag-hi8 24) lflag-lo24)
|
1995-10-31 19:19:30 -05:00
|
|
|
(decode-baud-rate ispeed-code) ispeed-code
|
|
|
|
(decode-baud-rate ospeed-code) ospeed-code
|
1995-10-16 18:19:16 -04:00
|
|
|
(char->ascii (string-ref control-chars ttychar/min))
|
|
|
|
(char->ascii (string-ref control-chars ttychar/time))))))
|
|
|
|
|
|
|
|
(define-errno-syscall (%tty-info fdes control-chars) %tty-info/errno
|
|
|
|
iflag-hi8 iflag-lo24
|
|
|
|
oflag-hi8 oflag-lo24
|
|
|
|
cflag-hi8 cflag-lo24
|
|
|
|
lflag-hi8 lflag-lo24
|
1995-10-31 19:19:30 -05:00
|
|
|
ispeed-code ospeed-code)
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define-foreign %tty-info/errno
|
1995-10-17 00:33:40 -04:00
|
|
|
(scheme_tcgetattr (integer fdes)
|
1995-10-22 08:34:53 -04:00
|
|
|
(var-string control-chars))
|
1995-10-16 18:19:16 -04:00
|
|
|
(to-scheme integer errno_or_false)
|
|
|
|
integer integer
|
|
|
|
integer integer
|
|
|
|
integer integer
|
|
|
|
integer integer
|
|
|
|
integer integer)
|
|
|
|
|
|
|
|
|
|
|
|
;;; (set-tty-info fdport option info) [Not exported]
|
|
|
|
;;; (set-tty-info/now fdport option info)
|
|
|
|
;;; (set-tty-info/drain fdport option info)
|
|
|
|
;;; (set-tty-info/flush fdport option info)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; Assign tty-info bits to a tty.
|
|
|
|
|
|
|
|
(define (set-tty-info fdport option info)
|
|
|
|
(let ((if (tty-info:input-flags info))
|
|
|
|
(of (tty-info:output-flags info))
|
|
|
|
(cf (tty-info:control-flags info))
|
|
|
|
(lf (tty-info:local-flags info))
|
|
|
|
(cc (tty-info:control-chars info))
|
1995-10-31 19:19:30 -05:00
|
|
|
(is (%tty-info:input-speed-code info))
|
|
|
|
(os (%tty-info:output-speed-code info)))
|
1995-10-16 18:19:16 -04:00
|
|
|
(let ((iflag-hi8 (arithmetic-shift if -24))
|
|
|
|
(iflag-lo24 (bitwise-and if #xffffff))
|
|
|
|
(oflag-hi8 (arithmetic-shift of -24))
|
|
|
|
(oflag-lo24 (bitwise-and of #xffffff))
|
|
|
|
(cflag-hi8 (arithmetic-shift cf -24))
|
|
|
|
(cflag-lo24 (bitwise-and cf #xffffff))
|
|
|
|
(lflag-hi8 (arithmetic-shift lf -24))
|
|
|
|
(lflag-lo24 (bitwise-and lf #xffffff)))
|
1996-09-11 21:43:53 -04:00
|
|
|
(sleazy-call/fdes fdport
|
1995-10-16 18:19:16 -04:00
|
|
|
(lambda (fd)
|
|
|
|
(%set-tty-info fd option
|
|
|
|
cc
|
|
|
|
iflag-hi8 iflag-lo24
|
|
|
|
oflag-hi8 oflag-lo24
|
|
|
|
cflag-hi8 cflag-lo24
|
|
|
|
lflag-hi8 lflag-lo24
|
|
|
|
is os
|
|
|
|
(tty-info:min info)
|
|
|
|
(tty-info:time info)))))))
|
|
|
|
|
1995-10-19 04:22:56 -04:00
|
|
|
|
1996-08-22 16:13:14 -04:00
|
|
|
(define-errno-syscall (%set-tty-info fdes option
|
|
|
|
control-chars
|
|
|
|
iflag-hi8 iflag-lo24
|
|
|
|
oflag-hi8 oflag-lo24
|
|
|
|
cflag-hi8 cflag-lo24
|
|
|
|
lflag-hi8 lflag-lo24
|
|
|
|
ispeed-code ospeed-code
|
|
|
|
min time)
|
1995-10-16 18:19:16 -04:00
|
|
|
%set-tty-info/errno)
|
|
|
|
|
1995-10-19 04:22:56 -04:00
|
|
|
|
1995-10-16 18:19:16 -04:00
|
|
|
(define-foreign %set-tty-info/errno
|
1995-10-17 00:33:40 -04:00
|
|
|
(scheme_tcsetattr (integer fdes)
|
|
|
|
(integer option)
|
|
|
|
(string control-chars)
|
|
|
|
(integer iflag-hi8)
|
|
|
|
(integer iflag-lo24)
|
|
|
|
(integer oflag-hi8)
|
|
|
|
(integer oflag-lo24)
|
|
|
|
(integer cflag-hi8)
|
|
|
|
(integer cflag-lo24)
|
|
|
|
(integer lflag-hi8)
|
|
|
|
(integer lflag-lo24)
|
1995-10-31 19:19:30 -05:00
|
|
|
(integer ispeed-code)
|
|
|
|
(integer ospeed-code)
|
1995-10-17 00:33:40 -04:00
|
|
|
(integer min)
|
|
|
|
(integer time))
|
1995-10-16 18:19:16 -04:00
|
|
|
(to-scheme integer errno_or_false))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Exported procs
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
1995-10-19 04:22:56 -04:00
|
|
|
;;; Note that the magic %set-tty-info/foo constants must be defined before this
|
|
|
|
;;; file is loaded due to the set-tty-info/foo definitions below.
|
1995-10-16 18:19:16 -04:00
|
|
|
|
1995-10-19 04:22:56 -04:00
|
|
|
(define (make-tty-info-setter how)
|
|
|
|
(lambda (fdport info) (set-tty-info fdport how info)))
|
1995-10-16 18:19:16 -04:00
|
|
|
|
1995-10-19 04:22:56 -04:00
|
|
|
(define set-tty-info/now (make-tty-info-setter %set-tty-info/now))
|
|
|
|
(define set-tty-info/drain (make-tty-info-setter %set-tty-info/drain))
|
|
|
|
(define set-tty-info/flush (make-tty-info-setter %set-tty-info/flush))
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;; Send a break on the serial line.
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(define (send-tty-break fdport . maybe-duration)
|
1996-09-11 21:43:53 -04:00
|
|
|
(sleazy-call/fdes fdport
|
1995-10-16 18:19:16 -04:00
|
|
|
(lambda (fdes)
|
1996-04-19 14:39:14 -04:00
|
|
|
(%send-tty-break-fdes fdes (:optional maybe-duration 0)))))
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define-errno-syscall (%send-tty-break-fdes fdes duration)
|
|
|
|
%send-tty-break-fdes/errno)
|
|
|
|
|
|
|
|
(define-foreign %send-tty-break-fdes/errno
|
|
|
|
(tcsendbreak (integer fdes) (integer duration))
|
|
|
|
(to-scheme integer errno_or_false))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Drain the main vein.
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(define (drain-tty fdport)
|
|
|
|
(cond ((integer? fdport) (%tcdrain fdport)) ; File descriptor.
|
|
|
|
((fdport? fdport) ; Scheme port -- flush first.
|
|
|
|
(force-output fdport)
|
1996-09-11 21:43:53 -04:00
|
|
|
(sleazy-call/fdes fdport %tcdrain))
|
1995-10-16 18:19:16 -04:00
|
|
|
(else (error "Illegal argument to DRAIN-TTY" fdport))))
|
|
|
|
|
|
|
|
(define-errno-syscall (%tcdrain fdes) %tcdrain/errno)
|
1995-10-31 22:52:02 -05:00
|
|
|
(define-foreign %tcdrain/errno (tcdrain (integer fdes)) no-declare ; Ultrix
|
1995-10-16 18:19:16 -04:00
|
|
|
(to-scheme integer errno_or_false))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Flushing the device queues. (tcflush)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
1995-10-19 04:22:56 -04:00
|
|
|
;;; Note that the magic %flush-tty/foo constants must be defined before this
|
|
|
|
;;; file is loaded due to the flush-tty/foo definitions below.
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define (make-tty-flusher flag)
|
|
|
|
(lambda (fdport)
|
1996-09-11 21:43:53 -04:00
|
|
|
(sleazy-call/fdes fdport (lambda (fdes) (%tcflush fdes flag)))))
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define flush-tty/input (make-tty-flusher %flush-tty/input))
|
|
|
|
(define flush-tty/output (make-tty-flusher %flush-tty/output))
|
|
|
|
(define flush-tty/both (make-tty-flusher %flush-tty/both))
|
|
|
|
|
|
|
|
(define-errno-syscall (%tcflush fdes flag) %tcflush/errno)
|
1995-10-31 22:52:02 -05:00
|
|
|
(define-foreign %tcflush/errno (tcflush (integer fdes) (integer flag))
|
|
|
|
no-declare ; Ultrix
|
1995-10-16 18:19:16 -04:00
|
|
|
(to-scheme integer errno_or_false))
|
|
|
|
|
|
|
|
|
|
|
|
;;; Stopping and starting I/O (tcflow)
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
1995-10-19 04:22:56 -04:00
|
|
|
;;; Note that the magic %tcflow/foo constants must be defined before this
|
|
|
|
;;; file is loaded due to the definitions below.
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define (make-flow-controller action)
|
|
|
|
(lambda (fdport)
|
1996-09-11 21:43:53 -04:00
|
|
|
(sleazy-call/fdes fdport (lambda (fdes) (%tcflow fdes action)))))
|
1995-10-16 18:19:16 -04:00
|
|
|
|
1995-10-17 00:33:40 -04:00
|
|
|
(define start-tty-output (make-flow-controller %tcflow/start-out))
|
|
|
|
(define stop-tty-output (make-flow-controller %tcflow/stop-out))
|
|
|
|
(define start-tty-input (make-flow-controller %tcflow/start-in))
|
|
|
|
(define stop-tty-input (make-flow-controller %tcflow/stop-in))
|
1995-10-16 18:19:16 -04:00
|
|
|
|
|
|
|
(define-errno-syscall (%tcflow fdes action) %tcflow/errno)
|
|
|
|
|
|
|
|
(define-foreign %tcflow/errno
|
1995-10-31 22:52:02 -05:00
|
|
|
(tcflow (integer fdes) (integer action)) no-declare ; Ultrix
|
1995-10-16 18:19:16 -04:00
|
|
|
(to-scheme integer errno_or_false))
|
1995-10-19 04:22:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;; Baud rate translation
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
1995-10-31 19:19:30 -05:00
|
|
|
;;; We should just move these guys out to the tty-consts file.
|
|
|
|
;;; We currently search a vector of (code . speed) pairs.
|
1995-10-19 04:22:56 -04:00
|
|
|
|
|
|
|
(define (encode-baud-rate speed) ; 9600 -> value of BAUD/9600
|
|
|
|
(do ((i (- (vector-length baud-rates) 1) (- i 1)))
|
1995-10-31 19:19:30 -05:00
|
|
|
((eqv? (cdr (vector-ref baud-rates i)) speed)
|
|
|
|
(car (vector-ref baud-rates i)))
|
1995-10-19 04:22:56 -04:00
|
|
|
(if (< i 0) (error "Unknown baud rate." speed))))
|
|
|
|
|
1995-10-31 19:19:30 -05:00
|
|
|
(define (decode-baud-rate code) ; BAUD/9600 -> 9600
|
|
|
|
(do ((i (- (vector-length baud-rates) 1) (- i 1)))
|
|
|
|
((eqv? (car (vector-ref baud-rates i)) code)
|
|
|
|
(cdr (vector-ref baud-rates i)))
|
|
|
|
(if (< i 0) (error "Unknown baud rate code." code))))
|
1995-10-26 16:37:35 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;; Set/Get tty process group
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
|
|
|
(define (set-tty-process-group port/fd proc-group)
|
1996-09-11 21:43:53 -04:00
|
|
|
(sleazy-call/fdes port/fd
|
1995-10-26 16:37:35 -04:00
|
|
|
(lambda (fd)
|
|
|
|
(%set-tty-process-group fd (if (integer? proc-group)
|
|
|
|
proc-group
|
|
|
|
(proc:pid proc-group))))))
|
|
|
|
|
1996-08-22 16:13:14 -04:00
|
|
|
(define-errno-syscall (%set-tty-process-group fdes pid)
|
1995-10-26 16:37:35 -04:00
|
|
|
%set-tty-process-group/errno)
|
|
|
|
|
|
|
|
(define-foreign %set-tty-process-group/errno (tcsetpgrp (fixnum fdes)
|
|
|
|
(pid_t pid))
|
1995-10-31 22:52:02 -05:00
|
|
|
no-declare ; Ultrix
|
1995-10-26 16:37:35 -04:00
|
|
|
(to-scheme integer errno_or_false))
|
|
|
|
|
|
|
|
(define (tty-process-group port/fd)
|
1996-09-11 21:43:53 -04:00
|
|
|
(sleazy-call/fdes port/fd %tty-process-group))
|
1995-10-26 16:37:35 -04:00
|
|
|
|
|
|
|
(define-errno-syscall (%tty-process-group fd) %tty-process-group/errno
|
|
|
|
pid)
|
|
|
|
|
|
|
|
(define-foreign %tty-process-group/errno (tcgetpgrp (fixnum fdes))
|
1995-10-31 22:52:02 -05:00
|
|
|
no-declare ; Ultrix
|
1995-10-26 16:37:35 -04:00
|
|
|
(multi-rep (to-scheme pid_t errno_or_false)
|
|
|
|
pid_t))
|
|
|
|
|
|
|
|
;;; (open-control-tty fname [flags])
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;; Open a control tty, return a port.
|
|
|
|
;;; This procedure is only guaranteed to work when the process doesn't already
|
|
|
|
;;; have a control tty -- e.g., right after a (BECOME-PROCESS-LEADER) call.
|
|
|
|
;;; This limted functionality is about all we can provide portably across BSD,
|
|
|
|
;;; SunOS, and SVR4.
|
|
|
|
|
1995-10-27 07:47:53 -04:00
|
|
|
(define (open-control-tty ttyname . maybe-flags)
|
1996-04-19 14:39:14 -04:00
|
|
|
(let ((flags (:optional maybe-flags open/read+write)))
|
1996-08-24 04:52:34 -04:00
|
|
|
(let lp ()
|
|
|
|
(receive (errno fd) (open-control-tty/errno ttyname flags)
|
|
|
|
(cond ((not errno)
|
1996-09-11 21:43:53 -04:00
|
|
|
(let ((access (bitwise-and flags open/access-mask)))
|
|
|
|
((if (or (= access open/read)
|
|
|
|
(= access open/read+write))
|
|
|
|
make-input-fdport
|
|
|
|
make-output-fdport)
|
|
|
|
fd 1)))
|
1996-08-24 04:52:34 -04:00
|
|
|
((= errno/intr errno) (lp))
|
|
|
|
(else (errno-error errno open-control-tty ttyname flags)))))))
|
1995-10-26 16:37:35 -04:00
|
|
|
|
|
|
|
(define-foreign open-control-tty/errno (open_ctty (string ttyname)
|
|
|
|
(fixnum flags))
|
|
|
|
(multi-rep (to-scheme integer errno_or_false)
|
|
|
|
integer))
|
|
|
|
|