msconfig.c revision 1.4 1 /* $NetBSD: msconfig.c,v 1.4 2003/10/28 11:46:39 he Exp $ */
2
3 /*
4 * Copyright (c) 1996 Thomas Gerner.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Thomas Gerner.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <errno.h>
34 #include <stdio.h>
35 #include <unistd.h>
36 #include <stdlib.h>
37 #include <string.h>
38 #include <fcntl.h>
39 #include <sys/ioctl.h>
40 #include <machine/msioctl.h>
41
42 void usage(char *name)
43 {
44 fprintf(stderr,"usage: %s [ -f dev ] [ on | off ]\n", name);
45 exit(1);
46 }
47
48 int
49 main(int argc, char **argv)
50 {
51 char *mousedev = "/dev/mouse";
52 int set_emul = 0;
53 int emul3b = 0;
54 int i = 1;
55 int fd;
56
57 if ((i < argc) && !strcmp(argv[i], "-f")) {
58 i++;
59 if(i >= argc)
60 usage(argv[0]);
61 mousedev = argv[i];
62 i++;
63 }
64 if ((i < argc) && !strcmp(argv[i], "on")) {
65 i++;
66 set_emul = 1;
67 emul3b = 1;
68 } else if ((i < argc) && !strcmp(argv[i], "off")) {
69 i++;
70 set_emul = 1;
71 }
72 if (i < argc)
73 usage(argv[0]);
74
75 if ((fd = open(mousedev,O_RDONLY | O_NONBLOCK)) < 0) {
76 fprintf(stderr, "%s: open %s: %s\n", argv[0], mousedev,
77 strerror(errno));
78 exit(1);
79 }
80 if(set_emul) {
81 if(ioctl(fd, MIOCS3B_EMUL, (char *)&emul3b) < 0) {;
82 fprintf(stderr, "%s: %s\n", argv[0], strerror(errno));
83 close(fd);
84 exit(1);
85 }
86 }
87 if(ioctl(fd, MIOCG3B_EMUL, (char *)&emul3b) < 0) {;
88 fprintf(stderr, "%s: %s\n", argv[0], strerror(errno));
89 close(fd);
90 exit(1);
91 }
92 if(emul3b)
93 printf("State of 3 button emulation: ON\n");
94 else
95 printf("State of 3 button emulation: OFF\n");
96
97 close(fd);
98 exit(0);
99 }
100