File: check_header_guards.py

package info (click to toggle)
teeworlds 0.6.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,020 kB
  • ctags: 6,997
  • sloc: cpp: 42,825; python: 3,527; ansic: 3,016; objc: 328; makefile: 52; sh: 6
file content (35 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (7)
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
33
34
35
import os


PATH = "../src/"


def check_file(filename):
	file = open(filename)
	while 1:
		line = file.readline()
		if len(line) == 0:
			break
		if line[0] == "/" or line[0] == "*" or line[0] == "\r" or line[0] == "\n" or line[0] == "\t":
			continue
		if line[:7] == "#ifndef":
			hg = "#ifndef " + ("_".join(filename.split(PATH)[1].split("/"))[:-2]).upper() + "_H"
			if line[:-1] != hg:
				print "Wrong header guard in " + filename
		else:
			print "Missing header guard in " + filename
		break
	file.close()



def check_dir(dir):
	list = os.listdir(dir)
	for file in list:
		if os.path.isdir(dir+file):
			if file != "external" and file != "generated":
				check_dir(dir+file+"/")
		elif file[-2:] == ".h" and file != "keynames.h":
			check_file(dir+file)

check_dir(PATH)