ia64/xen-unstable

view tools/ioemu/keymaps.c @ 15841:c5f735271e22

[IA64] Foreign p2m: Fix vti domain builder.

It should set arch_domain::convmem_end.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Alex Williamson <alex.williamson@hp.com>
date Thu Sep 06 13:48:43 2007 -0600 (2007-09-06)
parents c64f2a0dc2d7
children e44c6b67a483
line source
1 /*
2 * QEMU keysym to keycode conversion using rdesktop keymaps
3 *
4 * Copyright (c) 2004 Johannes Schindelin
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
25 static int get_keysym(const char *name)
26 {
27 name2keysym_t *p;
28 for(p = name2keysym; p->name != NULL; p++) {
29 if (!strcmp(p->name, name))
30 return p->keysym;
31 }
32 return 0;
33 }
35 struct key_range {
36 int start;
37 int end;
38 struct key_range *next;
39 };
41 #define MAX_NORMAL_KEYCODE 512
42 #define MAX_EXTRA_COUNT 256
43 typedef struct {
44 uint16_t keysym2keycode[MAX_NORMAL_KEYCODE];
45 struct {
46 int keysym;
47 uint16_t keycode;
48 } keysym2keycode_extra[MAX_EXTRA_COUNT];
49 int extra_count;
50 struct key_range *keypad_range;
51 struct key_range *numlock_range;
52 struct key_range *shift_range;
53 } kbd_layout_t;
55 static void add_to_key_range(struct key_range **krp, int code) {
56 struct key_range *kr;
57 for (kr = *krp; kr; kr = kr->next) {
58 if (code >= kr->start && code <= kr->end)
59 break;
60 if (code == kr->start - 1) {
61 kr->start--;
62 break;
63 }
64 if (code == kr->end + 1) {
65 kr->end++;
66 break;
67 }
68 }
69 if (kr == NULL) {
70 kr = qemu_mallocz(sizeof(*kr));
71 if (kr) {
72 kr->start = kr->end = code;
73 kr->next = *krp;
74 *krp = kr;
75 }
76 }
77 }
79 static kbd_layout_t *parse_keyboard_layout(const char *language,
80 kbd_layout_t * k)
81 {
82 FILE *f;
83 char file_name[1024];
84 char line[1024];
85 int len;
87 snprintf(file_name, sizeof(file_name),
88 "%s/keymaps/%s", bios_dir, language);
90 if (!k)
91 k = qemu_mallocz(sizeof(kbd_layout_t));
92 if (!k)
93 return 0;
94 if (!(f = fopen(file_name, "r"))) {
95 fprintf(stderr,
96 "Could not read keymap file: '%s'\n", file_name);
97 return 0;
98 }
99 for(;;) {
100 if (fgets(line, 1024, f) == NULL)
101 break;
102 len = strlen(line);
103 if (len > 0 && line[len - 1] == '\n')
104 line[len - 1] = '\0';
105 if (line[0] == '#')
106 continue;
107 if (!strncmp(line, "map ", 4))
108 continue;
109 if (!strncmp(line, "include ", 8)) {
110 parse_keyboard_layout(line + 8, k);
111 } else {
112 char *end_of_keysym = line;
113 while (*end_of_keysym != 0 && *end_of_keysym != ' ')
114 end_of_keysym++;
115 if (*end_of_keysym) {
116 int keysym;
117 *end_of_keysym = 0;
118 keysym = get_keysym(line);
119 if (keysym == 0) {
120 // fprintf(stderr, "Warning: unknown keysym %s\n", line);
121 } else {
122 const char *rest = end_of_keysym + 1;
123 char *rest2;
124 int keycode = strtol(rest, &rest2, 0);
126 if (rest && strstr(rest, "numlock")) {
127 add_to_key_range(&k->keypad_range, keycode);
128 add_to_key_range(&k->numlock_range, keysym);
129 fprintf(stderr, "keypad keysym %04x keycode %d\n", keysym, keycode);
130 }
131 if (rest && strstr(rest, "shift")) {
132 add_to_key_range(&k->shift_range, keysym);
133 fprintf(stderr, "shift keysym %04x keycode %d\n", keysym, keycode);
134 }
136 /* if(keycode&0x80)
137 keycode=(keycode<<8)^0x80e0; */
138 if (keysym < MAX_NORMAL_KEYCODE) {
139 //fprintf(stderr,"Setting keysym %s (%d) to %d\n",line,keysym,keycode);
140 k->keysym2keycode[keysym] = keycode;
141 } else {
142 if (k->extra_count >= MAX_EXTRA_COUNT) {
143 fprintf(stderr,
144 "Warning: Could not assign keysym %s (0x%x) because of memory constraints.\n",
145 line, keysym);
146 } else {
147 #if 0
148 fprintf(stderr, "Setting %d: %d,%d\n",
149 k->extra_count, keysym, keycode);
150 #endif
151 k->keysym2keycode_extra[k->extra_count].
152 keysym = keysym;
153 k->keysym2keycode_extra[k->extra_count].
154 keycode = keycode;
155 k->extra_count++;
156 }
157 }
158 }
159 }
160 }
161 }
162 fclose(f);
163 return k;
164 }
166 static void *init_keyboard_layout(const char *language)
167 {
168 return parse_keyboard_layout(language, 0);
169 }
171 static int keysym2scancode(void *kbd_layout, int keysym)
172 {
173 kbd_layout_t *k = kbd_layout;
174 if (keysym < MAX_NORMAL_KEYCODE) {
175 if (k->keysym2keycode[keysym] == 0)
176 fprintf(stderr, "Warning: no scancode found for keysym %d\n",
177 keysym);
178 return k->keysym2keycode[keysym];
179 } else {
180 int i;
181 #ifdef XK_ISO_Left_Tab
182 if (keysym == XK_ISO_Left_Tab)
183 keysym = XK_Tab;
184 #endif
185 for (i = 0; i < k->extra_count; i++)
186 if (k->keysym2keycode_extra[i].keysym == keysym)
187 return k->keysym2keycode_extra[i].keycode;
188 }
189 return 0;
190 }
192 static int keycodeIsKeypad(void *kbd_layout, int keycode)
193 {
194 kbd_layout_t *k = kbd_layout;
195 struct key_range *kr;
197 for (kr = k->keypad_range; kr; kr = kr->next)
198 if (keycode >= kr->start && keycode <= kr->end)
199 return 1;
200 return 0;
201 }
203 static int keysymIsNumlock(void *kbd_layout, int keysym)
204 {
205 kbd_layout_t *k = kbd_layout;
206 struct key_range *kr;
208 for (kr = k->numlock_range; kr; kr = kr->next)
209 if (keysym >= kr->start && keysym <= kr->end)
210 return 1;
211 return 0;
212 }
214 static int keysymIsShift(void *kbd_layout, int keysym)
215 {
216 kbd_layout_t *k = kbd_layout;
217 struct key_range *kr;
219 for (kr = k->shift_range; kr; kr = kr->next)
220 if (keysym >= kr->start && keysym <= kr->end)
221 return 1;
222 return 0;
223 }