1#!/usr/bin/env python
2from __future__ import print_function
3import re
4import os
5
6
7prefix = os.environ.get('X11_HEADERS_PREFIX', '/usr')
8HEADERS = [
9    prefix + '/include/X11/keysymdef.h',
10    prefix + '/include/X11/XF86keysym.h',
11    prefix + '/include/X11/Sunkeysym.h',
12    prefix + '/include/X11/DECkeysym.h',
13    prefix + '/include/X11/HPkeysym.h',
14]
15
16print('''#ifndef _XKBCOMMON_KEYSYMS_H
17#define _XKBCOMMON_KEYSYMS_H
18
19/* This file is autogenerated; please do not commit directly. */
20
21#define XKB_KEY_NoSymbol                    0x000000  /* Special KeySym */
22''')
23for path in HEADERS:
24    with open(path) as header:
25        for line in header:
26            if '#ifdef' in line or '#ifndef' in line or '#endif' in line:
27                continue
28
29            # Remove #define _OSF_Keysyms and such.
30            if '#define _' in line:
31                continue
32
33            # Handle a duplicate definition in HPkeysyms.h which kicks in if
34            # it's not already defined.
35            if 'XK_Ydiaeresis' in line and '0x100000ee' in line:
36                continue
37
38            line = re.sub(r'#define\s*(\w*)XK_', r'#define XKB_KEY_\1', line)
39
40            print(line, end='')
41print('\n\n#endif')
42