1*2b949d04SAndroid Build Coastguard Worker#!/usr/bin/env python 2*2b949d04SAndroid Build Coastguard Workerfrom __future__ import print_function 3*2b949d04SAndroid Build Coastguard Workerimport re 4*2b949d04SAndroid Build Coastguard Workerimport os 5*2b949d04SAndroid Build Coastguard Worker 6*2b949d04SAndroid Build Coastguard Worker# expected format: 7*2b949d04SAndroid Build Coastguard Worker# #define XF86XK_FooBar _EVDEVK(0x123) /* some optional comment */ 8*2b949d04SAndroid Build Coastguard Workerevdev_pattern = re.compile(r'^#define\s+XF86XK_(?P<name>\w+)\s+_EVDEVK\((?P<value>0x[0-9A-Fa-f]+)\)') 9*2b949d04SAndroid Build Coastguard Worker 10*2b949d04SAndroid Build Coastguard Workerprefix = os.environ.get('X11_HEADERS_PREFIX', '/usr') 11*2b949d04SAndroid Build Coastguard WorkerHEADERS = [ 12*2b949d04SAndroid Build Coastguard Worker prefix + '/include/X11/keysymdef.h', 13*2b949d04SAndroid Build Coastguard Worker prefix + '/include/X11/XF86keysym.h', 14*2b949d04SAndroid Build Coastguard Worker prefix + '/include/X11/Sunkeysym.h', 15*2b949d04SAndroid Build Coastguard Worker prefix + '/include/X11/DECkeysym.h', 16*2b949d04SAndroid Build Coastguard Worker prefix + '/include/X11/HPkeysym.h', 17*2b949d04SAndroid Build Coastguard Worker] 18*2b949d04SAndroid Build Coastguard Worker 19*2b949d04SAndroid Build Coastguard Workerprint('''#ifndef _XKBCOMMON_KEYSYMS_H 20*2b949d04SAndroid Build Coastguard Worker#define _XKBCOMMON_KEYSYMS_H 21*2b949d04SAndroid Build Coastguard Worker 22*2b949d04SAndroid Build Coastguard Worker/* This file is autogenerated; please do not commit directly. */ 23*2b949d04SAndroid Build Coastguard Worker 24*2b949d04SAndroid Build Coastguard Worker#define XKB_KEY_NoSymbol 0x000000 /* Special KeySym */ 25*2b949d04SAndroid Build Coastguard Worker''') 26*2b949d04SAndroid Build Coastguard Workerfor path in HEADERS: 27*2b949d04SAndroid Build Coastguard Worker with open(path) as header: 28*2b949d04SAndroid Build Coastguard Worker for line in header: 29*2b949d04SAndroid Build Coastguard Worker if '#ifdef' in line or '#ifndef' in line or '#endif' in line: 30*2b949d04SAndroid Build Coastguard Worker continue 31*2b949d04SAndroid Build Coastguard Worker 32*2b949d04SAndroid Build Coastguard Worker # Remove #define _OSF_Keysyms and such. 33*2b949d04SAndroid Build Coastguard Worker if '#define _' in line: 34*2b949d04SAndroid Build Coastguard Worker continue 35*2b949d04SAndroid Build Coastguard Worker 36*2b949d04SAndroid Build Coastguard Worker # Handle a duplicate definition in HPkeysyms.h which kicks in if 37*2b949d04SAndroid Build Coastguard Worker # it's not already defined. 38*2b949d04SAndroid Build Coastguard Worker if 'XK_Ydiaeresis' in line and '0x100000ee' in line: 39*2b949d04SAndroid Build Coastguard Worker continue 40*2b949d04SAndroid Build Coastguard Worker 41*2b949d04SAndroid Build Coastguard Worker # Replace the xorgproto _EVDEVK macro with the actual value 42*2b949d04SAndroid Build Coastguard Worker # 0x10081000 is the base, the evdev hex code is added to that. 43*2b949d04SAndroid Build Coastguard Worker # We replace to make parsing of the keys later easier. 44*2b949d04SAndroid Build Coastguard Worker match = re.match(evdev_pattern, line) 45*2b949d04SAndroid Build Coastguard Worker if match: 46*2b949d04SAndroid Build Coastguard Worker value = 0x10081000 + int(match.group('value'), 16) 47*2b949d04SAndroid Build Coastguard Worker line = re.sub(r'_EVDEVK\(0x([0-9A-Fa-f]+)\)', '{:#x}'.format(value), line) 48*2b949d04SAndroid Build Coastguard Worker 49*2b949d04SAndroid Build Coastguard Worker line = re.sub(r'#define\s*(\w*)XK_', r'#define XKB_KEY_\1', line) 50*2b949d04SAndroid Build Coastguard Worker 51*2b949d04SAndroid Build Coastguard Worker print(line, end='') 52*2b949d04SAndroid Build Coastguard Workerprint('\n\n#endif') 53