xref: /openbsd-src/lib/libcurses/tinfo/lib_kernel.c (revision 92dd1ec0a89df25171bc5d61a3d95ea1a68cef0b)
1 /*	$OpenBSD: lib_kernel.c,v 1.1 1999/01/18 19:10:17 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998 Free Software Foundation, Inc.                        *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
33  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
34  ****************************************************************************/
35 
36 
37 /*
38  *	lib_kernel.c
39  *
40  *	Misc. low-level routines:
41  *		erasechar()
42  *		killchar()
43  *		flushinp()
44  *
45  * The baudrate() and delay_output() functions could logically live here,
46  * but are in other modules to reduce the static-link size of programs
47  * that use only these facilities.
48  */
49 
50 #include <curses.priv.h>
51 #include <term.h>	/* cur_term */
52 
53 MODULE_ID("$From: lib_kernel.c,v 1.19 1998/12/20 00:18:45 tom Exp $")
54 
55 /*
56  *	erasechar()
57  *
58  *	Return erase character as given in cur_term->Ottyb.
59  *
60  */
61 
62 char
63 erasechar(void)
64 {
65 	T((T_CALLED("erasechar()")));
66 
67 	if (cur_term != 0) {
68 #ifdef TERMIOS
69 		returnCode(cur_term->Ottyb.c_cc[VERASE]);
70 #else
71 		returnCode(cur_term->Ottyb.sg_erase);
72 #endif
73 	}
74 	returnCode(ERR);
75 }
76 
77 
78 
79 /*
80  *	killchar()
81  *
82  *	Return kill character as given in cur_term->Ottyb.
83  *
84  */
85 
86 char
87 killchar(void)
88 {
89 	T((T_CALLED("killchar()")));
90 
91 	if (cur_term != 0) {
92 #ifdef TERMIOS
93 		returnCode(cur_term->Ottyb.c_cc[VKILL]);
94 #else
95 		returnCode(cur_term->Ottyb.sg_kill);
96 #endif
97 	}
98 	returnCode(ERR);
99 }
100 
101 
102 
103 /*
104  *	flushinp()
105  *
106  *	Flush any input on cur_term->Filedes
107  *
108  */
109 
110 int flushinp(void)
111 {
112 	T((T_CALLED("flushinp()")));
113 
114 	if (cur_term != 0) {
115 #ifdef TERMIOS
116 		tcflush(cur_term->Filedes, TCIFLUSH);
117 #else
118 		errno = 0;
119 		do {
120 		    ioctl(cur_term->Filedes, TIOCFLUSH, 0);
121 		} while
122 		    (errno == EINTR);
123 #endif
124 		if (SP) {
125 			SP->_fifohead = -1;
126 			SP->_fifotail = 0;
127 			SP->_fifopeek = 0;
128 		}
129 		returnCode(OK);
130 	}
131 	returnCode(ERR);
132 }
133