From afbd93cbbb2045922b10de4595d615bb4260f1d9 Mon Sep 17 00:00:00 2001 From: Mark Edgar Date: Sun, 20 Oct 2013 18:00:13 +0200 Subject: [PATCH] Replace mappedkeys[] with sorting on key[]. --- config.def.h | 10 ---------- st.c | 23 +++++++++++------------ 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/config.def.h b/config.def.h index def6c9e..5922561 100644 --- a/config.def.h +++ b/config.def.h @@ -133,17 +133,7 @@ static Shortcut shortcuts[] = { * * 0: no value * * > 0: crlf mode is enabled * * < 0: crlf mode is disabled - * - * Be careful with the order of the definitons because st searchs in - * this table sequentially, so any XK_ANY_MOD must be in the last - * position for a key. - */ - -/* - * If you want keys other than the X11 function keys (0xFD00 - 0xFFFF) - * to be mapped below, add them to this array. */ -static KeySym mappedkeys[] = { -1 }; /* * Which bits of the state should be ignored. By default the state bit for the diff --git a/st.c b/st.c index 50b58a7..29d07cf 100644 --- a/st.c +++ b/st.c @@ -68,6 +68,7 @@ char *argv0; /* macros */ #define SERRNO strerror(errno) +#define CMP(a, b) ((a) < (b) ? -1 : (a) > (b)) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) #define LEN(a) (sizeof(a) / sizeof(a[0])) @@ -412,6 +413,7 @@ static void xresize(int, int); static void expose(XEvent *); static void visibility(XEvent *); static void unmap(XEvent *); +static int keycmp(const void *, const void *); static char *kmap(KeySym, uint); static void kpress(XEvent *); static void cmessage(XEvent *); @@ -3517,22 +3519,18 @@ numlock(const Arg *dummy) { term.numlock ^= 1; } +int +keycmp(const void *a, const void *b) { + const Key *k1 = a, *k2 = b; + int c = CMP(k1->k, k2->k); + return c ? c : CMP(k1->mask, k2->mask); +} + char* kmap(KeySym k, uint state) { Key *kp; - int i; - - /* Check for mapped keys out of X11 function keys. */ - for(i = 0; i < LEN(mappedkeys); i++) { - if(mappedkeys[i] == k) - break; - } - if(i == LEN(mappedkeys)) { - if((k & 0xFFFF) < 0xFD00) - return NULL; - } - for(kp = key; kp < key + LEN(key); kp++) { + for(kp = key; kp < key + LEN(key) && kp->k <= k; kp++) { if(kp->k != k) continue; @@ -3828,6 +3826,7 @@ main(int argc, char *argv[]) { } ARGEND; run: + qsort(key, LEN(key), sizeof *key, keycmp); setlocale(LC_CTYPE, ""); XSetLocaleModifiers(""); tnew(80, 24); -- 1.8.4