2 * shtty.c -- abstract interface to the terminal, focusing on capabilities.
5 /* Copyright (C) 1999 Free Software Foundation, Inc.
7 This file is part of GNU Bush, the Bourne Again SHell.
9 Bush is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
14 Bush is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with Bush. If not, see <http://www.gnu.org/licenses/>.
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 internally-saved 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 tty associated with FD and TTP into one-character-at-a-time mode */
154 ttfd_onechar (fd
, ttp
)
158 if (tt_setonechar(ttp
) < 0)
160 return (ttsetattr (fd
, ttp
));
163 /* Set the terminal into one-character-at-a-time mode */
172 return (ttfd_onechar (0, &tt
));
176 * Change attributes in ttp so that when it is installed using
177 * ttsetattr, the terminal will be in no-echo mode.
183 #if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
184 ttp
->c_lflag
&= ~(ECHO
|ECHOK
|ECHONL
);
186 ttp
->sg_flags
&= ~ECHO
;
192 /* Set the tty associated with FD and TTP into no-echo mode */
194 ttfd_noecho (fd
, ttp
)
198 if (tt_setnoecho (ttp
) < 0)
200 return (ttsetattr (fd
, ttp
));
203 /* Set the terminal into no-echo mode */
212 return (ttfd_noecho (0, &tt
));
216 * Change attributes in ttp so that when it is installed using
217 * ttsetattr, the terminal will be in eight-bit mode (pass8).
223 #if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
224 ttp
->c_iflag
&= ~ISTRIP
;
226 ttp
->c_cflag
&= ~PARENB
;
228 ttp
->sg_flags
|= ANYP
;
234 /* Set the tty associated with FD and TTP into eight-bit mode */
236 ttfd_eightbit (fd
, ttp
)
240 if (tt_seteightbit (ttp
) < 0)
242 return (ttsetattr (fd
, ttp
));
245 /* Set the terminal into eight-bit mode */
254 return (ttfd_eightbit (0, &tt
));
258 * Change attributes in ttp so that when it is installed using
259 * ttsetattr, the terminal will be in non-canonical input mode.
265 #if defined (TERMIOS_TTY_DRIVER) || defined (TERMIO_TTY_DRIVER)
266 ttp
->c_lflag
&= ~ICANON
;
272 /* Set the tty associated with FD and TTP into non-canonical mode */
274 ttfd_nocanon (fd
, ttp
)
278 if (tt_setnocanon (ttp
) < 0)
280 return (ttsetattr (fd
, ttp
));
283 /* Set the terminal into non-canonical mode */
292 return (ttfd_nocanon (0, &tt
));
296 * Change attributes in ttp so that when it is installed using
297 * ttsetattr, the terminal will be in cbreak, no-echo mode.
303 if (tt_setonechar (ttp
) < 0)
305 return (tt_setnoecho (ttp
));
308 /* Set the tty associated with FD and TTP into cbreak (no-echo,
309 one-character-at-a-time) mode */
311 ttfd_cbreak (fd
, ttp
)
315 if (tt_setcbreak (ttp
) < 0)
317 return (ttsetattr (fd
, ttp
));
320 /* Set the terminal into cbreak (no-echo, one-character-at-a-time) mode */
329 return (ttfd_cbreak (0, &tt
));