[at-spi2-core/keysym2ucs-lookup] Fix keysym2ucs lookup



commit 1161336910efaf1a71d0cb16c60eaf98d545535c
Author: Samuel Thibault <samuel thibault ens-lyon org>
Date:   Tue Jul 7 09:16:49 2020 +0200

    Fix keysym2ucs lookup
    
    The ucs2keysym table cannot be sorted both by ucs value *and* by keysym
    value. It happens to be sorted by ucs value, so replace keysym binary
    search with linear search.
    
    This fixes the event_string for various characters.

 registryd/ucs2keysym.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
---
diff --git a/registryd/ucs2keysym.c b/registryd/ucs2keysym.c
index ad237c0..43bad6d 100644
--- a/registryd/ucs2keysym.c
+++ b/registryd/ucs2keysym.c
@@ -824,9 +824,7 @@ long ucs2keysym (long ucs)
 
 long keysym2ucs(long keysym)
 {
-    int min = 0;
-    int max = sizeof(keysymtab) / sizeof(struct codepair) - 1;
-    int mid;
+    int i;
 
     /* first check for Latin-1 characters (1:1 mapping) */
     if ((keysym >= 0x0020 && keysym <= 0x007e) ||
@@ -837,16 +835,10 @@ long keysym2ucs(long keysym)
     if ((keysym & 0xff000000) == 0x01000000)
        return keysym & 0x00ffffff;
 
-    /* binary search in table */
-    while (max >= min) {
-       mid = (min + max) / 2;
-       if (keysymtab[mid].keysym < keysym)
-           min = mid + 1;
-       else if (keysymtab[mid].keysym > keysym)
-           max = mid - 1;
-       else {
+    for (i = 0; i < sizeof(keysymtab) / sizeof(keysymtab[0]); i++) {
+       if (keysymtab[i].keysym == keysym) {
            /* found it */
-           return keysymtab[mid].ucs;
+           return keysymtab[i].ucs;
        }
     }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]