2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
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. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
26 ** The routines to handle option setting.
30 #include <curses.priv.h>
32 #include <term.h> /* keypad_xmit, keypad_local, meta_on, meta_off */
33 /* cursor_visible,cursor_normal,cursor_invisible */
35 MODULE_ID("$Id: lib_options.c,v 1.22 1997/05/01 23:46:18 Alexander.V.Lukyanov Exp $")
39 T((T_CALLED("has_ic()")));
40 returnCode((insert_character || parm_ich
41 || (enter_insert_mode && exit_insert_mode))
42 && (delete_character || parm_dch));
47 T((T_CALLED("has_il()")));
48 returnCode((insert_line || parm_insert_line)
49 && (delete_line || parm_delete_line));
52 int idlok(WINDOW *win, bool flag)
54 T((T_CALLED("idlok(%p,%d)"), win, flag));
56 _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region);
61 void idcok(WINDOW *win, bool flag)
63 T((T_CALLED("idcok(%p,%d)"), win, flag));
65 _nc_idcok = win->_idcok = flag && has_ic();
71 int clearok(WINDOW *win, bool flag)
73 T((T_CALLED("clearok(%p,%d)"), win, flag));
80 void immedok(WINDOW *win, bool flag)
82 T((T_CALLED("immedok(%p,%d)"), win, flag));
89 int leaveok(WINDOW *win, bool flag)
91 T((T_CALLED("leaveok(%p,%d)"), win, flag));
102 int scrollok(WINDOW *win, bool flag)
104 T((T_CALLED("scrollok(%p,%d)"), win, flag));
112 T((T_CALLED("halfdelay(%d)"), t));
114 if (t < 1 || t > 255)
122 int nodelay(WINDOW *win, bool flag)
124 T((T_CALLED("nodelay(%p,%d)"), win, flag));
128 else win->_delay = -1;
132 int notimeout(WINDOW *win, bool f)
134 T((T_CALLED("notimout(%p,%d)"), win, f));
140 int wtimeout(WINDOW *win, int delay)
142 T((T_CALLED("wtimeout(%p,%d)"), win, delay));
148 static void init_keytry(void);
149 static void add_to_try(char *, short);
151 /* Turn the keypad on/off
153 * Note: we flush the output because changing this mode causes some terminals
154 * to emit different escape sequences for cursor and keypad keys. If we don't
155 * flush, then the next wgetch may get the escape sequence that corresponds to
156 * the terminal state _before_ switching modes.
158 int _nc_keypad(bool flag)
160 if (flag && keypad_xmit)
162 TPUTS_TRACE("keypad_xmit");
164 (void) fflush(SP->_ofp);
166 else if (! flag && keypad_local)
168 TPUTS_TRACE("keypad_local");
170 (void) fflush(SP->_ofp);
173 if (SP->_keytry == UNINITIALISED)
178 int keypad(WINDOW *win, bool flag)
180 T((T_CALLED("keypad(%p,%d)"), win, flag));
182 win->_use_keypad = flag;
183 returnCode(_nc_keypad(flag));
187 int meta(WINDOW *win GCC_UNUSED, bool flag)
189 T((T_CALLED("meta(%p,%d)"), win, flag));
191 SP->_use_meta = flag;
195 TPUTS_TRACE("meta_on");
198 else if (! flag && meta_off)
200 TPUTS_TRACE("meta_off");
206 /* curs_set() moved here to narrow the kernel interface */
208 int curs_set(int vis)
210 int cursor = SP->_cursor;
212 T((T_CALLED("curs_set(%d)"), vis));
214 if (vis < 0 || vis > 2)
224 TPUTS_TRACE("cursor_visible");
225 putp(cursor_visible);
233 TPUTS_TRACE("cursor_normal");
240 if (cursor_invisible)
242 TPUTS_TRACE("cursor_invisible");
243 putp(cursor_invisible);
250 (void) fflush(SP->_ofp);
252 returnCode(cursor==-1 ? 1 : cursor);
258 ** Construct the try for the current terminal's keypad keys.
263 static struct tries *newtry;
265 static void init_keytry(void)
271 #include <keys.tries>
275 SP->_keytry = newtry;
279 static void add_to_try(char *str, short code)
281 static bool out_of_memory = FALSE;
282 struct tries *ptr, *savedptr;
284 if (! str || out_of_memory)
288 ptr = savedptr = newtry;
291 while (ptr->ch != (unsigned char) *str
292 && ptr->sibling != 0)
295 if (ptr->ch == (unsigned char) *str) {
306 if ((ptr->sibling = typeCalloc(struct tries,1)) == 0) {
307 out_of_memory = TRUE;
311 savedptr = ptr = ptr->sibling;
315 ptr->ch = (unsigned char) *str;
322 } else { /* newtry == 0 :: First sequence to be added */
323 savedptr = ptr = newtry = typeCalloc(struct tries,1);
326 out_of_memory = TRUE;
333 ptr->ch = (unsigned char) *str;
338 /* at this point, we are adding to the try. ptr->child == 0 */
341 ptr->child = typeCalloc(struct tries,1);
346 out_of_memory = TRUE;
350 savedptr = ptr->child;
361 ptr->ch = (unsigned char) *str;
370 int typeahead(int fd)
372 T((T_CALLED("typeahead(%d)"), fd));
380 ** Return TRUE if the current terminal has the given key
385 static int has_key_internal(int keycode, struct tries *tp)
389 else if (tp->value == keycode)
392 return(has_key_internal(keycode, tp->child)
393 || has_key_internal(keycode, tp->sibling));
396 int has_key(int keycode)
398 T((T_CALLED("has_key(%d)"), keycode));
399 returnCode(has_key_internal(keycode, SP->_keytry));