2012-10-16 08:05:33 -06:00
|
|
|
#!/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]
|
|
|
|
|
2013-07-17 16:56:03 -06:00
|
|
|
print('''
|
|
|
|
/**
|
|
|
|
* This file comes from libxkbcommon and was generated by makekeys.py
|
|
|
|
* You can always fetch the latest version from:
|
|
|
|
* https://raw.github.com/xkbcommon/libxkbcommon/master/src/ks_tables.h
|
|
|
|
*/
|
|
|
|
''')
|
2013-07-17 15:49:10 -06:00
|
|
|
|
2013-07-17 16:07:31 -06:00
|
|
|
entry_offsets = {}
|
|
|
|
|
2014-01-01 11:01:12 -07:00
|
|
|
print('''
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Woverlength-strings"
|
2014-01-10 15:26:58 -07:00
|
|
|
static const char *keysym_names =
|
2014-01-01 11:01:12 -07:00
|
|
|
'''.strip())
|
2013-07-17 16:07:31 -06:00
|
|
|
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
|
2014-01-01 11:01:12 -07:00
|
|
|
print('''
|
|
|
|
;
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
'''.strip())
|
2013-07-17 16:07:31 -06:00
|
|
|
|
|
|
|
print('''
|
2013-07-17 15:49:10 -06:00
|
|
|
struct name_keysym {
|
2012-10-16 08:05:33 -06:00
|
|
|
xkb_keysym_t keysym;
|
2013-07-17 16:07:31 -06:00
|
|
|
uint32_t offset;
|
2012-10-16 08:05:33 -06:00
|
|
|
};\n''')
|
|
|
|
|
2013-07-17 16:07:31 -06:00
|
|
|
def print_entries(x):
|
|
|
|
for (name, value) in x:
|
|
|
|
print(' {{ 0x{value:08x}, {offs} }}, /* {name} */'.format(offs=entry_offsets[name], value=value, name=name))
|
|
|
|
|
2013-07-17 15:44:07 -06:00
|
|
|
print('static const struct name_keysym name_to_keysym[] = {')
|
2013-07-17 16:07:31 -06:00
|
|
|
print_entries(sorted(entries, key=lambda e: e[0].lower()))
|
2012-10-16 08:05:33 -06:00
|
|
|
print('};\n')
|
|
|
|
|
|
|
|
# *.sort() is stable so we always get the first keysym for duplicate
|
2013-07-17 15:44:07 -06:00
|
|
|
print('static const struct name_keysym keysym_to_name[] = {')
|
2013-07-17 16:07:31 -06:00
|
|
|
print_entries(next(g[1]) for g in itertools.groupby(sorted(entries, key=lambda e: e[1]), key=lambda e: e[1]))
|
2012-10-16 08:05:33 -06:00
|
|
|
print('};')
|