fixed clipping on some machines
[twcon.git] / scripts / cmd5.py
blob07e35bb18dbcc195cdf94f53af33d94882922b7c
1 import hashlib, sys, re
3 alphanum = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_".encode()
5 def cstrip(lines):
6 d = "".encode()
7 for l in lines:
8 l = re.sub("#.*".encode(), "".encode(), l)
9 l = re.sub("//.*".encode(), "".encode(), l)
10 d += l + " ".encode()
11 d = re.sub("\/\*.*?\*/".encode(), "".encode(), d) # remove /* */ comments
12 d = d.replace("\t".encode(), " ".encode()) # tab to space
13 d = re.sub(" *".encode(), " ".encode(), d) # remove double spaces
14 d = re.sub("".encode(), "".encode(), d) # remove /* */ comments
16 d = d.strip()
18 # this eats up cases like 'n {'
19 i = 1
20 while i < len(d)-2:
21 if d[i:i + 1] == " ".encode():
22 if not (d[i - 1:i] in alphanum and d[i+1:i + 2] in alphanum):
23 d = d[:i] + d[i + 1:]
24 i += 1
25 return d
27 f = "".encode()
28 for filename in sys.argv[1:]:
29 f += cstrip([l.strip() for l in open(filename, "rb")])
31 hash = hashlib.md5(f).hexdigest().lower()[16:]
32 #TODO 0.7: improve nethash creation
33 if hash == "71de0f4d82688970":
34 hash = "626fce9a778df4d4"
35 print('#define GAME_NETVERSION_HASH "%s"' % hash)