1 /* Copyright (C) 1999 Free Software Foundation, Inc.
3 This file is part of GNU Bash, the Bourne Again SHell.
5 Bash is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
10 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 You should have received a copy of the GNU General Public License along
16 with Bash; see the file COPYING. If not, write to the Free Software
17 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
20 * shtty.c -- abstract interface to the terminal, focusing on capabilities.
33 static TTYSTRUCT ttin, ttout;
34 static int ttsaved = 0;
41 #ifdef TERMIOS_TTY_DRIVER
42 return tcgetattr(fd, ttp);
44 # ifdef TERMIO_TTY_DRIVER
45 return ioctl(fd, TCGETA, ttp);
47 return ioctl(fd, TIOCGETP, ttp);
57 #ifdef TERMIOS_TTY_DRIVER
58 return tcsetattr(fd, TCSADRAIN, ttp);
60 # ifdef TERMIO_TTY_DRIVER
61 return ioctl(fd, TCSETAW, ttp);
63 return ioctl(fd, TIOCSETN, ttp);
74 ttgetattr (1, &ttout);
84 ttsetattr (1, &ttout);
88 /* Retrieve the attributes associated with tty fd FD. */
94 return ((TTYSTRUCT *)0);
100 return ((TTYSTRUCT *)0);
104 * Change attributes in ttp so that when it is installed using
105 * ttsetattr, the terminal will be in one-char-at-a-time mode.
111 #if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
113 /* XXX - might not want this -- it disables erase and kill processing. */
114 ttp->c_lflag &= ~ICANON;
116 ttp->c_lflag |= ISIG;
118 ttp->c_lflag |= IEXTEN;
121 ttp->c_iflag |= ICRNL; /* make sure we get CR->NL on input */
122 ttp->c_iflag &= ~INLCR; /* but no NL->CR */
125 ttp->c_oflag |= OPOST;
128 ttp->c_oflag |= ONLCR;
131 ttp->c_oflag &= ~OCRNL;
134 ttp->c_oflag &= ~ONOCR;
137 ttp->c_oflag &= ~ONLRET;
141 ttp->c_cc[VTIME] = 0;
145 ttp->sg_flags |= CBREAK;
152 /* Set the terminal into one-character-at-a-time mode */
161 if (tt_setonechar(&tt) < 0)
163 return (ttsetattr (0, &tt));
167 * Change attributes in ttp so that when it is installed using
168 * ttsetattr, the terminal will be in no-echo mode.
174 #if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
175 ttp->c_lflag &= ~(ECHO|ECHOK|ECHONL);
177 ttp->sg_flags &= ~ECHO;
183 /* Set the terminal into no-echo mode */
192 if (tt_setnoecho (&tt) < 0)
194 return (ttsetattr (0, &tt));
198 * Change attributes in ttp so that when it is installed using
199 * ttsetattr, the terminal will be in eight-bit mode (pass8).
205 #if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
206 ttp->c_iflag &= ~ISTRIP;
208 ttp->c_cflag &= ~PARENB;
210 ttp->sg_flags |= ANYP;
216 /* Set the terminal into eight-bit mode */
225 if (tt_seteightbit (&tt) < 0)
227 return (ttsetattr (0, &tt));
231 * Change attributes in ttp so that when it is installed using
232 * ttsetattr, the terminal will be in non-canonical input mode.
238 #if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
239 ttp->c_lflag &= ~ICANON;
245 /* Set the terminal into non-canonical mode */
254 if (tt_setnocanon (&tt) < 0)
256 return (ttsetattr (0, &tt));
260 * Change attributes in ttp so that when it is installed using
261 * ttsetattr, the terminal will be in cbreak, no-echo mode.
267 if (tt_setonechar (ttp) < 0)
269 return (tt_setnoecho (ttp));
272 /* Set the terminal into cbreak (no-echo, one-character-at-a-time) mode */
281 if (tt_setcbreak (&tt) < 0)
283 return (ttsetattr (0, &tt));