File: cmd5.py

package info (click to toggle)
teeworlds 0.5.2-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 12,216 kB
  • ctags: 11,218
  • sloc: ansic: 30,497; cpp: 17,419; python: 2,730; asm: 946; objc: 325; makefile: 22; sh: 6
file content (32 lines) | stat: -rw-r--r-- 788 bytes parent folder | download | duplicates (2)
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
import md5, sys, re
m = md5.new()

alphanum = "0123456789abcdefghijklmnopqrstuvwzyxABCDEFGHIJKLMNOPQRSTUVWXYZ_"

def cstrip(lines):
	d = ""	
	for l in lines:
		l = re.sub("#.*", "", l)
		l = re.sub("//.*", "", l)
		d += l + " "
	d = re.sub("\/\*.*?\*/", "", d) # remove /* */ comments
	d = d.replace("\t", " ") # tab to space
	d = re.sub("  *", " ", d) # remove double spaces
	d = re.sub("", "", d) # remove /* */ comments
	
	d = d.strip()
	
	# this eats up cases like 'n {'
	i = 1
	while i < len(d)-2:
		if d[i] == ' ':
			if not (d[i-1] in alphanum and d[i+1] in alphanum):
				d = d[:i] + d[i+1:]
		i += 1
	return d

f = ""
for filename in sys.argv[1:]:
	f += cstrip([l.strip() for l in file(filename)])

print '#define GAME_NETVERSION_HASH "%s"' % md5.new(f).hexdigest().lower()[16:]