Fixed: compilation if SIMU_DISKIO = ON (#5723)
[opentx.git] / tools / include-guard.py
blob5a60f6b270592d47fdef2207663900cefc4120d4
1 #!/usr/bin/env python
3 from __future__ import print_function
5 import sys
6 import os
8 for filename in sys.argv[1:]:
9 with open(filename, "r") as f:
10 lines = f.readlines()
12 newguard = "_" + os.path.basename(filename).upper().replace(".", "_") + "_"
14 for i, line in enumerate(lines):
15 line = line.strip()
16 if line.startswith("#ifndef "):
17 guard = line[8:]
18 if lines[i + 1].strip() == "#define %s" % guard:
19 print(filename, ":", guard, "=>", newguard)
20 lines[i] = "#ifndef %s\n" % newguard
21 lines[i + 1] = "#define %s\n" % newguard
22 end = -1
23 while not lines[end].strip().startswith("#endif"):
24 end -= 1
25 lines[end] = "#endif // %s\n" % newguard
26 with open(filename, "w") as f:
27 f.write("".join(lines))
28 break