X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Flib_options.c;h=5cdd1d468077887f9d7130dc3f610f9dac091bb2;hp=05bd47685dd617543bd937d9f086667d24d9da7d;hb=c4d90db4f4e50bb8a971955ce4812262da4a50bc;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01 diff --git a/ncurses/tinfo/lib_options.c b/ncurses/tinfo/lib_options.c index 05bd4768..5cdd1d46 100644 --- a/ncurses/tinfo/lib_options.c +++ b/ncurses/tinfo/lib_options.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001,2002 Free Software Foundation, Inc. * + * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -29,6 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ /* @@ -42,7 +43,7 @@ #include -MODULE_ID("$Id: lib_options.c,v 1.46 2002/02/02 19:40:54 tom Exp $") +MODULE_ID("$Id: lib_options.c,v 1.50 2006/12/30 16:03:27 tom Exp $") NCURSES_EXPORT(int) idlok(WINDOW *win, bool flag) @@ -72,7 +73,7 @@ halfdelay(int t) { T((T_CALLED("halfdelay(%d)"), t)); - if (t < 1 || t > 255) + if (t < 1 || t > 255 || SP == 0) returnCode(ERR); cbreak(); @@ -98,7 +99,7 @@ nodelay(WINDOW *win, bool flag) NCURSES_EXPORT(int) notimeout(WINDOW *win, bool f) { - T((T_CALLED("notimout(%p,%d)"), win, f)); + T((T_CALLED("notimeout(%p,%d)"), win, f)); if (win) { win->_notimeout = f; @@ -133,19 +134,24 @@ keypad(WINDOW *win, bool flag) NCURSES_EXPORT(int) meta(WINDOW *win GCC_UNUSED, bool flag) { + int result = ERR; + /* Ok, we stay relaxed and don't signal an error if win is NULL */ T((T_CALLED("meta(%p,%d)"), win, flag)); - SP->_use_meta = flag; - - if (flag && meta_on) { - TPUTS_TRACE("meta_on"); - putp(meta_on); - } else if (!flag && meta_off) { - TPUTS_TRACE("meta_off"); - putp(meta_off); + if (SP != 0) { + SP->_use_meta = flag; + + if (flag && meta_on) { + TPUTS_TRACE("meta_on"); + putp(meta_on); + } else if (!flag && meta_off) { + TPUTS_TRACE("meta_off"); + putp(meta_off); + } + result = OK; } - returnCode(OK); + returnCode(result); } /* curs_set() moved here to narrow the kernel interface */ @@ -153,51 +159,56 @@ meta(WINDOW *win GCC_UNUSED, bool flag) NCURSES_EXPORT(int) curs_set(int vis) { - int cursor = SP->_cursor; + int result = ERR; T((T_CALLED("curs_set(%d)"), vis)); - - if (vis < 0 || vis > 2) - returnCode(ERR); - - if (vis == cursor) - returnCode(cursor); - - switch (vis) { - case 2: - if (cursor_visible) { - TPUTS_TRACE("cursor_visible"); - putp(cursor_visible); - } else - returnCode(ERR); - break; - case 1: - if (cursor_normal) { - TPUTS_TRACE("cursor_normal"); - putp(cursor_normal); - } else - returnCode(ERR); - break; - case 0: - if (cursor_invisible) { - TPUTS_TRACE("cursor_invisible"); - putp(cursor_invisible); - } else - returnCode(ERR); - break; + if (SP != 0 && vis >= 0 && vis <= 2) { + int cursor = SP->_cursor; + + if (vis == cursor) { + result = cursor; + } else { + result = (cursor == -1 ? 1 : cursor); + switch (vis) { + case 2: + if (cursor_visible) { + TPUTS_TRACE("cursor_visible"); + putp(cursor_visible); + } else + result = ERR; + break; + case 1: + if (cursor_normal) { + TPUTS_TRACE("cursor_normal"); + putp(cursor_normal); + } else + result = ERR; + break; + case 0: + if (cursor_invisible) { + TPUTS_TRACE("cursor_invisible"); + putp(cursor_invisible); + } else + result = ERR; + break; + } + SP->_cursor = vis; + _nc_flush(); + } } - SP->_cursor = vis; - _nc_flush(); - - returnCode(cursor == -1 ? 1 : cursor); + returnCode(result); } NCURSES_EXPORT(int) typeahead(int fd) { T((T_CALLED("typeahead(%d)"), fd)); - SP->_checkfd = fd; - returnCode(OK); + if (SP != 0) { + SP->_checkfd = fd; + returnCode(OK); + } else { + returnCode(ERR); + } } /* @@ -209,7 +220,7 @@ typeahead(int fd) #if NCURSES_EXT_FUNCS static int -has_key_internal(int keycode, struct tries *tp) +has_key_internal(int keycode, TRIES *tp) { if (tp == 0) return (FALSE); @@ -224,7 +235,7 @@ NCURSES_EXPORT(int) has_key(int keycode) { T((T_CALLED("has_key(%d)"), keycode)); - returnCode(has_key_internal(keycode, SP->_keytry)); + returnCode(SP != 0 ? has_key_internal(keycode, SP->_keytry) : FALSE); } #endif /* NCURSES_EXT_FUNCS */ @@ -248,10 +259,12 @@ _nc_keypad(bool flag) _nc_flush(); } - if (flag && !SP->_tried) { - _nc_init_keytry(); - SP->_tried = TRUE; + if (SP != 0) { + if (flag && !SP->_tried) { + _nc_init_keytry(); + SP->_tried = TRUE; + } + SP->_keypad_on = flag; } - SP->_keypad_on = flag; return (OK); }