]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_options.c
ncurses 5.4
[ncurses.git] / ncurses / tinfo / lib_options.c
index b58602af72bbec024892408cc4fa5874406222d7..0edf9d5a9a0191094e9a5c235c54896887fe61ad 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2002,2003 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            *
  *                                                                          *
  * 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 <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
 /****************************************************************************
  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-2003               *
  ****************************************************************************/
 
 /*
  ****************************************************************************/
 
 /*
@@ -42,9 +43,9 @@
 
 #include <term.h>
 
 
 #include <term.h>
 
-MODULE_ID("$Id: lib_options.c,v 1.39 2000/03/12 00:19:11 tom Exp $")
+MODULE_ID("$Id: lib_options.c,v 1.47 2003/10/25 19:51:38 tom Exp $")
 
 
-int
+NCURSES_EXPORT(int)
 idlok(WINDOW *win, bool flag)
 {
     T((T_CALLED("idlok(%p,%d)"), win, flag));
 idlok(WINDOW *win, bool flag)
 {
     T((T_CALLED("idlok(%p,%d)"), win, flag));
@@ -56,7 +57,7 @@ idlok(WINDOW *win, bool flag)
        returnCode(ERR);
 }
 
        returnCode(ERR);
 }
 
-void
+NCURSES_EXPORT(void)
 idcok(WINDOW *win, bool flag)
 {
     T((T_CALLED("idcok(%p,%d)"), win, flag));
 idcok(WINDOW *win, bool flag)
 {
     T((T_CALLED("idcok(%p,%d)"), win, flag));
@@ -67,12 +68,12 @@ idcok(WINDOW *win, bool flag)
     returnVoid;
 }
 
     returnVoid;
 }
 
-int
+NCURSES_EXPORT(int)
 halfdelay(int t)
 {
     T((T_CALLED("halfdelay(%d)"), t));
 
 halfdelay(int t)
 {
     T((T_CALLED("halfdelay(%d)"), t));
 
-    if (t < 1 || t > 255)
+    if (t < 1 || t > 255 || SP == 0)
        returnCode(ERR);
 
     cbreak();
        returnCode(ERR);
 
     cbreak();
@@ -80,7 +81,7 @@ halfdelay(int t)
     returnCode(OK);
 }
 
     returnCode(OK);
 }
 
-int
+NCURSES_EXPORT(int)
 nodelay(WINDOW *win, bool flag)
 {
     T((T_CALLED("nodelay(%p,%d)"), win, flag));
 nodelay(WINDOW *win, bool flag)
 {
     T((T_CALLED("nodelay(%p,%d)"), win, flag));
@@ -95,7 +96,7 @@ nodelay(WINDOW *win, bool flag)
        returnCode(ERR);
 }
 
        returnCode(ERR);
 }
 
-int
+NCURSES_EXPORT(int)
 notimeout(WINDOW *win, bool f)
 {
     T((T_CALLED("notimout(%p,%d)"), win, f));
 notimeout(WINDOW *win, bool f)
 {
     T((T_CALLED("notimout(%p,%d)"), win, f));
@@ -107,7 +108,7 @@ notimeout(WINDOW *win, bool f)
        returnCode(ERR);
 }
 
        returnCode(ERR);
 }
 
-void
+NCURSES_EXPORT(void)
 wtimeout(WINDOW *win, int delay)
 {
     T((T_CALLED("wtimeout(%p,%d)"), win, delay));
 wtimeout(WINDOW *win, int delay)
 {
     T((T_CALLED("wtimeout(%p,%d)"), win, delay));
@@ -115,9 +116,10 @@ wtimeout(WINDOW *win, int delay)
     if (win) {
        win->_delay = delay;
     }
     if (win) {
        win->_delay = delay;
     }
+    returnVoid;
 }
 
 }
 
-int
+NCURSES_EXPORT(int)
 keypad(WINDOW *win, bool flag)
 {
     T((T_CALLED("keypad(%p,%d)"), win, flag));
 keypad(WINDOW *win, bool flag)
 {
     T((T_CALLED("keypad(%p,%d)"), win, flag));
@@ -129,27 +131,32 @@ keypad(WINDOW *win, bool flag)
        returnCode(ERR);
 }
 
        returnCode(ERR);
 }
 
-int
+NCURSES_EXPORT(int)
 meta(WINDOW *win GCC_UNUSED, bool flag)
 {
 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));
 
     /* 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 */
 
 }
 
 /* curs_set() moved here to narrow the kernel interface */
 
-int
+NCURSES_EXPORT(int)
 curs_set(int vis)
 {
     int cursor = SP->_cursor;
 curs_set(int vis)
 {
     int cursor = SP->_cursor;
@@ -191,12 +198,16 @@ curs_set(int vis)
     returnCode(cursor == -1 ? 1 : cursor);
 }
 
     returnCode(cursor == -1 ? 1 : cursor);
 }
 
-int
+NCURSES_EXPORT(int)
 typeahead(int fd)
 {
     T((T_CALLED("typeahead(%d)"), fd));
 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);
+    }
 }
 
 /*
 }
 
 /*
@@ -206,7 +217,7 @@ typeahead(int fd)
 **
 */
 
 **
 */
 
-#ifdef NCURSES_EXT_FUNCS
+#if NCURSES_EXT_FUNCS
 static int
 has_key_internal(int keycode, struct tries *tp)
 {
 static int
 has_key_internal(int keycode, struct tries *tp)
 {
@@ -216,14 +227,14 @@ has_key_internal(int keycode, struct tries *tp)
        return (TRUE);
     else
        return (has_key_internal(keycode, tp->child)
        return (TRUE);
     else
        return (has_key_internal(keycode, tp->child)
-           || has_key_internal(keycode, tp->sibling));
+               || has_key_internal(keycode, tp->sibling));
 }
 
 }
 
-int
+NCURSES_EXPORT(int)
 has_key(int keycode)
 {
     T((T_CALLED("has_key(%d)"), keycode));
 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 */
 
 }
 #endif /* NCURSES_EXT_FUNCS */
 
@@ -234,7 +245,7 @@ has_key(int keycode)
  * flush, then the next wgetch may get the escape sequence that corresponds to
  * the terminal state _before_ switching modes.
  */
  * flush, then the next wgetch may get the escape sequence that corresponds to
  * the terminal state _before_ switching modes.
  */
-int
+NCURSES_EXPORT(int)
 _nc_keypad(bool flag)
 {
     if (flag && keypad_xmit) {
 _nc_keypad(bool flag)
 {
     if (flag && keypad_xmit) {
@@ -247,9 +258,10 @@ _nc_keypad(bool flag)
        _nc_flush();
     }
 
        _nc_flush();
     }
 
-    if (flag && !SP->_tried) {
+    if (flag && SP != 0 && !SP->_tried) {
        _nc_init_keytry();
        SP->_tried = TRUE;
     }
        _nc_init_keytry();
        SP->_tried = TRUE;
     }
+    SP->_keypad_on = flag;
     return (OK);
 }
     return (OK);
 }