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