Eli Bendersky | 3921e8e | 2010-05-21 09:05:39 +0300 | [diff] [blame^] | 1 | #----------------------------------------------------------------- |
| 2 | # pycparser: use_cpp_libc.py |
| 3 | # |
| 4 | # Shows how to use the provided 'cpp' (on Windows, substitute for |
| 5 | # the 'real' cpp if you're on Linux/Unix) and "fake" libc includes |
| 6 | # to parse a file that includes standard C headers. |
| 7 | # |
| 8 | # Copyright (C) 2008-2009, Eli Bendersky |
| 9 | # License: LGPL |
| 10 | #----------------------------------------------------------------- |
| 11 | import sys |
| 12 | |
| 13 | # This is not required if you've installed pycparser into |
| 14 | # your site-packages/ with setup.py |
| 15 | # |
| 16 | sys.path.insert(0, '..') |
| 17 | |
| 18 | # Portable cpp path for Windows and Linux/Unix |
| 19 | CPPPATH = '../utils/cpp.exe' if sys.platform == 'win32' else 'cpp' |
| 20 | |
| 21 | from pycparser import parse_file |
| 22 | |
| 23 | |
| 24 | if __name__ == "__main__": |
| 25 | if len(sys.argv) > 1: |
| 26 | filename = sys.argv[1] |
| 27 | else: |
| 28 | filename = 'c_files/year.c' |
| 29 | |
| 30 | ast = parse_file(filename, use_cpp=True, |
| 31 | cpp_path=CPPPATH, |
| 32 | cpp_args=r'-I../utils/fake_libc_include') |
| 33 | |
| 34 | ast.show() |
| 35 | |