tty.c revision 1.28.2.1 1 1.28.2.1 grant /* $NetBSD: tty.c,v 1.28.2.1 2003/06/16 13:14:50 grant 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.28.2.1 grant __RCSID("$NetBSD: tty.c,v 1.28.2.1 2003/06/16 13:14:50 grant 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.26 christos 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.25 blymn if (_cursesi_gettmode(_cursesi_screen) == ERR)
95 1.25 blymn return ERR;
96 1.11 mrg
97 1.25 blymn __GT = _cursesi_screen->GT;
98 1.25 blymn __NONL = _cursesi_screen->NONL;
99 1.25 blymn return OK;
100 1.25 blymn }
101 1.25 blymn
102 1.25 blymn /*
103 1.25 blymn * _cursesi_gettmode --
104 1.25 blymn * Do the terminal type initialisation for the tty attached to the
105 1.25 blymn * given screen.
106 1.25 blymn */
107 1.25 blymn int
108 1.25 blymn _cursesi_gettmode(SCREEN *screen)
109 1.25 blymn {
110 1.25 blymn screen->useraw = 0;
111 1.25 blymn
112 1.25 blymn if (tcgetattr(fileno(screen->infd), &screen->orig_termios))
113 1.2 cgd return (ERR);
114 1.2 cgd
115 1.25 blymn screen->baset = screen->orig_termios;
116 1.25 blymn screen->baset.c_oflag &= ~OXTABS;
117 1.28 blymn
118 1.25 blymn screen->GT = 0; /* historical. was used before we wired OXTABS off */
119 1.25 blymn screen->NONL = (screen->baset.c_oflag & ONLCR) == 0;
120 1.1 mycroft
121 1.2 cgd /*
122 1.2 cgd * XXX
123 1.2 cgd * System V and SMI systems overload VMIN and VTIME, such that
124 1.2 cgd * VMIN is the same as the VEOF element, and VTIME is the same
125 1.2 cgd * as the VEOL element. This means that, if VEOF was ^D, the
126 1.2 cgd * default VMIN is 4. Majorly stupid.
127 1.2 cgd */
128 1.25 blymn screen->cbreakt = screen->baset;
129 1.25 blymn screen->cbreakt.c_lflag &= ~(ECHO | ECHONL | ICANON);
130 1.25 blymn screen->cbreakt.c_cc[VMIN] = 1;
131 1.25 blymn screen->cbreakt.c_cc[VTIME] = 0;
132 1.25 blymn
133 1.25 blymn screen->rawt = screen->cbreakt;
134 1.25 blymn screen->rawt.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | INLCR | IGNCR |
135 1.25 blymn ICRNL | IXON);
136 1.25 blymn screen->rawt.c_oflag &= ~OPOST;
137 1.25 blymn screen->rawt.c_lflag &= ~(ISIG | IEXTEN);
138 1.2 cgd
139 1.2 cgd /*
140 1.2 cgd * In general, curses should leave hardware-related settings alone.
141 1.2 cgd * This includes parity and word size. Older versions set the tty
142 1.2 cgd * to 8 bits, no parity in raw(), but this is considered to be an
143 1.2 cgd * artifact of the old tty interface. If it's desired to change
144 1.2 cgd * parity and word size, the TCSASOFT bit has to be removed from the
145 1.2 cgd * calls that switch to/from "raw" mode.
146 1.2 cgd */
147 1.2 cgd if (!__tcaction) {
148 1.25 blymn screen->rawt.c_iflag &= ~ISTRIP;
149 1.25 blymn screen->rawt.c_cflag &= ~(CSIZE | PARENB);
150 1.25 blymn screen->rawt.c_cflag |= CS8;
151 1.2 cgd }
152 1.1 mycroft
153 1.25 blymn screen->curt = &screen->baset;
154 1.25 blymn return (tcsetattr(fileno(screen->infd), __tcaction ?
155 1.25 blymn TCSASOFT | TCSADRAIN : TCSADRAIN, screen->curt) ? ERR : OK);
156 1.1 mycroft }
157 1.1 mycroft
158 1.1 mycroft int
159 1.15 blymn raw(void)
160 1.1 mycroft {
161 1.28.2.1 grant #ifdef DEBUG
162 1.28.2.1 grant __CTRACE("raw()\n");
163 1.28.2.1 grant #endif
164 1.9 phil /* Check if we need to restart ... */
165 1.25 blymn if (_cursesi_screen->endwin)
166 1.23 jdc __restartwin();
167 1.11 mrg
168 1.25 blymn _cursesi_screen->useraw = __pfast = __rawmode = 1;
169 1.25 blymn _cursesi_screen->curt = &_cursesi_screen->rawt;
170 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
171 1.25 blymn TCSASOFT | TCSADRAIN : TCSADRAIN,
172 1.25 blymn _cursesi_screen->curt) ? ERR : OK);
173 1.1 mycroft }
174 1.1 mycroft
175 1.1 mycroft int
176 1.15 blymn noraw(void)
177 1.1 mycroft {
178 1.28.2.1 grant #ifdef DEBUG
179 1.28.2.1 grant __CTRACE("noraw()\n");
180 1.28.2.1 grant #endif
181 1.9 phil /* Check if we need to restart ... */
182 1.25 blymn if (_cursesi_screen->endwin)
183 1.23 jdc __restartwin();
184 1.11 mrg
185 1.25 blymn _cursesi_screen->useraw = __pfast = __rawmode = 0;
186 1.25 blymn _cursesi_screen->curt = &_cursesi_screen->baset;
187 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
188 1.25 blymn TCSASOFT | TCSADRAIN : TCSADRAIN,
189 1.25 blymn _cursesi_screen->curt) ? ERR : OK);
190 1.1 mycroft }
191 1.1 mycroft
192 1.1 mycroft int
193 1.15 blymn cbreak(void)
194 1.1 mycroft {
195 1.28.2.1 grant #ifdef DEBUG
196 1.28.2.1 grant __CTRACE("cbreak()\n");
197 1.28.2.1 grant #endif
198 1.9 phil /* Check if we need to restart ... */
199 1.25 blymn if (_cursesi_screen->endwin)
200 1.23 jdc __restartwin();
201 1.11 mrg
202 1.1 mycroft __rawmode = 1;
203 1.25 blymn _cursesi_screen->curt = _cursesi_screen->useraw ?
204 1.25 blymn &_cursesi_screen->rawt : &_cursesi_screen->cbreakt;
205 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
206 1.25 blymn TCSASOFT | TCSADRAIN : TCSADRAIN,
207 1.25 blymn _cursesi_screen->curt) ? ERR : OK);
208 1.1 mycroft }
209 1.1 mycroft
210 1.1 mycroft int
211 1.15 blymn nocbreak(void)
212 1.1 mycroft {
213 1.28.2.1 grant #ifdef DEBUG
214 1.28.2.1 grant __CTRACE("nocbreak()\n");
215 1.28.2.1 grant #endif
216 1.9 phil /* Check if we need to restart ... */
217 1.25 blymn if (_cursesi_screen->endwin)
218 1.23 jdc __restartwin();
219 1.1 mycroft
220 1.1 mycroft __rawmode = 0;
221 1.25 blymn _cursesi_screen->curt = _cursesi_screen->useraw ?
222 1.25 blymn &_cursesi_screen->rawt : &_cursesi_screen->baset;
223 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
224 1.25 blymn TCSASOFT | TCSADRAIN : TCSADRAIN,
225 1.25 blymn _cursesi_screen->curt) ? ERR : OK);
226 1.1 mycroft }
227 1.11 mrg
228 1.11 mrg int
229 1.15 blymn __delay(void)
230 1.11 mrg {
231 1.11 mrg /* Check if we need to restart ... */
232 1.25 blymn if (_cursesi_screen->endwin)
233 1.23 jdc __restartwin();
234 1.11 mrg
235 1.25 blymn _cursesi_screen->rawt.c_cc[VMIN] = 1;
236 1.25 blymn _cursesi_screen->rawt.c_cc[VTIME] = 0;
237 1.25 blymn _cursesi_screen->cbreakt.c_cc[VMIN] = 1;
238 1.25 blymn _cursesi_screen->cbreakt.c_cc[VTIME] = 0;
239 1.25 blymn _cursesi_screen->baset.c_cc[VMIN] = 1;
240 1.25 blymn _cursesi_screen->baset.c_cc[VTIME] = 0;
241 1.11 mrg
242 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
243 1.25 blymn TCSASOFT : TCSANOW, _cursesi_screen->curt) ? ERR : OK);
244 1.11 mrg }
245 1.11 mrg
246 1.11 mrg int
247 1.15 blymn __nodelay(void)
248 1.11 mrg {
249 1.11 mrg /* Check if we need to restart ... */
250 1.25 blymn if (_cursesi_screen->endwin)
251 1.23 jdc __restartwin();
252 1.11 mrg
253 1.25 blymn _cursesi_screen->rawt.c_cc[VMIN] = 0;
254 1.25 blymn _cursesi_screen->rawt.c_cc[VTIME] = 0;
255 1.25 blymn _cursesi_screen->cbreakt.c_cc[VMIN] = 0;
256 1.25 blymn _cursesi_screen->cbreakt.c_cc[VTIME] = 0;
257 1.25 blymn _cursesi_screen->baset.c_cc[VMIN] = 0;
258 1.25 blymn _cursesi_screen->baset.c_cc[VTIME] = 0;
259 1.11 mrg
260 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
261 1.25 blymn TCSASOFT : TCSANOW, _cursesi_screen->curt) ? ERR : OK);
262 1.11 mrg }
263 1.11 mrg
264 1.11 mrg void
265 1.15 blymn __save_termios(void)
266 1.11 mrg {
267 1.11 mrg /* Check if we need to restart ... */
268 1.25 blymn if (_cursesi_screen->endwin)
269 1.23 jdc __restartwin();
270 1.11 mrg
271 1.25 blymn _cursesi_screen->ovmin = _cursesi_screen->cbreakt.c_cc[VMIN];
272 1.25 blymn _cursesi_screen->ovtime = _cursesi_screen->cbreakt.c_cc[VTIME];
273 1.11 mrg }
274 1.11 mrg
275 1.11 mrg void
276 1.15 blymn __restore_termios(void)
277 1.11 mrg {
278 1.11 mrg /* Check if we need to restart ... */
279 1.25 blymn if (_cursesi_screen->endwin)
280 1.23 jdc __restartwin();
281 1.11 mrg
282 1.25 blymn _cursesi_screen->rawt.c_cc[VMIN] = _cursesi_screen->ovmin;
283 1.25 blymn _cursesi_screen->rawt.c_cc[VTIME] = _cursesi_screen->ovtime;
284 1.25 blymn _cursesi_screen->cbreakt.c_cc[VMIN] = _cursesi_screen->ovmin;
285 1.25 blymn _cursesi_screen->cbreakt.c_cc[VTIME] = _cursesi_screen->ovtime;
286 1.25 blymn _cursesi_screen->baset.c_cc[VMIN] = _cursesi_screen->ovmin;
287 1.25 blymn _cursesi_screen->baset.c_cc[VTIME] = _cursesi_screen->ovtime;
288 1.11 mrg }
289 1.11 mrg
290 1.11 mrg int
291 1.15 blymn __timeout(int delay)
292 1.11 mrg {
293 1.11 mrg /* Check if we need to restart ... */
294 1.25 blymn if (_cursesi_screen->endwin)
295 1.23 jdc __restartwin();
296 1.11 mrg
297 1.25 blymn _cursesi_screen->ovmin = _cursesi_screen->cbreakt.c_cc[VMIN];
298 1.25 blymn _cursesi_screen->ovtime = _cursesi_screen->cbreakt.c_cc[VTIME];
299 1.25 blymn _cursesi_screen->rawt.c_cc[VMIN] = 0;
300 1.25 blymn _cursesi_screen->rawt.c_cc[VTIME] = delay;
301 1.25 blymn _cursesi_screen->cbreakt.c_cc[VMIN] = 0;
302 1.25 blymn _cursesi_screen->cbreakt.c_cc[VTIME] = delay;
303 1.25 blymn _cursesi_screen->baset.c_cc[VMIN] = 0;
304 1.25 blymn _cursesi_screen->baset.c_cc[VTIME] = delay;
305 1.25 blymn
306 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
307 1.25 blymn TCSASOFT | TCSANOW : TCSANOW,
308 1.25 blymn _cursesi_screen->curt) ? ERR : OK);
309 1.11 mrg }
310 1.11 mrg
311 1.11 mrg int
312 1.15 blymn __notimeout(void)
313 1.11 mrg {
314 1.11 mrg /* Check if we need to restart ... */
315 1.25 blymn if (_cursesi_screen->endwin)
316 1.23 jdc __restartwin();
317 1.11 mrg
318 1.25 blymn _cursesi_screen->rawt.c_cc[VMIN] = 1;
319 1.25 blymn _cursesi_screen->rawt.c_cc[VTIME] = 0;
320 1.25 blymn _cursesi_screen->cbreakt.c_cc[VMIN] = 1;
321 1.25 blymn _cursesi_screen->cbreakt.c_cc[VTIME] = 0;
322 1.25 blymn _cursesi_screen->baset.c_cc[VMIN] = 1;
323 1.25 blymn _cursesi_screen->baset.c_cc[VTIME] = 0;
324 1.25 blymn
325 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
326 1.25 blymn TCSASOFT | TCSANOW : TCSANOW,
327 1.25 blymn _cursesi_screen->curt) ? ERR : OK);
328 1.11 mrg }
329 1.11 mrg
330 1.1 mycroft int
331 1.15 blymn echo(void)
332 1.1 mycroft {
333 1.28.2.1 grant #ifdef DEBUG
334 1.28.2.1 grant __CTRACE("echo()\n");
335 1.28.2.1 grant #endif
336 1.9 phil /* Check if we need to restart ... */
337 1.25 blymn if (_cursesi_screen->endwin)
338 1.23 jdc __restartwin();
339 1.9 phil
340 1.1 mycroft __echoit = 1;
341 1.17 mycroft return (OK);
342 1.1 mycroft }
343 1.1 mycroft
344 1.1 mycroft int
345 1.15 blymn noecho(void)
346 1.1 mycroft {
347 1.28.2.1 grant #ifdef DEBUG
348 1.28.2.1 grant __CTRACE("noecho()\n");
349 1.28.2.1 grant #endif
350 1.9 phil /* Check if we need to restart ... */
351 1.25 blymn if (_cursesi_screen->endwin)
352 1.23 jdc __restartwin();
353 1.9 phil
354 1.1 mycroft __echoit = 0;
355 1.17 mycroft return (OK);
356 1.1 mycroft }
357 1.1 mycroft
358 1.1 mycroft int
359 1.15 blymn nl(void)
360 1.1 mycroft {
361 1.28.2.1 grant #ifdef DEBUG
362 1.28.2.1 grant __CTRACE("nl()\n");
363 1.28.2.1 grant #endif
364 1.9 phil /* Check if we need to restart ... */
365 1.25 blymn if (_cursesi_screen->endwin)
366 1.23 jdc __restartwin();
367 1.9 phil
368 1.25 blymn _cursesi_screen->rawt.c_iflag |= ICRNL;
369 1.25 blymn _cursesi_screen->rawt.c_oflag |= ONLCR;
370 1.25 blymn _cursesi_screen->cbreakt.c_iflag |= ICRNL;
371 1.25 blymn _cursesi_screen->cbreakt.c_oflag |= ONLCR;
372 1.25 blymn _cursesi_screen->baset.c_iflag |= ICRNL;
373 1.25 blymn _cursesi_screen->baset.c_oflag |= ONLCR;
374 1.25 blymn
375 1.28.2.1 grant _cursesi_screen->nl = 1;
376 1.25 blymn _cursesi_screen->pfast = _cursesi_screen->rawmode;
377 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
378 1.25 blymn TCSASOFT | TCSADRAIN : TCSADRAIN,
379 1.25 blymn _cursesi_screen->curt) ? ERR : OK);
380 1.1 mycroft }
381 1.1 mycroft
382 1.1 mycroft int
383 1.15 blymn nonl(void)
384 1.1 mycroft {
385 1.28.2.1 grant #ifdef DEBUG
386 1.28.2.1 grant __CTRACE("nonl()\n");
387 1.28.2.1 grant #endif
388 1.9 phil /* Check if we need to restart ... */
389 1.25 blymn if (_cursesi_screen->endwin)
390 1.23 jdc __restartwin();
391 1.9 phil
392 1.25 blymn _cursesi_screen->rawt.c_iflag &= ~ICRNL;
393 1.25 blymn _cursesi_screen->rawt.c_oflag &= ~ONLCR;
394 1.25 blymn _cursesi_screen->cbreakt.c_iflag &= ~ICRNL;
395 1.25 blymn _cursesi_screen->cbreakt.c_oflag &= ~ONLCR;
396 1.25 blymn _cursesi_screen->baset.c_iflag &= ~ICRNL;
397 1.25 blymn _cursesi_screen->baset.c_oflag &= ~ONLCR;
398 1.1 mycroft
399 1.28.2.1 grant _cursesi_screen->nl = 0;
400 1.1 mycroft __pfast = 1;
401 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
402 1.25 blymn TCSASOFT | TCSADRAIN : TCSADRAIN,
403 1.25 blymn _cursesi_screen->curt) ? ERR : OK);
404 1.2 cgd }
405 1.2 cgd
406 1.14 jdc int
407 1.15 blymn intrflush(WINDOW *win, bool bf) /*ARGSUSED*/
408 1.14 jdc {
409 1.14 jdc /* Check if we need to restart ... */
410 1.25 blymn if (_cursesi_screen->endwin)
411 1.23 jdc __restartwin();
412 1.14 jdc
413 1.14 jdc if (bf) {
414 1.25 blymn _cursesi_screen->rawt.c_lflag &= ~NOFLSH;
415 1.25 blymn _cursesi_screen->cbreakt.c_lflag &= ~NOFLSH;
416 1.25 blymn _cursesi_screen->baset.c_lflag &= ~NOFLSH;
417 1.14 jdc } else {
418 1.25 blymn _cursesi_screen->rawt.c_lflag |= NOFLSH;
419 1.25 blymn _cursesi_screen->cbreakt.c_lflag |= NOFLSH;
420 1.25 blymn _cursesi_screen->baset.c_lflag |= NOFLSH;
421 1.14 jdc }
422 1.14 jdc
423 1.14 jdc __pfast = 1;
424 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
425 1.25 blymn TCSASOFT | TCSADRAIN : TCSADRAIN,
426 1.25 blymn _cursesi_screen->curt) ? ERR : OK);
427 1.14 jdc }
428 1.14 jdc
429 1.2 cgd void
430 1.25 blymn __startwin(SCREEN *screen)
431 1.2 cgd {
432 1.6 cgd
433 1.25 blymn (void) fflush(screen->infd);
434 1.6 cgd
435 1.6 cgd /*
436 1.6 cgd * Some C libraries default to a 1K buffer when talking to a tty.
437 1.6 cgd * With a larger screen, especially across a network, we'd like
438 1.6 cgd * to get it to all flush in a single write. Make it twice as big
439 1.6 cgd * as just the characters (so that we have room for cursor motions
440 1.11 mrg * and attribute information) but no more than 8K.
441 1.6 cgd */
442 1.25 blymn if (screen->stdbuf == NULL) {
443 1.25 blymn screen->len = LINES * COLS * 2;
444 1.25 blymn if (screen->len > 8192)
445 1.25 blymn screen->len = 8192;
446 1.25 blymn if ((screen->stdbuf = malloc(screen->len)) == NULL)
447 1.25 blymn screen->len = 0;
448 1.6 cgd }
449 1.25 blymn (void) setvbuf(screen->outfd, screen->stdbuf, _IOFBF, screen->len);
450 1.2 cgd
451 1.27 blymn t_puts(screen->cursesi_genbuf, __tc_ti, 0, __cputchar_args,
452 1.27 blymn (void *) screen->outfd);
453 1.27 blymn t_puts(screen->cursesi_genbuf, __tc_vs, 0, __cputchar_args,
454 1.27 blymn (void *) screen->outfd);
455 1.25 blymn if (screen->curscr->flags & __KEYPAD)
456 1.27 blymn t_puts(screen->cursesi_genbuf, __tc_ks, 0, __cputchar_args,
457 1.27 blymn (void *) screen->outfd);
458 1.25 blymn screen->endwin = 0;
459 1.1 mycroft }
460 1.1 mycroft
461 1.1 mycroft int
462 1.15 blymn endwin(void)
463 1.1 mycroft {
464 1.8 phil return __stopwin();
465 1.11 mrg }
466 1.11 mrg
467 1.13 blymn bool
468 1.15 blymn isendwin(void)
469 1.11 mrg {
470 1.25 blymn return (_cursesi_screen->endwin ? TRUE : FALSE);
471 1.11 mrg }
472 1.11 mrg
473 1.11 mrg int
474 1.15 blymn flushinp(void)
475 1.11 mrg {
476 1.25 blymn (void) fpurge(_cursesi_screen->infd);
477 1.11 mrg return (OK);
478 1.14 jdc }
479 1.14 jdc
480 1.1 mycroft /*
481 1.1 mycroft * The following routines, savetty and resetty are completely useless and
482 1.1 mycroft * are left in only as stubs. If people actually use them they will almost
483 1.1 mycroft * certainly screw up the state of the world.
484 1.1 mycroft */
485 1.25 blymn /*static struct termios savedtty;*/
486 1.1 mycroft int
487 1.15 blymn savetty(void)
488 1.1 mycroft {
489 1.25 blymn return (tcgetattr(fileno(_cursesi_screen->infd),
490 1.25 blymn &_cursesi_screen->savedtty) ? ERR : OK);
491 1.1 mycroft }
492 1.1 mycroft
493 1.1 mycroft int
494 1.15 blymn resetty(void)
495 1.1 mycroft {
496 1.25 blymn return (tcsetattr(fileno(_cursesi_screen->infd), __tcaction ?
497 1.25 blymn TCSASOFT | TCSADRAIN : TCSADRAIN,
498 1.25 blymn &_cursesi_screen->savedtty) ? ERR : OK);
499 1.19 blymn }
500 1.19 blymn
501 1.19 blymn /*
502 1.19 blymn * erasechar --
503 1.19 blymn * Return the character of the erase key.
504 1.19 blymn *
505 1.19 blymn */
506 1.19 blymn char
507 1.19 blymn erasechar(void)
508 1.19 blymn {
509 1.25 blymn return _cursesi_screen->baset.c_cc[VERASE];
510 1.19 blymn }
511 1.19 blymn
512 1.19 blymn /*
513 1.19 blymn * killchar --
514 1.19 blymn * Return the character of the kill key.
515 1.19 blymn */
516 1.19 blymn char
517 1.19 blymn killchar(void)
518 1.19 blymn {
519 1.25 blymn return _cursesi_screen->baset.c_cc[VKILL];
520 1.1 mycroft }
521