-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathok.py
58 lines (52 loc) · 1.41 KB
/
ok.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys,getopt
import modules.brainfuckModule.brainfuck as brainfuck
ENCODE = {
'.?':'>', '?.':'<',
'..':'+', '!!':'-',
'!.':'.', '.!':',',
'!?':'[', '?!':']'
}
def readFromFile(filePath):
result = ''
try:
with open(filePath,'r') as f:
resultArr = f.readlines()
result = ''.join(resultArr)
except Exception as e:
print 'filePath illegal'
result = ''
return result
def convert(oriStrings):
res = [x for x in oriStrings if x=='!' or x=='.' or x=='?']
resStr = ''.join(res)
brainfuckArr = []
for i in range(0,len(resStr),2):
# print resStr[i:i+2]
val = ENCODE.get(resStr[i:i+2], None)
if val:
brainfuckArr.append(val)
else:
print 'convertwith illegal charter'
break
brainfuckStr = ''.join(brainfuckArr)
print brainfuckStr
brainfuck.evaluate(brainfuckStr)
# print brainfuckStr
if __name__ == '__main__':
opts, args = getopt.getopt(sys.argv[1:], 'f:i:')
filePath = ''
oriStrings = ''
num = 10
for op, value in opts:
if op=='-f':
filePath = value
elif op == '-i':
oriStrings = value
if len(filePath)>0:
oriStrings = readFromFile(filePath)
if len(oriStrings)>0:
convert(oriStrings)
else:
print 'stringbuffer none'