Expand PMF_FN_* macros.
[netbsd-mini2440.git] / usr.sbin / hilinfo / hilinfo.c
blob08d7c0385854637c833682482902b927d8d001ef
1 /*
2 * Copyright (c) 1987-1993, The University of Utah and
3 * the Center for Software Science at the University of Utah (CSS).
4 * All rights reserved.
6 * Permission to use, copy, modify and distribute this software is hereby
7 * granted provided that (1) source code retains these copyright, permission,
8 * and disclaimer notices, and (2) redistributions including binaries
9 * reproduce the notices in supporting documentation, and (3) all advertising
10 * materials mentioning features or use of this software display the following
11 * acknowledgement: ``This product includes software developed by the Center
12 * for Software Science at the University of Utah.''
14 * THE UNIVERSITY OF UTAH AND CSS ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS
15 * IS" CONDITION. THE UNIVERSITY OF UTAH AND CSS DISCLAIM ANY LIABILITY OF
16 * ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * CSS requests users of this software to return to css-dist@cs.utah.edu any
19 * improvements that they make and grant CSS redistribution rights.
21 * from: Utah $Hdr: hilinfo.c 1.3 94/04/04$
22 * $NetBSD: hilinfo.c,v 1.5 2002/05/30 18:01:03 thorpej Exp $
25 #include <sys/cdefs.h>
26 #ifndef lint
27 __RCSID("$NetBSD: hilinfo.c,v 1.5 2002/05/30 18:01:03 thorpej Exp $");
28 #endif
30 #include <sys/types.h>
31 #include <sys/ioctl.h>
32 #include <dev/hilioctl.h>
33 #include <errno.h>
34 #include <fcntl.h>
35 #include <string.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <unistd.h>
40 int aflg = 0;
41 int tflg = 1;
42 char *dname;
43 struct _hilbuf11 hi;
44 struct _hilbuf16 sc;
46 struct hil_info {
47 u_char hil_lo;
48 u_char hil_hi;
49 const char *hil_name;
50 } info[] = {
51 {0xA0, 0xFF, "keyboard"},
52 {0x60, 0x6B, "mouse"},
53 {0x90, 0x97, "tablet"},
54 {0x34, 0x34, "id-module"},
55 {0x30, 0x30, "button-box"},
56 {0x00, 0x00, "unknown"},
59 int getinfo __P((void));
60 int main __P((int, char **));
61 const char *tname __P((void));
62 void printall __P((void));
63 void usage __P((void));
65 int
66 main(argc, argv)
67 int argc;
68 char **argv;
70 int c;
71 int multi;
73 while ((c = getopt(argc, argv, "at")) != -1)
74 switch (c) {
75 /* everything */
76 case 'a':
77 aflg++;
78 tflg = 0;
79 break;
80 /* type */
81 case 't':
82 tflg++;
83 aflg = 0;
84 break;
85 /* bogon */
86 case '?':
87 usage();
89 if (optind == argc)
90 usage();
91 multi = (argc - optind) - 1;
92 while (optind < argc) {
93 dname = argv[optind];
94 if (multi)
95 printf("%s: ", dname);
96 if (getinfo()) {
97 if (aflg)
98 printall();
99 else if (tflg)
100 printf("%s\n", tname());
102 optind++;
104 exit(0);
108 getinfo()
110 int f;
112 f = open(dname, 0);
113 if (f < 0 || ioctl(f, HILIOCID, &hi) < 0) {
114 if (tflg)
115 printf(errno == EBUSY ? "busy\n" : "none\n");
116 else {
117 printf("error\n");
118 perror(dname);
120 close(f);
121 return(0);
123 (void) ioctl(f, HILIOCSC, &sc);
124 close(f);
125 return(1);
128 void
129 printall()
131 int i;
133 printf("%s: %s, info: ", dname, tname());
134 for (i = 0; i < 11; i++)
135 printf("%2.2x", hi.string[i]);
136 if (strcmp(tname(), "id-module") == 0) {
137 printf(", sc: ");
138 for (i = 0; i < 16; i++)
139 printf("%2.2x", sc.string[i]);
141 printf("\n");
144 const char *
145 tname()
147 struct hil_info *hp;
149 for (hp = info; hp->hil_lo; hp++)
150 if (hi.string[0] >= hp->hil_lo && hi.string[0] <= hp->hil_hi)
151 break;
152 if (hi.string[0] == 0x61 && hi.string[1] == 0x13)
153 return("knobs");
154 return(hp->hil_name);
157 void
158 usage()
161 fprintf(stderr, "usage: %s [-at] device\n", getprogname());
162 exit(1);