--- rxvt-unicode/src/keyboard.C 2011/11/30 20:01:41 1.50 +++ rxvt-unicode/src/keyboard.C 2011/12/03 11:47:19 1.55 @@ -107,74 +107,29 @@ } } -// a wrapper for register_translation that converts the input string -// to utf-8 and expands 'list' syntax. void -keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const char *trans) +keyboard_manager::register_user_translation (KeySym keysym, unsigned int state, const wchar_t *ws) { - wchar_t *wc = rxvt_mbstowcs (trans); - char *translation = rxvt_wcstoutf8 (wc); - free (wc); + char *translation = rxvt_wcstoutf8 (ws); - if (strncmp (translation, "list", 4) == 0 && translation [4] - && strlen (translation) < STRING_MAX) - { - char *prefix = translation + 4; - char *middle = strchr (prefix + 1, translation [4]); - char *suffix = strrchr (prefix + 1, translation [4]); - - if (suffix && middle && suffix > middle + 1) - { - int range = suffix - middle - 1; - int prefix_len = middle - prefix - 1; - char buf[STRING_MAX]; - - memcpy (buf, prefix + 1, prefix_len); - strcpy (buf + prefix_len + 1, suffix + 1); - - for (int i = 0; i < range; i++) - { - buf [prefix_len] = middle [i + 1]; - register_translation (keysym + i, state, strdup (buf)); - } - - free (translation); - return; - } - else - rxvt_warn ("unable to parse list-type keysym '%s', processing as normal keysym.\n", translation); - } - - register_translation (keysym, state, translation); -} - -void -keyboard_manager::register_translation (KeySym keysym, unsigned int state, char *translation) -{ keysym_t *key = new keysym_t; - if (key && translation) - { - key->keysym = keysym; - key->state = state; - key->str = translation; - key->type = keysym_t::STRING; + if (!key) + rxvt_fatal ("memory allocation failure. aborting.\n"); - if (strncmp (translation, "builtin:", 8) == 0) - key->type = keysym_t::BUILTIN; + key->keysym = keysym; + key->state = state; + key->str = translation; + key->type = keysym_t::STRING; - if (keymap.size () == keymap.capacity ()) - keymap.reserve (keymap.size () * 2); + if (strncmp (translation, "builtin:", 8) == 0) + key->type = keysym_t::BUILTIN; - keymap.push_back (key); - hash[0] = 3; - } - else - { - delete key; - free (translation); - rxvt_fatal ("memory allocation failure. aborting.\n"); - } + if (keymap.size () == keymap.capacity ()) + keymap.reserve (keymap.size () * 2); + + keymap.push_back (key); + hash[0] = 3; } bool @@ -199,10 +154,10 @@ if (key->type != keysym_t::BUILTIN) { - wchar_t *wc = rxvt_utf8towcs (key->str); - char *str = rxvt_wcstombs (wc); + wchar_t *ws = rxvt_utf8towcs (key->str); + char *str = rxvt_wcstombs (ws); // TODO: do (some) translations, unescaping etc, here (allow \u escape etc.) - free (wc); + free (ws); output_string (term, str);