ks_tables: Put all keysym names in one giant block
This makes the file take two segments instead of potentially many, causing relocation issues.master
parent
938a2c379b
commit
68c61e7f7d
25
makekeys.py
25
makekeys.py
|
@ -6,20 +6,33 @@ pattern = re.compile(r'^#define\s+XKB_KEY_(?P<name>\w+)\s+(?P<value>0x[0-9a-fA-F
|
|||
matches = [pattern.match(line) for line in open(sys.argv[1])]
|
||||
entries = [(m.group("name"), int(m.group("value"), 16)) for m in matches if m]
|
||||
|
||||
print('''/* This file is autogenerated from Makefile.am; please do not commit directly. */
|
||||
print('/* This file is autogenerated from Makefile.am; please do not commit directly. */\n')
|
||||
|
||||
entry_offsets = {}
|
||||
|
||||
print('const char *keysym_names =')
|
||||
offs = 0
|
||||
for (name, _) in sorted(entries, key=lambda e: e[0].lower()):
|
||||
entry_offsets[name] = offs
|
||||
print(' "{name}\\0"'.format(name=name))
|
||||
offs += len(name) + 1
|
||||
print(';')
|
||||
|
||||
print('''
|
||||
struct name_keysym {
|
||||
const char *name;
|
||||
xkb_keysym_t keysym;
|
||||
uint32_t offset;
|
||||
};\n''')
|
||||
|
||||
def print_entries(x):
|
||||
for (name, value) in x:
|
||||
print(' {{ 0x{value:08x}, {offs} }}, /* {name} */'.format(offs=entry_offsets[name], value=value, name=name))
|
||||
|
||||
print('static const struct name_keysym name_to_keysym[] = {')
|
||||
for (name, _) in sorted(entries, key=lambda e: e[0].lower()):
|
||||
print(' {{ "{name}", XKB_KEY_{name} }},'.format(name=name))
|
||||
print_entries(sorted(entries, key=lambda e: e[0].lower()))
|
||||
print('};\n')
|
||||
|
||||
# *.sort() is stable so we always get the first keysym for duplicate
|
||||
print('static const struct name_keysym keysym_to_name[] = {')
|
||||
for (name, _) in (next(g[1]) for g in itertools.groupby(sorted(entries, key=lambda e: e[1]), key=lambda e: e[1])):
|
||||
print(' {{ "{name}", XKB_KEY_{name} }},'.format(name=name))
|
||||
print_entries(next(g[1]) for g in itertools.groupby(sorted(entries, key=lambda e: e[1]), key=lambda e: e[1]))
|
||||
print('};')
|
||||
|
|
32
src/keysym.c
32
src/keysym.c
|
@ -53,24 +53,29 @@
|
|||
#include "keysym.h"
|
||||
#include "ks_tables.h"
|
||||
|
||||
static inline const char *
|
||||
get_name(const struct name_keysym *entry)
|
||||
{
|
||||
return keysym_names + entry->offset;
|
||||
}
|
||||
|
||||
static int
|
||||
compare_by_keysym(const void *a, const void *b)
|
||||
{
|
||||
const struct name_keysym *key = a, *entry = b;
|
||||
return key->keysym - (int32_t)entry->keysym;
|
||||
const struct name_keysym *entry = b;
|
||||
return *(const int32_t *)(a) - entry->keysym;
|
||||
}
|
||||
|
||||
static int
|
||||
compare_by_name(const void *a, const void *b)
|
||||
{
|
||||
const struct name_keysym *key = a, *entry = b;
|
||||
return strcasecmp(key->name, entry->name);
|
||||
const struct name_keysym *entry = b;
|
||||
return strcasecmp((const char *)a, get_name(entry));
|
||||
}
|
||||
|
||||
XKB_EXPORT int
|
||||
xkb_keysym_get_name(xkb_keysym_t ks, char *buffer, size_t size)
|
||||
{
|
||||
const struct name_keysym search = { .name = NULL, .keysym = ks };
|
||||
const struct name_keysym *entry;
|
||||
|
||||
if ((ks & ((unsigned long) ~0x1fffffff)) != 0) {
|
||||
|
@ -78,12 +83,12 @@ xkb_keysym_get_name(xkb_keysym_t ks, char *buffer, size_t size)
|
|||
return -1;
|
||||
}
|
||||
|
||||
entry = bsearch(&search, keysym_to_name,
|
||||
entry = bsearch(&ks, keysym_to_name,
|
||||
ARRAY_SIZE(keysym_to_name),
|
||||
sizeof(*keysym_to_name),
|
||||
compare_by_keysym);
|
||||
if (entry)
|
||||
return snprintf(buffer, size, "%s", entry->name);
|
||||
return snprintf(buffer, size, "%s", get_name(entry));
|
||||
|
||||
/* Unnamed Unicode codepoint. */
|
||||
if (ks >= 0x01000100 && ks <= 0x0110ffff) {
|
||||
|
@ -119,15 +124,15 @@ find_sym(const struct name_keysym *entry, const char *name, bool icase)
|
|||
if (!entry)
|
||||
return NULL;
|
||||
|
||||
if (!icase && strcmp(entry->name, name) == 0)
|
||||
if (!icase && strcmp(get_name(entry), name) == 0)
|
||||
return entry;
|
||||
if (icase && xkb_keysym_is_lower(entry->keysym))
|
||||
return entry;
|
||||
|
||||
for (iter = entry - 1; iter >= name_to_keysym; --iter) {
|
||||
if (!icase && strcmp(iter->name, name) == 0)
|
||||
if (!icase && strcmp(get_name(iter), name) == 0)
|
||||
return iter;
|
||||
if (strcasecmp(iter->name, entry->name) != 0)
|
||||
if (strcasecmp(get_name(iter), get_name(entry)) != 0)
|
||||
break;
|
||||
if (icase && xkb_keysym_is_lower(iter->keysym))
|
||||
return iter;
|
||||
|
@ -135,9 +140,9 @@ find_sym(const struct name_keysym *entry, const char *name, bool icase)
|
|||
|
||||
last = name_to_keysym + len;
|
||||
for (iter = entry + 1; iter < last; ++iter) {
|
||||
if (!icase && strcmp(iter->name, name) == 0)
|
||||
if (!icase && strcmp(get_name(iter), name) == 0)
|
||||
return iter;
|
||||
if (strcasecmp(iter->name, entry->name) != 0)
|
||||
if (strcasecmp(get_name(iter), get_name(entry)) != 0)
|
||||
break;
|
||||
if (icase && xkb_keysym_is_lower(iter->keysym))
|
||||
return iter;
|
||||
|
@ -151,7 +156,6 @@ find_sym(const struct name_keysym *entry, const char *name, bool icase)
|
|||
XKB_EXPORT xkb_keysym_t
|
||||
xkb_keysym_from_name(const char *s, enum xkb_keysym_flags flags)
|
||||
{
|
||||
const struct name_keysym search = { .name = s, .keysym = 0 };
|
||||
const struct name_keysym *entry;
|
||||
char *tmp;
|
||||
xkb_keysym_t val;
|
||||
|
@ -160,7 +164,7 @@ xkb_keysym_from_name(const char *s, enum xkb_keysym_flags flags)
|
|||
if (flags & ~XKB_KEYSYM_CASE_INSENSITIVE)
|
||||
return XKB_KEY_NoSymbol;
|
||||
|
||||
entry = bsearch(&search, name_to_keysym,
|
||||
entry = bsearch(s, name_to_keysym,
|
||||
ARRAY_SIZE(name_to_keysym),
|
||||
sizeof(*name_to_keysym),
|
||||
compare_by_name);
|
||||
|
|
11765
src/ks_tables.h
11765
src/ks_tables.h
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue