ddnet/scripts/cmd5.py
GreYFoX 35d16bd58c Merge branch 'master' of git://github.com/oy/teeworlds into DDRace0611
Conflicts:
	src/engine/console.h
	src/engine/server.h
	src/engine/server/server.cpp
	src/engine/shared/config_variables.h
	src/engine/shared/console.cpp
	src/engine/shared/console.h
	src/engine/shared/network_server.cpp
	src/game/client/components/console.cpp
	src/game/client/components/console.h
	src/game/client/components/menus_browser.cpp
	src/game/client/gameclient.cpp
	src/game/editor/editor.cpp
	src/game/editor/editor.h
	src/game/editor/io.cpp
	src/game/editor/layer_tiles.cpp
	src/game/editor/popups.cpp
	src/game/gamecore.cpp
	src/game/mapitems.h
	src/game/server/entities/character.cpp
	src/game/server/entities/laser.cpp
	src/game/server/gamecontext.cpp
	src/game/server/gamecontroller.cpp
	src/game/server/gamecontroller.h
	src/game/server/gamemodes/ctf.cpp
	src/game/server/player.cpp
	src/game/variables.h
2011-08-13 02:01:40 +02:00

37 lines
1.1 KiB
Python

import hashlib, sys, re, os
alphanum = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_".encode()
def cstrip(lines):
d = "".encode()
for l in lines:
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
d = d.strip()
# this eats up cases like 'n {'
i = 1
while i < len(d)-2:
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:]
i += 1
return d
f = "".encode()
for filename in sys.argv[1:]:
f += cstrip([l.strip() for l in open(filename, "rb")])
hash = hashlib.md5(f).hexdigest().lower()[16:]
#TODO 0.7: improve nethash creation
if hash == "3dc531e4296de555":
hash = "626fce9a778df4d4"
print('#define GAME_NETVERSION_HASH "%s"' % hash)
print('#define GIT_SHORTREV_HASH "%s"' % os.popen('git rev-parse HEAD').readline(8))