2019-05-13 21:54:14 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2019-06-07 13:52:33 +00:00
|
|
|
import os, re
|
2019-05-13 21:54:14 +00:00
|
|
|
|
2019-06-01 14:29:41 +00:00
|
|
|
regex = re.compile('(#ifndef (?:.*)_H\n#define .*$)', re.MULTILINE)
|
2019-05-13 21:54:14 +00:00
|
|
|
|
2019-06-07 13:52:33 +00:00
|
|
|
hppfiles = []
|
2019-05-13 21:54:14 +00:00
|
|
|
for root, dirs, files in os.walk(os.curdir):
|
|
|
|
for f in files:
|
|
|
|
if f.endswith(('.hpp', '.h')):
|
2019-06-07 13:52:33 +00:00
|
|
|
hppfiles.append('%s/%s' % (root, f))
|
2019-05-13 21:54:14 +00:00
|
|
|
|
2019-06-07 13:52:33 +00:00
|
|
|
for hpp in hppfiles:
|
|
|
|
hpp = os.path.realpath(hpp)
|
|
|
|
with open(hpp, 'r') as f:
|
2019-05-13 21:54:14 +00:00
|
|
|
cppcontent = f.read()
|
|
|
|
if '#pragma once' in cppcontent:
|
|
|
|
continue
|
2019-06-01 14:29:41 +00:00
|
|
|
for match in regex.findall(cppcontent):
|
2019-06-07 13:52:33 +00:00
|
|
|
with open(hpp, 'w') as f:
|
|
|
|
print('adding pragma once to: %s' % hpp)
|
2019-05-13 21:54:14 +00:00
|
|
|
cppcontent = cppcontent.replace(match, '#pragma once\n\n%s' % match)
|
|
|
|
f.write(cppcontent)
|