Home | History | Annotate | Line # | Download | only in libcurses
tty.c revision 1.38
      1  1.38       jdc /*	$NetBSD: tty.c,v 1.38 2006/08/23 19:23:55 jdc Exp $	*/
      2   1.7     mikel 
      3   1.1   mycroft /*-
      4   1.6       cgd  * Copyright (c) 1992, 1993, 1994
      5   1.2       cgd  *	The Regents of the University of California.  All rights reserved.
      6   1.1   mycroft  *
      7   1.1   mycroft  * Redistribution and use in source and binary forms, with or without
      8   1.1   mycroft  * modification, are permitted provided that the following conditions
      9   1.1   mycroft  * are met:
     10   1.1   mycroft  * 1. Redistributions of source code must retain the above copyright
     11   1.1   mycroft  *    notice, this list of conditions and the following disclaimer.
     12   1.1   mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1   mycroft  *    notice, this list of conditions and the following disclaimer in the
     14   1.1   mycroft  *    documentation and/or other materials provided with the distribution.
     15  1.35       agc  * 3. Neither the name of the University nor the names of its contributors
     16   1.1   mycroft  *    may be used to endorse or promote products derived from this software
     17   1.1   mycroft  *    without specific prior written permission.
     18   1.1   mycroft  *
     19   1.1   mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     20   1.1   mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21   1.1   mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22   1.1   mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     23   1.1   mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1   mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25   1.1   mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1   mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1   mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1   mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1   mycroft  * SUCH DAMAGE.
     30   1.1   mycroft  */
     31   1.1   mycroft 
     32   1.7     mikel #include <sys/cdefs.h>
     33   1.1   mycroft #ifndef lint
     34   1.7     mikel #if 0
     35  1.10     perry static char sccsid[] = "@(#)tty.c	8.6 (Berkeley) 1/10/95";
     36   1.7     mikel #else
     37  1.38       jdc __RCSID("$NetBSD: tty.c,v 1.38 2006/08/23 19:23:55 jdc Exp $");
     38   1.7     mikel #endif
     39  1.11       mrg #endif				/* not lint */
     40  1.11       mrg 
     41  1.11       mrg #include <sys/types.h>
     42   1.1   mycroft 
     43   1.6       cgd #include <stdlib.h>
     44   1.1   mycroft #include <termios.h>
     45   1.1   mycroft #include <unistd.h>
     46  1.16     blymn #include <sys/fcntl.h>
     47  1.16     blymn #include <sys/ioctl.h>
     48   1.1   mycroft 
     49   1.6       cgd #include "curses.h"
     50  1.14       jdc #include "curses_private.h"
     51   1.6       cgd 
     52   1.2       cgd /*
     53   1.2       cgd  * In general, curses should leave tty hardware settings alone (speed, parity,
     54   1.2       cgd  * word size).  This is most easily done in BSD by using TCSASOFT on all
     55   1.2       cgd  * tcsetattr calls.  On other systems, it would be better to get and restore
     56   1.2       cgd  * those attributes at each change, or at least when stopped and restarted.
     57   1.2       cgd  * See also the comments in getterm().
     58   1.2       cgd  */
     59   1.2       cgd #ifdef TCSASOFT
     60  1.11       mrg int	__tcaction = 1;			/* Ignore hardware settings. */
     61   1.2       cgd #else
     62  1.11       mrg int	__tcaction = 0;
     63   1.2       cgd #endif
     64   1.2       cgd 
     65   1.2       cgd #ifndef	OXTABS
     66   1.2       cgd #ifdef	XTABS			/* SMI uses XTABS. */
     67   1.2       cgd #define	OXTABS	XTABS
     68   1.2       cgd #else
     69   1.2       cgd #define	OXTABS	0
     70   1.2       cgd #endif
     71   1.2       cgd #endif
     72  1.26  christos 
     73  1.26  christos /*
     74  1.26  christos  * baudrate --
     75  1.26  christos  *	Return the current baudrate
     76  1.26  christos  */
     77  1.26  christos int
     78  1.26  christos baudrate(void)
     79  1.26  christos {
     80  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
     81  1.29    itojun 		return 0;
     82  1.29    itojun 
     83  1.29    itojun 	return cfgetospeed(&_cursesi_screen->baset);
     84  1.26  christos }
     85   1.2       cgd 
     86   1.1   mycroft /*
     87   1.1   mycroft  * gettmode --
     88   1.1   mycroft  *	Do terminal type initialization.
     89   1.1   mycroft  */
     90   1.1   mycroft int
     91  1.15     blymn gettmode(void)
     92   1.1   mycroft {
     93  1.25     blymn 	if (_cursesi_gettmode(_cursesi_screen) == ERR)
     94  1.25     blymn 		return ERR;
     95  1.11       mrg 
     96  1.25     blymn 	__GT = _cursesi_screen->GT;
     97  1.25     blymn 	__NONL = _cursesi_screen->NONL;
     98  1.25     blymn 	return OK;
     99  1.25     blymn }
    100  1.25     blymn 
    101  1.25     blymn /*
    102  1.25     blymn  * _cursesi_gettmode --
    103  1.25     blymn  *      Do the terminal type initialisation for the tty attached to the
    104  1.25     blymn  *  given screen.
    105  1.25     blymn  */
    106  1.25     blymn int
    107  1.25     blymn _cursesi_gettmode(SCREEN *screen)
    108  1.25     blymn {
    109  1.25     blymn 	screen->useraw = 0;
    110  1.25     blymn 
    111  1.29    itojun 	if (tcgetattr(fileno(screen->infd), &screen->orig_termios)) {
    112  1.29    itojun 		/* if the input fd is not a tty try the output */
    113  1.29    itojun 		if (tcgetattr(fileno(screen->infd), &screen->orig_termios)) {
    114  1.29    itojun 			/* not a tty ... we will disable tty related stuff */
    115  1.29    itojun 			screen->notty = TRUE;
    116  1.29    itojun 			__GT = 0;
    117  1.29    itojun 			__NONL = 0;
    118  1.29    itojun 			return (OK);
    119  1.29    itojun 		}
    120  1.29    itojun 	}
    121   1.2       cgd 
    122  1.25     blymn 	screen->baset = screen->orig_termios;
    123  1.25     blymn 	screen->baset.c_oflag &= ~OXTABS;
    124  1.28     blymn 
    125  1.25     blymn 	screen->GT = 0;	/* historical. was used before we wired OXTABS off */
    126  1.25     blymn 	screen->NONL = (screen->baset.c_oflag & ONLCR) == 0;
    127   1.1   mycroft 
    128   1.2       cgd 	/*
    129   1.2       cgd 	 * XXX
    130   1.2       cgd 	 * System V and SMI systems overload VMIN and VTIME, such that
    131   1.2       cgd 	 * VMIN is the same as the VEOF element, and VTIME is the same
    132   1.2       cgd 	 * as the VEOL element.  This means that, if VEOF was ^D, the
    133   1.2       cgd 	 * default VMIN is 4.  Majorly stupid.
    134   1.2       cgd 	 */
    135  1.25     blymn 	screen->cbreakt = screen->baset;
    136  1.25     blymn 	screen->cbreakt.c_lflag &= ~(ECHO | ECHONL | ICANON);
    137  1.25     blymn 	screen->cbreakt.c_cc[VMIN] = 1;
    138  1.25     blymn 	screen->cbreakt.c_cc[VTIME] = 0;
    139  1.25     blymn 
    140  1.25     blymn 	screen->rawt = screen->cbreakt;
    141  1.25     blymn 	screen->rawt.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INLCR | IGNCR |
    142  1.25     blymn 				  ICRNL | IXON);
    143  1.25     blymn 	screen->rawt.c_oflag &= ~OPOST;
    144  1.25     blymn 	screen->rawt.c_lflag &= ~(ISIG | IEXTEN);
    145   1.2       cgd 
    146   1.2       cgd 	/*
    147   1.2       cgd 	 * In general, curses should leave hardware-related settings alone.
    148   1.2       cgd 	 * This includes parity and word size.  Older versions set the tty
    149   1.2       cgd 	 * to 8 bits, no parity in raw(), but this is considered to be an
    150   1.2       cgd 	 * artifact of the old tty interface.  If it's desired to change
    151   1.2       cgd 	 * parity and word size, the TCSASOFT bit has to be removed from the
    152   1.2       cgd 	 * calls that switch to/from "raw" mode.
    153   1.2       cgd 	 */
    154   1.2       cgd 	if (!__tcaction) {
    155  1.25     blymn 		screen->rawt.c_iflag &= ~ISTRIP;
    156  1.25     blymn 		screen->rawt.c_cflag &= ~(CSIZE | PARENB);
    157  1.25     blymn 		screen->rawt.c_cflag |= CS8;
    158   1.2       cgd 	}
    159   1.1   mycroft 
    160  1.25     blymn 	screen->curt = &screen->baset;
    161  1.25     blymn 	return (tcsetattr(fileno(screen->infd), __tcaction ?
    162  1.25     blymn 	    TCSASOFT | TCSADRAIN : TCSADRAIN, screen->curt) ? ERR : OK);
    163   1.1   mycroft }
    164   1.1   mycroft 
    165  1.36       wiz /*
    166  1.36       wiz  * raw --
    167  1.36       wiz  *	Put the terminal into raw mode
    168  1.36       wiz  */
    169   1.1   mycroft int
    170  1.15     blymn raw(void)
    171   1.1   mycroft {
    172  1.32       jdc #ifdef DEBUG
    173  1.32       jdc 	__CTRACE("raw()\n");
    174  1.32       jdc #endif
    175   1.9      phil 	/* Check if we need to restart ... */
    176  1.25     blymn 	if (_cursesi_screen->endwin)
    177  1.23       jdc 		__restartwin();
    178  1.11       mrg 
    179  1.25     blymn 	_cursesi_screen->useraw = __pfast = __rawmode = 1;
    180  1.25     blymn 	_cursesi_screen->curt = &_cursesi_screen->rawt;
    181  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    182  1.29    itojun 		return OK;
    183  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    184  1.25     blymn 			  TCSASOFT | TCSADRAIN : TCSADRAIN,
    185  1.25     blymn 			  _cursesi_screen->curt) ? ERR : OK);
    186   1.1   mycroft }
    187   1.1   mycroft 
    188  1.36       wiz /*
    189  1.36       wiz  * noraw --
    190  1.36       wiz  *	Put the terminal into cooked mode
    191  1.36       wiz  */
    192   1.1   mycroft int
    193  1.15     blymn noraw(void)
    194   1.1   mycroft {
    195  1.32       jdc #ifdef DEBUG
    196  1.32       jdc 	__CTRACE("noraw()\n");
    197  1.32       jdc #endif
    198   1.9      phil 	/* Check if we need to restart ... */
    199  1.25     blymn 	if (_cursesi_screen->endwin)
    200  1.23       jdc 		__restartwin();
    201  1.11       mrg 
    202  1.25     blymn 	_cursesi_screen->useraw = __pfast = __rawmode = 0;
    203  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    204  1.29    itojun 		return OK;
    205  1.25     blymn 	_cursesi_screen->curt = &_cursesi_screen->baset;
    206  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    207  1.25     blymn 			  TCSASOFT | TCSADRAIN : TCSADRAIN,
    208  1.25     blymn 			  _cursesi_screen->curt) ? ERR : OK);
    209   1.1   mycroft }
    210   1.1   mycroft 
    211  1.36       wiz /*
    212  1.36       wiz  * cbreak --
    213  1.36       wiz  * 	Enable cbreak mode
    214  1.36       wiz  */
    215   1.1   mycroft int
    216  1.15     blymn cbreak(void)
    217   1.1   mycroft {
    218  1.32       jdc #ifdef DEBUG
    219  1.32       jdc 	__CTRACE("cbreak()\n");
    220  1.32       jdc #endif
    221   1.9      phil 	/* Check if we need to restart ... */
    222  1.25     blymn 	if (_cursesi_screen->endwin)
    223  1.23       jdc 		__restartwin();
    224  1.11       mrg 
    225   1.1   mycroft 	__rawmode = 1;
    226  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    227  1.29    itojun 		return OK;
    228  1.25     blymn 	_cursesi_screen->curt = _cursesi_screen->useraw ?
    229  1.25     blymn 		&_cursesi_screen->rawt : &_cursesi_screen->cbreakt;
    230  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    231  1.25     blymn 			  TCSASOFT | TCSADRAIN : TCSADRAIN,
    232  1.25     blymn 			  _cursesi_screen->curt) ? ERR : OK);
    233   1.1   mycroft }
    234   1.1   mycroft 
    235  1.36       wiz /*
    236  1.36       wiz  * nocbreak --
    237  1.36       wiz  *	Disable cbreak mode
    238  1.36       wiz  */
    239   1.1   mycroft int
    240  1.15     blymn nocbreak(void)
    241   1.1   mycroft {
    242  1.32       jdc #ifdef DEBUG
    243  1.32       jdc 	__CTRACE("nocbreak()\n");
    244  1.32       jdc #endif
    245   1.9      phil 	/* Check if we need to restart ... */
    246  1.25     blymn 	if (_cursesi_screen->endwin)
    247  1.23       jdc 		__restartwin();
    248   1.1   mycroft 
    249   1.1   mycroft 	__rawmode = 0;
    250  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    251  1.29    itojun 		return OK;
    252  1.30     blymn 	  /* if we were in halfdelay mode then nuke the timeout */
    253  1.30     blymn 	if ((_cursesi_screen->half_delay == TRUE) &&
    254  1.30     blymn 	    (__notimeout() == ERR))
    255  1.30     blymn 		return ERR;
    256  1.30     blymn 
    257  1.30     blymn 	_cursesi_screen->half_delay = FALSE;
    258  1.25     blymn 	_cursesi_screen->curt = _cursesi_screen->useraw ?
    259  1.25     blymn 		&_cursesi_screen->rawt : &_cursesi_screen->baset;
    260  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    261  1.25     blymn 			  TCSASOFT | TCSADRAIN : TCSADRAIN,
    262  1.25     blymn 			  _cursesi_screen->curt) ? ERR : OK);
    263   1.1   mycroft }
    264  1.11       mrg 
    265  1.30     blymn /*
    266  1.30     blymn  * halfdelay --
    267  1.30     blymn  *    Put the terminal into cbreak mode with the specified timeout.
    268  1.30     blymn  *
    269  1.30     blymn  */
    270  1.30     blymn int
    271  1.31    atatat halfdelay(int duration)
    272  1.30     blymn {
    273  1.31    atatat 	if ((duration < 1) || (duration > 255))
    274  1.30     blymn 		return ERR;
    275  1.30     blymn 
    276  1.30     blymn 	if (cbreak() == ERR)
    277  1.30     blymn 		return ERR;
    278  1.30     blymn 
    279  1.31    atatat 	if (__timeout(duration) == ERR)
    280  1.30     blymn 		return ERR;
    281  1.30     blymn 
    282  1.30     blymn 	_cursesi_screen->half_delay = TRUE;
    283  1.30     blymn 	return OK;
    284  1.30     blymn }
    285  1.30     blymn 
    286  1.11       mrg int
    287  1.15     blymn __delay(void)
    288  1.11       mrg  {
    289  1.37  christos #ifdef DEBUG
    290  1.37  christos 	__CTRACE("__delay()\n");
    291  1.37  christos #endif
    292  1.11       mrg 	/* Check if we need to restart ... */
    293  1.25     blymn 	if (_cursesi_screen->endwin)
    294  1.23       jdc 		__restartwin();
    295  1.11       mrg 
    296  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    297  1.29    itojun 		return OK;
    298  1.25     blymn 	_cursesi_screen->rawt.c_cc[VMIN] = 1;
    299  1.25     blymn 	_cursesi_screen->rawt.c_cc[VTIME] = 0;
    300  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VMIN] = 1;
    301  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VTIME] = 0;
    302  1.25     blymn 	_cursesi_screen->baset.c_cc[VMIN] = 1;
    303  1.25     blymn 	_cursesi_screen->baset.c_cc[VTIME] = 0;
    304  1.11       mrg 
    305  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    306  1.25     blymn 		TCSASOFT : TCSANOW, _cursesi_screen->curt) ? ERR : OK);
    307  1.11       mrg }
    308  1.11       mrg 
    309  1.11       mrg int
    310  1.15     blymn __nodelay(void)
    311  1.11       mrg {
    312  1.37  christos #ifdef DEBUG
    313  1.37  christos 	__CTRACE("__nodelay()\n");
    314  1.37  christos #endif
    315  1.11       mrg 	/* Check if we need to restart ... */
    316  1.25     blymn 	if (_cursesi_screen->endwin)
    317  1.23       jdc 		__restartwin();
    318  1.11       mrg 
    319  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    320  1.29    itojun 		return OK;
    321  1.25     blymn 	_cursesi_screen->rawt.c_cc[VMIN] = 0;
    322  1.25     blymn 	_cursesi_screen->rawt.c_cc[VTIME] = 0;
    323  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VMIN] = 0;
    324  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VTIME] = 0;
    325  1.25     blymn 	_cursesi_screen->baset.c_cc[VMIN] = 0;
    326  1.25     blymn 	_cursesi_screen->baset.c_cc[VTIME] = 0;
    327  1.11       mrg 
    328  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    329  1.25     blymn 		TCSASOFT : TCSANOW, _cursesi_screen->curt) ? ERR : OK);
    330  1.11       mrg }
    331  1.11       mrg 
    332  1.11       mrg void
    333  1.15     blymn __save_termios(void)
    334  1.11       mrg {
    335  1.11       mrg 	/* Check if we need to restart ... */
    336  1.25     blymn 	if (_cursesi_screen->endwin)
    337  1.23       jdc 		__restartwin();
    338  1.11       mrg 
    339  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    340  1.29    itojun 		return;
    341  1.25     blymn 	_cursesi_screen->ovmin = _cursesi_screen->cbreakt.c_cc[VMIN];
    342  1.25     blymn 	_cursesi_screen->ovtime = _cursesi_screen->cbreakt.c_cc[VTIME];
    343  1.11       mrg }
    344  1.11       mrg 
    345  1.11       mrg void
    346  1.15     blymn __restore_termios(void)
    347  1.11       mrg {
    348  1.11       mrg 	/* Check if we need to restart ... */
    349  1.25     blymn 	if (_cursesi_screen->endwin)
    350  1.23       jdc 		__restartwin();
    351  1.11       mrg 
    352  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    353  1.29    itojun 		return;
    354  1.25     blymn 	_cursesi_screen->rawt.c_cc[VMIN] = _cursesi_screen->ovmin;
    355  1.25     blymn 	_cursesi_screen->rawt.c_cc[VTIME] = _cursesi_screen->ovtime;
    356  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VMIN] = _cursesi_screen->ovmin;
    357  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VTIME] = _cursesi_screen->ovtime;
    358  1.25     blymn 	_cursesi_screen->baset.c_cc[VMIN] = _cursesi_screen->ovmin;
    359  1.25     blymn 	_cursesi_screen->baset.c_cc[VTIME] = _cursesi_screen->ovtime;
    360  1.11       mrg }
    361  1.11       mrg 
    362  1.11       mrg int
    363  1.15     blymn __timeout(int delay)
    364  1.11       mrg {
    365  1.37  christos #ifdef DEBUG
    366  1.37  christos 	__CTRACE("__timeout()\n");
    367  1.37  christos #endif
    368  1.11       mrg 	/* Check if we need to restart ... */
    369  1.25     blymn 	if (_cursesi_screen->endwin)
    370  1.23       jdc 		__restartwin();
    371  1.11       mrg 
    372  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    373  1.29    itojun 		return OK;
    374  1.25     blymn 	_cursesi_screen->ovmin = _cursesi_screen->cbreakt.c_cc[VMIN];
    375  1.25     blymn 	_cursesi_screen->ovtime = _cursesi_screen->cbreakt.c_cc[VTIME];
    376  1.25     blymn 	_cursesi_screen->rawt.c_cc[VMIN] = 0;
    377  1.25     blymn 	_cursesi_screen->rawt.c_cc[VTIME] = delay;
    378  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VMIN] = 0;
    379  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VTIME] = delay;
    380  1.25     blymn 	_cursesi_screen->baset.c_cc[VMIN] = 0;
    381  1.25     blymn 	_cursesi_screen->baset.c_cc[VTIME] = delay;
    382  1.25     blymn 
    383  1.34       dsl 	return (tcsetattr(fileno(_cursesi_screen->infd),
    384  1.34       dsl 			  __tcaction ? TCSASOFT | TCSANOW : TCSANOW,
    385  1.25     blymn 			  _cursesi_screen->curt) ? ERR : OK);
    386  1.11       mrg }
    387  1.11       mrg 
    388  1.11       mrg int
    389  1.15     blymn __notimeout(void)
    390  1.11       mrg {
    391  1.37  christos #ifdef DEBUG
    392  1.37  christos 	__CTRACE("__notimeout()\n");
    393  1.37  christos #endif
    394  1.11       mrg 	/* Check if we need to restart ... */
    395  1.25     blymn 	if (_cursesi_screen->endwin)
    396  1.23       jdc 		__restartwin();
    397  1.11       mrg 
    398  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    399  1.29    itojun 		return OK;
    400  1.25     blymn 	_cursesi_screen->rawt.c_cc[VMIN] = 1;
    401  1.25     blymn 	_cursesi_screen->rawt.c_cc[VTIME] = 0;
    402  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VMIN] = 1;
    403  1.25     blymn 	_cursesi_screen->cbreakt.c_cc[VTIME] = 0;
    404  1.25     blymn 	_cursesi_screen->baset.c_cc[VMIN] = 1;
    405  1.25     blymn 	_cursesi_screen->baset.c_cc[VTIME] = 0;
    406  1.25     blymn 
    407  1.34       dsl 	return (tcsetattr(fileno(_cursesi_screen->infd),
    408  1.34       dsl 			  __tcaction ? TCSASOFT | TCSANOW : TCSANOW,
    409  1.25     blymn 			  _cursesi_screen->curt) ? ERR : OK);
    410  1.11       mrg }
    411  1.11       mrg 
    412   1.1   mycroft int
    413  1.15     blymn echo(void)
    414   1.1   mycroft {
    415  1.32       jdc #ifdef DEBUG
    416  1.32       jdc 	__CTRACE("echo()\n");
    417  1.32       jdc #endif
    418   1.9      phil 	/* Check if we need to restart ... */
    419  1.25     blymn 	if (_cursesi_screen->endwin)
    420  1.23       jdc 		__restartwin();
    421   1.9      phil 
    422   1.1   mycroft 	__echoit = 1;
    423  1.17   mycroft 	return (OK);
    424   1.1   mycroft }
    425   1.1   mycroft 
    426   1.1   mycroft int
    427  1.15     blymn noecho(void)
    428   1.1   mycroft {
    429  1.32       jdc #ifdef DEBUG
    430  1.32       jdc 	__CTRACE("noecho()\n");
    431  1.32       jdc #endif
    432   1.9      phil 	/* Check if we need to restart ... */
    433  1.25     blymn 	if (_cursesi_screen->endwin)
    434  1.23       jdc 		__restartwin();
    435   1.9      phil 
    436   1.1   mycroft 	__echoit = 0;
    437  1.17   mycroft 	return (OK);
    438   1.1   mycroft }
    439   1.1   mycroft 
    440   1.1   mycroft int
    441  1.15     blymn nl(void)
    442   1.1   mycroft {
    443  1.32       jdc #ifdef DEBUG
    444  1.32       jdc 	__CTRACE("nl()\n");
    445  1.32       jdc #endif
    446   1.9      phil 	/* Check if we need to restart ... */
    447  1.25     blymn 	if (_cursesi_screen->endwin)
    448  1.23       jdc 		__restartwin();
    449   1.9      phil 
    450  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    451  1.29    itojun 		return OK;
    452  1.25     blymn 	_cursesi_screen->rawt.c_iflag |= ICRNL;
    453  1.25     blymn 	_cursesi_screen->rawt.c_oflag |= ONLCR;
    454  1.25     blymn 	_cursesi_screen->cbreakt.c_iflag |= ICRNL;
    455  1.25     blymn 	_cursesi_screen->cbreakt.c_oflag |= ONLCR;
    456  1.25     blymn 	_cursesi_screen->baset.c_iflag |= ICRNL;
    457  1.25     blymn 	_cursesi_screen->baset.c_oflag |= ONLCR;
    458  1.25     blymn 
    459  1.32       jdc 	_cursesi_screen->nl = 1;
    460  1.25     blymn 	_cursesi_screen->pfast = _cursesi_screen->rawmode;
    461  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    462  1.25     blymn 			  TCSASOFT | TCSADRAIN : TCSADRAIN,
    463  1.25     blymn 			  _cursesi_screen->curt) ? ERR : OK);
    464   1.1   mycroft }
    465   1.1   mycroft 
    466   1.1   mycroft int
    467  1.15     blymn nonl(void)
    468   1.1   mycroft {
    469  1.32       jdc #ifdef DEBUG
    470  1.32       jdc 	__CTRACE("nonl()\n");
    471  1.32       jdc #endif
    472   1.9      phil 	/* Check if we need to restart ... */
    473  1.25     blymn 	if (_cursesi_screen->endwin)
    474  1.23       jdc 		__restartwin();
    475   1.9      phil 
    476  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    477  1.29    itojun 		return OK;
    478  1.25     blymn 	_cursesi_screen->rawt.c_iflag &= ~ICRNL;
    479  1.25     blymn 	_cursesi_screen->rawt.c_oflag &= ~ONLCR;
    480  1.25     blymn 	_cursesi_screen->cbreakt.c_iflag &= ~ICRNL;
    481  1.25     blymn 	_cursesi_screen->cbreakt.c_oflag &= ~ONLCR;
    482  1.25     blymn 	_cursesi_screen->baset.c_iflag &= ~ICRNL;
    483  1.25     blymn 	_cursesi_screen->baset.c_oflag &= ~ONLCR;
    484   1.1   mycroft 
    485  1.32       jdc 	_cursesi_screen->nl = 0;
    486   1.1   mycroft 	__pfast = 1;
    487  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    488  1.25     blymn 			  TCSASOFT | TCSADRAIN : TCSADRAIN,
    489  1.25     blymn 			  _cursesi_screen->curt) ? ERR : OK);
    490   1.2       cgd }
    491  1.33       jdc 
    492  1.33       jdc #ifndef _CURSES_USE_MACROS
    493  1.33       jdc void
    494  1.33       jdc noqiflush(void)
    495  1.33       jdc {
    496  1.33       jdc 	(void) intrflush(stdscr, FALSE);
    497  1.33       jdc }
    498  1.33       jdc 
    499  1.33       jdc void
    500  1.33       jdc qiflush(void)
    501  1.33       jdc {
    502  1.33       jdc 	(void) intrflush(stdscr, TRUE);
    503  1.33       jdc }
    504  1.33       jdc #endif	/* _CURSES_USE_MACROS */
    505   1.2       cgd 
    506  1.14       jdc int
    507  1.15     blymn intrflush(WINDOW *win, bool bf)	/*ARGSUSED*/
    508  1.14       jdc {
    509  1.14       jdc 	/* Check if we need to restart ... */
    510  1.25     blymn 	if (_cursesi_screen->endwin)
    511  1.23       jdc 		__restartwin();
    512  1.14       jdc 
    513  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    514  1.29    itojun 		return OK;
    515  1.14       jdc 	if (bf) {
    516  1.25     blymn 		_cursesi_screen->rawt.c_lflag &= ~NOFLSH;
    517  1.25     blymn 		_cursesi_screen->cbreakt.c_lflag &= ~NOFLSH;
    518  1.25     blymn 		_cursesi_screen->baset.c_lflag &= ~NOFLSH;
    519  1.14       jdc 	} else {
    520  1.25     blymn 		_cursesi_screen->rawt.c_lflag |= NOFLSH;
    521  1.25     blymn 		_cursesi_screen->cbreakt.c_lflag |= NOFLSH;
    522  1.25     blymn 		_cursesi_screen->baset.c_lflag |= NOFLSH;
    523  1.14       jdc 	}
    524  1.14       jdc 
    525  1.14       jdc 	__pfast = 1;
    526  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    527  1.25     blymn 			  TCSASOFT | TCSADRAIN : TCSADRAIN,
    528  1.25     blymn 			  _cursesi_screen->curt) ? ERR : OK);
    529  1.14       jdc }
    530  1.14       jdc 
    531   1.2       cgd void
    532  1.25     blymn __startwin(SCREEN *screen)
    533   1.2       cgd {
    534   1.6       cgd 
    535  1.25     blymn 	(void) fflush(screen->infd);
    536   1.6       cgd 
    537   1.6       cgd 	/*
    538   1.6       cgd 	 * Some C libraries default to a 1K buffer when talking to a tty.
    539   1.6       cgd 	 * With a larger screen, especially across a network, we'd like
    540   1.6       cgd 	 * to get it to all flush in a single write.  Make it twice as big
    541   1.6       cgd 	 * as just the characters (so that we have room for cursor motions
    542  1.11       mrg 	 * and attribute information) but no more than 8K.
    543   1.6       cgd 	 */
    544  1.25     blymn 	if (screen->stdbuf == NULL) {
    545  1.25     blymn 		screen->len = LINES * COLS * 2;
    546  1.25     blymn 		if (screen->len > 8192)
    547  1.25     blymn 			screen->len = 8192;
    548  1.25     blymn 		if ((screen->stdbuf = malloc(screen->len)) == NULL)
    549  1.25     blymn 			screen->len = 0;
    550   1.6       cgd 	}
    551  1.25     blymn 	(void) setvbuf(screen->outfd, screen->stdbuf, _IOFBF, screen->len);
    552   1.2       cgd 
    553  1.27     blymn 	t_puts(screen->cursesi_genbuf, __tc_ti, 0, __cputchar_args,
    554  1.27     blymn 	       (void *) screen->outfd);
    555  1.27     blymn 	t_puts(screen->cursesi_genbuf, __tc_vs, 0, __cputchar_args,
    556  1.27     blymn 	       (void *) screen->outfd);
    557  1.25     blymn 	if (screen->curscr->flags & __KEYPAD)
    558  1.27     blymn 		t_puts(screen->cursesi_genbuf, __tc_ks, 0, __cputchar_args,
    559  1.27     blymn 		       (void *) screen->outfd);
    560  1.25     blymn 	screen->endwin = 0;
    561   1.1   mycroft }
    562   1.1   mycroft 
    563   1.1   mycroft int
    564  1.15     blymn endwin(void)
    565   1.1   mycroft {
    566  1.38       jdc #ifdef DEBUG
    567  1.38       jdc 	__CTRACE("endwin\n");
    568  1.38       jdc #endif
    569   1.8      phil 	return __stopwin();
    570  1.11       mrg }
    571  1.11       mrg 
    572  1.13     blymn bool
    573  1.15     blymn isendwin(void)
    574  1.11       mrg {
    575  1.25     blymn 	return (_cursesi_screen->endwin ? TRUE : FALSE);
    576  1.11       mrg }
    577  1.11       mrg 
    578  1.11       mrg int
    579  1.15     blymn flushinp(void)
    580  1.11       mrg {
    581  1.25     blymn 	(void) fpurge(_cursesi_screen->infd);
    582  1.11       mrg 	return (OK);
    583  1.14       jdc }
    584  1.14       jdc 
    585   1.1   mycroft /*
    586   1.1   mycroft  * The following routines, savetty and resetty are completely useless and
    587   1.1   mycroft  * are left in only as stubs.  If people actually use them they will almost
    588   1.1   mycroft  * certainly screw up the state of the world.
    589   1.1   mycroft  */
    590  1.25     blymn /*static struct termios savedtty;*/
    591   1.1   mycroft int
    592  1.15     blymn savetty(void)
    593   1.1   mycroft {
    594  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    595  1.29    itojun 		return OK;
    596  1.25     blymn 	return (tcgetattr(fileno(_cursesi_screen->infd),
    597  1.25     blymn 			  &_cursesi_screen->savedtty) ? ERR : OK);
    598   1.1   mycroft }
    599   1.1   mycroft 
    600   1.1   mycroft int
    601  1.15     blymn resetty(void)
    602   1.1   mycroft {
    603  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    604  1.29    itojun 		return OK;
    605  1.25     blymn 	return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
    606  1.25     blymn 			  TCSASOFT | TCSADRAIN : TCSADRAIN,
    607  1.25     blymn 			  &_cursesi_screen->savedtty) ? ERR : OK);
    608  1.19     blymn }
    609  1.19     blymn 
    610  1.19     blymn /*
    611  1.19     blymn  * erasechar --
    612  1.19     blymn  *     Return the character of the erase key.
    613  1.19     blymn  */
    614  1.19     blymn char
    615  1.19     blymn erasechar(void)
    616  1.19     blymn {
    617  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    618  1.29    itojun 		return 0;
    619  1.25     blymn 	return _cursesi_screen->baset.c_cc[VERASE];
    620  1.19     blymn }
    621  1.19     blymn 
    622  1.19     blymn /*
    623  1.19     blymn  * killchar --
    624  1.19     blymn  *     Return the character of the kill key.
    625  1.19     blymn  */
    626  1.19     blymn char
    627  1.19     blymn killchar(void)
    628  1.19     blymn {
    629  1.29    itojun 	if (_cursesi_screen->notty == TRUE)
    630  1.29    itojun 		return 0;
    631  1.25     blymn 	return _cursesi_screen->baset.c_cc[VKILL];
    632   1.1   mycroft }
    633