3 # Copyright Hans Dembinski 2019
4 # Distributed under the Boost Software License, Version 1.0.
5 # See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt
8 from os.path import abspath, join
12 project_dir = "/".join(abspath(__file__).split("/")[:-2])
14 filename = abspath(sys.argv[1])
16 copyright = """// Copyright Hans Dembinski {}
18 // Distributed under the Boost Software License, Version 1.0.
19 // (See accompanying file LICENSE_1_0.txt
20 // or copy at http://www.boost.org/LICENSE_1_0.txt)
22 """.format(datetime.datetime.today().year)
24 if filename.endswith(".hpp"):
25 with open(filename) as f:
27 if not content.startswith("// Copyright"):
28 content = copyright + content
30 sub = filename[len(project_dir) + 1:]
31 if sub.startswith("include/boost/"):
32 sub = sub[len("include/boost/"):]
33 if sub.startswith("test/"):
34 sub = "histogram/" + sub
35 guard_name = "BOOST_" + sub.replace(".", "_").replace("/", "_").upper()
37 if guard_name not in content:
38 lines = content.split("\n")
39 for end, line in enumerate(lines):
40 if line.startswith("//"):
43 for start in range(end, len(lines)):
44 if lines[start] != "":
46 lines = lines[:end] + ["", "#ifndef " + guard_name, "#define " + guard_name, ""] + lines[start:]
47 while lines[-1] == "":
49 lines += ["", "#endif // " + guard_name, ""]
50 content = "\n".join(lines)
52 with open(filename, "w") as f: