chiark / gitweb /
separate page and code
authorian <ian>
Mon, 16 Jun 2008 00:31:29 +0000 (00:31 +0000)
committerian <ian>
Mon, 16 Jun 2008 00:31:29 +0000 (00:31 +0000)
hostside/evdev-manip.c

index 1634dbb6a792152b99080ef59da3b8c087ecc11c..29e1263bf243b0a5c5ab60f719b0bc2aab4317b4 100644 (file)
  *    --label LABEL         use LABEL instead of path in redacted output
  *
  *  per-device options (apply to all subsequent):
- *     --elide|show-unchanged      --elide-unchanged is default
  *     --evdev                     subsequent devices are evdev
  *     --hiddev                    subsequent devices are hiddev
- *                                  hiddev <str> are application and field
- *                                  both in hex,  page<<16 | usage
  *
  *  per-evdev options (apply to all subsequent):
  *     --[no-]grab                 --nograb is default
  *                          this part is in /proc/bus/usb/devices
  *                           and can thus be specified by caller
  *                          for evdev devices
+ *
+ *     evdev <str>... are type and code, each split up into
+ *     prefix and tail, eg EV_KEY KEY_EQUAL becomes EV KEY KEY EQUAL.
+ *     If the type or code is not found in our number-to-string
+ *     tables, the respective two <strs> are 0x and the value in hex.
+ *
+ *  per-hiddev options (apply to all subsequent):
+ *     --elide|show-unchanged      --elide-unchanged is default
+ *
+ *     hiddev <str>... are application and field.  In each case, page
+ *     and usage, both in hex, both at least two digits with 0x in
+ *     from of page only.  This matches what is shown in the USB HID
+ *     usage tables specification which can be found at
+ *     http://www.usb.org/developers/hidpage/
  */
 
 #include "common.h"
@@ -401,10 +412,20 @@ static void hiddev_dump(Device *d, const struct hiddev_usage_ref *ur) {
   putchar('\n');
 }
 
+static void hiddev_redact_pageusage(unsigned long code,
+                                   char sb_buf[2][7],
+                                   const char *strs[2]) {
+  assert(code <= 0xffffffffUL);
+  sprintf(sb_buf[0], "%#04lx", code >> 16);
+  sprintf(sb_buf[1], "%02lx", code & 0xffff);
+  strs[0]= sb_buf[0];
+  strs[1]= sb_buf[1];
+}
+
 static void hiddev_redact(Device *d, const struct hiddev_usage_ref *ur) {
   HiddevField *f;
-  char sb_app[9], sb_usage[9];
-  const char *strs[2];
+  char sb_app[2][7], sb_usage[2][7];
+  const char *strs[4];
 
   if (ur->field_index == HID_FIELD_INDEX_NONE)
     return;
@@ -413,14 +434,10 @@ static void hiddev_redact(Device *d, const struct hiddev_usage_ref *ur) {
   if (hiddev_elide(d, ur, f))
     return;
 
-  assert(f->fi.application <= 0xffffffffUL);
-  assert(ur->usage_code <= 0xffffffffUL);
-  sprintf(sb_app, "%lx", (unsigned long)f->fi.application);
-  sprintf(sb_usage, "%lx", (unsigned long)ur->usage_code);
+  hiddev_redact_pageusage(f->fi.application, sb_app,   &strs[0]);
+  hiddev_redact_pageusage(ur->usage_code,    sb_usage, &strs[2]);
 
-  strs[0]= sb_app;
-  strs[1]= sb_usage;
-  mode->redacted(d, 2,strs, ur->value);
+  mode->redacted(d, 4,strs, ur->value);
 }
 
 static void hiddev_readable(Device *d) {