Back to index

tetex-bin  3.0
lib_options.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2002,2003 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                        1996-2003               *
00033  ****************************************************************************/
00034 
00035 /*
00036 **     lib_options.c
00037 **
00038 **     The routines to handle option setting.
00039 **
00040 */
00041 
00042 #include <curses.priv.h>
00043 
00044 #include <term.h>
00045 
00046 MODULE_ID("$Id: lib_options.c,v 1.47 2003/10/25 19:51:38 tom Exp $")
00047 
00048 NCURSES_EXPORT(int)
00049 idlok(WINDOW *win, bool flag)
00050 {
00051     T((T_CALLED("idlok(%p,%d)"), win, flag));
00052 
00053     if (win) {
00054        _nc_idlok = win->_idlok = (flag && (has_il() || change_scroll_region));
00055        returnCode(OK);
00056     } else
00057        returnCode(ERR);
00058 }
00059 
00060 NCURSES_EXPORT(void)
00061 idcok(WINDOW *win, bool flag)
00062 {
00063     T((T_CALLED("idcok(%p,%d)"), win, flag));
00064 
00065     if (win)
00066        _nc_idcok = win->_idcok = (flag && has_ic());
00067 
00068     returnVoid;
00069 }
00070 
00071 NCURSES_EXPORT(int)
00072 halfdelay(int t)
00073 {
00074     T((T_CALLED("halfdelay(%d)"), t));
00075 
00076     if (t < 1 || t > 255 || SP == 0)
00077        returnCode(ERR);
00078 
00079     cbreak();
00080     SP->_cbreak = t + 1;
00081     returnCode(OK);
00082 }
00083 
00084 NCURSES_EXPORT(int)
00085 nodelay(WINDOW *win, bool flag)
00086 {
00087     T((T_CALLED("nodelay(%p,%d)"), win, flag));
00088 
00089     if (win) {
00090        if (flag == TRUE)
00091            win->_delay = 0;
00092        else
00093            win->_delay = -1;
00094        returnCode(OK);
00095     } else
00096        returnCode(ERR);
00097 }
00098 
00099 NCURSES_EXPORT(int)
00100 notimeout(WINDOW *win, bool f)
00101 {
00102     T((T_CALLED("notimout(%p,%d)"), win, f));
00103 
00104     if (win) {
00105        win->_notimeout = f;
00106        returnCode(OK);
00107     } else
00108        returnCode(ERR);
00109 }
00110 
00111 NCURSES_EXPORT(void)
00112 wtimeout(WINDOW *win, int delay)
00113 {
00114     T((T_CALLED("wtimeout(%p,%d)"), win, delay));
00115 
00116     if (win) {
00117        win->_delay = delay;
00118     }
00119     returnVoid;
00120 }
00121 
00122 NCURSES_EXPORT(int)
00123 keypad(WINDOW *win, bool flag)
00124 {
00125     T((T_CALLED("keypad(%p,%d)"), win, flag));
00126 
00127     if (win) {
00128        win->_use_keypad = flag;
00129        returnCode(_nc_keypad(flag));
00130     } else
00131        returnCode(ERR);
00132 }
00133 
00134 NCURSES_EXPORT(int)
00135 meta(WINDOW *win GCC_UNUSED, bool flag)
00136 {
00137     int result = ERR;
00138 
00139     /* Ok, we stay relaxed and don't signal an error if win is NULL */
00140     T((T_CALLED("meta(%p,%d)"), win, flag));
00141 
00142     if (SP != 0) {
00143        SP->_use_meta = flag;
00144 
00145        if (flag && meta_on) {
00146            TPUTS_TRACE("meta_on");
00147            putp(meta_on);
00148        } else if (!flag && meta_off) {
00149            TPUTS_TRACE("meta_off");
00150            putp(meta_off);
00151        }
00152        result = OK;
00153     }
00154     returnCode(result);
00155 }
00156 
00157 /* curs_set() moved here to narrow the kernel interface */
00158 
00159 NCURSES_EXPORT(int)
00160 curs_set(int vis)
00161 {
00162     int cursor = SP->_cursor;
00163 
00164     T((T_CALLED("curs_set(%d)"), vis));
00165 
00166     if (vis < 0 || vis > 2)
00167        returnCode(ERR);
00168 
00169     if (vis == cursor)
00170        returnCode(cursor);
00171 
00172     switch (vis) {
00173     case 2:
00174        if (cursor_visible) {
00175            TPUTS_TRACE("cursor_visible");
00176            putp(cursor_visible);
00177        } else
00178            returnCode(ERR);
00179        break;
00180     case 1:
00181        if (cursor_normal) {
00182            TPUTS_TRACE("cursor_normal");
00183            putp(cursor_normal);
00184        } else
00185            returnCode(ERR);
00186        break;
00187     case 0:
00188        if (cursor_invisible) {
00189            TPUTS_TRACE("cursor_invisible");
00190            putp(cursor_invisible);
00191        } else
00192            returnCode(ERR);
00193        break;
00194     }
00195     SP->_cursor = vis;
00196     _nc_flush();
00197 
00198     returnCode(cursor == -1 ? 1 : cursor);
00199 }
00200 
00201 NCURSES_EXPORT(int)
00202 typeahead(int fd)
00203 {
00204     T((T_CALLED("typeahead(%d)"), fd));
00205     if (SP != 0) {
00206        SP->_checkfd = fd;
00207        returnCode(OK);
00208     } else {
00209        returnCode(ERR);
00210     }
00211 }
00212 
00213 /*
00214 **      has_key()
00215 **
00216 **      Return TRUE if the current terminal has the given key
00217 **
00218 */
00219 
00220 #if NCURSES_EXT_FUNCS
00221 static int
00222 has_key_internal(int keycode, struct tries *tp)
00223 {
00224     if (tp == 0)
00225        return (FALSE);
00226     else if (tp->value == keycode)
00227        return (TRUE);
00228     else
00229        return (has_key_internal(keycode, tp->child)
00230               || has_key_internal(keycode, tp->sibling));
00231 }
00232 
00233 NCURSES_EXPORT(int)
00234 has_key(int keycode)
00235 {
00236     T((T_CALLED("has_key(%d)"), keycode));
00237     returnCode(SP != 0 ? has_key_internal(keycode, SP->_keytry) : FALSE);
00238 }
00239 #endif /* NCURSES_EXT_FUNCS */
00240 
00241 /* Turn the keypad on/off
00242  *
00243  * Note:  we flush the output because changing this mode causes some terminals
00244  * to emit different escape sequences for cursor and keypad keys.  If we don't
00245  * flush, then the next wgetch may get the escape sequence that corresponds to
00246  * the terminal state _before_ switching modes.
00247  */
00248 NCURSES_EXPORT(int)
00249 _nc_keypad(bool flag)
00250 {
00251     if (flag && keypad_xmit) {
00252        TPUTS_TRACE("keypad_xmit");
00253        putp(keypad_xmit);
00254        _nc_flush();
00255     } else if (!flag && keypad_local) {
00256        TPUTS_TRACE("keypad_local");
00257        putp(keypad_local);
00258        _nc_flush();
00259     }
00260 
00261     if (flag && SP != 0 && !SP->_tried) {
00262        _nc_init_keytry();
00263        SP->_tried = TRUE;
00264     }
00265     SP->_keypad_on = flag;
00266     return (OK);
00267 }