Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2025-08-09 08:19:08

0001 #!/usr/bin/env python
0002 #
0003 # Copyright 2007 Neal Norwitz
0004 # Portions Copyright 2007 Google Inc.
0005 #
0006 # Licensed under the Apache License, Version 2.0 (the "License");
0007 # you may not use this file except in compliance with the License.
0008 # You may obtain a copy of the License at
0009 #
0010 #      http://www.apache.org/licenses/LICENSE-2.0
0011 #
0012 # Unless required by applicable law or agreed to in writing, software
0013 # distributed under the License is distributed on an "AS IS" BASIS,
0014 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015 # See the License for the specific language governing permissions and
0016 # limitations under the License.
0017 
0018 """Generic utilities for C++ parsing."""
0019 
0020 __author__ = 'nnorwitz@google.com (Neal Norwitz)'
0021 
0022 
0023 import sys
0024 
0025 
0026 # Set to True to see the start/end token indices.
0027 DEBUG = True
0028 
0029 
0030 def ReadFile(filename, print_error=True):
0031     """Returns the contents of a file."""
0032     try:
0033         fp = open(filename)
0034         try:
0035             return fp.read()
0036         finally:
0037             fp.close()
0038     except IOError:
0039         if print_error:
0040             print('Error reading %s: %s' % (filename, sys.exc_info()[1]))
0041         return None