From 6aaedb813fa11ba0679c3051bc2eb28646b9506c Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 30 Aug 2025 16:53:58 -0700 Subject: Update to SDL3 --- .../SDL-3.2.20/build-scripts/rename_headers.py | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 src/contrib/SDL-3.2.20/build-scripts/rename_headers.py (limited to 'src/contrib/SDL-3.2.20/build-scripts/rename_headers.py') diff --git a/src/contrib/SDL-3.2.20/build-scripts/rename_headers.py b/src/contrib/SDL-3.2.20/build-scripts/rename_headers.py new file mode 100755 index 0000000..b61e477 --- /dev/null +++ b/src/contrib/SDL-3.2.20/build-scripts/rename_headers.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 +# +# This script renames SDL headers in the specified paths + +import argparse +import pathlib +import re + + +def do_include_replacements(paths): + replacements = [ + ( re.compile(r"(?:[\"<])(?:SDL2/)?SDL_image.h(?:[\">])"), r"" ), + ( re.compile(r"(?:[\"<])(?:SDL2/)?SDL_mixer.h(?:[\">])"), r"" ), + ( re.compile(r"(?:[\"<])(?:SDL2/)?SDL_net.h(?:[\">])"), r"" ), + ( re.compile(r"(?:[\"<])(?:SDL2/)?SDL_rtf.h(?:[\">])"), r"" ), + ( re.compile(r"(?:[\"<])(?:SDL2/)?SDL_ttf.h(?:[\">])"), r"" ), + ( re.compile(r"(?:[\"<])(?:SDL2/)?SDL_gamecontroller.h(?:[\">])"), r"" ), + ( re.compile(r"(?:[\"<])(?:SDL2/)?begin_code.h(?:[\">])"), r"" ), + ( re.compile(r"(?:[\"<])(?:SDL2/)?close_code.h(?:[\">])"), r"" ), + ( re.compile(r"(?:[\"<])(?:SDL2/)?(SDL[_a-z0-9]*\.h)(?:[\">])"), r"" ) + ] + for entry in paths: + path = pathlib.Path(entry) + if not path.exists(): + print("{} does not exist, skipping".format(entry)) + continue + + replace_headers_in_path(path, replacements) + + +def replace_headers_in_file(file, replacements): + try: + with file.open("r", encoding="UTF-8", newline="") as rfp: + original = rfp.read() + contents = original + for regex, replacement in replacements: + contents = regex.sub(replacement, contents) + if contents != original: + with file.open("w", encoding="UTF-8", newline="") as wfp: + wfp.write(contents) + except UnicodeDecodeError: + print("%s is not text, skipping" % file) + except Exception as err: + print("%s" % err) + + +def replace_headers_in_dir(path, replacements): + for entry in path.glob("*"): + if entry.is_dir(): + replace_headers_in_dir(entry, replacements) + else: + print("Processing %s" % entry) + replace_headers_in_file(entry, replacements) + + +def replace_headers_in_path(path, replacements): + if path.is_dir(): + replace_headers_in_dir(path, replacements) + else: + replace_headers_in_file(path, replacements) + + +def main(): + parser = argparse.ArgumentParser(fromfile_prefix_chars='@', description="Rename #include's for SDL3.") + parser.add_argument("args", metavar="PATH", nargs="*", help="Input source file") + args = parser.parse_args() + + try: + do_include_replacements(args.args) + except Exception as e: + print(e) + return 1 + +if __name__ == "__main__": + raise SystemExit(main()) -- cgit v1.2.3