--- sourceforge.net/trunk/rdesktop/xkeymap.c 2005/08/03 08:25:32 957 +++ sourceforge.net/trunk/rdesktop/xkeymap.c 2005/08/03 09:56:17 962 @@ -30,6 +30,7 @@ #include #include #include +#include #include "rdesktop.h" #include "scancodes.h" @@ -155,6 +156,63 @@ DEBUG_KBD(("\n")); } +void +xkeymap_from_locale(const char *locale) +{ + char *str, *ptr; + FILE *fp; + + /* Create a working copy */ + str = strdup(locale); + if (str == NULL) + { + perror("strdup"); + exit(1); + } + + /* Truncate at dot and at */ + ptr = strrchr(str, '.'); + if (ptr) + *ptr = '\0'; + ptr = strrchr(str, '@'); + if (ptr) + *ptr = '\0'; + + /* Replace _ with - */ + ptr = strrchr(str, '_'); + if (ptr) + *ptr = '-'; + + /* Convert to lowercase */ + ptr = str; + while (*ptr) + { + *ptr = tolower((int) *ptr); + ptr++; + } + + /* Try to open this keymap (da-dk) */ + fp = xkeymap_open(str); + if (fp == NULL) + { + /* Truncate at dash */ + ptr = strrchr(str, '-'); + if (ptr) + *ptr = '\0'; + + /* Try the short name (da) */ + fp = xkeymap_open(str); + } + + if (fp) + { + fclose(fp); + STRNCPY(keymapname, str, sizeof(keymapname)); + fprintf(stderr, "Autoselected keyboard map %s.\n", keymapname); + } +} + + /* Joins two path components. The result should be freed with xfree(). */ static char * @@ -184,13 +242,6 @@ char *home; FILE *fp; - /* Try KEYMAP_PATH */ - path1 = pathjoin(KEYMAP_PATH, filename); - fp = fopen(path1, "r"); - xfree(path1); - if (fp) - return fp; - /* Try ~/.rdesktop/keymaps */ home = getenv("HOME"); if (home) @@ -204,6 +255,13 @@ return fp; } + /* Try KEYMAP_PATH */ + path1 = pathjoin(KEYMAP_PATH, filename); + fp = fopen(path1, "r"); + xfree(path1); + if (fp) + return fp; + /* Try current directory, in case we are running from the source tree */ path1 = pathjoin("keymaps", filename); @@ -358,15 +416,6 @@ xkeymap_init(void) { unsigned int max_keycode; - char *mapname_ptr; - - /* Make keymapname lowercase */ - mapname_ptr = keymapname; - while (*mapname_ptr) - { - *mapname_ptr = tolower((int) *mapname_ptr); - mapname_ptr++; - } if (strcmp(keymapname, "none")) {