From aba0bc77a85bc5a13c648b0bb2adbe2e32c2f1f3 Mon Sep 17 00:00:00 2001 From: Kalle Olavi Niemitalo Date: Sun, 13 Aug 2006 14:24:28 +0300 Subject: [PATCH] parse_keystroke: Never write back to the input string. This fixes a bug: in the previous version, l_bind_key() modified the buffer whose address lua_tostring() returned, even though that is not allowed according to Lua documentation . The change affects the user interface: previously, if the user typed "ctrl+cokebottle" in the "Add keybinding" dialog box, ELinks would change the text in the widget to "Ctrl-cokebottle" before complaining that the keystroke is invalid. Now, it leaves the widget unchanged. This commit does not yet add const to parameters of parse_keystroke() and related functions. --- src/config/kbdbind.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/config/kbdbind.c b/src/config/kbdbind.c index f099c8f48..cea0db33e 100644 --- a/src/config/kbdbind.c +++ b/src/config/kbdbind.c @@ -372,23 +372,20 @@ read_key(unsigned char *key_str) int parse_keystroke(unsigned char *s, struct term_event_keyboard *kbd) { + unsigned char ctrlbuf[2]; + if (!strncasecmp(s, "Shift", 5) && (s[5] == '-' || s[5] == '+')) { /* Shift+a == shiFt-a == Shift-a */ - memcpy(s, "Shift-", 6); kbd->modifier = KBD_MOD_SHIFT; s += 6; } else if (!strncasecmp(s, "Ctrl", 4) && (s[4] == '-' || s[4] == '+')) { /* Ctrl+a == ctRl-a == Ctrl-a */ - memcpy(s, "Ctrl-", 5); kbd->modifier = KBD_MOD_CTRL; s += 5; - /* Ctrl-a == Ctrl-A */ - if (s[0] && !s[1]) s[0] = toupper(s[0]); } else if (!strncasecmp(s, "Alt", 3) && (s[3] == '-' || s[3] == '+')) { /* Alt+a == aLt-a == Alt-a */ - memcpy(s, "Alt-", 4); kbd->modifier = KBD_MOD_ALT; s += 4; @@ -397,6 +394,13 @@ parse_keystroke(unsigned char *s, struct term_event_keyboard *kbd) kbd->modifier = KBD_MOD_NONE; } + if ((kbd->modifier & KBD_MOD_CTRL) != 0 && s[0] && !s[1]) { + /* Ctrl-a == Ctrl-A */ + ctrlbuf[0] = toupper(s[0]); + ctrlbuf[1] = '\0'; + s = ctrlbuf; + } + kbd->key = read_key(s); return (kbd->key == KBD_UNDEF) ? -1 : 0; }