import re,sys,os,collections sh,g,out=sys.argv[1:4]; os.makedirs(out,exist_ok=True) origin={}; owner={'CultMath.hlsl':'core','CultMath.Interval.hlsl':'core','CultMath.Affine.hlsl':'core','CultMath.Cycles.hlsl':'cycles','CultMath.Phacelle.hlsl':'phacelle'} for fn,o in owner.items(): t=open(os.path.join(sh,fn)).read() for m in re.finditer(r'(?m)^(?:export\s+)?\w+\s+(cultmath_\w+)\s*\(',t): origin.setdefault(m.group(1),o) for m in re.finditer(r'(?m)^struct\s+(\w+)',t): origin.setdefault(m.group(1),o) text=open(g).read() # top-level chunks: struct blocks and function definitions; everything else is prologue lines=text.split('\n'); chunks=[]; i=0; pro=[] while i1][:6]) for o,b in files.items(): open(os.path.join(out,o+'.glsl'),'w').write('\n'.join(b)+'\n') print('split sizes', {o:len('\n'.join(b).split('\n')) for o,b in files.items()})