-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathformat_hex2.py
executable file
·33 lines (29 loc) · 1.04 KB
/
format_hex2.py
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
#!/usr/bin/env python3
# format the hex2 output of M1.py --comment which has # to
# comment on the instruction and typically ; comments after
# in the .s knight files we want to format
from sys import stdin, argv
justify_content, justify_first_comment = (int(argv[1]), int(argv[2]))
for line in stdin:
if line[0] in ':#;':
print(line, end='')
elif len(line.strip())==0:
print()
elif '#' in line and ';' in line:
content, comment_section = line.split('#', maxsplit=1 )
first_comment, second_comment = comment_section.split(';', maxsplit=1)
print( "\t%s # %s ; %s" % (
content.strip().ljust(justify_content),
first_comment.strip().ljust(justify_first_comment),
second_comment.strip(),
),
)
elif '#' in line:
content, comment_section = line.split('#', maxsplit=1 )
print( "\t%s # %s" % (
content.strip().ljust(justify_content),
comment_section.strip()
)
)
else:
print(line, end='')