import os dryRun = False failed = 0 def refactorLine(line): global failed # first check, ONE "node" is used, and ONE array access after it if line.count("node[") != 1 or line.split("node[")[1].count("]->") != 1: if "node[" in line and "]->" in line: failed += 1 if dryRun: print(line.strip()) return line #end # second check, a method is called if not ")" in line.split("node[")[1]: return line # break line ("begin"+node[index]->+"end") t1 = line.split("node[") begin = t1[0] t2 = t1[1].split("]->") index = t2[0] end = t2[1] begin += "nodes->" # function t3 = end.split("(",1) begin += t3[0]+"("+index if t3[1].startswith(")"): begin += t3[1] else: begin += ", "+t3[1]; #end return begin #end def refactorFile(name): file = open(name) lines = file.readlines() file.close(); newLines = [] for line in lines: newLines.append(refactorLine(line)) #end if dryRun: return file = open(name,"w") file.writelines(newLines) file.close(); #end for root, dirs, files in os.walk("."): if "externals" in root: continue for name in files: if name.endswith(".hpp") or name.endswith(".cpp") or name.endswith(".inl"): refactorFile(os.path.join(root,name)) #end #end #end