~ubuntu-branches/ubuntu/intrepid/xserver-xgl/intrepid

« back to all changes in this revision

Viewing changes to hw/xfree86/utils/kbd_mode/sun-kbd_mode.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthew Garrett
  • Date: 2006-02-13 14:21:43 UTC
  • Revision ID: james.westby@ubuntu.com-20060213142143-mad6z9xzem7hzxz9
Tags: upstream-7.0.0
ImportĀ upstreamĀ versionĀ 7.0.0

Show diffs side-by-side

added added

removed removed

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