3 import re, sys, itertools
5 pattern = re.compile(r'^#define\s+XKB_KEY_(?P<name>\w+)\s+(?P<value>0x[0-9a-fA-F]+)\s')
6 matches = [pattern.match(line) for line in open(sys.argv[1])]
7 entries = [(m.group("name"), int(m.group("value"), 16)) for m in matches if m]
9 print('''struct name_keysym {
14 print('static const struct name_keysym name_to_keysym[] = {')
15 for (name, _) in sorted(entries, key=lambda e: e[0].lower()):
16 print(' {{ "{name}", XKB_KEY_{name} }},'.format(name=name))
19 # *.sort() is stable so we always get the first keysym for duplicate
20 print('static const struct name_keysym keysym_to_name[] = {')
21 for (name, _) in (next(g[1]) for g in itertools.groupby(sorted(entries, key=lambda e: e[1]), key=lambda e: e[1])):
22 print(' {{ "{name}", XKB_KEY_{name} }},'.format(name=name))