Back to index

tetex-bin  3.0
lib_kernel.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2003,2004 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
00031  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
00032  *     and: Thomas E. Dickey 2002                                           *
00033  ****************************************************************************/
00034 
00035 /*
00036  *     lib_kernel.c
00037  *
00038  *     Misc. low-level routines:
00039  *            erasechar()
00040  *            killchar()
00041  *            flushinp()
00042  *
00043  * The baudrate() and delay_output() functions could logically live here,
00044  * but are in other modules to reduce the static-link size of programs
00045  * that use only these facilities.
00046  */
00047 
00048 #include <curses.priv.h>
00049 #include <term.h>           /* cur_term */
00050 
00051 MODULE_ID("$Id: lib_kernel.c,v 1.24 2004/05/08 17:11:21 tom Exp $")
00052 
00053 static int
00054 _nc_vdisable(void)
00055 {
00056     int value = -1;
00057 #if defined(_POSIX_VDISABLE) && HAVE_UNISTD_H
00058     value = _POSIX_VDISABLE;
00059 #endif
00060 #if defined(_PC_VDISABLE)
00061     if (value == -1) {
00062        value = fpathconf(0, _PC_VDISABLE);
00063        if (value == -1) {
00064            value = 0377;
00065        }
00066     }
00067 #elif defined(VDISABLE)
00068     if (value == -1)
00069        value = VDISABLE;
00070 #endif
00071     return value;
00072 }
00073 
00074 /*
00075  *     erasechar()
00076  *
00077  *     Return erase character as given in cur_term->Ottyb.
00078  *
00079  */
00080 
00081 NCURSES_EXPORT(char)
00082 erasechar(void)
00083 {
00084     int result = ERR;
00085     T((T_CALLED("erasechar()")));
00086 
00087     if (cur_term != 0) {
00088 #ifdef TERMIOS
00089        result = cur_term->Ottyb.c_cc[VERASE];
00090        if (result == _nc_vdisable())
00091            result = ERR;
00092 #else
00093        result = cur_term->Ottyb.sg_erase;
00094 #endif
00095     }
00096     returnCode(result);
00097 }
00098 
00099 /*
00100  *     killchar()
00101  *
00102  *     Return kill character as given in cur_term->Ottyb.
00103  *
00104  */
00105 
00106 NCURSES_EXPORT(char)
00107 killchar(void)
00108 {
00109     int result = ERR;
00110     T((T_CALLED("killchar()")));
00111 
00112     if (cur_term != 0) {
00113 #ifdef TERMIOS
00114        result = cur_term->Ottyb.c_cc[VKILL];
00115        if (result == _nc_vdisable())
00116            result = ERR;
00117 #else
00118        result = cur_term->Ottyb.sg_kill;
00119 #endif
00120     }
00121     returnCode(result);
00122 }
00123 
00124 /*
00125  *     flushinp()
00126  *
00127  *     Flush any input on cur_term->Filedes
00128  *
00129  */
00130 
00131 NCURSES_EXPORT(int)
00132 flushinp(void)
00133 {
00134     T((T_CALLED("flushinp()")));
00135 
00136     if (cur_term != 0) {
00137 #ifdef TERMIOS
00138        tcflush(cur_term->Filedes, TCIFLUSH);
00139 #else
00140        errno = 0;
00141        do {
00142            ioctl(cur_term->Filedes, TIOCFLUSH, 0);
00143        } while
00144            (errno == EINTR);
00145 #endif
00146        if (SP) {
00147            SP->_fifohead = -1;
00148            SP->_fifotail = 0;
00149            SP->_fifopeek = 0;
00150        }
00151        returnCode(OK);
00152     }
00153     returnCode(ERR);
00154 }