-#!/usr/bin/env python
+#!/usr/bin/env python3
from __future__ import print_function
import re
import os
+from pathlib import Path
# Expected format:
# #define XF86XK_FooBar 0x1234 /* some optional comment */
return f"""{define} XKB_KEY_{prefix}{name}{spacing}{value_str}"""
-prefix = os.environ.get("X11_HEADERS_PREFIX", "/usr")
-HEADERS = [
- 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",
-]
+prefix = Path(os.environ.get("X11_HEADERS_PREFIX", "/usr"))
+HEADERS = (
+ 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
#define XKB_KEY_NoSymbol 0x000000 /* Special KeySym */
"""
)
+
for path in HEADERS:
- with open(path) as header:
+ with path.open("rt", encoding="utf-8") as header:
for line in header:
if "#ifdef" in line or "#ifndef" in line or "#endif" in line:
continue