Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Implement ncurses extension has_key.



details:   https://anonhg.NetBSD.org/src/rev/d6df3abad42c
branches:  trunk
changeset: 820145:d6df3abad42c
user:      roy <roy%NetBSD.org@localhost>
date:      Sun Jan 01 03:06:06 2017 +0000

description:
Implement ncurses extension has_key.

diffstat:

 distrib/sets/lists/comp/mi   |   5 ++++-
 lib/libcurses/Makefile       |   5 +++--
 lib/libcurses/curses.h       |   3 ++-
 lib/libcurses/curses_input.3 |  14 ++++++++++++--
 lib/libcurses/getch.c        |  27 +++++++++++++++++++--------
 5 files changed, 40 insertions(+), 14 deletions(-)

diffs (193 lines):

diff -r 0152d3b6234c -r d6df3abad42c distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Sat Dec 31 22:54:56 2016 +0000
+++ b/distrib/sets/lists/comp/mi        Sun Jan 01 03:06:06 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.2087 2016/12/31 22:47:01 roy Exp $
+#      $NetBSD: mi,v 1.2088 2017/01/01 03:06:06 roy Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp                           comp-sys-root
@@ -6740,6 +6740,7 @@
 ./usr/share/man/cat3/has_colors.0              comp-c-catman           .cat
 ./usr/share/man/cat3/has_ic.0                  comp-c-catman           .cat
 ./usr/share/man/cat3/has_il.0                  comp-c-catman           .cat
+./usr/share/man/cat3/has_key.0                 comp-c-catman           .cat
 ./usr/share/man/cat3/hash.0                    comp-c-catman           .cat
 ./usr/share/man/cat3/hcreate.0                 comp-c-catman           .cat
 ./usr/share/man/cat3/hcreate_r.0               comp-c-catman           .cat
@@ -14085,6 +14086,7 @@
 ./usr/share/man/html3/has_colors.html          comp-c-htmlman          html
 ./usr/share/man/html3/has_ic.html              comp-c-htmlman          html
 ./usr/share/man/html3/has_il.html              comp-c-htmlman          html
+./usr/share/man/html3/has_key.html             comp-c-htmlman          html
 ./usr/share/man/html3/hash.html                        comp-c-htmlman          html
 ./usr/share/man/html3/hcreate.html             comp-c-htmlman          html
 ./usr/share/man/html3/hcreate_r.html           comp-c-htmlman          html
@@ -21347,6 +21349,7 @@
 ./usr/share/man/man3/has_colors.3              comp-c-man              .man
 ./usr/share/man/man3/has_ic.3                  comp-c-man              .man
 ./usr/share/man/man3/has_il.3                  comp-c-man              .man
+./usr/share/man/man3/has_key.3                 comp-c-man              .man
 ./usr/share/man/man3/hash.3                    comp-c-man              .man
 ./usr/share/man/man3/hcreate.3                 comp-c-man              .man
 ./usr/share/man/man3/hcreate_r.3               comp-c-man              .man
diff -r 0152d3b6234c -r d6df3abad42c lib/libcurses/Makefile
--- a/lib/libcurses/Makefile    Sat Dec 31 22:54:56 2016 +0000
+++ b/lib/libcurses/Makefile    Sun Jan 01 03:06:06 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.75 2016/12/31 22:47:01 roy Exp $
+#      $NetBSD: Makefile,v 1.76 2017/01/01 03:06:06 roy Exp $
 #      @(#)Makefile    8.2 (Berkeley) 1/2/94
 
 .include <bsd.own.mk>
@@ -91,7 +91,8 @@
         curses_tty.3 gettmode.3 \
         curses_cursor.3 getyx.3 curses_cursor.3 getsyx.3 \
         curses_color.3 has_colors.3 curses_tty.3 has_ic.3 \
-        curses_tty.3 halfdelay.3 curses_tty.3 has_il.3 \
+        curses_tty.3 halfdelay.3 curses_input.3 has_key.3 \
+        curses_tty.3 has_il.3 \
         curses_line.3 hline.3 curses_tty.3 idcok.3 \
         curses_tty.3 idlok.3 curses_inch.3 inch.3 \
         curses_inch.3 inchnstr.3 curses_inch.3 inchstr.3 \
diff -r 0152d3b6234c -r d6df3abad42c lib/libcurses/curses.h
--- a/lib/libcurses/curses.h    Sat Dec 31 22:54:56 2016 +0000
+++ b/lib/libcurses/curses.h    Sun Jan 01 03:06:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: curses.h,v 1.111 2016/12/31 22:47:01 roy Exp $ */
+/*     $NetBSD: curses.h,v 1.112 2017/01/01 03:06:06 roy Exp $ */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -677,6 +677,7 @@
 bool    has_colors(void);
 bool    has_ic(void);
 bool    has_il(void);
+int     has_key(int);
 int     hline(chtype, int);
 int     idcok(WINDOW *, bool);
 int     idlok(WINDOW *, bool);
diff -r 0152d3b6234c -r d6df3abad42c lib/libcurses/curses_input.3
--- a/lib/libcurses/curses_input.3      Sat Dec 31 22:54:56 2016 +0000
+++ b/lib/libcurses/curses_input.3      Sun Jan 01 03:06:06 2017 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: curses_input.3,v 1.22 2012/04/21 12:27:28 roy Exp $
+.\"    $NetBSD: curses_input.3,v 1.23 2017/01/01 03:06:06 roy Exp $
 .\"
 .\" Copyright (c) 2002
 .\"    Brett Lymn (blymn%NetBSD.org@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -30,7 +30,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"
-.Dd April 5, 2012
+.Dd January 1, 2017
 .Dt CURSES_INPUT 3
 .Os
 .Sh NAME
@@ -41,6 +41,7 @@
 .Nm mvwgetch ,
 .Nm define_key ,
 .Nm keyok ,
+.Nm has_key ,
 .Nm getnstr ,
 .Nm wgetnstr ,
 .Nm mvgetnstr ,
@@ -71,6 +72,8 @@
 .Ft int
 .Fn keyok "int key_symbol" "bool flag"
 .Ft int
+.Fn has_key "int key_symbol"
+.Ft int
 .Fn define_key "char *sequence" "int key_symbol"
 .Ft int
 .Fn getnstr "char *str" "int limit"
@@ -156,6 +159,13 @@
 was not recognised and will return the component characters one at a time to
 the caller.
 .Pp
+The
+.Fn has_key
+function takes a key value and returns
+.Dv TRUE
+if the current terminal recognises a key with that value, otherwise
+.Dv FALSE .
+.Pp
 Custom associations between sequences of characters and a key symbol can
 be made by using the
 .Fn define_key
diff -r 0152d3b6234c -r d6df3abad42c lib/libcurses/getch.c
--- a/lib/libcurses/getch.c     Sat Dec 31 22:54:56 2016 +0000
+++ b/lib/libcurses/getch.c     Sun Jan 01 03:06:06 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getch.c,v 1.59 2012/04/21 12:27:28 roy Exp $   */
+/*     $NetBSD: getch.c,v 1.60 2017/01/01 03:06:06 roy Exp $   */
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = "@(#)getch.c    8.2 (Berkeley) 5/4/94";
 #else
-__RCSID("$NetBSD: getch.c,v 1.59 2012/04/21 12:27:28 roy Exp $");
+__RCSID("$NetBSD: getch.c,v 1.60 2017/01/01 03:06:06 roy Exp $");
 #endif
 #endif                                 /* not lint */
 
@@ -216,7 +216,8 @@
 static key_entry_t *add_new_key(keymap_t *current, char ch, int key_type,
         int symbol);
 static void delete_key_sequence(keymap_t *current, int key_type);
-static void do_keyok(keymap_t *current, int key_type, bool flag, int *retval);
+static void do_keyok(keymap_t *current, int key_type, bool set, bool flag,
+       int *retval);
 static keymap_t *new_keymap(void); /* create a new keymap */
 static key_entry_t *new_key(void); /* create a new key entry */
 static wchar_t         inkey(int to, int delay);
@@ -733,7 +734,7 @@
 {
        int result = ERR;
 
-       do_keyok(_cursesi_screen->base_keymap, key_type, flag, &result);
+       do_keyok(_cursesi_screen->base_keymap, key_type, true, flag, &result);
        return result;
 }
 
@@ -742,8 +743,8 @@
  *       Does the actual work for keyok, we need to recurse through the
  * keymaps finding the passed key symbol.
  */
-void
-do_keyok(keymap_t *current, int key_type, bool flag, int *retval)
+static void
+do_keyok(keymap_t *current, int key_type, bool set, bool flag, int *retval)
 {
        key_entry_t *key;
        int i;
@@ -759,10 +760,11 @@
                key = current->key[current->mapping[i]];
 
                if (key->type == KEYMAP_MULTI)
-                       do_keyok(key->value.next, key_type, flag, retval);
+                       do_keyok(key->value.next, key_type, set, flag, retval);
                else if ((key->type == KEYMAP_LEAF)
                         && (key->value.symbol == key_type)) {
-                       key->enable = flag;
+                       if (set)
+                               key->enable = flag;
                        *retval = OK; /* we found at least one instance, ok */
                }
        }
@@ -966,3 +968,12 @@
        _cursesi_screen->unget_pos++;
        return OK;
 }
+
+int
+has_key(int key_type)
+{
+       int result = ERR;
+
+       do_keyok(_cursesi_screen->base_keymap, key_type, false, false, &result);
+       return result;
+}



Home | Main Index | Thread Index | Old Index