diff options
author | Pierre Le Marre <dev@wismill.eu> | 2023-09-28 07:18:51 +0200 |
---|---|---|
committer | Wismill <dev@wismill.eu> | 2023-09-28 07:48:37 +0200 |
commit | 9c2f0fdbed1315f20f287df1c0f85bc017619009 (patch) | |
tree | d490d2dfc860e108155d77d7ac84dd8e1220e292 | |
parent | 9d15c6a7a1834b02bcbabd4de736f58979759f29 (diff) | |
download | libxkbcommon-9c2f0fdbed1315f20f287df1c0f85bc017619009.tar.gz libxkbcommon-9c2f0fdbed1315f20f287df1c0f85bc017619009.tar.bz2 libxkbcommon-9c2f0fdbed1315f20f287df1c0f85bc017619009.zip |
scripts/makeheader: Minor improvements
Use `pathlib` for proper path handling.
-rwxr-xr-x | scripts/makeheader | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/scripts/makeheader b/scripts/makeheader index f2738bd..05d2c81 100755 --- a/scripts/makeheader +++ b/scripts/makeheader @@ -1,7 +1,8 @@ -#!/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 */ @@ -49,14 +50,14 @@ def make_keysym_entry(m: re.Match[str]) -> str: 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 @@ -72,8 +73,9 @@ print( #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 |