Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keysyms: Fix missing hpYdiaeresis #383

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/xkbcommon/xkbcommon-keysyms.h
Original file line number Diff line number Diff line change
Expand Up @@ -3207,6 +3207,7 @@ performance, or use of this material.
#define XKB_KEY_hpmute_asciitilde 0x100000ac
#define XKB_KEY_hplira 0x100000af
#define XKB_KEY_hpguilder 0x100000be
#define XKB_KEY_hpYdiaeresis 0x100000ee
#define XKB_KEY_hpIO 0x100000ee /* deprecated alias for hpYdiaeresis */
#define XKB_KEY_hplongminus 0x100000f6
#define XKB_KEY_hpblock 0x100000fc
Expand Down
48 changes: 42 additions & 6 deletions scripts/makeheader
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ keysym_entry_pattern = re.compile(
re.VERBOSE,
)

# Match keysym guarded by #ifndef
keysym_ifndef_pattern = re.compile(r"^#ifndef\s+(?P<prefix>\w*)XK_(?P<name>\w+)\s*$")

# Match remaining XK_ references in the comments, e.g we will replace:
# XF86XK_CamelCaseKernelName _EVDEVK(kernel value)
# #define XKB_KEY_SunCompose 0x0000FF20 /* Same as XK_Multi_key */
Expand All @@ -28,6 +31,10 @@ keysym_entry_pattern = re.compile(
xorgproto_keysym_prefix_pattern = re.compile(r"\b(?P<prefix>\w*)XK_(?!KOREAN\b)")


def make_keysym_name(m: re.Match[str]) -> str:
return m.group("prefix") + m.group("name")


def make_keysym_entry(m: re.Match[str]) -> str:
"""
Perform the substitutions
Expand Down Expand Up @@ -74,21 +81,50 @@ print(
"""
)

keysyms: set[str] = set()
for path in HEADERS:
pending_guarded_keysym: str | None = None
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:
# Duplicate keysym name guard
if m := keysym_ifndef_pattern.match(line):
if pending_guarded_keysym:
raise ValueError(f"Nested #ifndef {pending_guarded_keysym}")
pending_guarded_keysym = make_keysym_name(m)
continue

# Remove #define _OSF_Keysyms and such.
if "#define _" in line:
# Ignore C macro #ifdef/#ifndef
elif line.startswith("#ifdef") or line.startswith("#ifndef"):
if pending_guarded_keysym:
raise ValueError(f"Nested C macro {pending_guarded_keysym}")
continue

# Handle a duplicate definition in HPkeysyms.h which kicks in if
# it's not already defined.
if "XK_Ydiaeresis" in line and "0x100000ee" in line:
# Ignore C macro #endif and check end of keysym name guard
elif line.startswith("#endif"):
if pending_guarded_keysym:
pending_guarded_keysym = None
continue

# Remove #define _OSF_Keysyms and such.
elif line.startswith("#define _"):
continue

# Keysym entry: proceed various tests
if line.startswith("#") and (m := keysym_entry_pattern.match(line)):
name = make_keysym_name(m)
# Check expected guarded keysym, if relevant
if pending_guarded_keysym and name != pending_guarded_keysym:
raise ValueError(f"{path}: Malformed keysym name guard: {line}")
# Check if name already defined
elif name in keysyms:
if pending_guarded_keysym:
# Ignore guarded keysym
continue
else:
raise ValueError(f"{path}: Unguarded redefinition: {line}")
else:
keysyms.add(name)

# Perform _EVDEV and XK_ substitutions
line = keysym_entry_pattern.sub(make_keysym_entry, line)
line = xorgproto_keysym_prefix_pattern.sub(r"XKB_KEY_\1", line)
Expand Down
Loading