source: trunk/third/sysinfo/sunos-kbd.c @ 12269

Revision 12269, 6.1 KB checked in by ghudson, 26 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r12268, which included commits to RCS files with non-trunk default branches.
Line 
1#ifndef lint
2static char *RCSid = "$Revision: 1.1.1.1 $";
3#endif
4
5/*
6 * The code contained in this file is based on xkeycaps by
7 * Jamie Zawinski <jwz@lucid.com>.  It is been modified slightly
8 * for use with sysinfo.
9 */
10
11/* xkeycaps, Copyright (c) 1991, 1992, 1993 Jamie Zawinski <jwz@lucid.com>
12 *
13 * Permission to use, copy, modify, distribute, and sell this software and its
14 * documentation for any purpose is hereby granted without fee, provided that
15 * the above copyright notice appear in all copies and that both that
16 * copyright notice and this permission notice appear in supporting
17 * documentation.  No representations are made about the suitability of this
18 * software for any purpose.  It is provided "as is" without express or
19 * implied warranty.
20 */
21
22/* SunOS-specific stuff: if we're on console, we can query the keyboard
23   hardware directly to find out what kind it is.  I would have just put
24   this code in guess.c, but vuid_event.h defines a `struct keyboard'
25   that conflicts with our own...
26 */
27
28#include "defs.h"
29
30#if __STDC__
31#include <stdlib.h>
32#include <unistd.h>
33extern char *strdup (const char *);
34#endif
35
36#include <stdio.h>
37#include <sys/types.h>
38#include <string.h>
39#include <sys/time.h>
40#include <sys/stream.h>
41#include <sys/stropts.h>
42#include <sys/fcntl.h>
43#include <sys/ioctl.h>
44#if     defined(SVR4) || (defined(sunos) && OSMVER == 5)
45#include <sys/vuid_event.h>
46#include <sys/kbio.h>
47#include <sys/kbd.h>
48#else
49#include <sundev/vuid_event.h>
50#include <sundev/kbio.h>
51#include <sundev/kbd.h>
52#endif
53
54#define KBD_DEVICE              "/dev/kbd"
55
56char *
57xkeycaps_guess_local_keyboard_type ()
58{
59  int type = -1, layout = 0;
60  int kbdfd;
61
62  if ((kbdfd = open (KBD_DEVICE, O_WRONLY)) <= 0) {
63      SImsg(SIM_GERR, "Cannot open %s: %s.", KBD_DEVICE, SYSERR);
64      return 0;
65  }
66  if (ioctl (kbdfd, KIOCTYPE, &type) == -1)
67    {
68      SImsg(SIM_GERR, "ioctl KIOCTYPE of %s failed: %s.", KBD_DEVICE, SYSERR);
69      close (kbdfd);
70      return 0;
71    }
72  if (ioctl (kbdfd, KIOCLAYOUT, &layout) == -1)
73      SImsg(SIM_GERR, "ioctl KIOCLAYOUT of %s failed: %s.",KBD_DEVICE,SYSERR);
74  close (kbdfd);
75
76  switch (type) {
77  case -1:        return 0;
78  case KB_ASCII:  return "Generic ASCII Terminal";      /* Ascii terminal */
79  case KB_KLUNK:  return "MS103SD32-2"; /* Micro Switch 103SD32-2 */
80  case KB_VT100:  return "Sun VT100";   /* Keytronics VT100 compatible */
81  case KB_VT220:  return "Sun VT220";   /* vt220 Emulation */
82  case KB_VT220I: return "Sun VT220i";  /* International vt220 Emulation */
83  case KB_SUN2:   return "Sun Type-2";
84  case KB_SUN3:   return "Sun Type-3";
85  case KB_SUN4:
86    switch (layout) {
87    case  0: return "Sun Type-4 US Unix"; /* Part 320-1005-02 REV A. */
88    case  1: return "Sun Type-4 US Unix"; /* Part 320-1005-01 REV B.  Seems identical... */
89    case  2: return "Sun Type-4 Belgium/France";
90    case  3: return "Sun Type-4 French Canadian";
91    case  4: return "Sun Type-4 Danish";
92    case  5: return "Sun Type-4 German";
93    case  6: return "Sun Type-4 Italian";
94    case  7: return "Sun Type-4 Dutch";
95    case  8: return "Sun Type-4 Norwegian";
96    case  9: return "Sun Type-4 Portuguese";
97    case 10: return "Sun Type-4 Spanish";
98    case 11: return "Sun Type-4 Swedish/Finnish";
99    case 12: return "Sun Type-4 Swiss/French";
100    case 13: return "Sun Type-4 Swiss/German";
101    case 14: return "Sun Type-4 UK";
102    case 33: return "Sun Type-5 US PC";
103    case 34: return "Sun Type-5 US Unix";
104    case 35: return "Sun Type-5 French";
105    case 36: return "Sun Type-5 Danish";
106    case 37: return "Sun Type-5 German";
107    case 38: return "Sun Type-5 Italian";
108    case 39: return "Sun Type-5 Dutch";
109    case 40: return "Sun Type-5 Norwegian";
110    case 41: return "Sun Type-5 Portuguese";
111    case 42: return "Sun Type-5 Spanish";
112    case 43: return "Sun Type-5 Swedish/Finnish";
113    case 44: return "Sun Type-5 Swiss/French";
114    case 45: return "Sun Type-5 Swiss/German";
115    case 46: return "Sun Type-5 UK";
116    case 47: return "Sun Type-5 Korean";
117    case 48: return "Sun Type-5 Taiwanese";
118    case 49: return "Sun Type-5 Nihon-go";
119    case 50: return "Sun Type-5 French Canadian";
120    case 80: return "Sun Compact 1 US PC";
121    case 81: return "Sun Compact 1 US Unix";
122    case 82: return "Sun Compact 1 French";
123    case 83: return "Sun Compact 1 Danish";
124    case 84: return "Sun Compact 1 German";
125    case 85: return "Sun Compact 1 Italian";
126    case 86: return "Sun Compact 1 Dutch";
127    case 87: return "Sun Compact 1 Norwegian";
128    case 88: return "Sun Compact 1 Portuguese";
129    case 89: return "Sun Compact 1 Spanish";
130    case 90: return "Sun Compact 1 Swedish/Finnish";
131    case 91: return "Sun Compact 1 Swiss/French";
132    case 92: return "Sun Compact 1 Swiss/German";
133    case 93: return "Sun Compact 1 UK";
134    case 94: return "Sun Compact 1 Korean";
135    case 95: return "Sun Compact 1 Taiwanese";
136    case 96: return "Sun Compact 1 Nihon-go";
137    case 97: return "Sun Compact 1 French Canadian";
138    default:
139      {
140        char buf [255];
141        (void) snprintf(buf, sizeof(buf), "Sun Type-4 Layout %d", layout);
142        return strdup (buf);
143      }
144    }
145  default:
146    {
147      char buf [255];
148      if (layout)
149        (void) snprintf(buf, sizeof(buf), "Sun Type-%d Layout %d",
150                       type, layout);
151      else
152        (void) snprintf(buf, sizeof(buf), "Sun Type-%d", type);
153      return strdup (buf);
154    }
155  }
156}
157
158/*
159 * Keyboard Probe routine.
160 */
161extern DevInfo_t *ProbeKbd(TreePtr)
162    DevInfo_t                 **TreePtr;
163{
164    DevInfo_t                  *DevInfo;
165    DevInfo_t                  *KbdDev;
166    static char                *KbdType = NULL;
167
168    /*
169     * If we've already been called, return now.
170     */
171    if (KbdType)
172        return((DevInfo_t *) NULL);
173
174    KbdType = xkeycaps_guess_local_keyboard_type();
175    if (!KbdType)
176        return((DevInfo_t *) NULL);
177
178    if (!(KbdDev = NewDevInfo(NULL))) {
179        SImsg(SIM_GERR, "Cannot create new kbd device.");
180        return((DevInfo_t *) NULL);
181    }
182
183    KbdDev->Name = "kbd";
184    KbdDev->Type = DT_KEYBOARD;
185    KbdDev->Model = KbdType;
186
187    if (TreePtr && *TreePtr) {
188        DevInfo = *TreePtr;
189        /*
190         * Set device master to be the top node if the top node
191         * has no peers.
192         */
193        if (!DevInfo->Name &&
194            DevInfo->Slaves && !DevInfo->Slaves->Next)
195            KbdDev->Master = DevInfo->Slaves;
196    }
197
198    return(KbdDev);
199}
Note: See TracBrowser for help on using the repository browser.