3 from __future__
import print_function
8 for filename
in sys
.argv
[1:]:
9 with
open(filename
, "r") as f
:
12 newguard
= "_" + os
.path
.basename(filename
).upper().replace(".", "_") + "_"
14 for i
, line
in enumerate(lines
):
16 if line
.startswith("#ifndef "):
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
23 while not lines
[end
].strip().startswith("#endif"):
25 lines
[end
] = "#endif // %s\n" % newguard
26 with
open(filename
, "w") as f
:
27 f
.write("".join(lines
))