summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1995-01-17 17:01:40 (GMT)
committerGuido van Rossum <guido@python.org>1995-01-17 17:01:40 (GMT)
commit514d351d458c519d1f4f6fe645dfc18912d3e209 (patch)
tree645b76f057bca48a38aad6b6d3b61a6456c270af
parent3256e87dbc22f0a5a55d7c7eed0b1a3e42f79690 (diff)
downloadcpython-514d351d458c519d1f4f6fe645dfc18912d3e209.zip
cpython-514d351d458c519d1f4f6fe645dfc18912d3e209.tar.gz
cpython-514d351d458c519d1f4f6fe645dfc18912d3e209.tar.bz2
use $INCLUDE path (Mark Hammond)
-rwxr-xr-xTools/scripts/h2py.py33
1 files changed, 26 insertions, 7 deletions
diff --git a/Tools/scripts/h2py.py b/Tools/scripts/h2py.py
index db0dbd8..4cea235 100755
--- a/Tools/scripts/h2py.py
+++ b/Tools/scripts/h2py.py
@@ -38,6 +38,14 @@ p_char = regex.compile("'\(\\\\.[^\\\\]*\|[^\\\\]\)'")
filedict = {}
+try:
+ searchdirs=string.splitfields(os.environ['include'],';')
+except KeyError:
+ try:
+ searchdirs=string.splitfields(os.environ['INCLUDE'],';')
+ except KeyError:
+ searchdirs=['/usr/include']
+
def main():
opts, args = getopt.getopt(sys.argv[1:], 'i:')
for o, a in opts:
@@ -59,8 +67,10 @@ def main():
outfp = open(outfile, 'w')
outfp.write('# Generated by h2py from %s\n' % filename)
filedict = {}
- if filename[:13] == '/usr/include/':
- filedict[filename[13:]] = None
+ for dir in searchdirs:
+ if filename[:len(dir)] == dir:
+ filedict[filename[len(dir)+1:]] = None # no '/' trailing
+ break
process(fp, outfp)
outfp.close()
fp.close()
@@ -114,9 +124,18 @@ def process(fp, outfp, env = {}):
filename = line[a:b]
if not filedict.has_key(filename):
filedict[filename] = None
- outfp.write(
- '\n# Included from %s\n' % filename)
- inclfp = open('/usr/include/' + filename, 'r')
- process(inclfp, outfp, env)
-main()
+ inclfp = None
+ for dir in searchdirs:
+ try:
+ inclfp = open(dir + '/' + filename, 'r')
+ break
+ except IOError:
+ pass
+ if inclfp:
+ outfp.write(
+ '\n# Included from %s\n' % filename)
+ process(inclfp, outfp, env)
+ else:
+ sys.stderr.write('Warning - could not find file %s' % filename)
+main()