• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#-----------------------------------------------------------------
2# pycparser: using_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# Eli Bendersky [https://eli.thegreenplace.net/]
9# License: BSD
10#-----------------------------------------------------------------
11import sys
12
13# This is not required if you've installed pycparser into
14# your site-packages/ with setup.py
15#
16sys.path.extend(['.', '..'])
17
18from pycparser import parse_file
19
20
21if __name__ == "__main__":
22    if len(sys.argv) > 1:
23        filename  = sys.argv[1]
24    else:
25        filename = 'examples/c_files/year.c'
26
27    ast = parse_file(filename, use_cpp=True,
28            cpp_path='cpp',
29            cpp_args=r'-Iutils/fake_libc_include')
30    ast.show()
31