]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_kernel.c
ncurses 4.1
[ncurses.git] / ncurses / lib_kernel.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22
23 /*
24  *      lib_kernel.c
25  *
26  *      Misc. low-level routines:
27  *              napms()
28  *              reset_prog_mode()
29  *              reset_shell_mode()
30  *              erasechar()
31  *              killchar()
32  *              flushinp()
33  *              savetty()
34  *              resetty()
35  *
36  * The baudrate() and delay_output() functions could logically live here,
37  * but are in other modules to reduce the static-link size of programs
38  * that use only these facilities.
39  */
40
41 #include <curses.priv.h>
42 #include <term.h>       /* cur_term */
43
44 MODULE_ID("$Id: lib_kernel.c,v 1.13 1997/02/02 00:33:14 tom Exp $")
45
46 int napms(int ms)
47 {
48         T((T_CALLED("napms(%d)"), ms));
49
50         usleep(1000*(unsigned)ms);
51         returnCode(OK);
52 }
53
54 int reset_prog_mode(void)
55 {
56         T((T_CALLED("reset_prog_mode()")));
57
58         SET_TTY(cur_term->Filedes, &cur_term->Nttyb);
59         if (SP && stdscr && stdscr->_use_keypad)
60                 _nc_keypad(TRUE);
61
62         returnCode(OK);
63 }
64
65
66 int reset_shell_mode(void)
67 {
68         T((T_CALLED("reset_shell_mode()")));
69
70         if (SP)
71         {
72                 fflush(SP->_ofp);
73                 _nc_keypad(FALSE);
74         }
75
76         SET_TTY(cur_term->Filedes, &cur_term->Ottyb);
77         returnCode(OK);
78 }
79
80 /*
81  *      erasechar()
82  *
83  *      Return erase character as given in cur_term->Ottyb.
84  *
85  */
86
87 char
88 erasechar(void)
89 {
90         T((T_CALLED("erasechar()")));
91
92 #ifdef TERMIOS
93         returnCode(cur_term->Ottyb.c_cc[VERASE]);
94 #else
95         returnCode(cur_term->Ottyb.sg_erase);
96 #endif
97
98 }
99
100
101
102 /*
103  *      killchar()
104  *
105  *      Return kill character as given in cur_term->Ottyb.
106  *
107  */
108
109 char
110 killchar(void)
111 {
112         T((T_CALLED("killchar()")));
113
114 #ifdef TERMIOS
115         returnCode(cur_term->Ottyb.c_cc[VKILL]);
116 #else
117         returnCode(cur_term->Ottyb.sg_kill);
118 #endif
119 }
120
121
122
123 /*
124  *      flushinp()
125  *
126  *      Flush any input on cur_term->Filedes
127  *
128  */
129
130 int flushinp(void)
131 {
132         T((T_CALLED("flushinp()")));
133
134 #ifdef TERMIOS
135         tcflush(cur_term->Filedes, TCIFLUSH);
136 #else
137         errno = 0;
138         do {
139             ioctl(cur_term->Filedes, TIOCFLUSH, 0);
140         } while
141             (errno == EINTR);
142 #endif
143         if (SP) {
144                 SP->_fifohead = -1;
145                 SP->_fifotail = 0;
146                 SP->_fifopeek = 0;
147         }
148         returnCode(OK);
149
150 }
151
152 /*
153 **      savetty()  and  resetty()
154 **
155 */
156
157 static TTY   buf;
158
159 int savetty(void)
160 {
161         T((T_CALLED("savetty()")));
162
163         GET_TTY(cur_term->Filedes, &buf);
164         returnCode(OK);
165 }
166
167 int resetty(void)
168 {
169         T((T_CALLED("resetty()")));
170
171         SET_TTY(cur_term->Filedes, &buf);
172         returnCode(OK);
173 }