added "fixed some header guards and added a script to fix them all!" by Choupom
[twcon.git] / scripts / check_header_guards.py
blobbece10e9cac103b12d2e6bdf2dfbc1889332ad13
1 import os
4 PATH = "../src/"
7 def check_file(filename):
8 file = open(filename)
9 while 1:
10 line = file.readline()
11 if len(line) == 0:
12 break
13 if line[0] == "/" or line[0] == "*" or line[0] == "\r" or line[0] == "\n" or line[0] == "\t":
14 continue
15 if line[:7] == "#ifndef":
16 hg = "#ifndef " + ("_".join(filename.split(PATH)[1].split("/"))[:-2]).upper() + "_H"
17 if line[:-1] != hg:
18 print "Wrong header guard in " + filename
19 else:
20 print "Missing header guard in " + filename
21 break
22 file.close()
26 def check_dir(dir):
27 list = os.listdir(dir)
28 for file in list:
29 if os.path.isdir(dir+file):
30 if file != "external" and file != "generated":
31 check_dir(dir+file+"/")
32 elif file[-2:] == ".h" and file != "keynames.h":
33 check_file(dir+file)
35 check_dir(PATH)