rbj@uunet.UU.NET (Root Boy Jim) (01/15/91)
HELP! I need to do CBREAK/RAW I/O from a tty. For debugging purposes I and using /dev/tty, which is still open as STD{IN,OUT,ERR}. I am running on SunOS 4.1.1 Perl 3.0@41. I copied the ioctl.pl from a Sequent (4.2 BSD), but it seems to jive with #include <sys/ttold.h>. Here's my relevant (probably ugly) code: #! /bin/perl require 'ioctl.pl'; $IN = $0; # any file will do open(IN) || die "can't open $0: $!"; &openNDC || die "can't open NDC $!"; while (<IN>) { &authorize; } &closeNDC || die "can't close NDC $!"; exit(0); sub openNDC { $sgtty = 'ioekfl'; # place holder open(NDC,'+>/dev/tty') || # for testing die("/dev/tty: $!\n"); ioctl(NDC,$TIOCGETP,$sgtty) || die("TIOCGETP: $!\n"); @sgtty=unpack("ccccs",$sgtty); @sgtty[4] |= $CBREAK; @sgtty[4] &= $ECHO; ioctl(NDC,$TIOCSETP,pack('cccs',@sgtty)) || die("TIOCSETP: $!\n"); # Do I need these? select(NDC); $| = 1; # no buffer select(STDOUT); $| = 1; # no buffer } sub closeNDC { ioctl(NDC,$TIOCGETP,$sgtty) || die("TIOCGETP: $!\n"); close(NDC); } sub authorize { $ans = 'y'; # answer chop; print("authorize $_? "); # ask # Choice of next two methods sysread(NDC,$ans,1); # get answer # $ans = getc(NDC); # get answer print("$ans\r\n"); # echo } -- Root Boy Jim Cottrell <rbj@uunet.uu.net> Close the gap of the dark year in between