prefix_replace.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # this can be used to upgrade disassemblies that aren't too annotated.
  2. # won't do very well on the current zelda disasm.
  3. import os
  4. import sys
  5. def GetPrefixLine(l, a):
  6. for s in a:
  7. if s[0:len(l)] == l:
  8. return s
  9. return ""
  10. def GetComment(l):
  11. comment_start = l.find("//")
  12. if comment_start < 0:
  13. comment_start = l.find("->")
  14. if comment_start < 0:
  15. return ""
  16. while (l[comment_start-1] == ' ') or (l[comment_start-1] == '\t'):
  17. comment_start -= 1
  18. return l[comment_start:]
  19. def main():
  20. old_lines = open("DSP_UC_Zelda.txt", "r").readlines()
  21. # for l in old_lines:
  22. # print l
  23. new_lines = open("zeldanew.txt", "r").readlines()
  24. for i in range(0, len(old_lines)):
  25. prefix = old_lines[i][0:14]
  26. comment = GetComment(old_lines[i])
  27. new_line = GetPrefixLine(prefix, new_lines)
  28. if new_line:
  29. old_lines[i] = new_line[:-1] + comment[:-1] + "\n"
  30. for i in range(0, len(old_lines)):
  31. print old_lines[i],
  32. new_file = open("output.txt", "w")
  33. new_file.writelines(old_lines)
  34. main()