mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 02:42:55 +00:00
23 lines
682 B
Python
Executable file
23 lines
682 B
Python
Executable file
#!/usr/bin/python
|
|
|
|
import os, re
|
|
|
|
regex = re.compile('(#ifndef (?:.*)_H\n#define .*$)', re.MULTILINE)
|
|
|
|
hppfiles = []
|
|
for root, dirs, files in os.walk(os.curdir):
|
|
for f in files:
|
|
if f.endswith(('.hpp', '.h')):
|
|
hppfiles.append('%s/%s' % (root, f))
|
|
|
|
for hpp in hppfiles:
|
|
hpp = os.path.realpath(hpp)
|
|
with open(hpp, 'r') as f:
|
|
cppcontent = f.read()
|
|
if '#pragma once' in cppcontent:
|
|
continue
|
|
for match in regex.findall(cppcontent):
|
|
with open(hpp, 'w') as f:
|
|
print('adding pragma once to: %s' % hpp)
|
|
cppcontent = cppcontent.replace(match, '#pragma once\n\n%s' % match)
|
|
f.write(cppcontent)
|