68 lines
2.1 KiB
Python
Executable File
68 lines
2.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import argparse
|
|
import csv
|
|
import re
|
|
from pathlib import Path
|
|
|
|
|
|
FUNCTION = re.compile(r"^/\* [0-9a-fA-F]+ .+ \*/$")
|
|
|
|
|
|
def category(module: str) -> str:
|
|
if module.startswith("as3vm") or module == "avm2_microcode":
|
|
return "avm2"
|
|
if module.startswith("swf_draw") or module in {"gr_strokepath", "triangulate_ears"}:
|
|
return "renderer"
|
|
if module.startswith("swf_as3") or module == "as3_component_helpers":
|
|
return "flash-bindings"
|
|
if module.startswith("swf_"):
|
|
return "swf-runtime"
|
|
if module.startswith("iggy_api"):
|
|
return "public-api"
|
|
if module.startswith("iggy"):
|
|
return "runtime"
|
|
if module.startswith(("rr", "win32_", "durango_", "radss_")):
|
|
return "platform"
|
|
return "support"
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("source", type=Path)
|
|
parser.add_argument("members", type=Path)
|
|
parser.add_argument("output", type=Path)
|
|
args = parser.parse_args()
|
|
|
|
original_paths = {}
|
|
for path in args.members.read_text(encoding="utf-8").splitlines():
|
|
original_paths[path.rsplit("\\", 1)[-1].removesuffix(".obj")] = path
|
|
|
|
rows = []
|
|
for source in sorted(args.source.glob("*.c")):
|
|
module = source.stem
|
|
lines = source.read_text(encoding="utf-8").splitlines()
|
|
rows.append({
|
|
"module": module,
|
|
"category": category(module),
|
|
"functions": sum(bool(FUNCTION.match(line)) for line in lines),
|
|
"lines": len(lines),
|
|
"original_object": original_paths.get(module, ""),
|
|
})
|
|
|
|
args.output.parent.mkdir(parents=True, exist_ok=True)
|
|
with args.output.open("w", newline="", encoding="utf-8") as handle:
|
|
writer = csv.DictWriter(
|
|
handle,
|
|
fieldnames=rows[0].keys(),
|
|
delimiter="\t",
|
|
lineterminator="\n",
|
|
)
|
|
writer.writeheader()
|
|
writer.writerows(rows)
|
|
print(f"indexed {len(rows)} modules with {sum(row['functions'] for row in rows)} functions")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|