Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site rlgvax.UUCP Path: utzoo!linus!genrad!mit-eddi!mit-vax!eagle!harpo!seismo!rlgvax!guy From: guy@rlgvax.UUCP Newsgroups: net.unix-wizards Subject: Re: raw/cooked single char i/o Message-ID: <621@rlgvax.UUCP> Date: Sat, 11-Jun-83 00:58:31 EDT Article-I.D.: rlgvax.621 Posted: Sat Jun 11 00:58:31 1983 Date-Received: Sat, 11-Jun-83 11:02:57 EDT References: <211@gatech.UUCP> Organization: RLG Corp., Reston, VA Lines: 42 Leave the terminal in CBREAK mode (NOT RAW mode - see previous submission) all the time; if you want to disable the interrupt and quit characters, set them to '\0377' using the TIOCGETC and TIOCSETC "ioctl" calls. What you do is: #include #include #include main() { struct tchars oldtchars, newtchars; initialization; enter "curses"; crmode(); ioctl(_tty_ch, TIOCGETC, &oldtchars); newtchars = oldtchars; newtchars.t_intrc = '\0377'; newtchars.t_quitc = '\0377'; ioctl(_tty_ch, TIOCSETC, &newtchars); do whatever your program does; nocrmode(); ioctl(_tty_ch, TIOCSETC, &oldtchars); leave "curses"; exit(); } The reason typeahead was flushed was that you were going into and out of RAW mode before each read; going into or out of RAW (or CBREAK) mode flushes all typeahead. It also consumes a lot of CPU time; furthermore, it means that while you aren't waiting for a character your program is vulnerable to interrupts! If you are using the job control mechanism, you may want either to disable their control characters as well (see the manual page TTY(4)) or catch them. Guy Harris RLG Corporation {seismo,mcnc,we13,brl-bmd,allegra}!rlgvax!guy