2009-06-07 14:40:58 +00:00
|
|
|
import hashlib, sys, re
|
2007-08-22 21:13:33 +00:00
|
|
|
|
2011-02-06 18:18:31 +00:00
|
|
|
alphanum = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_".encode()
|
2007-08-22 21:13:33 +00:00
|
|
|
|
|
|
|
def cstrip(lines):
|
2011-01-29 17:55:21 +00:00
|
|
|
d = "".encode()
|
2007-08-22 21:13:33 +00:00
|
|
|
for l in lines:
|
2011-01-29 17:55:21 +00:00
|
|
|
l = re.sub("#.*".encode(), "".encode(), l)
|
|
|
|
l = re.sub("//.*".encode(), "".encode(), l)
|
|
|
|
d += l + " ".encode()
|
|
|
|
d = re.sub("\/\*.*?\*/".encode(), "".encode(), d) # remove /* */ comments
|
|
|
|
d = d.replace("\t".encode(), " ".encode()) # tab to space
|
|
|
|
d = re.sub(" *".encode(), " ".encode(), d) # remove double spaces
|
|
|
|
d = re.sub("".encode(), "".encode(), d) # remove /* */ comments
|
2011-02-06 18:18:31 +00:00
|
|
|
|
2007-08-22 21:13:33 +00:00
|
|
|
d = d.strip()
|
2011-02-06 18:18:31 +00:00
|
|
|
|
2007-08-22 21:13:33 +00:00
|
|
|
# this eats up cases like 'n {'
|
|
|
|
i = 1
|
|
|
|
while i < len(d)-2:
|
2011-02-06 18:18:31 +00:00
|
|
|
if d[i:i + 1] == " ".encode():
|
|
|
|
if not (d[i - 1:i] in alphanum and d[i+1:i + 2] in alphanum):
|
|
|
|
d = d[:i] + d[i + 1:]
|
2007-08-22 21:13:33 +00:00
|
|
|
i += 1
|
|
|
|
return d
|
|
|
|
|
2011-01-29 17:55:21 +00:00
|
|
|
f = "".encode()
|
2007-08-22 21:13:33 +00:00
|
|
|
for filename in sys.argv[1:]:
|
2011-01-06 11:41:24 +00:00
|
|
|
f += cstrip([l.strip() for l in open(filename, "rb")])
|
2007-08-22 21:13:33 +00:00
|
|
|
|
2011-01-29 17:55:21 +00:00
|
|
|
hash = hashlib.md5(f).hexdigest().lower()[16:]
|
2011-04-13 18:00:54 +00:00
|
|
|
#TODO 0.7: improve nethash creation
|
2011-04-13 18:48:50 +00:00
|
|
|
if hash == "6e28a475de43adfd":
|
2011-04-13 18:00:54 +00:00
|
|
|
hash = "626fce9a778df4d4"
|
2011-01-05 23:51:31 +00:00
|
|
|
print('#define GAME_NETVERSION_HASH "%s"' % hash)
|