-
Notifications
You must be signed in to change notification settings - Fork 206
Miscellaneous
vfsfitvnm edited this page May 15, 2023
·
6 revisions
This is just a spaghetti script that finds the differences among Unity headers:
import os
import sys
from warnings import filterwarnings
filterwarnings("ignore")
import re
from pyastyle import format
from shutil import rmtree
from functools import cmp_to_key
from distutils.version import LooseVersion
def grep_struct(file, struct):
with open(file, "r") as header:
matches = re.findall(f"typedef struct {struct}\n\{{.*\}} {struct};", header.read(), re.DOTALL)
if matches:
return format(matches[0], '--style=allman')
else:
print(f"{struct} is missing in {file}")
return None
src_folder = "./headers/"
dst_folder = "adjusted"
struct = sys.argv[1]
rmtree(f"./{dst_folder}/{struct}", ignore_errors=True)
os.makedirs(f"./{dst_folder}/{struct}")
values = [(file, grep_struct(src_folder + file, struct)) for file in sorted(os.listdir(src_folder), key=cmp_to_key(lambda f1, f2: LooseVersion(f1)._cmp(LooseVersion(f2)))) if file.endswith('.h')]
first_file = None
last_file = None
last_def = None
for (file, typedef) in values:
if typedef == None:
continue
if last_file == None:
first_file = file
last_file = file
last_def = typedef
with open(f"./{dst_folder}/{struct}/{file}", "w") as file:
file.write(typedef)
if typedef != last_def:
#os.rename(f"./{struct}/{first_file}", f"./{struct}/{first_file}-{last_file}")
with open(f"./{dst_folder}/{struct}/{file}", "w") as file:
file.write(typedef)
last_file = file
last_def = typedef