Path: utzoo!utgpu!water!watmath!clyde!cbosgd!ihnp4!ptsfa!ames!pasteur!ucbvax!hplabs!hpda!hpsmtc1!hpisod2!decot From: decot@hpisod2.HP.COM (Dave Decot) Newsgroups: comp.sys.hp Subject: Re: CBREAK on HP-UX 5.5 Message-ID: <16710004@hpisod2.HP.COM> Date: 23 Jan 88 03:55:33 GMT References: <1869@russell.STANFORD.EDU> Organization: Hewlett Packard, Cupertino Lines: 69 /* Routines for managing nonechoing, one-character-at-a-time tty reads */ /* Dave Decot, hpda!decot, 851023 */ /* cbreak() - sets terminal up for one-char-at-a-time reads */ /* normal() - restores terminal to initial state */ #include #include #include #ifndef hpux /* BSD style */ # include #else hpux /* HP-UX style (and other System V systems) */ # include #endif hpux static int tty_mode = 0; #ifdef TCGETA static struct termio orig_tty; static struct termio new_tty; #else static struct sgttyb orig_tty; static struct sgttyb new_tty; #endif cbreak() { if (tty_mode == 0) { #ifdef TCGETA ioctl(0, TCGETA, &orig_tty); #else ioctl(0, TIOCGETP, &orig_tty); #endif tty_mode = 1; new_tty = orig_tty; } #ifdef ICANON new_tty.c_lflag &= ~(ICANON | ECHO); new_tty.c_cc[VMIN] = 1; new_tty.c_cc[VTIME] = 0; ioctl(0, TCSETA, &new_tty); #else new_tty.sg_flags |= CBREAK; new_tty.sg_flags &= ~ECHO; ioctl(0, TIOCSETN, &new_tty); #endif } normal() { if (tty_mode == 1) { #ifdef TCSETA ioctl(0, TCSETA, &orig_tty); #else ioctl(0, TIOCSETN, &orig_tty); #endif new_tty = orig_tty; } }