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