Home | History | Annotate | Line # | Download | only in msconfig
msconfig.c revision 1.2
      1 /*	$NetBSD: msconfig.c,v 1.2 1998/01/05 07:02:52 perry 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 <stdio.h>
     34 #include <unistd.h>
     35 #include <string.h>
     36 #include <fcntl.h>
     37 #include <sys/errno.h>
     38 #include <sys/ioctl.h>
     39 #include <machine/msioctl.h>
     40 
     41 void usage(char *name)
     42 {
     43     fprintf(stderr,"usage: %s [ -f dev ] [ on | off ]\n", name);
     44     exit(1);
     45 }
     46 
     47 int
     48 main(int argc, char **argv)
     49 {
     50     char *mousedev = "/dev/mouse";
     51     int set_emul = 0;
     52     int emul3b = 0;
     53     int i = 1;
     54     int fd;
     55 
     56     if ((i < argc) && !strcmp(argv[i], "-f")) {
     57 	i++;
     58 	if(i >= argc)
     59 	    usage(argv[0]);
     60 	mousedev = argv[i];
     61 	i++;
     62     }
     63     if ((i < argc) && !strcmp(argv[i], "on")) {
     64 	i++;
     65 	set_emul = 1;
     66 	emul3b = 1;
     67     } else if ((i < argc) && !strcmp(argv[i], "off")) {
     68 	i++;
     69 	set_emul = 1;
     70     }
     71     if (i < argc)
     72 	usage(argv[0]);
     73 
     74     if ((fd = open(mousedev,O_RDONLY | O_NONBLOCK)) < 0) {
     75 	fprintf(stderr, "%s: open %s: %s\n", argv[0], mousedev,
     76 		strerror(errno));
     77 	exit(1);
     78     }
     79     if(set_emul) {
     80 	if(ioctl(fd, MIOCS3B_EMUL, (char *)&emul3b) < 0) {;
     81 	    fprintf(stderr, "%s: %s\n", argv[0], strerror(errno));
     82 	    close(fd);
     83 	    exit(1);
     84 	}
     85     }
     86     if(ioctl(fd, MIOCG3B_EMUL, (char *)&emul3b) < 0) {;
     87 	fprintf(stderr, "%s: %s\n", argv[0], strerror(errno));
     88 	close(fd);
     89 	exit(1);
     90     }
     91     if(emul3b)
     92 	printf("State of 3 button emulation: ON\n");
     93     else
     94 	printf("State of 3 button emulation: OFF\n");
     95 
     96     close(fd);
     97     exit(0);
     98 }
     99