Maxim mbed development library
tools/misc/find_c_includes.py@0:0e018d759a2a, 2016-11-08 (annotated)
- Committer:
- switches
- Date:
- Tue Nov 08 18:27:11 2016 +0000
- Revision:
- 0:0e018d759a2a
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
switches | 0:0e018d759a2a | 1 | #!/usr/bin/env python |
switches | 0:0e018d759a2a | 2 | |
switches | 0:0e018d759a2a | 3 | import os |
switches | 0:0e018d759a2a | 4 | import re |
switches | 0:0e018d759a2a | 5 | |
switches | 0:0e018d759a2a | 6 | def main(path='.', pattern=r'#include\s+"([^"]*\.(?:c|cpp))"'): |
switches | 0:0e018d759a2a | 7 | pattern = re.compile(pattern) |
switches | 0:0e018d759a2a | 8 | |
switches | 0:0e018d759a2a | 9 | for root, dirs, files in os.walk(path, followlinks=True): |
switches | 0:0e018d759a2a | 10 | for file in files: |
switches | 0:0e018d759a2a | 11 | with open(os.path.join(root, file)) as f: |
switches | 0:0e018d759a2a | 12 | for line in f.read().splitlines(): |
switches | 0:0e018d759a2a | 13 | m = re.search(pattern, line) |
switches | 0:0e018d759a2a | 14 | if m: |
switches | 0:0e018d759a2a | 15 | print os.path.relpath(os.path.join(root, m.group(1))) |
switches | 0:0e018d759a2a | 16 | |
switches | 0:0e018d759a2a | 17 | |
switches | 0:0e018d759a2a | 18 | if __name__ == "__main__": |
switches | 0:0e018d759a2a | 19 | import sys |
switches | 0:0e018d759a2a | 20 | main(*sys.argv[1:]) |
switches | 0:0e018d759a2a | 21 |