summaryrefslogtreecommitdiffstats
path: root/lib/libcurses/lib_options.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1997-12-03 05:20:47 +0000
committermillert <millert@openbsd.org>1997-12-03 05:20:47 +0000
commit6f4099fecac342eeff29dd2bf0512f777a62a591 (patch)
tree30035276ed4d5b07245464d724dd101dc9b5efb4 /lib/libcurses/lib_options.c
parentmerge of ncurses-4.1-971129 (diff)
downloadwireguard-openbsd-6f4099fecac342eeff29dd2bf0512f777a62a591.tar.xz
wireguard-openbsd-6f4099fecac342eeff29dd2bf0512f777a62a591.zip
Merge of ncurses-4.1-971129
Diffstat (limited to 'lib/libcurses/lib_options.c')
-rw-r--r--lib/libcurses/lib_options.c196
1 files changed, 116 insertions, 80 deletions
diff --git a/lib/libcurses/lib_options.c b/lib/libcurses/lib_options.c
index be33dd2e446..7af726649ad 100644
--- a/lib/libcurses/lib_options.c
+++ b/lib/libcurses/lib_options.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: lib_options.c,v 1.3 1997/12/03 05:21:26 millert Exp $ */
+
/***************************************************************************
* COPYRIGHT NOTICE *
@@ -34,6 +36,8 @@
MODULE_ID("Id: lib_options.c,v 1.22 1997/05/01 23:46:18 Alexander.V.Lukyanov Exp $")
+static void add_to_try(char *, short);
+
int has_ic(void)
{
T((T_CALLED("has_ic()")));
@@ -53,8 +57,12 @@ int idlok(WINDOW *win, bool flag)
{
T((T_CALLED("idlok(%p,%d)"), win, flag));
- _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region);
- returnCode(OK);
+ if (win) {
+ _nc_idlok = win->_idlok = flag && (has_il() || change_scroll_region);
+ returnCode(OK);
+ }
+ else
+ returnCode(ERR);
}
@@ -62,7 +70,8 @@ void idcok(WINDOW *win, bool flag)
{
T((T_CALLED("idcok(%p,%d)"), win, flag));
- _nc_idcok = win->_idcok = flag && has_ic();
+ if (win)
+ _nc_idcok = win->_idcok = flag && has_ic();
returnVoid;
}
@@ -72,8 +81,12 @@ int clearok(WINDOW *win, bool flag)
{
T((T_CALLED("clearok(%p,%d)"), win, flag));
- win->_clear = flag;
- returnCode(OK);
+ if (win) {
+ win->_clear = flag;
+ returnCode(OK);
+ }
+ else
+ returnCode(ERR);
}
@@ -81,7 +94,8 @@ void immedok(WINDOW *win, bool flag)
{
T((T_CALLED("immedok(%p,%d)"), win, flag));
- win->_immed = flag;
+ if (win)
+ win->_immed = flag;
returnVoid;
}
@@ -90,12 +104,16 @@ int leaveok(WINDOW *win, bool flag)
{
T((T_CALLED("leaveok(%p,%d)"), win, flag));
- win->_leaveok = flag;
- if (flag == TRUE)
- curs_set(0);
+ if (win) {
+ win->_leaveok = flag;
+ if (flag == TRUE)
+ curs_set(0);
+ else
+ curs_set(1);
+ returnCode(OK);
+ }
else
- curs_set(1);
- returnCode(OK);
+ returnCode(ERR);
}
@@ -103,8 +121,12 @@ int scrollok(WINDOW *win, bool flag)
{
T((T_CALLED("scrollok(%p,%d)"), win, flag));
- win->_scroll = flag;
- returnCode(OK);
+ if (win) {
+ win->_scroll = flag;
+ returnCode(OK);
+ }
+ else
+ returnCode(ERR);
}
int halfdelay(int t)
@@ -123,69 +145,56 @@ int nodelay(WINDOW *win, bool flag)
{
T((T_CALLED("nodelay(%p,%d)"), win, flag));
- if (flag == TRUE)
- win->_delay = 0;
- else win->_delay = -1;
- returnCode(OK);
+ if (win) {
+ if (flag == TRUE)
+ win->_delay = 0;
+ else win->_delay = -1;
+ returnCode(OK);
+ }
+ else
+ returnCode(ERR);
}
int notimeout(WINDOW *win, bool f)
{
T((T_CALLED("notimout(%p,%d)"), win, f));
- win->_notimeout = f;
- returnCode(OK);
+ if (win) {
+ win->_notimeout = f;
+ returnCode(OK);
+ }
+ else
+ returnCode(ERR);
}
int wtimeout(WINDOW *win, int delay)
{
T((T_CALLED("wtimeout(%p,%d)"), win, delay));
- win->_delay = delay;
- returnCode(OK);
-}
-
-static void init_keytry(void);
-static void add_to_try(char *, short);
-
-/* Turn the keypad on/off
- *
- * Note: we flush the output because changing this mode causes some terminals
- * to emit different escape sequences for cursor and keypad keys. If we don't
- * flush, then the next wgetch may get the escape sequence that corresponds to
- * the terminal state _before_ switching modes.
- */
-int _nc_keypad(bool flag)
-{
- if (flag && keypad_xmit)
- {
- TPUTS_TRACE("keypad_xmit");
- putp(keypad_xmit);
- (void) fflush(SP->_ofp);
- }
- else if (! flag && keypad_local)
- {
- TPUTS_TRACE("keypad_local");
- putp(keypad_local);
- (void) fflush(SP->_ofp);
+ if (win) {
+ win->_delay = delay;
+ returnCode(OK);
}
-
- if (SP->_keytry == UNINITIALISED)
- init_keytry();
- return(OK);
+ else
+ returnCode(ERR);
}
int keypad(WINDOW *win, bool flag)
{
T((T_CALLED("keypad(%p,%d)"), win, flag));
- win->_use_keypad = flag;
- returnCode(_nc_keypad(flag));
+ if (win) {
+ win->_use_keypad = flag;
+ returnCode(_nc_keypad(flag));
+ }
+ else
+ returnCode(ERR);
}
int meta(WINDOW *win GCC_UNUSED, bool 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;
@@ -252,6 +261,38 @@ int cursor = SP->_cursor;
returnCode(cursor==-1 ? 1 : cursor);
}
+int typeahead(int fd)
+{
+ T((T_CALLED("typeahead(%d)"), fd));
+ SP->_checkfd = fd;
+ returnCode(OK);
+}
+
+/*
+** has_key()
+**
+** Return TRUE if the current terminal has the given key
+**
+*/
+
+
+static int has_key_internal(int keycode, struct tries *tp)
+{
+ if (tp == 0)
+ return(FALSE);
+ else if (tp->value == keycode)
+ return(TRUE);
+ else
+ return(has_key_internal(keycode, tp->child)
+ || has_key_internal(keycode, tp->sibling));
+}
+
+int has_key(int keycode)
+{
+ T((T_CALLED("has_key(%d)"), keycode));
+ returnCode(has_key_internal(keycode, SP->_keytry));
+}
+
/*
** init_keytry()
**
@@ -367,34 +408,29 @@ struct tries *ptr, *savedptr;
return;
}
-int typeahead(int fd)
-{
- T((T_CALLED("typeahead(%d)"), fd));
- SP->_checkfd = fd;
- returnCode(OK);
-}
-
-/*
-** has_key()
-**
-** Return TRUE if the current terminal has the given key
-**
-*/
-
-
-static int has_key_internal(int keycode, struct tries *tp)
+/* Turn the keypad on/off
+ *
+ * Note: we flush the output because changing this mode causes some terminals
+ * to emit different escape sequences for cursor and keypad keys. If we don't
+ * flush, then the next wgetch may get the escape sequence that corresponds to
+ * the terminal state _before_ switching modes.
+ */
+int _nc_keypad(bool flag)
{
- if (!tp)
- return(FALSE);
- else if (tp->value == keycode)
- return(TRUE);
- else
- return(has_key_internal(keycode, tp->child)
- || has_key_internal(keycode, tp->sibling));
-}
+ if (flag && keypad_xmit)
+ {
+ TPUTS_TRACE("keypad_xmit");
+ putp(keypad_xmit);
+ (void) fflush(SP->_ofp);
+ }
+ else if (! flag && keypad_local)
+ {
+ TPUTS_TRACE("keypad_local");
+ putp(keypad_local);
+ (void) fflush(SP->_ofp);
+ }
-int has_key(int keycode)
-{
- T((T_CALLED("has_key(%d)"), keycode));
- returnCode(has_key_internal(keycode, SP->_keytry));
+ if (SP->_keytry == UNINITIALISED)
+ init_keytry();
+ return(OK);
}