Source-Changes-HG archive

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

[src/trunk]: src Teach hid_parse_usage_in_page() how to understand hex litera...



details:   https://anonhg.NetBSD.org/src/rev/df7330f6f5de
branches:  trunk
changeset: 342627:df7330f6f5de
user:      jakllsch <jakllsch%NetBSD.org@localhost>
date:      Sat Jan 02 01:24:44 2016 +0000

description:
Teach hid_parse_usage_in_page() how to understand hex literals, in
addition to the usual table lookup.

diffstat:

 lib/libusbhid/usage.c          |   8 +++++---
 tests/lib/libusbhid/t_usbhid.c |  10 ++++++++--
 2 files changed, 13 insertions(+), 5 deletions(-)

diffs (74 lines):

diff -r 8a1706e06281 -r df7330f6f5de lib/libusbhid/usage.c
--- a/lib/libusbhid/usage.c     Sat Jan 02 01:04:15 2016 +0000
+++ b/lib/libusbhid/usage.c     Sat Jan 02 01:24:44 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: usage.c,v 1.8 2016/01/02 01:04:15 jakllsch Exp $       */
+/*     $NetBSD: usage.c,v 1.9 2016/01/02 01:24:44 jakllsch Exp $       */
 
 /*
  * Copyright (c) 1999 Lennart Augustsson <augustss%NetBSD.org@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: usage.c,v 1.8 2016/01/02 01:04:15 jakllsch Exp $");
+__RCSID("$NetBSD: usage.c,v 1.9 2016/01/02 01:24:44 jakllsch Exp $");
 
 #include <assert.h>
 #include <ctype.h>
@@ -214,7 +214,6 @@
        return -1;
 }
 
-/* XXX handle hex */
 int
 hid_parse_usage_in_page(const char *name)
 {
@@ -231,6 +230,9 @@
        for (k = 0; k < npages; k++)
                if (strncmp(pages[k].name, name, l) == 0)
                        goto found;
+       if (sscanf(name, "%x:%x", &k, &j) == 2) {
+               return (k << 16) | j;
+       }
        return -1;
  found:
        sep++;
diff -r 8a1706e06281 -r df7330f6f5de tests/lib/libusbhid/t_usbhid.c
--- a/tests/lib/libusbhid/t_usbhid.c    Sat Jan 02 01:04:15 2016 +0000
+++ b/tests/lib/libusbhid/t_usbhid.c    Sat Jan 02 01:24:44 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_usbhid.c,v 1.5 2016/01/02 01:04:15 jakllsch Exp $    */
+/*     $NetBSD: t_usbhid.c,v 1.6 2016/01/02 01:24:44 jakllsch Exp $    */
 
 /*
  * Copyright (c) 2016 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_usbhid.c,v 1.5 2016/01/02 01:04:15 jakllsch Exp $");
+__RCSID("$NetBSD: t_usbhid.c,v 1.6 2016/01/02 01:24:44 jakllsch Exp $");
 
 #include <atf-c.h>
 
@@ -158,6 +158,9 @@
        atf_tc_set_md_var(tc, "descr", "Test libusbhid usage.c");
 }
 
+#define MYx_ATF_CHECK_EQ(d, v) \
+       ATF_CHECK_EQ_MSG(d, v, "== %x", (d))
+
 ATF_TC_BODY(check_hid_usage, tc)
 {
        char usages_path[PATH_MAX];
@@ -194,6 +197,9 @@
        ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page(
            "Quick_zephyrs_blow_vexing_daft_Jim_:Usage_ID_65535_%"),
            0xff2affff);
+
+       MYx_ATF_CHECK_EQ((uint32_t)hid_parse_usage_in_page("0xff2a:0xff1b"),
+           0xff2aff1b);
 }
 
 #define MYd_ATF_CHECK_EQ(d, v) \



Home | Main Index | Thread Index | Old Index