Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 514d351

Browse files
committed
use $INCLUDE path (Mark Hammond)
1 parent 3256e87 commit 514d351

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

Tools/scripts/h2py.py

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838

3939
filedict = {}
4040

41+
try:
42+
searchdirs=string.splitfields(os.environ['include'],';')
43+
except KeyError:
44+
try:
45+
searchdirs=string.splitfields(os.environ['INCLUDE'],';')
46+
except KeyError:
47+
searchdirs=['/usr/include']
48+
4149
def main():
4250
opts, args = getopt.getopt(sys.argv[1:], 'i:')
4351
for o, a in opts:
@@ -59,8 +67,10 @@ def main():
5967
outfp = open(outfile, 'w')
6068
outfp.write('# Generated by h2py from %s\n' % filename)
6169
filedict = {}
62-
if filename[:13] == '/usr/include/':
63-
filedict[filename[13:]] = None
70+
for dir in searchdirs:
71+
if filename[:len(dir)] == dir:
72+
filedict[filename[len(dir)+1:]] = None # no '/' trailing
73+
break
6474
process(fp, outfp)
6575
outfp.close()
6676
fp.close()
@@ -114,9 +124,18 @@ def process(fp, outfp, env = {}):
114124
filename = line[a:b]
115125
if not filedict.has_key(filename):
116126
filedict[filename] = None
117-
outfp.write(
118-
'\n# Included from %s\n' % filename)
119-
inclfp = open('/usr/include/' + filename, 'r')
120-
process(inclfp, outfp, env)
121-
main()
127+
inclfp = None
128+
for dir in searchdirs:
129+
try:
130+
inclfp = open(dir + '/' + filename, 'r')
131+
break
132+
except IOError:
133+
pass
134+
if inclfp:
135+
outfp.write(
136+
'\n# Included from %s\n' % filename)
137+
process(inclfp, outfp, env)
138+
else:
139+
sys.stderr.write('Warning - could not find file %s' % filename)
122140

141+
main()

0 commit comments

Comments
 (0)