| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
import os |
| 5 |
import sys |
| 6 |
|
| 7 |
def GetPrefixLine(l, a): |
| 8 |
for s in a: |
| 9 |
if s[0:len(l)] == l: |
| 10 |
return s |
| 11 |
return "" |
| 12 |
|
| 13 |
def GetComment(l): |
| 14 |
comment_start = l.find("//") |
| 15 |
if comment_start < 0: |
| 16 |
comment_start = l.find("->") |
| 17 |
if comment_start < 0: |
| 18 |
return "" |
| 19 |
|
| 20 |
while (l[comment_start-1] == ' ') or (l[comment_start-1] == '\t'): |
| 21 |
comment_start -= 1 |
| 22 |
|
| 23 |
return l[comment_start:] |
| 24 |
|
| 25 |
|
| 26 |
def main(): |
| 27 |
old_lines = open("DSP_UC_Zelda.txt", "r").readlines() |
| 28 |
|
| 29 |
|
| 30 |
new_lines = open("zeldanew.txt", "r").readlines() |
| 31 |
|
| 32 |
for i in range(0, len(old_lines)): |
| 33 |
prefix = old_lines[i][0:14] |
| 34 |
comment = GetComment(old_lines[i]) |
| 35 |
new_line = GetPrefixLine(prefix, new_lines) |
| 36 |
if new_line: |
| 37 |
old_lines[i] = new_line[:-1] + comment[:-1] + "\n" |
| 38 |
|
| 39 |
for i in range(0, len(old_lines)): |
| 40 |
print old_lines[i], |
| 41 |
|
| 42 |
new_file = open("output.txt", "w") |
| 43 |
new_file.writelines(old_lines) |
| 44 |
|
| 45 |
main() |