Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/bash/src/lib/readline/rltty.c |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /* rltty.c -- functions to prepare and restore the terminal for readline's | - | ||||||||||||||||||
2 | use. */ | - | ||||||||||||||||||
3 | - | |||||||||||||||||||
4 | /* Copyright (C) 1992-2017 Free Software Foundation, Inc. | - | ||||||||||||||||||
5 | - | |||||||||||||||||||
6 | This file is part of the GNU Readline Library (Readline), a library | - | ||||||||||||||||||
7 | for reading lines of text with interactive input and history editing. | - | ||||||||||||||||||
8 | - | |||||||||||||||||||
9 | Readline 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. | - | ||||||||||||||||||
13 | - | |||||||||||||||||||
14 | Readline 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. | - | ||||||||||||||||||
18 | - | |||||||||||||||||||
19 | You should have received a copy of the GNU General Public License | - | ||||||||||||||||||
20 | along with Readline. If not, see <http://www.gnu.org/licenses/>. | - | ||||||||||||||||||
21 | */ | - | ||||||||||||||||||
22 | - | |||||||||||||||||||
23 | #define READLINE_LIBRARY | - | ||||||||||||||||||
24 | - | |||||||||||||||||||
25 | #if defined (HAVE_CONFIG_H) | - | ||||||||||||||||||
26 | # include <config.h> | - | ||||||||||||||||||
27 | #endif | - | ||||||||||||||||||
28 | - | |||||||||||||||||||
29 | #include <sys/types.h> | - | ||||||||||||||||||
30 | #include <signal.h> | - | ||||||||||||||||||
31 | #include <errno.h> | - | ||||||||||||||||||
32 | #include <stdio.h> | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #if defined (HAVE_UNISTD_H) | - | ||||||||||||||||||
35 | # include <unistd.h> | - | ||||||||||||||||||
36 | #endif /* HAVE_UNISTD_H */ | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | #include "rldefs.h" | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | #include "rltty.h" | - | ||||||||||||||||||
41 | #if defined (HAVE_SYS_IOCTL_H) | - | ||||||||||||||||||
42 | # include <sys/ioctl.h> /* include for declaration of ioctl */ | - | ||||||||||||||||||
43 | #endif | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | #include "readline.h" | - | ||||||||||||||||||
46 | #include "rlprivate.h" | - | ||||||||||||||||||
47 | - | |||||||||||||||||||
48 | #if !defined (errno) | - | ||||||||||||||||||
49 | extern int errno; | - | ||||||||||||||||||
50 | #endif /* !errno */ | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | rl_vintfunc_t *rl_prep_term_function = rl_prep_terminal; | - | ||||||||||||||||||
53 | rl_voidfunc_t *rl_deprep_term_function = rl_deprep_terminal; | - | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | static void set_winsize PARAMS((int)); | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | /* **************************************************************** */ | - | ||||||||||||||||||
58 | /* */ | - | ||||||||||||||||||
59 | /* Saving and Restoring the TTY */ | - | ||||||||||||||||||
60 | /* */ | - | ||||||||||||||||||
61 | /* **************************************************************** */ | - | ||||||||||||||||||
62 | - | |||||||||||||||||||
63 | /* Non-zero means that the terminal is in a prepped state. There are several | - | ||||||||||||||||||
64 | flags that are OR'd in to denote whether or not we have sent various | - | ||||||||||||||||||
65 | init strings to the terminal. */ | - | ||||||||||||||||||
66 | #define TPX_PREPPED 0x01 | - | ||||||||||||||||||
67 | #define TPX_BRACKPASTE 0x02 | - | ||||||||||||||||||
68 | #define TPX_METAKEY 0x04 | - | ||||||||||||||||||
69 | - | |||||||||||||||||||
70 | static int terminal_prepped; | - | ||||||||||||||||||
71 | - | |||||||||||||||||||
72 | static _RL_TTY_CHARS _rl_tty_chars, _rl_last_tty_chars; | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | /* If non-zero, means that this process has called tcflow(fd, TCOOFF) | - | ||||||||||||||||||
75 | and output is suspended. */ | - | ||||||||||||||||||
76 | #if defined (__ksr1__) | - | ||||||||||||||||||
77 | static int ksrflow; | - | ||||||||||||||||||
78 | #endif | - | ||||||||||||||||||
79 | - | |||||||||||||||||||
80 | /* Dummy call to force a backgrounded readline to stop before it tries | - | ||||||||||||||||||
81 | to get the tty settings. */ | - | ||||||||||||||||||
82 | static void | - | ||||||||||||||||||
83 | set_winsize (tty) | - | ||||||||||||||||||
84 | int tty; | - | ||||||||||||||||||
85 | { | - | ||||||||||||||||||
86 | #if defined (TIOCGWINSZ) | - | ||||||||||||||||||
87 | struct winsize w; | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | if (ioctl (tty, TIOCGWINSZ, &w) == 0)
| 0 | ||||||||||||||||||
90 | (void) ioctl (tty, TIOCSWINSZ, &w); never executed: (void) ioctl (tty, 0x5414 , &w); | 0 | ||||||||||||||||||
91 | #endif /* TIOCGWINSZ */ | - | ||||||||||||||||||
92 | } never executed: end of block | 0 | ||||||||||||||||||
93 | - | |||||||||||||||||||
94 | #if defined (NO_TTY_DRIVER) | - | ||||||||||||||||||
95 | /* Nothing */ | - | ||||||||||||||||||
96 | #elif defined (NEW_TTY_DRIVER) | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | /* Values for the `flags' field of a struct bsdtty. This tells which | - | ||||||||||||||||||
99 | elements of the struct bsdtty have been fetched from the system and | - | ||||||||||||||||||
100 | are valid. */ | - | ||||||||||||||||||
101 | #define SGTTY_SET 0x01 | - | ||||||||||||||||||
102 | #define LFLAG_SET 0x02 | - | ||||||||||||||||||
103 | #define TCHARS_SET 0x04 | - | ||||||||||||||||||
104 | #define LTCHARS_SET 0x08 | - | ||||||||||||||||||
105 | - | |||||||||||||||||||
106 | struct bsdtty { | - | ||||||||||||||||||
107 | struct sgttyb sgttyb; /* Basic BSD tty driver information. */ | - | ||||||||||||||||||
108 | int lflag; /* Local mode flags, like LPASS8. */ | - | ||||||||||||||||||
109 | #if defined (TIOCGETC) | - | ||||||||||||||||||
110 | struct tchars tchars; /* Terminal special characters, including ^S and ^Q. */ | - | ||||||||||||||||||
111 | #endif | - | ||||||||||||||||||
112 | #if defined (TIOCGLTC) | - | ||||||||||||||||||
113 | struct ltchars ltchars; /* 4.2 BSD editing characters */ | - | ||||||||||||||||||
114 | #endif | - | ||||||||||||||||||
115 | int flags; /* Bitmap saying which parts of the struct are valid. */ | - | ||||||||||||||||||
116 | }; | - | ||||||||||||||||||
117 | - | |||||||||||||||||||
118 | #define TIOTYPE struct bsdtty | - | ||||||||||||||||||
119 | - | |||||||||||||||||||
120 | static TIOTYPE otio; | - | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | static void save_tty_chars PARAMS((TIOTYPE *)); | - | ||||||||||||||||||
123 | static int _get_tty_settings PARAMS((int, TIOTYPE *)); | - | ||||||||||||||||||
124 | static int get_tty_settings PARAMS((int, TIOTYPE *)); | - | ||||||||||||||||||
125 | static int _set_tty_settings PARAMS((int, TIOTYPE *)); | - | ||||||||||||||||||
126 | static int set_tty_settings PARAMS((int, TIOTYPE *)); | - | ||||||||||||||||||
127 | - | |||||||||||||||||||
128 | static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *)); | - | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t *)); | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | static void | - | ||||||||||||||||||
133 | save_tty_chars (TIOTYPE *tiop) | - | ||||||||||||||||||
134 | { | - | ||||||||||||||||||
135 | _rl_last_tty_chars = _rl_tty_chars; | - | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | if (tiop->flags & SGTTY_SET) | - | ||||||||||||||||||
138 | { | - | ||||||||||||||||||
139 | _rl_tty_chars.t_erase = tiop->sgttyb.sg_erase; | - | ||||||||||||||||||
140 | _rl_tty_chars.t_kill = tiop->sgttyb.sg_kill; | - | ||||||||||||||||||
141 | } | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | if (tiop->flags & TCHARS_SET) | - | ||||||||||||||||||
144 | { | - | ||||||||||||||||||
145 | _rl_intr_char = _rl_tty_chars.t_intr = tiop->tchars.t_intrc; | - | ||||||||||||||||||
146 | _rl_quit_char = _rl_tty_chars.t_quit = tiop->tchars.t_quitc; | - | ||||||||||||||||||
147 | - | |||||||||||||||||||
148 | _rl_tty_chars.t_start = tiop->tchars.t_startc; | - | ||||||||||||||||||
149 | _rl_tty_chars.t_stop = tiop->tchars.t_stopc; | - | ||||||||||||||||||
150 | _rl_tty_chars.t_eof = tiop->tchars.t_eofc; | - | ||||||||||||||||||
151 | _rl_tty_chars.t_eol = '\n'; | - | ||||||||||||||||||
152 | _rl_tty_chars.t_eol2 = tiop->tchars.t_brkc; | - | ||||||||||||||||||
153 | } | - | ||||||||||||||||||
154 | - | |||||||||||||||||||
155 | if (tiop->flags & LTCHARS_SET) | - | ||||||||||||||||||
156 | { | - | ||||||||||||||||||
157 | _rl_susp_char = _rl_tty_chars.t_susp = tiop->ltchars.t_suspc; | - | ||||||||||||||||||
158 | - | |||||||||||||||||||
159 | _rl_tty_chars.t_dsusp = tiop->ltchars.t_dsuspc; | - | ||||||||||||||||||
160 | _rl_tty_chars.t_reprint = tiop->ltchars.t_rprntc; | - | ||||||||||||||||||
161 | _rl_tty_chars.t_flush = tiop->ltchars.t_flushc; | - | ||||||||||||||||||
162 | _rl_tty_chars.t_werase = tiop->ltchars.t_werasc; | - | ||||||||||||||||||
163 | _rl_tty_chars.t_lnext = tiop->ltchars.t_lnextc; | - | ||||||||||||||||||
164 | } | - | ||||||||||||||||||
165 | - | |||||||||||||||||||
166 | _rl_tty_chars.t_status = -1; | - | ||||||||||||||||||
167 | } | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | static int | - | ||||||||||||||||||
170 | get_tty_settings (int tty, TIOTYPE *tiop) | - | ||||||||||||||||||
171 | { | - | ||||||||||||||||||
172 | set_winsize (tty); | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | tiop->flags = tiop->lflag = 0; | - | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | errno = 0; | - | ||||||||||||||||||
177 | if (ioctl (tty, TIOCGETP, &(tiop->sgttyb)) < 0) | - | ||||||||||||||||||
178 | return -1; | - | ||||||||||||||||||
179 | tiop->flags |= SGTTY_SET; | - | ||||||||||||||||||
180 | - | |||||||||||||||||||
181 | #if defined (TIOCLGET) | - | ||||||||||||||||||
182 | if (ioctl (tty, TIOCLGET, &(tiop->lflag)) == 0) | - | ||||||||||||||||||
183 | tiop->flags |= LFLAG_SET; | - | ||||||||||||||||||
184 | #endif | - | ||||||||||||||||||
185 | - | |||||||||||||||||||
186 | #if defined (TIOCGETC) | - | ||||||||||||||||||
187 | if (ioctl (tty, TIOCGETC, &(tiop->tchars)) == 0) | - | ||||||||||||||||||
188 | tiop->flags |= TCHARS_SET; | - | ||||||||||||||||||
189 | #endif | - | ||||||||||||||||||
190 | - | |||||||||||||||||||
191 | #if defined (TIOCGLTC) | - | ||||||||||||||||||
192 | if (ioctl (tty, TIOCGLTC, &(tiop->ltchars)) == 0) | - | ||||||||||||||||||
193 | tiop->flags |= LTCHARS_SET; | - | ||||||||||||||||||
194 | #endif | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | return 0; | - | ||||||||||||||||||
197 | } | - | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | static int | - | ||||||||||||||||||
200 | set_tty_settings (int tty, TIOTYPE *tiop) | - | ||||||||||||||||||
201 | { | - | ||||||||||||||||||
202 | if (tiop->flags & SGTTY_SET) | - | ||||||||||||||||||
203 | { | - | ||||||||||||||||||
204 | ioctl (tty, TIOCSETN, &(tiop->sgttyb)); | - | ||||||||||||||||||
205 | tiop->flags &= ~SGTTY_SET; | - | ||||||||||||||||||
206 | } | - | ||||||||||||||||||
207 | _rl_echoing_p = 1; | - | ||||||||||||||||||
208 | - | |||||||||||||||||||
209 | #if defined (TIOCLSET) | - | ||||||||||||||||||
210 | if (tiop->flags & LFLAG_SET) | - | ||||||||||||||||||
211 | { | - | ||||||||||||||||||
212 | ioctl (tty, TIOCLSET, &(tiop->lflag)); | - | ||||||||||||||||||
213 | tiop->flags &= ~LFLAG_SET; | - | ||||||||||||||||||
214 | } | - | ||||||||||||||||||
215 | #endif | - | ||||||||||||||||||
216 | - | |||||||||||||||||||
217 | #if defined (TIOCSETC) | - | ||||||||||||||||||
218 | if (tiop->flags & TCHARS_SET) | - | ||||||||||||||||||
219 | { | - | ||||||||||||||||||
220 | ioctl (tty, TIOCSETC, &(tiop->tchars)); | - | ||||||||||||||||||
221 | tiop->flags &= ~TCHARS_SET; | - | ||||||||||||||||||
222 | } | - | ||||||||||||||||||
223 | #endif | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | #if defined (TIOCSLTC) | - | ||||||||||||||||||
226 | if (tiop->flags & LTCHARS_SET) | - | ||||||||||||||||||
227 | { | - | ||||||||||||||||||
228 | ioctl (tty, TIOCSLTC, &(tiop->ltchars)); | - | ||||||||||||||||||
229 | tiop->flags &= ~LTCHARS_SET; | - | ||||||||||||||||||
230 | } | - | ||||||||||||||||||
231 | #endif | - | ||||||||||||||||||
232 | - | |||||||||||||||||||
233 | return 0; | - | ||||||||||||||||||
234 | } | - | ||||||||||||||||||
235 | - | |||||||||||||||||||
236 | static void | - | ||||||||||||||||||
237 | prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop) | - | ||||||||||||||||||
238 | { | - | ||||||||||||||||||
239 | _rl_echoing_p = (oldtio.sgttyb.sg_flags & ECHO); | - | ||||||||||||||||||
240 | _rl_echoctl = (oldtio.sgttyb.sg_flags & ECHOCTL); | - | ||||||||||||||||||
241 | - | |||||||||||||||||||
242 | /* Copy the original settings to the structure we're going to use for | - | ||||||||||||||||||
243 | our settings. */ | - | ||||||||||||||||||
244 | tiop->sgttyb = oldtio.sgttyb; | - | ||||||||||||||||||
245 | tiop->lflag = oldtio.lflag; | - | ||||||||||||||||||
246 | #if defined (TIOCGETC) | - | ||||||||||||||||||
247 | tiop->tchars = oldtio.tchars; | - | ||||||||||||||||||
248 | #endif | - | ||||||||||||||||||
249 | #if defined (TIOCGLTC) | - | ||||||||||||||||||
250 | tiop->ltchars = oldtio.ltchars; | - | ||||||||||||||||||
251 | #endif | - | ||||||||||||||||||
252 | tiop->flags = oldtio.flags; | - | ||||||||||||||||||
253 | - | |||||||||||||||||||
254 | /* First, the basic settings to put us into character-at-a-time, no-echo | - | ||||||||||||||||||
255 | input mode. */ | - | ||||||||||||||||||
256 | tiop->sgttyb.sg_flags &= ~(ECHO | CRMOD); | - | ||||||||||||||||||
257 | tiop->sgttyb.sg_flags |= CBREAK; | - | ||||||||||||||||||
258 | - | |||||||||||||||||||
259 | /* If this terminal doesn't care how the 8th bit is used, then we can | - | ||||||||||||||||||
260 | use it for the meta-key. If only one of even or odd parity is | - | ||||||||||||||||||
261 | specified, then the terminal is using parity, and we cannot. */ | - | ||||||||||||||||||
262 | #if !defined (ANYP) | - | ||||||||||||||||||
263 | # define ANYP (EVENP | ODDP) | - | ||||||||||||||||||
264 | #endif | - | ||||||||||||||||||
265 | if (((oldtio.sgttyb.sg_flags & ANYP) == ANYP) || | - | ||||||||||||||||||
266 | ((oldtio.sgttyb.sg_flags & ANYP) == 0)) | - | ||||||||||||||||||
267 | { | - | ||||||||||||||||||
268 | tiop->sgttyb.sg_flags |= ANYP; | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | /* Hack on local mode flags if we can. */ | - | ||||||||||||||||||
271 | #if defined (TIOCLGET) | - | ||||||||||||||||||
272 | # if defined (LPASS8) | - | ||||||||||||||||||
273 | tiop->lflag |= LPASS8; | - | ||||||||||||||||||
274 | # endif /* LPASS8 */ | - | ||||||||||||||||||
275 | #endif /* TIOCLGET */ | - | ||||||||||||||||||
276 | } | - | ||||||||||||||||||
277 | - | |||||||||||||||||||
278 | #if defined (TIOCGETC) | - | ||||||||||||||||||
279 | # if defined (USE_XON_XOFF) | - | ||||||||||||||||||
280 | /* Get rid of terminal output start and stop characters. */ | - | ||||||||||||||||||
281 | tiop->tchars.t_stopc = -1; /* C-s */ | - | ||||||||||||||||||
282 | tiop->tchars.t_startc = -1; /* C-q */ | - | ||||||||||||||||||
283 | - | |||||||||||||||||||
284 | /* If there is an XON character, bind it to restart the output. */ | - | ||||||||||||||||||
285 | if (oldtio.tchars.t_startc != -1) | - | ||||||||||||||||||
286 | rl_bind_key (oldtio.tchars.t_startc, rl_restart_output); | - | ||||||||||||||||||
287 | # endif /* USE_XON_XOFF */ | - | ||||||||||||||||||
288 | - | |||||||||||||||||||
289 | /* If there is an EOF char, bind _rl_eof_char to it. */ | - | ||||||||||||||||||
290 | if (oldtio.tchars.t_eofc != -1) | - | ||||||||||||||||||
291 | _rl_eof_char = oldtio.tchars.t_eofc; | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | # if defined (NO_KILL_INTR) | - | ||||||||||||||||||
294 | /* Get rid of terminal-generated SIGQUIT and SIGINT. */ | - | ||||||||||||||||||
295 | tiop->tchars.t_quitc = -1; /* C-\ */ | - | ||||||||||||||||||
296 | tiop->tchars.t_intrc = -1; /* C-c */ | - | ||||||||||||||||||
297 | # endif /* NO_KILL_INTR */ | - | ||||||||||||||||||
298 | #endif /* TIOCGETC */ | - | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | #if defined (TIOCGLTC) | - | ||||||||||||||||||
301 | /* Make the interrupt keys go away. Just enough to make people happy. */ | - | ||||||||||||||||||
302 | tiop->ltchars.t_dsuspc = -1; /* C-y */ | - | ||||||||||||||||||
303 | tiop->ltchars.t_lnextc = -1; /* C-v */ | - | ||||||||||||||||||
304 | #endif /* TIOCGLTC */ | - | ||||||||||||||||||
305 | } | - | ||||||||||||||||||
306 | - | |||||||||||||||||||
307 | #else /* !defined (NEW_TTY_DRIVER) */ | - | ||||||||||||||||||
308 | - | |||||||||||||||||||
309 | #if !defined (VMIN) | - | ||||||||||||||||||
310 | # define VMIN VEOF | - | ||||||||||||||||||
311 | #endif | - | ||||||||||||||||||
312 | - | |||||||||||||||||||
313 | #if !defined (VTIME) | - | ||||||||||||||||||
314 | # define VTIME VEOL | - | ||||||||||||||||||
315 | #endif | - | ||||||||||||||||||
316 | - | |||||||||||||||||||
317 | #if defined (TERMIOS_TTY_DRIVER) | - | ||||||||||||||||||
318 | # define TIOTYPE struct termios | - | ||||||||||||||||||
319 | # define DRAIN_OUTPUT(fd) tcdrain (fd) | - | ||||||||||||||||||
320 | # define GETATTR(tty, tiop) (tcgetattr (tty, tiop)) | - | ||||||||||||||||||
321 | # ifdef M_UNIX | - | ||||||||||||||||||
322 | # define SETATTR(tty, tiop) (tcsetattr (tty, TCSANOW, tiop)) | - | ||||||||||||||||||
323 | # else | - | ||||||||||||||||||
324 | # define SETATTR(tty, tiop) (tcsetattr (tty, TCSADRAIN, tiop)) | - | ||||||||||||||||||
325 | # endif /* !M_UNIX */ | - | ||||||||||||||||||
326 | #else | - | ||||||||||||||||||
327 | # define TIOTYPE struct termio | - | ||||||||||||||||||
328 | # define DRAIN_OUTPUT(fd) | - | ||||||||||||||||||
329 | # define GETATTR(tty, tiop) (ioctl (tty, TCGETA, tiop)) | - | ||||||||||||||||||
330 | # define SETATTR(tty, tiop) (ioctl (tty, TCSETAW, tiop)) | - | ||||||||||||||||||
331 | #endif /* !TERMIOS_TTY_DRIVER */ | - | ||||||||||||||||||
332 | - | |||||||||||||||||||
333 | static TIOTYPE otio; | - | ||||||||||||||||||
334 | - | |||||||||||||||||||
335 | static void save_tty_chars PARAMS((TIOTYPE *)); | - | ||||||||||||||||||
336 | static int _get_tty_settings PARAMS((int, TIOTYPE *)); | - | ||||||||||||||||||
337 | static int get_tty_settings PARAMS((int, TIOTYPE *)); | - | ||||||||||||||||||
338 | static int _set_tty_settings PARAMS((int, TIOTYPE *)); | - | ||||||||||||||||||
339 | static int set_tty_settings PARAMS((int, TIOTYPE *)); | - | ||||||||||||||||||
340 | - | |||||||||||||||||||
341 | static void prepare_terminal_settings PARAMS((int, TIOTYPE, TIOTYPE *)); | - | ||||||||||||||||||
342 | - | |||||||||||||||||||
343 | static void set_special_char PARAMS((Keymap, TIOTYPE *, int, rl_command_func_t *)); | - | ||||||||||||||||||
344 | static void _rl_bind_tty_special_chars PARAMS((Keymap, TIOTYPE)); | - | ||||||||||||||||||
345 | - | |||||||||||||||||||
346 | #if defined (FLUSHO) | - | ||||||||||||||||||
347 | # define OUTPUT_BEING_FLUSHED(tp) (tp->c_lflag & FLUSHO) | - | ||||||||||||||||||
348 | #else | - | ||||||||||||||||||
349 | # define OUTPUT_BEING_FLUSHED(tp) 0 | - | ||||||||||||||||||
350 | #endif | - | ||||||||||||||||||
351 | - | |||||||||||||||||||
352 | static void | - | ||||||||||||||||||
353 | save_tty_chars (TIOTYPE *tiop) | - | ||||||||||||||||||
354 | { | - | ||||||||||||||||||
355 | _rl_last_tty_chars = _rl_tty_chars; | - | ||||||||||||||||||
356 | - | |||||||||||||||||||
357 | _rl_tty_chars.t_eof = tiop->c_cc[VEOF]; | - | ||||||||||||||||||
358 | _rl_tty_chars.t_eol = tiop->c_cc[VEOL]; | - | ||||||||||||||||||
359 | #ifdef VEOL2 | - | ||||||||||||||||||
360 | _rl_tty_chars.t_eol2 = tiop->c_cc[VEOL2]; | - | ||||||||||||||||||
361 | #endif | - | ||||||||||||||||||
362 | _rl_tty_chars.t_erase = tiop->c_cc[VERASE]; | - | ||||||||||||||||||
363 | #ifdef VWERASE | - | ||||||||||||||||||
364 | _rl_tty_chars.t_werase = tiop->c_cc[VWERASE]; | - | ||||||||||||||||||
365 | #endif | - | ||||||||||||||||||
366 | _rl_tty_chars.t_kill = tiop->c_cc[VKILL]; | - | ||||||||||||||||||
367 | #ifdef VREPRINT | - | ||||||||||||||||||
368 | _rl_tty_chars.t_reprint = tiop->c_cc[VREPRINT]; | - | ||||||||||||||||||
369 | #endif | - | ||||||||||||||||||
370 | _rl_intr_char = _rl_tty_chars.t_intr = tiop->c_cc[VINTR]; | - | ||||||||||||||||||
371 | _rl_quit_char = _rl_tty_chars.t_quit = tiop->c_cc[VQUIT]; | - | ||||||||||||||||||
372 | #ifdef VSUSP | - | ||||||||||||||||||
373 | _rl_susp_char = _rl_tty_chars.t_susp = tiop->c_cc[VSUSP]; | - | ||||||||||||||||||
374 | #endif | - | ||||||||||||||||||
375 | #ifdef VDSUSP | - | ||||||||||||||||||
376 | _rl_tty_chars.t_dsusp = tiop->c_cc[VDSUSP]; | - | ||||||||||||||||||
377 | #endif | - | ||||||||||||||||||
378 | #ifdef VSTART | - | ||||||||||||||||||
379 | _rl_tty_chars.t_start = tiop->c_cc[VSTART]; | - | ||||||||||||||||||
380 | #endif | - | ||||||||||||||||||
381 | #ifdef VSTOP | - | ||||||||||||||||||
382 | _rl_tty_chars.t_stop = tiop->c_cc[VSTOP]; | - | ||||||||||||||||||
383 | #endif | - | ||||||||||||||||||
384 | #ifdef VLNEXT | - | ||||||||||||||||||
385 | _rl_tty_chars.t_lnext = tiop->c_cc[VLNEXT]; | - | ||||||||||||||||||
386 | #endif | - | ||||||||||||||||||
387 | #ifdef VDISCARD | - | ||||||||||||||||||
388 | _rl_tty_chars.t_flush = tiop->c_cc[VDISCARD]; | - | ||||||||||||||||||
389 | #endif | - | ||||||||||||||||||
390 | #ifdef VSTATUS | - | ||||||||||||||||||
391 | _rl_tty_chars.t_status = tiop->c_cc[VSTATUS]; | - | ||||||||||||||||||
392 | #endif | - | ||||||||||||||||||
393 | } never executed: end of block | 0 | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | #if defined (_AIX) || defined (_AIX41) | - | ||||||||||||||||||
396 | /* Currently this is only used on AIX */ | - | ||||||||||||||||||
397 | static void | - | ||||||||||||||||||
398 | rltty_warning (char *msg) | - | ||||||||||||||||||
399 | char *msg; | - | ||||||||||||||||||
400 | { | - | ||||||||||||||||||
401 | _rl_errmsg ("warning: %s", msg); | - | ||||||||||||||||||
402 | } | - | ||||||||||||||||||
403 | #endif | - | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | #if defined (_AIX) | - | ||||||||||||||||||
406 | void | - | ||||||||||||||||||
407 | setopost (TIOTYPE *tp) | - | ||||||||||||||||||
408 | { | - | ||||||||||||||||||
409 | if ((tp->c_oflag & OPOST) == 0) | - | ||||||||||||||||||
410 | { | - | ||||||||||||||||||
411 | _rl_errmsg ("warning: turning on OPOST for terminal\r"); | - | ||||||||||||||||||
412 | tp->c_oflag |= OPOST|ONLCR; | - | ||||||||||||||||||
413 | } | - | ||||||||||||||||||
414 | } | - | ||||||||||||||||||
415 | #endif | - | ||||||||||||||||||
416 | - | |||||||||||||||||||
417 | static int | - | ||||||||||||||||||
418 | _get_tty_settings (int tty, TIOTYPE *tiop) | - | ||||||||||||||||||
419 | { | - | ||||||||||||||||||
420 | int ioctl_ret; | - | ||||||||||||||||||
421 | - | |||||||||||||||||||
422 | while (1) | - | ||||||||||||||||||
423 | { | - | ||||||||||||||||||
424 | ioctl_ret = GETATTR (tty, tiop); | - | ||||||||||||||||||
425 | if (ioctl_ret < 0)
| 0 | ||||||||||||||||||
426 | { | - | ||||||||||||||||||
427 | if (errno != EINTR)
| 0 | ||||||||||||||||||
428 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
429 | else | - | ||||||||||||||||||
430 | continue; never executed: continue; | 0 | ||||||||||||||||||
431 | } | - | ||||||||||||||||||
432 | if (OUTPUT_BEING_FLUSHED (tiop))
| 0 | ||||||||||||||||||
433 | { | - | ||||||||||||||||||
434 | #if defined (FLUSHO) | - | ||||||||||||||||||
435 | _rl_errmsg ("warning: turning off output flushing"); | - | ||||||||||||||||||
436 | tiop->c_lflag &= ~FLUSHO; | - | ||||||||||||||||||
437 | break; never executed: break; | 0 | ||||||||||||||||||
438 | #else | - | ||||||||||||||||||
439 | continue; | - | ||||||||||||||||||
440 | #endif | - | ||||||||||||||||||
441 | } | - | ||||||||||||||||||
442 | break; never executed: break; | 0 | ||||||||||||||||||
443 | } | - | ||||||||||||||||||
444 | - | |||||||||||||||||||
445 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
446 | } | - | ||||||||||||||||||
447 | - | |||||||||||||||||||
448 | static int | - | ||||||||||||||||||
449 | get_tty_settings (int tty, TIOTYPE *tiop) | - | ||||||||||||||||||
450 | { | - | ||||||||||||||||||
451 | set_winsize (tty); | - | ||||||||||||||||||
452 | - | |||||||||||||||||||
453 | errno = 0; | - | ||||||||||||||||||
454 | if (_get_tty_settings (tty, tiop) < 0)
| 0 | ||||||||||||||||||
455 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | #if defined (_AIX) | - | ||||||||||||||||||
458 | setopost(tiop); | - | ||||||||||||||||||
459 | #endif | - | ||||||||||||||||||
460 | - | |||||||||||||||||||
461 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
462 | } | - | ||||||||||||||||||
463 | - | |||||||||||||||||||
464 | static int | - | ||||||||||||||||||
465 | _set_tty_settings (int tty, TIOTYPE *tiop) | - | ||||||||||||||||||
466 | { | - | ||||||||||||||||||
467 | while (SETATTR (tty, tiop) < 0)
| 0 | ||||||||||||||||||
468 | { | - | ||||||||||||||||||
469 | if (errno != EINTR)
| 0 | ||||||||||||||||||
470 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
471 | errno = 0; | - | ||||||||||||||||||
472 | } never executed: end of block | 0 | ||||||||||||||||||
473 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
474 | } | - | ||||||||||||||||||
475 | - | |||||||||||||||||||
476 | static int | - | ||||||||||||||||||
477 | set_tty_settings (int tty, TIOTYPE *tiop) | - | ||||||||||||||||||
478 | { | - | ||||||||||||||||||
479 | if (_set_tty_settings (tty, tiop) < 0)
| 0 | ||||||||||||||||||
480 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
481 | - | |||||||||||||||||||
482 | #if 0 | - | ||||||||||||||||||
483 | - | |||||||||||||||||||
484 | #if defined (TERMIOS_TTY_DRIVER) | - | ||||||||||||||||||
485 | # if defined (__ksr1__) | - | ||||||||||||||||||
486 | if (ksrflow) | - | ||||||||||||||||||
487 | { | - | ||||||||||||||||||
488 | ksrflow = 0; | - | ||||||||||||||||||
489 | tcflow (tty, TCOON); | - | ||||||||||||||||||
490 | } | - | ||||||||||||||||||
491 | # else /* !ksr1 */ | - | ||||||||||||||||||
492 | tcflow (tty, TCOON); /* Simulate a ^Q. */ | - | ||||||||||||||||||
493 | # endif /* !ksr1 */ | - | ||||||||||||||||||
494 | #else | - | ||||||||||||||||||
495 | ioctl (tty, TCXONC, 1); /* Simulate a ^Q. */ | - | ||||||||||||||||||
496 | #endif /* !TERMIOS_TTY_DRIVER */ | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | #endif /* 0 */ | - | ||||||||||||||||||
499 | - | |||||||||||||||||||
500 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
501 | } | - | ||||||||||||||||||
502 | - | |||||||||||||||||||
503 | static void | - | ||||||||||||||||||
504 | prepare_terminal_settings (int meta_flag, TIOTYPE oldtio, TIOTYPE *tiop) | - | ||||||||||||||||||
505 | { | - | ||||||||||||||||||
506 | int sc; | - | ||||||||||||||||||
507 | Keymap kmap; | - | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | _rl_echoing_p = (oldtio.c_lflag & ECHO); | - | ||||||||||||||||||
510 | #if defined (ECHOCTL) | - | ||||||||||||||||||
511 | _rl_echoctl = (oldtio.c_lflag & ECHOCTL); | - | ||||||||||||||||||
512 | #endif | - | ||||||||||||||||||
513 | - | |||||||||||||||||||
514 | tiop->c_lflag &= ~(ICANON | ECHO); | - | ||||||||||||||||||
515 | - | |||||||||||||||||||
516 | if ((unsigned char) oldtio.c_cc[VEOF] != (unsigned char) _POSIX_VDISABLE)
| 0 | ||||||||||||||||||
517 | _rl_eof_char = oldtio.c_cc[VEOF]; never executed: _rl_eof_char = oldtio.c_cc[ 4 ]; | 0 | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | #if defined (USE_XON_XOFF) | - | ||||||||||||||||||
520 | #if defined (IXANY) | - | ||||||||||||||||||
521 | tiop->c_iflag &= ~(IXON | IXANY); | - | ||||||||||||||||||
522 | #else | - | ||||||||||||||||||
523 | /* `strict' Posix systems do not define IXANY. */ | - | ||||||||||||||||||
524 | tiop->c_iflag &= ~IXON; | - | ||||||||||||||||||
525 | #endif /* IXANY */ | - | ||||||||||||||||||
526 | #endif /* USE_XON_XOFF */ | - | ||||||||||||||||||
527 | - | |||||||||||||||||||
528 | /* Only turn this off if we are using all 8 bits. */ | - | ||||||||||||||||||
529 | if (((tiop->c_cflag & CSIZE) == CS8) || meta_flag)
| 0 | ||||||||||||||||||
530 | tiop->c_iflag &= ~(ISTRIP | INPCK); never executed: tiop->c_iflag &= ~( 0000040 | 0000020 ); | 0 | ||||||||||||||||||
531 | - | |||||||||||||||||||
532 | /* Make sure we differentiate between CR and NL on input. */ | - | ||||||||||||||||||
533 | tiop->c_iflag &= ~(ICRNL | INLCR); | - | ||||||||||||||||||
534 | - | |||||||||||||||||||
535 | #if !defined (HANDLE_SIGNALS) | - | ||||||||||||||||||
536 | tiop->c_lflag &= ~ISIG; | - | ||||||||||||||||||
537 | #else | - | ||||||||||||||||||
538 | tiop->c_lflag |= ISIG; | - | ||||||||||||||||||
539 | #endif | - | ||||||||||||||||||
540 | - | |||||||||||||||||||
541 | tiop->c_cc[VMIN] = 1; | - | ||||||||||||||||||
542 | tiop->c_cc[VTIME] = 0; | - | ||||||||||||||||||
543 | - | |||||||||||||||||||
544 | #if defined (FLUSHO) | - | ||||||||||||||||||
545 | if (OUTPUT_BEING_FLUSHED (tiop))
| 0 | ||||||||||||||||||
546 | { | - | ||||||||||||||||||
547 | tiop->c_lflag &= ~FLUSHO; | - | ||||||||||||||||||
548 | oldtio.c_lflag &= ~FLUSHO; | - | ||||||||||||||||||
549 | } never executed: end of block | 0 | ||||||||||||||||||
550 | #endif | - | ||||||||||||||||||
551 | - | |||||||||||||||||||
552 | /* Turn off characters that we need on Posix systems with job control, | - | ||||||||||||||||||
553 | just to be sure. This includes ^Y and ^V. This should not really | - | ||||||||||||||||||
554 | be necessary. */ | - | ||||||||||||||||||
555 | #if defined (TERMIOS_TTY_DRIVER) && defined (_POSIX_VDISABLE) | - | ||||||||||||||||||
556 | - | |||||||||||||||||||
557 | #if defined (VLNEXT) | - | ||||||||||||||||||
558 | tiop->c_cc[VLNEXT] = _POSIX_VDISABLE; | - | ||||||||||||||||||
559 | #endif | - | ||||||||||||||||||
560 | - | |||||||||||||||||||
561 | #if defined (VDSUSP) | - | ||||||||||||||||||
562 | tiop->c_cc[VDSUSP] = _POSIX_VDISABLE; | - | ||||||||||||||||||
563 | #endif | - | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | /* Conditionally disable some other tty special characters if there is a | - | ||||||||||||||||||
566 | key binding for them in the current keymap. Readline ordinarily doesn't | - | ||||||||||||||||||
567 | bind these characters, but an application or user might. */ | - | ||||||||||||||||||
568 | #if defined (VI_MODE) | - | ||||||||||||||||||
569 | kmap = (rl_editing_mode == vi_mode) ? vi_insertion_keymap : _rl_keymap;
| 0 | ||||||||||||||||||
570 | #else | - | ||||||||||||||||||
571 | kmap = _rl_keymap; | - | ||||||||||||||||||
572 | #endif | - | ||||||||||||||||||
573 | #if defined (VDISCARD) | - | ||||||||||||||||||
574 | sc = tiop->c_cc[VDISCARD]; | - | ||||||||||||||||||
575 | if (sc != _POSIX_VDISABLE && kmap[(unsigned char)sc].type == ISFUNC)
| 0 | ||||||||||||||||||
576 | tiop->c_cc[VDISCARD] = _POSIX_VDISABLE; never executed: tiop->c_cc[ 13 ] = '\0' ; | 0 | ||||||||||||||||||
577 | #endif /* VDISCARD */ | - | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | #endif /* TERMIOS_TTY_DRIVER && _POSIX_VDISABLE */ | - | ||||||||||||||||||
580 | } never executed: end of block | 0 | ||||||||||||||||||
581 | #endif /* !NEW_TTY_DRIVER */ | - | ||||||||||||||||||
582 | - | |||||||||||||||||||
583 | /* Put the terminal in CBREAK mode so that we can detect key presses. */ | - | ||||||||||||||||||
584 | #if defined (NO_TTY_DRIVER) | - | ||||||||||||||||||
585 | void | - | ||||||||||||||||||
586 | rl_prep_terminal (int meta_flag) | - | ||||||||||||||||||
587 | { | - | ||||||||||||||||||
588 | _rl_echoing_p = 1; | - | ||||||||||||||||||
589 | } | - | ||||||||||||||||||
590 | - | |||||||||||||||||||
591 | void | - | ||||||||||||||||||
592 | rl_deprep_terminal (void) | - | ||||||||||||||||||
593 | { | - | ||||||||||||||||||
594 | } | - | ||||||||||||||||||
595 | - | |||||||||||||||||||
596 | #else /* ! NO_TTY_DRIVER */ | - | ||||||||||||||||||
597 | void | - | ||||||||||||||||||
598 | rl_prep_terminal (int meta_flag) | - | ||||||||||||||||||
599 | { | - | ||||||||||||||||||
600 | int tty, nprep; | - | ||||||||||||||||||
601 | TIOTYPE tio; | - | ||||||||||||||||||
602 | - | |||||||||||||||||||
603 | if (terminal_prepped)
| 0 | ||||||||||||||||||
604 | return; never executed: return; | 0 | ||||||||||||||||||
605 | - | |||||||||||||||||||
606 | /* Try to keep this function from being INTerrupted. */ | - | ||||||||||||||||||
607 | _rl_block_sigint (); | - | ||||||||||||||||||
608 | - | |||||||||||||||||||
609 | tty = rl_instream ? fileno (rl_instream) : fileno (stdin);
| 0 | ||||||||||||||||||
610 | - | |||||||||||||||||||
611 | if (get_tty_settings (tty, &tio) < 0)
| 0 | ||||||||||||||||||
612 | { | - | ||||||||||||||||||
613 | #if defined (ENOTSUP) | - | ||||||||||||||||||
614 | /* MacOS X and Linux, at least, lie about the value of errno if | - | ||||||||||||||||||
615 | tcgetattr fails. */ | - | ||||||||||||||||||
616 | if (errno == ENOTTY || errno == EINVAL || errno == ENOTSUP)
| 0 | ||||||||||||||||||
617 | #else | - | ||||||||||||||||||
618 | if (errno == ENOTTY || errno == EINVAL) | - | ||||||||||||||||||
619 | #endif | - | ||||||||||||||||||
620 | _rl_echoing_p = 1; /* XXX */ never executed: _rl_echoing_p = 1; | 0 | ||||||||||||||||||
621 | - | |||||||||||||||||||
622 | _rl_release_sigint (); | - | ||||||||||||||||||
623 | return; never executed: return; | 0 | ||||||||||||||||||
624 | } | - | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | otio = tio; | - | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | if (_rl_bind_stty_chars)
| 0 | ||||||||||||||||||
629 | { | - | ||||||||||||||||||
630 | #if defined (VI_MODE) | - | ||||||||||||||||||
631 | /* If editing in vi mode, make sure we restore the bindings in the | - | ||||||||||||||||||
632 | insertion keymap no matter what keymap we ended up in. */ | - | ||||||||||||||||||
633 | if (rl_editing_mode == vi_mode)
| 0 | ||||||||||||||||||
634 | rl_tty_unset_default_bindings (vi_insertion_keymap); never executed: rl_tty_unset_default_bindings (vi_insertion_keymap); | 0 | ||||||||||||||||||
635 | else | - | ||||||||||||||||||
636 | #endif | - | ||||||||||||||||||
637 | rl_tty_unset_default_bindings (_rl_keymap); never executed: rl_tty_unset_default_bindings (_rl_keymap); | 0 | ||||||||||||||||||
638 | } | - | ||||||||||||||||||
639 | save_tty_chars (&otio); | - | ||||||||||||||||||
640 | RL_SETSTATE(RL_STATE_TTYCSAVED); | - | ||||||||||||||||||
641 | if (_rl_bind_stty_chars)
| 0 | ||||||||||||||||||
642 | { | - | ||||||||||||||||||
643 | #if defined (VI_MODE) | - | ||||||||||||||||||
644 | /* If editing in vi mode, make sure we set the bindings in the | - | ||||||||||||||||||
645 | insertion keymap no matter what keymap we ended up in. */ | - | ||||||||||||||||||
646 | if (rl_editing_mode == vi_mode)
| 0 | ||||||||||||||||||
647 | _rl_bind_tty_special_chars (vi_insertion_keymap, tio); never executed: _rl_bind_tty_special_chars (vi_insertion_keymap, tio); | 0 | ||||||||||||||||||
648 | else | - | ||||||||||||||||||
649 | #endif | - | ||||||||||||||||||
650 | _rl_bind_tty_special_chars (_rl_keymap, tio); never executed: _rl_bind_tty_special_chars (_rl_keymap, tio); | 0 | ||||||||||||||||||
651 | } | - | ||||||||||||||||||
652 | - | |||||||||||||||||||
653 | prepare_terminal_settings (meta_flag, otio, &tio); | - | ||||||||||||||||||
654 | - | |||||||||||||||||||
655 | if (set_tty_settings (tty, &tio) < 0)
| 0 | ||||||||||||||||||
656 | { | - | ||||||||||||||||||
657 | _rl_release_sigint (); | - | ||||||||||||||||||
658 | return; never executed: return; | 0 | ||||||||||||||||||
659 | } | - | ||||||||||||||||||
660 | - | |||||||||||||||||||
661 | if (_rl_enable_keypad)
| 0 | ||||||||||||||||||
662 | _rl_control_keypad (1); never executed: _rl_control_keypad (1); | 0 | ||||||||||||||||||
663 | - | |||||||||||||||||||
664 | nprep = TPX_PREPPED; | - | ||||||||||||||||||
665 | - | |||||||||||||||||||
666 | if (_rl_enable_bracketed_paste)
| 0 | ||||||||||||||||||
667 | { | - | ||||||||||||||||||
668 | fprintf (rl_outstream, BRACK_PASTE_INIT); | - | ||||||||||||||||||
669 | nprep |= TPX_BRACKPASTE; | - | ||||||||||||||||||
670 | } never executed: end of block | 0 | ||||||||||||||||||
671 | - | |||||||||||||||||||
672 | fflush (rl_outstream); | - | ||||||||||||||||||
673 | terminal_prepped = nprep; | - | ||||||||||||||||||
674 | RL_SETSTATE(RL_STATE_TERMPREPPED); | - | ||||||||||||||||||
675 | - | |||||||||||||||||||
676 | _rl_release_sigint (); | - | ||||||||||||||||||
677 | } never executed: end of block | 0 | ||||||||||||||||||
678 | - | |||||||||||||||||||
679 | /* Restore the terminal's normal settings and modes. */ | - | ||||||||||||||||||
680 | void | - | ||||||||||||||||||
681 | rl_deprep_terminal (void) | - | ||||||||||||||||||
682 | { | - | ||||||||||||||||||
683 | int tty; | - | ||||||||||||||||||
684 | - | |||||||||||||||||||
685 | if (terminal_prepped == 0)
| 0 | ||||||||||||||||||
686 | return; never executed: return; | 0 | ||||||||||||||||||
687 | - | |||||||||||||||||||
688 | /* Try to keep this function from being interrupted. */ | - | ||||||||||||||||||
689 | _rl_block_sigint (); | - | ||||||||||||||||||
690 | - | |||||||||||||||||||
691 | tty = rl_instream ? fileno (rl_instream) : fileno (stdin);
| 0 | ||||||||||||||||||
692 | - | |||||||||||||||||||
693 | if (terminal_prepped & TPX_BRACKPASTE)
| 0 | ||||||||||||||||||
694 | fprintf (rl_outstream, BRACK_PASTE_FINI); never executed: fprintf (rl_outstream, "\033[?2004l\r"); | 0 | ||||||||||||||||||
695 | - | |||||||||||||||||||
696 | if (_rl_enable_keypad)
| 0 | ||||||||||||||||||
697 | _rl_control_keypad (0); never executed: _rl_control_keypad (0); | 0 | ||||||||||||||||||
698 | - | |||||||||||||||||||
699 | fflush (rl_outstream); | - | ||||||||||||||||||
700 | - | |||||||||||||||||||
701 | if (set_tty_settings (tty, &otio) < 0)
| 0 | ||||||||||||||||||
702 | { | - | ||||||||||||||||||
703 | _rl_release_sigint (); | - | ||||||||||||||||||
704 | return; never executed: return; | 0 | ||||||||||||||||||
705 | } | - | ||||||||||||||||||
706 | - | |||||||||||||||||||
707 | terminal_prepped = 0; | - | ||||||||||||||||||
708 | RL_UNSETSTATE(RL_STATE_TERMPREPPED); | - | ||||||||||||||||||
709 | - | |||||||||||||||||||
710 | _rl_release_sigint (); | - | ||||||||||||||||||
711 | } never executed: end of block | 0 | ||||||||||||||||||
712 | #endif /* !NO_TTY_DRIVER */ | - | ||||||||||||||||||
713 | - | |||||||||||||||||||
714 | /* Set readline's idea of whether or not it is echoing output to the terminal, | - | ||||||||||||||||||
715 | returning the old value. */ | - | ||||||||||||||||||
716 | int | - | ||||||||||||||||||
717 | rl_tty_set_echoing (int u) | - | ||||||||||||||||||
718 | { | - | ||||||||||||||||||
719 | int o; | - | ||||||||||||||||||
720 | - | |||||||||||||||||||
721 | o = _rl_echoing_p; | - | ||||||||||||||||||
722 | _rl_echoing_p = u; | - | ||||||||||||||||||
723 | return o; never executed: return o; | 0 | ||||||||||||||||||
724 | } | - | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | /* **************************************************************** */ | - | ||||||||||||||||||
727 | /* */ | - | ||||||||||||||||||
728 | /* Bogus Flow Control */ | - | ||||||||||||||||||
729 | /* */ | - | ||||||||||||||||||
730 | /* **************************************************************** */ | - | ||||||||||||||||||
731 | - | |||||||||||||||||||
732 | int | - | ||||||||||||||||||
733 | rl_restart_output (int count, int key) | - | ||||||||||||||||||
734 | { | - | ||||||||||||||||||
735 | #if defined (__MINGW32__) | - | ||||||||||||||||||
736 | return 0; | - | ||||||||||||||||||
737 | #else /* !__MING32__ */ | - | ||||||||||||||||||
738 | - | |||||||||||||||||||
739 | int fildes = fileno (rl_outstream); | - | ||||||||||||||||||
740 | #if defined (TIOCSTART) | - | ||||||||||||||||||
741 | #if defined (apollo) | - | ||||||||||||||||||
742 | ioctl (&fildes, TIOCSTART, 0); | - | ||||||||||||||||||
743 | #else | - | ||||||||||||||||||
744 | ioctl (fildes, TIOCSTART, 0); | - | ||||||||||||||||||
745 | #endif /* apollo */ | - | ||||||||||||||||||
746 | - | |||||||||||||||||||
747 | #else /* !TIOCSTART */ | - | ||||||||||||||||||
748 | # if defined (TERMIOS_TTY_DRIVER) | - | ||||||||||||||||||
749 | # if defined (__ksr1__) | - | ||||||||||||||||||
750 | if (ksrflow) | - | ||||||||||||||||||
751 | { | - | ||||||||||||||||||
752 | ksrflow = 0; | - | ||||||||||||||||||
753 | tcflow (fildes, TCOON); | - | ||||||||||||||||||
754 | } | - | ||||||||||||||||||
755 | # else /* !ksr1 */ | - | ||||||||||||||||||
756 | tcflow (fildes, TCOON); /* Simulate a ^Q. */ | - | ||||||||||||||||||
757 | # endif /* !ksr1 */ | - | ||||||||||||||||||
758 | # else /* !TERMIOS_TTY_DRIVER */ | - | ||||||||||||||||||
759 | # if defined (TCXONC) | - | ||||||||||||||||||
760 | ioctl (fildes, TCXONC, TCOON); | - | ||||||||||||||||||
761 | # endif /* TCXONC */ | - | ||||||||||||||||||
762 | # endif /* !TERMIOS_TTY_DRIVER */ | - | ||||||||||||||||||
763 | #endif /* !TIOCSTART */ | - | ||||||||||||||||||
764 | - | |||||||||||||||||||
765 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
766 | #endif /* !__MINGW32__ */ | - | ||||||||||||||||||
767 | } | - | ||||||||||||||||||
768 | - | |||||||||||||||||||
769 | int | - | ||||||||||||||||||
770 | rl_stop_output (int count, int key) | - | ||||||||||||||||||
771 | { | - | ||||||||||||||||||
772 | #if defined (__MINGW32__) | - | ||||||||||||||||||
773 | return 0; | - | ||||||||||||||||||
774 | #else | - | ||||||||||||||||||
775 | - | |||||||||||||||||||
776 | int fildes = fileno (rl_instream); | - | ||||||||||||||||||
777 | - | |||||||||||||||||||
778 | #if defined (TIOCSTOP) | - | ||||||||||||||||||
779 | # if defined (apollo) | - | ||||||||||||||||||
780 | ioctl (&fildes, TIOCSTOP, 0); | - | ||||||||||||||||||
781 | # else | - | ||||||||||||||||||
782 | ioctl (fildes, TIOCSTOP, 0); | - | ||||||||||||||||||
783 | # endif /* apollo */ | - | ||||||||||||||||||
784 | #else /* !TIOCSTOP */ | - | ||||||||||||||||||
785 | # if defined (TERMIOS_TTY_DRIVER) | - | ||||||||||||||||||
786 | # if defined (__ksr1__) | - | ||||||||||||||||||
787 | ksrflow = 1; | - | ||||||||||||||||||
788 | # endif /* ksr1 */ | - | ||||||||||||||||||
789 | tcflow (fildes, TCOOFF); | - | ||||||||||||||||||
790 | # else | - | ||||||||||||||||||
791 | # if defined (TCXONC) | - | ||||||||||||||||||
792 | ioctl (fildes, TCXONC, TCOON); | - | ||||||||||||||||||
793 | # endif /* TCXONC */ | - | ||||||||||||||||||
794 | # endif /* !TERMIOS_TTY_DRIVER */ | - | ||||||||||||||||||
795 | #endif /* !TIOCSTOP */ | - | ||||||||||||||||||
796 | - | |||||||||||||||||||
797 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
798 | #endif /* !__MINGW32__ */ | - | ||||||||||||||||||
799 | } | - | ||||||||||||||||||
800 | - | |||||||||||||||||||
801 | /* **************************************************************** */ | - | ||||||||||||||||||
802 | /* */ | - | ||||||||||||||||||
803 | /* Default Key Bindings */ | - | ||||||||||||||||||
804 | /* */ | - | ||||||||||||||||||
805 | /* **************************************************************** */ | - | ||||||||||||||||||
806 | - | |||||||||||||||||||
807 | #if !defined (NO_TTY_DRIVER) | - | ||||||||||||||||||
808 | #define SET_SPECIAL(sc, func) set_special_char(kmap, &ttybuff, sc, func) | - | ||||||||||||||||||
809 | #endif | - | ||||||||||||||||||
810 | - | |||||||||||||||||||
811 | #if defined (NO_TTY_DRIVER) | - | ||||||||||||||||||
812 | - | |||||||||||||||||||
813 | #define SET_SPECIAL(sc, func) | - | ||||||||||||||||||
814 | #define RESET_SPECIAL(c) | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | #elif defined (NEW_TTY_DRIVER) | - | ||||||||||||||||||
817 | static void | - | ||||||||||||||||||
818 | set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func) | - | ||||||||||||||||||
819 | { | - | ||||||||||||||||||
820 | if (sc != -1 && kmap[(unsigned char)sc].type == ISFUNC) | - | ||||||||||||||||||
821 | kmap[(unsigned char)sc].function = func; | - | ||||||||||||||||||
822 | } | - | ||||||||||||||||||
823 | - | |||||||||||||||||||
824 | #define RESET_SPECIAL(c) \ | - | ||||||||||||||||||
825 | if (c != -1 && kmap[(unsigned char)c].type == ISFUNC) \ | - | ||||||||||||||||||
826 | kmap[(unsigned char)c].function = rl_insert; | - | ||||||||||||||||||
827 | - | |||||||||||||||||||
828 | static void | - | ||||||||||||||||||
829 | _rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff) | - | ||||||||||||||||||
830 | { | - | ||||||||||||||||||
831 | if (ttybuff.flags & SGTTY_SET) | - | ||||||||||||||||||
832 | { | - | ||||||||||||||||||
833 | SET_SPECIAL (ttybuff.sgttyb.sg_erase, rl_rubout); | - | ||||||||||||||||||
834 | SET_SPECIAL (ttybuff.sgttyb.sg_kill, rl_unix_line_discard); | - | ||||||||||||||||||
835 | } | - | ||||||||||||||||||
836 | - | |||||||||||||||||||
837 | # if defined (TIOCGLTC) | - | ||||||||||||||||||
838 | if (ttybuff.flags & LTCHARS_SET) | - | ||||||||||||||||||
839 | { | - | ||||||||||||||||||
840 | SET_SPECIAL (ttybuff.ltchars.t_werasc, rl_unix_word_rubout); | - | ||||||||||||||||||
841 | SET_SPECIAL (ttybuff.ltchars.t_lnextc, rl_quoted_insert); | - | ||||||||||||||||||
842 | } | - | ||||||||||||||||||
843 | # endif /* TIOCGLTC */ | - | ||||||||||||||||||
844 | } | - | ||||||||||||||||||
845 | - | |||||||||||||||||||
846 | #else /* !NEW_TTY_DRIVER */ | - | ||||||||||||||||||
847 | static void | - | ||||||||||||||||||
848 | set_special_char (Keymap kmap, TIOTYPE *tiop, int sc, rl_command_func_t *func) | - | ||||||||||||||||||
849 | { | - | ||||||||||||||||||
850 | unsigned char uc; | - | ||||||||||||||||||
851 | - | |||||||||||||||||||
852 | uc = tiop->c_cc[sc]; | - | ||||||||||||||||||
853 | if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC)
| 0 | ||||||||||||||||||
854 | kmap[uc].function = func; never executed: kmap[uc].function = func; | 0 | ||||||||||||||||||
855 | } never executed: end of block | 0 | ||||||||||||||||||
856 | - | |||||||||||||||||||
857 | /* used later */ | - | ||||||||||||||||||
858 | #define RESET_SPECIAL(uc) \ | - | ||||||||||||||||||
859 | if (uc != (unsigned char)_POSIX_VDISABLE && kmap[uc].type == ISFUNC) \ | - | ||||||||||||||||||
860 | kmap[uc].function = rl_insert; | - | ||||||||||||||||||
861 | - | |||||||||||||||||||
862 | static void | - | ||||||||||||||||||
863 | _rl_bind_tty_special_chars (Keymap kmap, TIOTYPE ttybuff) | - | ||||||||||||||||||
864 | { | - | ||||||||||||||||||
865 | SET_SPECIAL (VERASE, rl_rubout); | - | ||||||||||||||||||
866 | SET_SPECIAL (VKILL, rl_unix_line_discard); | - | ||||||||||||||||||
867 | - | |||||||||||||||||||
868 | # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) | - | ||||||||||||||||||
869 | SET_SPECIAL (VLNEXT, rl_quoted_insert); | - | ||||||||||||||||||
870 | # endif /* VLNEXT && TERMIOS_TTY_DRIVER */ | - | ||||||||||||||||||
871 | - | |||||||||||||||||||
872 | # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) | - | ||||||||||||||||||
873 | # if defined (VI_MODE) | - | ||||||||||||||||||
874 | if (rl_editing_mode == vi_mode)
| 0 | ||||||||||||||||||
875 | SET_SPECIAL (VWERASE, rl_vi_unix_word_rubout); never executed: set_special_char(kmap, &ttybuff, 14 , rl_vi_unix_word_rubout); | 0 | ||||||||||||||||||
876 | else | - | ||||||||||||||||||
877 | # endif | - | ||||||||||||||||||
878 | SET_SPECIAL (VWERASE, rl_unix_word_rubout); never executed: set_special_char(kmap, &ttybuff, 14 , rl_unix_word_rubout); | 0 | ||||||||||||||||||
879 | # endif /* VWERASE && TERMIOS_TTY_DRIVER */ | - | ||||||||||||||||||
880 | } | - | ||||||||||||||||||
881 | - | |||||||||||||||||||
882 | #endif /* !NEW_TTY_DRIVER */ | - | ||||||||||||||||||
883 | - | |||||||||||||||||||
884 | /* Set the system's default editing characters to their readline equivalents | - | ||||||||||||||||||
885 | in KMAP. Should be static, now that we have rl_tty_set_default_bindings. */ | - | ||||||||||||||||||
886 | void | - | ||||||||||||||||||
887 | rltty_set_default_bindings (Keymap kmap) | - | ||||||||||||||||||
888 | { | - | ||||||||||||||||||
889 | #if !defined (NO_TTY_DRIVER) | - | ||||||||||||||||||
890 | TIOTYPE ttybuff; | - | ||||||||||||||||||
891 | int tty; | - | ||||||||||||||||||
892 | - | |||||||||||||||||||
893 | tty = fileno (rl_instream); | - | ||||||||||||||||||
894 | - | |||||||||||||||||||
895 | if (get_tty_settings (tty, &ttybuff) == 0)
| 0 | ||||||||||||||||||
896 | _rl_bind_tty_special_chars (kmap, ttybuff); never executed: _rl_bind_tty_special_chars (kmap, ttybuff); | 0 | ||||||||||||||||||
897 | #endif | - | ||||||||||||||||||
898 | } never executed: end of block | 0 | ||||||||||||||||||
899 | - | |||||||||||||||||||
900 | /* New public way to set the system default editing chars to their readline | - | ||||||||||||||||||
901 | equivalents. */ | - | ||||||||||||||||||
902 | void | - | ||||||||||||||||||
903 | rl_tty_set_default_bindings (Keymap kmap) | - | ||||||||||||||||||
904 | { | - | ||||||||||||||||||
905 | rltty_set_default_bindings (kmap); | - | ||||||||||||||||||
906 | } never executed: end of block | 0 | ||||||||||||||||||
907 | - | |||||||||||||||||||
908 | /* Rebind all of the tty special chars that readline worries about back | - | ||||||||||||||||||
909 | to self-insert. Call this before saving the current terminal special | - | ||||||||||||||||||
910 | chars with save_tty_chars(). This only works on POSIX termios or termio | - | ||||||||||||||||||
911 | systems. */ | - | ||||||||||||||||||
912 | void | - | ||||||||||||||||||
913 | rl_tty_unset_default_bindings (Keymap kmap) | - | ||||||||||||||||||
914 | { | - | ||||||||||||||||||
915 | /* Don't bother before we've saved the tty special chars at least once. */ | - | ||||||||||||||||||
916 | if (RL_ISSTATE(RL_STATE_TTYCSAVED) == 0)
| 0 | ||||||||||||||||||
917 | return; never executed: return; | 0 | ||||||||||||||||||
918 | - | |||||||||||||||||||
919 | RESET_SPECIAL (_rl_tty_chars.t_erase); never executed: kmap[_rl_tty_chars.t_erase].function = rl_insert;
| 0 | ||||||||||||||||||
920 | RESET_SPECIAL (_rl_tty_chars.t_kill); never executed: kmap[_rl_tty_chars.t_kill].function = rl_insert;
| 0 | ||||||||||||||||||
921 | - | |||||||||||||||||||
922 | # if defined (VLNEXT) && defined (TERMIOS_TTY_DRIVER) | - | ||||||||||||||||||
923 | RESET_SPECIAL (_rl_tty_chars.t_lnext); never executed: kmap[_rl_tty_chars.t_lnext].function = rl_insert;
| 0 | ||||||||||||||||||
924 | # endif /* VLNEXT && TERMIOS_TTY_DRIVER */ | - | ||||||||||||||||||
925 | - | |||||||||||||||||||
926 | # if defined (VWERASE) && defined (TERMIOS_TTY_DRIVER) | - | ||||||||||||||||||
927 | RESET_SPECIAL (_rl_tty_chars.t_werase); never executed: kmap[_rl_tty_chars.t_werase].function = rl_insert;
| 0 | ||||||||||||||||||
928 | # endif /* VWERASE && TERMIOS_TTY_DRIVER */ | - | ||||||||||||||||||
929 | } never executed: end of block | 0 | ||||||||||||||||||
930 | - | |||||||||||||||||||
931 | #if defined (HANDLE_SIGNALS) | - | ||||||||||||||||||
932 | - | |||||||||||||||||||
933 | #if defined (NEW_TTY_DRIVER) || defined (NO_TTY_DRIVER) | - | ||||||||||||||||||
934 | int | - | ||||||||||||||||||
935 | _rl_disable_tty_signals (void) | - | ||||||||||||||||||
936 | { | - | ||||||||||||||||||
937 | return 0; | - | ||||||||||||||||||
938 | } | - | ||||||||||||||||||
939 | - | |||||||||||||||||||
940 | int | - | ||||||||||||||||||
941 | _rl_restore_tty_signals (void) | - | ||||||||||||||||||
942 | { | - | ||||||||||||||||||
943 | return 0; | - | ||||||||||||||||||
944 | } | - | ||||||||||||||||||
945 | #else | - | ||||||||||||||||||
946 | - | |||||||||||||||||||
947 | static TIOTYPE sigstty, nosigstty; | - | ||||||||||||||||||
948 | static int tty_sigs_disabled = 0; | - | ||||||||||||||||||
949 | - | |||||||||||||||||||
950 | int | - | ||||||||||||||||||
951 | _rl_disable_tty_signals (void) | - | ||||||||||||||||||
952 | { | - | ||||||||||||||||||
953 | if (tty_sigs_disabled)
| 0 | ||||||||||||||||||
954 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
955 | - | |||||||||||||||||||
956 | if (_get_tty_settings (fileno (rl_instream), &sigstty) < 0)
| 0 | ||||||||||||||||||
957 | return -1; never executed: return -1; | 0 | ||||||||||||||||||
958 | - | |||||||||||||||||||
959 | nosigstty = sigstty; | - | ||||||||||||||||||
960 | - | |||||||||||||||||||
961 | nosigstty.c_lflag &= ~ISIG; | - | ||||||||||||||||||
962 | nosigstty.c_iflag &= ~IXON; | - | ||||||||||||||||||
963 | - | |||||||||||||||||||
964 | if (_set_tty_settings (fileno (rl_instream), &nosigstty) < 0)
| 0 | ||||||||||||||||||
965 | return (_set_tty_settings (fileno (rl_instream), &sigstty)); never executed: return (_set_tty_settings (fileno (rl_instream), &sigstty)); | 0 | ||||||||||||||||||
966 | - | |||||||||||||||||||
967 | tty_sigs_disabled = 1; | - | ||||||||||||||||||
968 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
969 | } | - | ||||||||||||||||||
970 | - | |||||||||||||||||||
971 | int | - | ||||||||||||||||||
972 | _rl_restore_tty_signals (void) | - | ||||||||||||||||||
973 | { | - | ||||||||||||||||||
974 | int r; | - | ||||||||||||||||||
975 | - | |||||||||||||||||||
976 | if (tty_sigs_disabled == 0)
| 0 | ||||||||||||||||||
977 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
978 | - | |||||||||||||||||||
979 | r = _set_tty_settings (fileno (rl_instream), &sigstty); | - | ||||||||||||||||||
980 | - | |||||||||||||||||||
981 | if (r == 0)
| 0 | ||||||||||||||||||
982 | tty_sigs_disabled = 0; never executed: tty_sigs_disabled = 0; | 0 | ||||||||||||||||||
983 | - | |||||||||||||||||||
984 | return r; never executed: return r; | 0 | ||||||||||||||||||
985 | } | - | ||||||||||||||||||
986 | #endif /* !NEW_TTY_DRIVER */ | - | ||||||||||||||||||
987 | - | |||||||||||||||||||
988 | #endif /* HANDLE_SIGNALS */ | - | ||||||||||||||||||
Source code | Switch to Preprocessed file |