-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxfk
executable file
·60 lines (51 loc) · 1.43 KB
/
xfk
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
"""
Conver .bf brainfuck string into font encoded .pdf or vice versa
"""
import sys
from xfuck import brainfuck
from xfuck.bf_to_xf import bf_file_2_pdf
from xfuck.xf2bf import xf2bf
#from pprint import pprint
#from pdfrw import PdfReader
#from xfuck.fonts import get_key
def main(argv):
filepath = ""
if len(argv) >= 1:
a0 = argv[0]
if a0.endswith(".bf"):
print("Brainfuck source file, converting into xfuck-pdf")
r = bf_file_2_pdf(a0)
print("Created result xfuck-pdf: %s" % r)
elif a0.endswith(".pdf"):
#print("PDF source file")
filepath = a0
src = xf2bf(filepath)
if len(argv) >= 2 and argv[1].endswith(".bf"):
with open(argv[1], "w") as f:
f.write(src)
else:
brainfuck.evaluate(src)
else:
print("use: xfk path/to/source.(bf|pdf)")
else:
print("No arguments")
if __name__ == '__main__':
main(sys.argv[1:])
"""
r = PdfReader(sys.argv[1], decompress=True)
key = get_key(r)
keys = list(key.keys())
brainfuck_chars = "><+-.,[]"
src = ""
for p in r.pages:
for token in p.Contents.stream.replace("\n", "").split(" "):
if token not in key:
continue
src += brainfuck_chars[keys.index(token)]
if len(sys.argv) > 2:
skip = int(sys.argv[2])
else:
skip = 0
brainfuck.evaluate(src[skip+8:])
"""