summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2008-11-08 06:31:04 +0000
committerEric S. Raymond <esr@thyrsus.com>2008-11-08 06:31:04 +0000
commit61f0613d8a0b389c5931b9dfad3a4d916a40055a (patch)
tree395202374648d8f37fb9872cd17cb7e79c4c9317
parentbf5e0604c4596f83eaf0fbaf33e6572d6beceabe (diff)
downloaddeheader-61f0613d8a0b389c5931b9dfad3a4d916a40055a.tar.gz
deheader-61f0613d8a0b389c5931b9dfad3a4d916a40055a.tar.bz2
deheader-61f0613d8a0b389c5931b9dfad3a4d916a40055a.tar.xz
deheader-61f0613d8a0b389c5931b9dfad3a4d916a40055a.zip
Ignore conditional inclusions.
-rwxr-xr-xdeheader30
1 files changed, 19 insertions, 11 deletions
diff --git a/deheader b/deheader
index 4fdb4ef..4e6c00b 100755
--- a/deheader
+++ b/deheader
@@ -30,20 +30,27 @@ def trim(line):
else:
return `line`
-def extract_includes(sourcefile, ignores, verbosity):
+def extract_includes(sourcefile, ignore, verbosity):
"Extract a list of #include lines used in a given sourcfile."
includes = []
+ ifdepth = 0
for line in open(sourcefile):
- if line.startswith("#include"):
+ if line.startswith("#ifdef") or line.startswith("#ifndef"):
+ ifdepth += 1
+ elif line.startswith("#endif"):
+ ifdepth -= 1
+ elif line.startswith("#include"):
if verbosity:
- print "deheader: %s requires %s" % (sourcefile, trim(line))
- for stopper in ignores:
- if stopper.search(line):
- if verbosity:
- print "deheader: ignoring %s" % (trim(line))
- break
- else:
+ name = trim(line)
+ print "deheader: %s requires %s" % (sourcefile, name)
+ if ignore.search(line):
+ if verbosity:
+ print "deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern)
+ continue
+ if ifdepth == 0:
includes.append(line)
+ elif verbose:
+ print "deheader: ignoring %s (conditional inclusion)" % name
return includes
def compile(source, msg="", verbosity=0):
@@ -135,11 +142,12 @@ if __name__ == "__main__":
sys.stderr.write(__doc__)
sys.exit(0)
elif switch in ('-i', '--ignore'):
- ignores.append(re.compile(val))
+ ignores.append(val)
elif switch in ('-r', '--remove'):
remove = True
elif switch in ('-v', '--verbose'):
verbose += 1
+ ignore = re.compile("|".join(ignores))
for sourcefile in arguments:
- deheader(sourcefile, ignores, verbose)
+ deheader(sourcefile, ignore, verbose)