summaryrefslogtreecommitdiff
path: root/docs/DSP/prefix_replace.py
blob: 5c2c80f11a793db7ef96e5b6a9ecd242f28598d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# this can be used to upgrade disassemblies that aren't too annotated.
# won't do very well on the current zelda disasm.

import os
import sys

def GetPrefixLine(l, a):
  for s in a:
    if s[0:len(l)] == l:
      return s
  return ""
  
def GetComment(l):
  comment_start = l.find("//")
  if comment_start < 0:
    comment_start = l.find("->")
  if comment_start < 0:
    return ""
  
  while (l[comment_start-1] == ' ') or (l[comment_start-1] == '\t'):
    comment_start -= 1
    
  return l[comment_start:]


def main():
  old_lines = open("DSP_UC_Zelda.txt", "r").readlines()
  # for l in old_lines:
  #  print l
  new_lines = open("zeldanew.txt", "r").readlines()
  
  for i in range(0, len(old_lines)):
    prefix = old_lines[i][0:14]
    comment = GetComment(old_lines[i])
    new_line = GetPrefixLine(prefix, new_lines)
    if new_line:
      old_lines[i] = new_line[:-1] + comment[:-1] + "\n"
  
  for i in range(0, len(old_lines)):
    print old_lines[i],
   
  new_file = open("output.txt", "w")
  new_file.writelines(old_lines)
  
main()