Check the doxygen version
[platform/upstream/libxkbcommon.git] / scripts / makeheader
index 7b7a07e..bb0db59 100755 (executable)
@@ -1,15 +1,19 @@
 #!/usr/bin/env python
-
 from __future__ import print_function
 import re
+import os
 
+# expected format:
+# #define XF86XK_FooBar _EVDEVK(0x123) /* some optional comment */
+evdev_pattern = re.compile(r'^#define\s+XF86XK_(?P<name>\w+)\s+_EVDEVK\((?P<value>0x[0-9A-Fa-f]+)\)')
 
+prefix = os.environ.get('X11_HEADERS_PREFIX', '/usr')
 HEADERS = [
-    '/usr/include/X11/keysymdef.h',
-    '/usr/include/X11/XF86keysym.h',
-    '/usr/include/X11/Sunkeysym.h',
-    '/usr/include/X11/DECkeysym.h',
-    '/usr/include/X11/HPkeysym.h',
+    prefix + '/include/X11/keysymdef.h',
+    prefix + '/include/X11/XF86keysym.h',
+    prefix + '/include/X11/Sunkeysym.h',
+    prefix + '/include/X11/DECkeysym.h',
+    prefix + '/include/X11/HPkeysym.h',
 ]
 
 print('''#ifndef _XKBCOMMON_KEYSYMS_H
@@ -17,6 +21,11 @@ print('''#ifndef _XKBCOMMON_KEYSYMS_H
 
 /* This file is autogenerated; please do not commit directly. */
 
+/**
+ * @file
+ * Key symbols (keysyms) definitions.
+ */
+
 #define XKB_KEY_NoSymbol                    0x000000  /* Special KeySym */
 ''')
 for path in HEADERS:
@@ -34,6 +43,14 @@ for path in HEADERS:
             if 'XK_Ydiaeresis' in line and '0x100000ee' in line:
                 continue
 
+            # Replace the xorgproto _EVDEVK macro with the actual value
+            # 0x10081000 is the base, the evdev hex code is added to that.
+            # We replace to make parsing of the keys later easier.
+            match = re.match(evdev_pattern, line)
+            if match:
+                value = 0x10081000 + int(match.group('value'), 16)
+                line = re.sub(r'_EVDEVK\(0x([0-9A-Fa-f]+)\)', '{:#x}'.format(value), line)
+
             line = re.sub(r'#define\s*(\w*)XK_', r'#define XKB_KEY_\1', line)
 
             print(line, end='')