1/* $Xorg: kbd_mode.c,v 1.3 2000/08/17 19:48:29 cpqbld Exp $ */ 2/************************************************************ 3Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA. 4 5 All Rights Reserved 6 7Permission to use, copy, modify, and distribute this 8software and its documentation for any purpose and without 9fee is hereby granted, provided that the above copyright no- 10tice appear in all copies and that both that copyright no- 11tice and this permission notice appear in supporting docu- 12mentation, and that the names of Sun or The Open Group 13not be used in advertising or publicity pertaining to 14distribution of the software without specific prior 15written permission. Sun and The Open Group make no 16representations about the suitability of this software for 17any purpose. It is provided "as is" without any express or 18implied warranty. 19 20SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 21INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT- 22NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI- 23ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 24ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 25PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 26OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 27THE USE OR PERFORMANCE OF THIS SOFTWARE. 28 29********************************************************/ 30/* $XFree86: xc/programs/Xserver/hw/sun/kbd_mode.c,v 3.12 2003/10/07 21:39:43 herrb Exp $ */ 31 32/* 33static char sccsid[] = "@(#)kbd_mode.c 7.1 87/04/13"; 34 */ 35 36/* 37 * Copyright 1986 by Sun Microsystems, Inc. 38 * 39 * kbd_mode: set keyboard encoding mode 40 */ 41 42#include <sys/types.h> 43#include <sys/file.h> 44#include <sys/ioctl.h> 45#if defined(SVR4) || defined(__bsdi__) 46#include <fcntl.h> 47#ifndef __bsdi__ 48#include <sys/kbio.h> 49#include <sys/kbd.h> 50#else 51#include <unistd.h> 52#include </sys/sparc/dev/kbio.h> 53#include </sys/sparc/dev/kbd.h> 54#endif 55#else 56#ifndef CSRG_BASED 57#include <sundev/kbio.h> 58#include <sundev/kbd.h> 59#else 60#include <machine/kbio.h> 61#include <machine/kbd.h> 62#endif 63#endif 64#include <stdio.h> 65#include <stdlib.h> 66#include <unistd.h> 67 68static void die(char*); 69static void usage(void); 70static int kbd_fd; 71 72int 73main(argc, argv) 74 int argc; 75 char** argv; 76{ 77 int code = 0, translate, direct = -1; 78 char led; 79 int click; 80 81 if ((kbd_fd = open("/dev/kbd", O_RDONLY, 0)) < 0) { 82 die("Couldn't open /dev/kbd"); 83 } 84 argc--; argv++; 85 if (argc-- && **argv == '-') { 86 code = *(++*argv); 87 } else { 88 usage(); 89 } 90 switch (code) { 91 case 'a': 92 case 'A': 93 translate = TR_ASCII; 94 direct = 0; 95 break; 96 case 'e': 97 case 'E': 98 translate = TR_EVENT; 99 break; 100 case 'n': 101 case 'N': 102 translate = TR_NONE; 103 break; 104 case 'u': 105 case 'U': 106 translate = TR_UNTRANS_EVENT; 107 break; 108 default: 109 usage(); 110 } 111#ifdef KIOCSLED 112 led = 0; 113 if (ioctl(kbd_fd, KIOCSLED, &led)) 114 die("Couldn't set LEDs"); 115#endif 116#ifdef KIOCCMD 117 click = KBD_CMD_NOCLICK; 118 if (ioctl(kbd_fd, KIOCCMD, &click)) 119 die("Couldn't set click"); 120#endif 121 if (ioctl(kbd_fd, KIOCTRANS, (caddr_t) &translate)) 122 die("Couldn't set translation"); 123 if (direct != -1 && ioctl(kbd_fd, KIOCSDIRECT, (caddr_t) &direct)) 124 die("Couldn't set redirect"); 125 return 0; 126} 127 128static void 129die(char *msg) 130{ 131 fprintf(stderr, "%s\n", msg); 132 exit(1); 133} 134 135static void 136usage(void) 137{ 138 int translate; 139 140 if (ioctl(kbd_fd, KIOCGTRANS, (caddr_t) &translate)) { 141 die("Couldn't inquire current translation"); 142 } 143 fprintf(stderr, "kbd_mode {-a | -e | -n | -u }\n"); 144 fprintf(stderr, "\tfor ascii, encoded (normal) SunView events,\n"); 145 fprintf(stderr, " \tnon-encoded, or unencoded SunView events, resp.\n"); 146 fprintf(stderr, "Current mode is %s.\n", 147 ( translate == 0 ? "n (non-translated bytes)" : 148 ( translate == 1 ? "a (ascii bytes)" : 149 ( translate == 2 ? "e (encoded events)" : 150 /* translate == 3 */ "u (unencoded events)")))); 151 exit(1); 152} 153 154 155