9 pattern = re.compile(r"^#define\s+XKB_KEY_(?P<name>\w+)\s+(?P<value>0x[0-9a-fA-F]+)\s")
10 matches = [pattern.match(line) for line in open(sys.argv[1])]
11 entries = [(m.group("name"), int(m.group("value"), 16)) for m in matches if m]
13 entries_isorted = sorted(entries, key=lambda e: e[0].lower())
14 entries_kssorted = sorted(entries, key=lambda e: e[1])
19 * This file comes from libxkbcommon and was generated by makekeys.py
20 * You can always fetch the latest version from:
21 * https://raw.github.com/xkbcommon/libxkbcommon/master/src/ks_tables.h
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Woverlength-strings"
34 static const char *keysym_names =
38 for name, _ in entries_isorted:
39 entry_offsets[name] = offs
40 print(' "{name}\\0"'.format(name=name))
46 #pragma GCC diagnostic pop
53 static const uint16_t keysym_name_G[] = {
58 keysym_name_hash_f(const char *key, const char *T)
61 for (size_t i = 0; key[i] != '\0'; i++)
62 sum += T[i % $NS] * key[i];
67 keysym_name_perfect_hash(const char *key)
70 keysym_name_G[keysym_name_hash_f(key, "$S1")] +
71 keysym_name_G[keysym_name_hash_f(key, "$S2")]
76 perfect_hash.generate_code(
77 keys=[name for name, value in entries_isorted],
94 " {{ 0x{value:08x}, {offs} }}, /* {name} */".format(
95 offs=entry_offsets[name], value=value, name=name
100 print("static const struct name_keysym name_to_keysym[] = {")
101 print_entries(entries_isorted)
104 # *.sort() is stable so we always get the first keysym for duplicate
105 print("static const struct name_keysym keysym_to_name[] = {")
107 next(g[1]) for g in itertools.groupby(entries_kssorted, key=lambda e: e[1])