Sync OpenBSD patchset 757:

Simplify xterm modifier detection by treating as a bitmask + 1. Spotted
by and diff from Emanuele Giaquinta.
This commit is contained in:
Tiago Cunha 2010-09-07 13:21:18 +00:00
parent 33df467d40
commit afcc29a51d

View File

@ -1,4 +1,4 @@
/* $Id: xterm-keys.c,v 1.5 2009-12-04 22:14:47 tcunha Exp $ */ /* $Id: xterm-keys.c,v 1.6 2010-09-07 13:21:18 tcunha Exp $ */
/* /*
* Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
@ -114,27 +114,21 @@ int
xterm_keys_modifiers(const char *template, const char *buf, size_t len) xterm_keys_modifiers(const char *template, const char *buf, size_t len)
{ {
size_t idx; size_t idx;
int param, modifiers;
idx = strcspn(template, "_"); idx = strcspn(template, "_");
if (idx >= len) if (idx >= len)
return (0); return (0);
switch (buf[idx]) { param = buf[idx] - '1';
case '2':
return (KEYC_SHIFT); modifiers = 0;
case '3': if (param & 1)
return (KEYC_ESCAPE); modifiers |= KEYC_SHIFT;
case '4': if (param & 2)
return (KEYC_SHIFT|KEYC_ESCAPE); modifiers |= KEYC_ESCAPE;
case '5': if (param & 4)
return (KEYC_CTRL); modifiers |= KEYC_CTRL;
case '6': return (modifiers);
return (KEYC_SHIFT|KEYC_CTRL);
case '7':
return (KEYC_ESCAPE|KEYC_CTRL);
case '8':
return (KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL);
}
return (0);
} }
/* /*
@ -171,30 +165,19 @@ xterm_keys_lookup(int key)
int modifiers; int modifiers;
char *out; char *out;
#define KEY_MODIFIERS(key, modifiers) \ modifiers = 1;
(((key) & (KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL)) == (modifiers)) if (key & KEYC_SHIFT)
modifiers = 0; modifiers += 1;
if (KEY_MODIFIERS(key, KEYC_SHIFT)) if (key & KEYC_ESCAPE)
modifiers = 2; modifiers += 2;
else if (KEY_MODIFIERS(key, KEYC_ESCAPE)) if (key & KEYC_CTRL)
modifiers = 3; modifiers += 4;
else if (KEY_MODIFIERS(key, KEYC_SHIFT|KEYC_ESCAPE))
modifiers = 4;
else if (KEY_MODIFIERS(key, KEYC_CTRL))
modifiers = 5;
else if (KEY_MODIFIERS(key, KEYC_SHIFT|KEYC_CTRL))
modifiers = 6;
else if (KEY_MODIFIERS(key, KEYC_ESCAPE|KEYC_CTRL))
modifiers = 7;
else if (KEY_MODIFIERS(key, KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL))
modifiers = 8;
#undef KEY_MODIFIERS
/* /*
* If the key has no modifiers, return NULL and let it fall through to * If the key has no modifiers, return NULL and let it fall through to
* the normal lookup. * the normal lookup.
*/ */
if (modifiers == 0) if (modifiers == 1)
return (NULL); return (NULL);
/* Otherwise, find the key in the table. */ /* Otherwise, find the key in the table. */