2018-07-06 13:45:05 +00:00
|
|
|
#!/usr/bin/env python3
|
2011-04-13 18:22:10 +00:00
|
|
|
import os
|
2018-07-06 13:45:05 +00:00
|
|
|
import sys
|
2011-04-13 18:22:10 +00:00
|
|
|
|
2018-07-25 07:15:09 +00:00
|
|
|
os.chdir(os.path.dirname(__file__) + "/..")
|
2011-04-13 18:22:10 +00:00
|
|
|
|
2018-07-06 13:45:05 +00:00
|
|
|
PATH = "src/"
|
2018-07-06 14:11:38 +00:00
|
|
|
EXCEPTIONS = [
|
2022-05-06 23:08:51 +00:00
|
|
|
"src/base/unicode/confusables.h",
|
2019-01-07 22:49:20 +00:00
|
|
|
"src/base/unicode/confusables_data.h",
|
2022-05-06 23:08:51 +00:00
|
|
|
"src/base/unicode/tolower.h",
|
2019-01-07 22:49:20 +00:00
|
|
|
"src/base/unicode/tolower_data.h",
|
2018-07-06 14:11:38 +00:00
|
|
|
"src/tools/config_common.h"
|
|
|
|
]
|
2011-04-13 18:22:10 +00:00
|
|
|
|
|
|
|
def check_file(filename):
|
2018-07-06 14:11:38 +00:00
|
|
|
if filename in EXCEPTIONS:
|
|
|
|
return False
|
2018-07-06 13:45:05 +00:00
|
|
|
error = False
|
|
|
|
with open(filename) as file:
|
|
|
|
for line in file:
|
2018-07-06 14:11:38 +00:00
|
|
|
if line == "// This file can be included several times.\n":
|
2018-07-06 13:45:05 +00:00
|
|
|
break
|
|
|
|
if line[0] == "/" or line[0] == "*" or line[0] == "\r" or line[0] == "\n" or line[0] == "\t":
|
|
|
|
continue
|
2022-06-12 10:34:20 +00:00
|
|
|
header_guard = "#ifndef " + ("_".join(filename.split(PATH)[1].split("/"))[:-2]).upper() + "_H"
|
2018-07-06 13:45:05 +00:00
|
|
|
if line.startswith("#ifndef"):
|
2020-12-02 14:22:26 +00:00
|
|
|
if line[:-1] != header_guard:
|
2018-07-06 13:45:05 +00:00
|
|
|
error = True
|
2022-06-12 10:34:20 +00:00
|
|
|
print("Wrong header guard in {}, is: {}, should be: {}".format(filename, line[:-1], header_guard))
|
2018-07-06 13:45:05 +00:00
|
|
|
else:
|
|
|
|
error = True
|
2022-06-12 10:34:20 +00:00
|
|
|
print("Missing header guard in {}, should be: {}".format(filename, header_guard))
|
2011-04-13 18:22:10 +00:00
|
|
|
break
|
2018-07-06 13:45:05 +00:00
|
|
|
return error
|
2011-04-13 18:22:10 +00:00
|
|
|
|
2020-12-02 14:22:26 +00:00
|
|
|
def check_dir(directory):
|
2018-07-06 13:45:05 +00:00
|
|
|
errors = 0
|
2020-12-02 14:22:26 +00:00
|
|
|
file_list = os.listdir(directory)
|
|
|
|
for file in file_list:
|
|
|
|
path = directory + file
|
2018-07-06 13:45:05 +00:00
|
|
|
if os.path.isdir(path):
|
2020-12-02 14:22:26 +00:00
|
|
|
if file not in ("external", "generated"):
|
2018-07-06 13:45:05 +00:00
|
|
|
errors += check_dir(path + "/")
|
|
|
|
elif file.endswith(".h") and file != "keynames.h":
|
|
|
|
errors += check_file(path)
|
|
|
|
return errors
|
2011-04-13 18:22:10 +00:00
|
|
|
|
2018-07-06 13:45:05 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(int(check_dir(PATH) != 0))
|