30 |
#include <ctype.h> |
#include <ctype.h> |
31 |
#include <limits.h> |
#include <limits.h> |
32 |
#include <time.h> |
#include <time.h> |
33 |
|
#include <string.h> |
34 |
#include "rdesktop.h" |
#include "rdesktop.h" |
35 |
#include "scancodes.h" |
#include "scancodes.h" |
36 |
|
|
55 |
|
|
56 |
static void update_modifier_state(uint8 scancode, BOOL pressed); |
static void update_modifier_state(uint8 scancode, BOOL pressed); |
57 |
|
|
58 |
/* Free key_translation structure, included linked list */ |
/* Free key_translation structure, including linked list */ |
59 |
static void |
static void |
60 |
free_key_translation(key_translation * ptr) |
free_key_translation(key_translation * ptr) |
61 |
{ |
{ |
156 |
DEBUG_KBD(("\n")); |
DEBUG_KBD(("\n")); |
157 |
} |
} |
158 |
|
|
159 |
|
/* Joins two path components. The result should be freed with |
160 |
|
xfree(). */ |
161 |
|
static char * |
162 |
|
pathjoin(const char *a, const char *b) |
163 |
|
{ |
164 |
|
char *result; |
165 |
|
result = xmalloc(PATH_MAX * 2 + 1); |
166 |
|
|
167 |
|
if (b[0] == '/') |
168 |
|
{ |
169 |
|
strncpy(result, b, PATH_MAX); |
170 |
|
} |
171 |
|
else |
172 |
|
{ |
173 |
|
strncpy(result, a, PATH_MAX); |
174 |
|
strcat(result, "/"); |
175 |
|
strncat(result, b, PATH_MAX); |
176 |
|
} |
177 |
|
return result; |
178 |
|
} |
179 |
|
|
180 |
|
/* Try to open a keymap with fopen() */ |
181 |
|
FILE * |
182 |
|
xkeymap_open(const char *filename) |
183 |
|
{ |
184 |
|
char *path1, *path2; |
185 |
|
char *home; |
186 |
|
FILE *fp; |
187 |
|
|
188 |
|
/* Try ~/.rdesktop/keymaps */ |
189 |
|
home = getenv("HOME"); |
190 |
|
if (home) |
191 |
|
{ |
192 |
|
path1 = pathjoin(home, ".rdesktop/keymaps"); |
193 |
|
path2 = pathjoin(path1, filename); |
194 |
|
xfree(path1); |
195 |
|
fp = fopen(path2, "r"); |
196 |
|
xfree(path2); |
197 |
|
if (fp) |
198 |
|
return fp; |
199 |
|
} |
200 |
|
|
201 |
|
/* Try KEYMAP_PATH */ |
202 |
|
path1 = pathjoin(KEYMAP_PATH, filename); |
203 |
|
fp = fopen(path1, "r"); |
204 |
|
xfree(path1); |
205 |
|
if (fp) |
206 |
|
return fp; |
207 |
|
|
208 |
|
/* Try current directory, in case we are running from the source |
209 |
|
tree */ |
210 |
|
path1 = pathjoin("keymaps", filename); |
211 |
|
fp = fopen(path1, "r"); |
212 |
|
xfree(path1); |
213 |
|
if (fp) |
214 |
|
return fp; |
215 |
|
|
216 |
|
return NULL; |
217 |
|
} |
218 |
|
|
219 |
static BOOL |
static BOOL |
220 |
xkeymap_read(char *mapname) |
xkeymap_read(char *mapname) |
221 |
{ |
{ |
222 |
FILE *fp; |
FILE *fp; |
223 |
char line[KEYMAP_MAX_LINE_LENGTH]; |
char line[KEYMAP_MAX_LINE_LENGTH]; |
|
char path[PATH_MAX], inplace_path[PATH_MAX]; |
|
224 |
unsigned int line_num = 0; |
unsigned int line_num = 0; |
225 |
unsigned int line_length = 0; |
unsigned int line_length = 0; |
226 |
char *keyname, *p; |
char *keyname, *p; |
228 |
uint8 scancode; |
uint8 scancode; |
229 |
uint16 modifiers; |
uint16 modifiers; |
230 |
|
|
231 |
|
fp = xkeymap_open(mapname); |
|
strcpy(path, KEYMAP_PATH); |
|
|
strncat(path, mapname, sizeof(path) - sizeof(KEYMAP_PATH)); |
|
|
|
|
|
fp = fopen(path, "r"); |
|
232 |
if (fp == NULL) |
if (fp == NULL) |
233 |
{ |
{ |
234 |
/* in case we are running from the source tree */ |
error("Failed to open keymap %s\n", mapname); |
235 |
strcpy(inplace_path, "keymaps/"); |
return False; |
|
strncat(inplace_path, mapname, sizeof(inplace_path) - sizeof("keymaps/")); |
|
|
|
|
|
fp = fopen(inplace_path, "r"); |
|
|
if (fp == NULL) |
|
|
{ |
|
|
error("Failed to open keymap %s\n", path); |
|
|
return False; |
|
|
} |
|
236 |
} |
} |
237 |
|
|
238 |
/* FIXME: More tolerant on white space */ |
/* FIXME: More tolerant on white space */ |
361 |
unsigned int max_keycode; |
unsigned int max_keycode; |
362 |
char *mapname_ptr; |
char *mapname_ptr; |
363 |
|
|
|
/* Make keymapname lowercase */ |
|
|
mapname_ptr = keymapname; |
|
|
while (*mapname_ptr) |
|
|
{ |
|
|
*mapname_ptr = tolower((int) *mapname_ptr); |
|
|
mapname_ptr++; |
|
|
} |
|
|
|
|
364 |
if (strcmp(keymapname, "none")) |
if (strcmp(keymapname, "none")) |
365 |
{ |
{ |
366 |
if (xkeymap_read(keymapname)) |
if (xkeymap_read(keymapname)) |