xref: /freebsd/contrib/cortex-strings/scripts/fixup.py (revision 5dae51da3da0cc94d17bd67b308fad304ebec7e0)
1"""Simple script that enables target specific blocks based on the first argument.
2
3Matches comment blocks like this:
4
5/* For Foo: abc
6def
7*/
8
9and de-comments them giving:
10abc
11def
12"""
13import re
14import sys
15
16def main():
17    key = sys.argv[1]
18    expr = re.compile(r'/\* For %s:\s([^*]+)\*/' % key, re.M)
19
20    for arg in sys.argv[2:]:
21        with open(arg) as f:
22            body = f.read()
23        with open(arg, 'w') as f:
24            f.write(expr.sub(r'\1', body))
25
26if __name__ == '__main__':
27    main()
28