~smartboyhw/wubi/bug-1080090-new

« back to all changes in this revision

Viewing changes to src/grubutil/common/.svn/text-base/keytab.c.svn-base

  • Committer: Howard Chan
  • Date: 2012-11-20 10:16:05 UTC
  • Revision ID: smartboyhw@gmail.com-20121120101605-qfmjfsdynpzg9an9
Added images

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  GRUB Utilities --  Utilities for GRUB Legacy, GRUB2 and GRUB for DOS
3
 
 *  Copyright (C) 2007 Bean (bean123ch@gmail.com)
4
 
 *
5
 
 *  This program is free software: you can redistribute it and/or modify
6
 
 *  it under the terms of the GNU General Public License as published by
7
 
 *  the Free Software Foundation, either version 3 of the License, or
8
 
 *  (at your option) any later version.
9
 
 *
10
 
 *  This program is distributed in the hope that it will be useful,
11
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 *  GNU General Public License for more details.
14
 
 *
15
 
 *  You should have received a copy of the GNU General Public License
16
 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 
 */
18
 
 
19
 
#include <stdio.h>
20
 
#include <stdlib.h>
21
 
#include <string.h>
22
 
 
23
 
typedef struct
24
 
{
25
 
  unsigned short code[4];
26
 
  char *name;
27
 
} key_tab_t;
28
 
 
29
 
key_tab_t key_table[] = {
30
 
  {{0x1E61, 0x1E41, 0x1E01, 0x1E00}, "A"},
31
 
  {{0x3062, 0x3042, 0x3002, 0x3000}, "B"},
32
 
  {{0x2E63, 0x2E43, 0x2E03, 0x2E00}, "C"},
33
 
  {{0x2064, 0x2044, 0x2004, 0x2000}, "D"},
34
 
  {{0x1265, 0x1245, 0x1205, 0x1200}, "E"},
35
 
  {{0x2166, 0x2146, 0x2106, 0x2100}, "F"},
36
 
  {{0x2267, 0x2247, 0x2207, 0x2200}, "G"},
37
 
  {{0x2368, 0x2348, 0x2308, 0x2300}, "H"},
38
 
  {{0x1769, 0x1749, 0x1709, 0x1700}, "I"},
39
 
  {{0x246A, 0x244A, 0x240A, 0x2400}, "J"},
40
 
  {{0x256B, 0x254B, 0x250B, 0x2500}, "K"},
41
 
  {{0x266C, 0x264C, 0x260C, 0x2600}, "L"},
42
 
  {{0x326D, 0x324D, 0x320D, 0x3200}, "M"},
43
 
  {{0x316E, 0x314E, 0x310E, 0x3100}, "N"},
44
 
  {{0x186F, 0x184F, 0x180F, 0x1800}, "O"},
45
 
  {{0x1970, 0x1950, 0x1910, 0x1900}, "P"},
46
 
  {{0x1071, 0x1051, 0x1011, 0x1000}, "Q"},
47
 
  {{0x1372, 0x1352, 0x1312, 0x1300}, "R"},
48
 
  {{0x1F73, 0x1F53, 0x1F13, 0x1F00}, "S"},
49
 
  {{0x1474, 0x1454, 0x1414, 0x1400}, "T"},
50
 
  {{0x1675, 0x1655, 0x1615, 0x1600}, "U"},
51
 
  {{0x2F76, 0x2F56, 0x2F16, 0x2F00}, "V"},
52
 
  {{0x1177, 0x1157, 0x1117, 0x1100}, "W"},
53
 
  {{0x2D78, 0x2D58, 0x2D18, 0x2D00}, "X"},
54
 
  {{0x1579, 0x1559, 0x1519, 0x1500}, "Y"},
55
 
  {{0x2C7A, 0x2C5A, 0x2C1A, 0x2C00}, "Z"},
56
 
  {{0x0231, 0x0221, 0x0000, 0x7800}, "1"},
57
 
  {{0x0332, 0x0340, 0x0300, 0x7900}, "2"},
58
 
  {{0x0433, 0x0423, 0x0000, 0x7A00}, "3"},
59
 
  {{0x0534, 0x0524, 0x0000, 0x7B00}, "4"},
60
 
  {{0x0635, 0x0625, 0x0000, 0x7C00}, "5"},
61
 
  {{0x0736, 0x075E, 0x071E, 0x7D00}, "6"},
62
 
  {{0x0837, 0x0826, 0x0000, 0x7E00}, "7"},
63
 
  {{0x0938, 0x092A, 0x0000, 0x7F00}, "8"},
64
 
  {{0x0A39, 0x0A28, 0x0000, 0x8000}, "9"},
65
 
  {{0x0B30, 0x0B29, 0x0000, 0x8100}, "0"},
66
 
  {{0x0C2D, 0x0C5F, 0x0C1F, 0x8200}, "-"},
67
 
  {{0x0D3D, 0x0D2B, 0x0000, 0x8300}, "="},
68
 
  {{0x1A5B, 0x1A7B, 0x1A1B, 0x1A00}, "["},
69
 
  {{0x1B5D, 0x1B7D, 0x1B1D, 0x1B00}, "]"},
70
 
  {{0x273B, 0x273A, 0x0000, 0x2700}, ";"},
71
 
  {{0x2827, 0x2822, 0x0000, 0x0000}, "'"},
72
 
  {{0x2960, 0x297E, 0x0000, 0x0000}, "`"},
73
 
  {{0x2B5C, 0x2B7C, 0x2B1C, 0x2600}, "\\"},
74
 
  {{0x332C, 0x333C, 0x0000, 0x0000}, ","},
75
 
  {{0x342E, 0x343E, 0x0000, 0x0000}, "."},
76
 
  {{0x352F, 0x353F, 0x0000, 0x0000}, "/"},
77
 
  {{0x3B00, 0x5400, 0x5E00, 0x6800}, "F1"},
78
 
  {{0x3C00, 0x5500, 0x5F00, 0x6900}, "F2"},
79
 
  {{0x3D00, 0x5600, 0x6000, 0x6A00}, "F3"},
80
 
  {{0x3E00, 0x5700, 0x6100, 0x6B00}, "F4"},
81
 
  {{0x3F00, 0x5800, 0x6200, 0x6C00}, "F5"},
82
 
  {{0x4000, 0x5900, 0x6300, 0x6D00}, "F6"},
83
 
  {{0x4100, 0x5A00, 0x6400, 0x6E00}, "F7"},
84
 
  {{0x4200, 0x5B00, 0x6500, 0x6F00}, "F8"},
85
 
  {{0x4300, 0x5C00, 0x6600, 0x7000}, "F9"},
86
 
  {{0x4400, 0x5D00, 0x6700, 0x7100}, "F10"},
87
 
  {{0x8500, 0x8700, 0x8900, 0x8B00}, "F11"},
88
 
  {{0x8600, 0x8800, 0x8A00, 0x8C00}, "F12"},
89
 
  {{0x0E08, 0x0E08, 0x0E7F, 0x0E00}, "BACKSPACE"},
90
 
  {{0x5300, 0x532E, 0x9300, 0xA300}, "DEL"},
91
 
  {{0x5000, 0x5032, 0x9100, 0xA000}, "DOWN"},
92
 
  {{0x4F00, 0x4F31, 0x7500, 0x9F00}, "END"},
93
 
  {{0x1C0D, 0x1C0D, 0x1C0A, 0xA600}, "ENTER"},
94
 
  {{0x011B, 0x011B, 0x011B, 0x0100}, "ESC"},
95
 
  {{0x4700, 0x4737, 0x7700, 0x9700}, "HOME"},
96
 
  {{0x5200, 0x5230, 0x9200, 0xA200}, "INS"},
97
 
  {{0x0000, 0x4C35, 0x8F00, 0x0000}, "KEY-5"},
98
 
  {{0x372A, 0x0000, 0x9600, 0x3700}, "KEY-*"},
99
 
  {{0x4A2D, 0x4A2D, 0x8E00, 0x4A00}, "KEY--"},
100
 
  {{0x4E2B, 0x4E2B, 0x0000, 0x4E00}, "KEY-+"},
101
 
  {{0x352F, 0x352F, 0x9500, 0xA400}, "KEY-/"},
102
 
  {{0x4B00, 0x4B34, 0x7300, 0x9B00}, "LEFT"},
103
 
  {{0x5100, 0x5133, 0x7600, 0xA100}, "PGDN"},
104
 
  {{0x4900, 0x4939, 0x8400, 0x9900}, "PGUP"},
105
 
  {{0x0000, 0x0000, 0x7200, 0x0000}, "PRTSC"},
106
 
  {{0x4D00, 0x4D36, 0x7400, 0x9D00}, "RIGHT"},
107
 
  {{0x3920, 0x3920, 0x3920, 0x3920}, "SPACE"},
108
 
  {{0x0F09, 0x0F00, 0x9400, 0xA500}, "TAB"},
109
 
  {{0x4800, 0x4838, 0x8D00, 0x9800}, "UP"},
110
 
  {{0x0000, 0x0000, 0x0000, 0x0000}, (void *) 0}
111
 
};
112
 
 
113
 
char *
114
 
str_upcase (char *str)
115
 
{
116
 
  int i;
117
 
 
118
 
  for (i = 0; str[i]; i++)
119
 
    if ((str[i] >= 'a') && (str[i] <= 'z'))
120
 
      str[i] -= 'a' - 'A';
121
 
 
122
 
  return str;
123
 
}
124
 
 
125
 
int
126
 
get_keycode (char *key)
127
 
{
128
 
  int idx, i;
129
 
  char *str;
130
 
 
131
 
  if ((key[0] == '0') && (key[1] == 'x'))
132
 
    {
133
 
      int code;
134
 
 
135
 
      code = strtoul (key, NULL, 0);
136
 
      return ((code <= 0) || (code >= 0xFFFF)) ? 0 : code;
137
 
    }
138
 
  str = key;
139
 
  str_upcase (str);
140
 
  idx = 0;
141
 
  if (!strncmp (str, "SHIFT-", 6))
142
 
    {
143
 
      idx = 1;
144
 
      str += 6;
145
 
    }
146
 
  else if (!strncmp (str, "CTRL-", 5))
147
 
    {
148
 
      idx = 2;
149
 
      str += 5;
150
 
    }
151
 
  else if (!strncmp (str, "ALT-", 4))
152
 
    {
153
 
      idx = 3;
154
 
      str += 4;
155
 
    }
156
 
  for (i = 0; key_table[i].name; i++)
157
 
    {
158
 
      if (!strcmp (str, key_table[i].name))
159
 
        return key_table[i].code[idx];
160
 
    }
161
 
  return 0;
162
 
}
163
 
 
164
 
static char keyname_buf[16];
165
 
 
166
 
char *
167
 
get_keyname (unsigned short code)
168
 
{
169
 
  int i;
170
 
 
171
 
  for (i = 0; key_table[i].name; i++)
172
 
    {
173
 
      int j;
174
 
 
175
 
      for (j = 0; j < 4; j++)
176
 
        {        
177
 
          if (key_table[i].code[j] == code)
178
 
            {
179
 
              char *p;
180
 
              
181
 
              switch (j)
182
 
                {
183
 
                case 0:
184
 
                  p = "";
185
 
                  break;
186
 
                case 1:
187
 
                  p = "shift-";
188
 
                  break;
189
 
                case 2:
190
 
                  p = "ctrl-";
191
 
                  break;
192
 
                case 3:
193
 
                  p = "alt-";
194
 
                  break;
195
 
                }
196
 
 
197
 
              sprintf (keyname_buf, "%s%s", p, key_table[i].name);
198
 
              return keyname_buf;
199
 
            }
200
 
        }
201
 
    }
202
 
 
203
 
  sprintf (keyname_buf, "0x%x", code);
204
 
  return keyname_buf;
205
 
}