blob: fa9e6a70ba1a9f63f1f8d19f7b042dd95fde56af [file] [log] [blame]
Eli Bendersky3921e8e2010-05-21 09:05:39 +03001#-----------------------------------------------------------------
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#
eli.bendersky84a6a632011-04-29 09:00:43 +03008# Copyright (C) 2008-2011, Eli Bendersky
9# License: BSD
Eli Bendersky3921e8e2010-05-21 09:05:39 +030010#-----------------------------------------------------------------
11import sys
12
13# This is not required if you've installed pycparser into
14# your site-packages/ with setup.py
15#
16sys.path.insert(0, '..')
17
18# Portable cpp path for Windows and Linux/Unix
19CPPPATH = '../utils/cpp.exe' if sys.platform == 'win32' else 'cpp'
20
21from pycparser import parse_file
22
23
24if __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