-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_min.py
41 lines (31 loc) · 1.04 KB
/
create_min.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
34
35
36
37
38
39
40
41
import re
if '__main__' == __name__:
re_comment = re.compile(r"^(.*);.*$")
re_newline = re.compile(r"^(.*)\n$")
re_whitespace = re.compile(r"^\s*$")
def process_line(line):
m = re_comment.match(line)
if m:
line = m.groups(1)[0]
m = re_newline.match(line)
if m:
line = m.groups(1)[0]
line = line.rstrip()
if re_whitespace.match(line):
return None
else: return line
with open('./quine.s', 'r') as fin:
all_lines = [y for y in [process_line(x) for x in fin] if y is not None]
with open('./quine.min.s', 'w') as fout:
for line in all_lines:
fout.write(line + '\n')
first_line = True
for line in all_lines:
if first_line:
fout.write(" ")
first_line = False
else:
fout.write(" , ")
line = line.replace("\"", "\", 0x22, \"")
fout.write("\"" + line + "\", 0x0A \\\n")
fout.write(" , 0x00\n")