blob: e9b8a8bf62d92da0966cbccc9fac7226d50201dc [file] [log] [blame]
Eli Bendersky3921e8e2010-05-21 09:05:39 +03001#-----------------------------------------------------------------
Eli Bendersky64782f52014-04-23 16:53:39 -07002# pycparser: using_cpp_libc.py
Eli Bendersky3921e8e2010-05-21 09:05:39 +03003#
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 Bendersky64782f52014-04-23 16:53:39 -07008# Copyright (C) 2008-2014, Eli Bendersky
eli.bendersky84a6a632011-04-29 09:00:43 +03009# 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#
Benf86dea12012-02-03 06:24:55 +020016sys.path.extend(['.', '..'])
Eli Bendersky3921e8e2010-05-21 09:05:39 +030017
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()