27 lines
1.1 KiB
Python
27 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""Enforce legacy 32-bit wire/Bindery layouts on LP64; do not migrate live DBs."""
|
|
from pathlib import Path
|
|
import sys,re
|
|
root=Path(sys.argv[1])
|
|
p=root/'include/emutli.h';s=p.read_text()
|
|
old='typedef unsigned long int uint32;'
|
|
if old in s:s=s.replace(old,'#include <stdint.h>\ntypedef uint32_t uint32; /* MARS_FIXED_WIDTH_V1 */')
|
|
elif 'MARS_FIXED_WIDTH_V1' not in s:raise SystemExit('Unsupported uint32 declaration')
|
|
p.write_text(s)
|
|
# Every long conversion in these sscanf calls targets the legacy uint32 typedef.
|
|
for name in ['emutli.c','emutli1.c','nwserv.c','tools.c']:
|
|
p=root/'src'/name;s=p.read_text()
|
|
pattern=r'(sscanf\s*\([^;]+;)'
|
|
def fix(m):
|
|
call=m.group(0)
|
|
# Only the known IPX/debug parser sites use long formats in this upstream.
|
|
call=call.replace('%lx','%" SCNx32 "').replace('%ld','%" SCNu32 "')
|
|
return call
|
|
s=re.sub(pattern,fix,s)
|
|
if '#include <inttypes.h>' not in s:s='#include <inttypes.h>\n'+s
|
|
p.write_text(s)
|
|
for name in ['nwroute.c','nwdbm.c']:
|
|
p=root/'src'/name;s=p.read_text().replace('%08lX','%08" PRIX32 "')
|
|
if '#include <inttypes.h>' not in s:s='#include <inttypes.h>\n'+s
|
|
p.write_text(s)
|