File indexing completed on 2024-11-10 04:30:25
0001 #1 is generate_fishcode.py 0002 #2 is md5sum 0003 #3 is the output file 0004 #4 are the parameters for cut 0005 import sys 0006 import re 0007 import hashlib 0008 0009 fp = open(sys.argv[1], "rb") 0010 r = fp.read() 0011 fp.close() 0012 0013 m = hashlib.md5() 0014 m.update(r) 0015 sm = m.hexdigest() 0016 0017 fp = open(sys.argv[1], "r") 0018 r = fp.read() 0019 fp.close() 0020 0021 fp = open(sys.argv[3], "w") 0022 fp.write('#define CHECKSUM "%s"\n' % sm) 0023 fp.write('static const char *fishCode(\n') 0024 0025 r = re.sub(r'\\', r'\\\\', r) 0026 r = re.sub(r'"', r'\\"', r) 0027 p = re.compile('^[ ]*', re.M) 0028 r = p.sub('"', r) 0029 p = re.compile(r'^"# .*\n*', re.M) 0030 r = p.sub('', r) 0031 p = re.compile('[ ]*$', re.M) 0032 r = p.sub(r'\\n"', r) 0033 p = re.compile(r'^"\\n"\n?', re.M) 0034 r = p.sub('', r) 0035 r = re.sub(r'{CHECKSUM}', sm, r, 1) 0036 fp.write(r + ");\n") 0037 fp.close()