1 /* $OpenBSD: parsetest.c,v 1.1 2018/07/09 09:03:29 mpi Exp $ */ 2 /* 3 * Copyright (c) 2018 David Bern <david.ml.bern@gmail.com> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <dev/usb/usb.h> 19 #include <dev/usb/usbhid.h> 20 21 #include <err.h> 22 #include <stdio.h> 23 #include <stdlib.h> 24 #include <usbhid.h> 25 26 int 27 main(int argc, char *argv[]) 28 { 29 char *table = NULL; 30 char usage[1024]; 31 int testval; 32 const char *errstr; 33 34 if (hid_start(table) == -1) 35 errx(1, "\nUnable to load table"); 36 37 /* No args given, just test if able to load table */ 38 if (argc < 2) 39 return 0; 40 41 testval = strtonum(argv[1], 0x0, 0xFFFFFFFF, &errstr); 42 if (errstr != NULL) 43 errx(1, "\nInvalid argument"); 44 45 snprintf(usage, sizeof(usage), "%s:%s", 46 hid_usage_page(HID_PAGE(testval)), 47 hid_usage_in_page(testval)); 48 49 return (hid_parse_usage_in_page(usage) != testval); 50 } 51