Hash :
68c61e7f
Author :
Date :
2013-07-17T18:07:31
ks_tables: Put all keysym names in one giant block This makes the file take two segments instead of potentially many, causing relocation issues.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/usr/bin/env python
import re, sys, itertools
pattern = re.compile(r'^#define\s+XKB_KEY_(?P<name>\w+)\s+(?P<value>0x[0-9a-fA-F]+)\s')
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. */\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 {
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[] = {')
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[] = {')
print_entries(next(g[1]) for g in itertools.groupby(sorted(entries, key=lambda e: e[1]), key=lambda e: e[1]))
print('};')