summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorEli Bendersky <eliben@gmail.com>2015-04-21 14:42:56 -0700
committerEli Bendersky <eliben@gmail.com>2015-04-21 14:42:56 -0700
commit331f81f994b3447be17fa93040f6713c02949ec8 (patch)
tree3e55669ac9ef9e0b3e843067717c9b589d451d38 /examples
parentb17da15ad70e0062019f6f9a78406410313184e8 (diff)
downloadpycparser-331f81f994b3447be17fa93040f6713c02949ec8.tar.gz
Fix up examples to run properly from the main source dir
Diffstat (limited to 'examples')
-rw-r--r--examples/func_calls.py8
-rw-r--r--examples/func_defs.py7
-rw-r--r--examples/using_cpp_libc.py8
-rw-r--r--examples/using_gcc_E_libc.py6
4 files changed, 12 insertions, 17 deletions
diff --git a/examples/func_calls.py b/examples/func_calls.py
index f56f153..72c64d3 100644
--- a/examples/func_calls.py
+++ b/examples/func_calls.py
@@ -4,7 +4,7 @@
# Using pycparser for printing out all the calls of some function
# in a C file.
#
-# Copyright (C) 2008-2011, Eli Bendersky
+# Copyright (C) 2008-2015, Eli Bendersky
# License: BSD
#-----------------------------------------------------------------
from __future__ import print_function
@@ -12,7 +12,6 @@ import sys
# This is not required if you've installed pycparser into
# your site-packages/ with setup.py
-#
sys.path.extend(['.', '..'])
from pycparser import c_parser, c_ast, parse_file
@@ -27,8 +26,7 @@ class FuncCallVisitor(c_ast.NodeVisitor):
def visit_FuncCall(self, node):
if node.name.name == self.funcname:
- print('%s called at %s' % (
- self.funcname, node.name.coord))
+ print('%s called at %s' % (self.funcname, node.name.coord))
def show_func_calls(filename, funcname):
@@ -42,7 +40,7 @@ if __name__ == "__main__":
filename = sys.argv[1]
func = sys.argv[2]
else:
- filename = 'c_files/hash.c'
+ filename = 'examples/c_files/hash.c'
func = 'malloc'
show_func_calls(filename, func)
diff --git a/examples/func_defs.py b/examples/func_defs.py
index 6cc5084..eacca41 100644
--- a/examples/func_defs.py
+++ b/examples/func_defs.py
@@ -7,7 +7,7 @@
# This is a simple example of traversing the AST generated by
# pycparser.
#
-# Copyright (C) 2008-2011, Eli Bendersky
+# Copyright (C) 2008-2015, Eli Bendersky
# License: BSD
#-----------------------------------------------------------------
from __future__ import print_function
@@ -15,7 +15,6 @@ import sys
# This is not required if you've installed pycparser into
# your site-packages/ with setup.py
-#
sys.path.extend(['.', '..'])
from pycparser import c_parser, c_ast, parse_file
@@ -23,7 +22,6 @@ from pycparser import c_parser, c_ast, parse_file
# A simple visitor for FuncDef nodes that prints the names and
# locations of function definitions.
-#
class FuncDefVisitor(c_ast.NodeVisitor):
def visit_FuncDef(self, node):
print('%s at %s' % (node.decl.name, node.decl.coord))
@@ -32,7 +30,6 @@ class FuncDefVisitor(c_ast.NodeVisitor):
def show_func_defs(filename):
# Note that cpp is used. Provide a path to your own cpp or
# make sure one exists in PATH.
- #
ast = parse_file(filename, use_cpp=True)
v = FuncDefVisitor()
@@ -43,6 +40,6 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
- filename = 'c_files/memmgr.c'
+ filename = 'examples/c_files/memmgr.c'
show_func_defs(filename)
diff --git a/examples/using_cpp_libc.py b/examples/using_cpp_libc.py
index e9b8a8b..89ca68c 100644
--- a/examples/using_cpp_libc.py
+++ b/examples/using_cpp_libc.py
@@ -5,7 +5,7 @@
# the 'real' cpp if you're on Linux/Unix) and "fake" libc includes
# to parse a file that includes standard C headers.
#
-# Copyright (C) 2008-2014, Eli Bendersky
+# Copyright (C) 2008-2015, Eli Bendersky
# License: BSD
#-----------------------------------------------------------------
import sys
@@ -16,7 +16,7 @@ import sys
sys.path.extend(['.', '..'])
# Portable cpp path for Windows and Linux/Unix
-CPPPATH = '../utils/cpp.exe' if sys.platform == 'win32' else 'cpp'
+CPPPATH = 'utils/cpp.exe' if sys.platform == 'win32' else 'cpp'
from pycparser import parse_file
@@ -25,10 +25,10 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
- filename = 'c_files/year.c'
+ filename = 'examples/c_files/year.c'
ast = parse_file(filename, use_cpp=True,
cpp_path=CPPPATH,
- cpp_args=r'-I../utils/fake_libc_include')
+ cpp_args=r'-Iutils/fake_libc_include')
ast.show()
diff --git a/examples/using_gcc_E_libc.py b/examples/using_gcc_E_libc.py
index 5e9c61a..789c0c3 100644
--- a/examples/using_gcc_E_libc.py
+++ b/examples/using_gcc_E_libc.py
@@ -5,7 +5,7 @@
# of 'cpp'. The same can be achieved with Clang instead of gcc. If you have
# Clang installed, simply replace 'gcc' with 'clang' here.
#
-# Copyright (C) 2008-2014, Eli Bendersky
+# Copyright (C) 2008-2015, Eli Bendersky
# License: BSD
#-------------------------------------------------------------------------------
import sys
@@ -22,10 +22,10 @@ if __name__ == "__main__":
if len(sys.argv) > 1:
filename = sys.argv[1]
else:
- filename = 'c_files/year.c'
+ filename = 'examples/c_files/year.c'
ast = parse_file(filename, use_cpp=True,
cpp_path='gcc',
- cpp_args=['-E', r'-I../utils/fake_libc_include'])
+ cpp_args=['-E', r'-Iutils/fake_libc_include'])
ast.show()