Created
June 10, 2019 08:43
-
-
Save marxin/945c7bc01fe375141526284031e85db6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import os | |
import re | |
""" | |
Transform: | |
#define LDAP_CONTROL_VLVRESPONSE_W (const WCHAR []){'2','.','1','6','.', \ | |
'8','4','0','.','1','.','1','1','3','7','3','0','.','3','.','4','.','1','0',0} | |
into: | |
static const WCHAR LDAP_CONTROL_VLVRESPONSE_W[] = {'2','.','1','6','.', \ | |
'8','4','0','.','1','.','1','1','3','7','3','0','.','3','.','4','.','1','0',0}; | |
""" | |
r = re.compile('^#\s*define\s*([^\s]*)\s*\(const WCHAR\s*\[\]\)') | |
for root, dirs, files in os.walk('.'): | |
for f in files: | |
if f.endswith('.h'): | |
p = os.path.join(root, f) | |
lines = list(open(p).readlines()) | |
for i, l in enumerate(lines): | |
l = l.strip() | |
m = r.match(l) | |
if m != None: | |
start = m.start(0) | |
end = m.end(0) | |
newl = 'static const WCHAR ' + m.group(1) + '[] = ' + l[end:] | |
print(newl) | |
if l.endswith('}'): | |
newl += ';\n' | |
else: | |
newl += '\n' | |
c = 1 | |
while True: | |
l2 = lines[i + c].strip() | |
if l2.endswith('}'): | |
lines[i + c] = l2 + ';\n' | |
break | |
c += 1 | |
lines[i] = newl | |
with open(p, 'w') as f: | |
for l in lines: | |
f.write(l) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment