summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Brooks <db48x@db48x.net>2015-07-04 23:32:45 -0700
committerEric S. Raymond <esr@thyrsus.com>2015-07-05 12:45:03 -0400
commit3712dc75949603484e2d2d70e1b5a6bd4ecefd34 (patch)
treef32f8aa18db6686d70f59a4c8d2c16436070d0a3
parent91fbb0000f95cab8c444f0b0ea9f370a4e80a7cb (diff)
downloaddeheader-3712dc75949603484e2d2d70e1b5a6bd4ecefd34.tar.gz
deheader-3712dc75949603484e2d2d70e1b5a6bd4ecefd34.tar.bz2
deheader-3712dc75949603484e2d2d70e1b5a6bd4ecefd34.tar.xz
deheader-3712dc75949603484e2d2d70e1b5a6bd4ecefd34.zip
Notice preprocessor directives with whitespace after the hash-mark...
...and before the directive name
-rwxr-xr-xdeheader48
1 files changed, 28 insertions, 20 deletions
diff --git a/deheader b/deheader
index a38175e..4c0d29c 100755
--- a/deheader
+++ b/deheader
@@ -1269,26 +1269,25 @@ class InclusionMap:
seen = []
conditions = []
for line in open(sourcefile):
- if line.startswith("#ifndef"):
- conditions.append(line[7:].strip())
- elif line.startswith("#ifdef"):
- conditions.append(line[6:].strip())
- elif line.startswith("#if"):
- conditions.append(line[3:].strip())
- elif line.startswith("#endif"):
+ c = match_preproc(["ifndef", "ifdef", "if"], line)
+ if c is not False:
+ conditions.append(c)
+ elif match_preproc("endif", line) is not False:
conditions.pop()
- elif line.startswith("#include"):
- if verbosity >= PROGRESS_DEBUG:
- name = trim(line)
- print "deheader: %s includes %s" % (sourcefile, name)
- if ignore and ignore.search(line):
+ else:
+ f = match_preproc("include", line)
+ if f is not False:
if verbosity >= PROGRESS_DEBUG:
- print "deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern)
- continue
- if not conditions or conditions == ["S_SPLINT_S"]:
- includes.append(line)
- elif verbose > 1:
- print "deheader: ignoring %s (conditional inclusion)" % name
+ name = trim(f)
+ print "deheader: %s includes %s" % (sourcefile, name)
+ if ignore and ignore.search(line):
+ if verbosity >= PROGRESS_DEBUG:
+ print "deheader: ignoring %s (exclusion match with %s)." % (name, ignore.pattern)
+ continue
+ if not conditions or conditions == ["S_SPLINT_S"]:
+ includes.append(line)
+ elif verbose > 1:
+ print "deheader: ignoring %s (conditional inclusion)" % name
for (r, c, h) in compiled:
if c.search(line):
if not set(h).issubset(set(seen)):
@@ -1335,9 +1334,18 @@ class SaveForModification:
pass
os.rename(self.original, self.filename)
+def match_preproc(directives, line):
+ if not isinstance(directives, list):
+ directives = [directives]
+ regexp = "|".join(["#\s*" + d for d in directives])
+ m = re.match(regexp, line)
+ if m:
+ return line[m.span()[1]:].strip()
+ return False
+
def trim(line):
"Get file reference from an #include, retaining <> if a system header."
- trimmed = line[9:].strip()
+ trimmed = re.sub("^#\s*include", "", line).strip()
if trimmed[0] in '"':
return '"' + trimmed.split('"')[1] + '"'
elif trimmed[0] == '<':
@@ -1423,7 +1431,7 @@ def deheader(sourcefile, maker, includes, requires, remove, verbose):
includes[:], requires, verbose)
if unneeded:
for line in unneeded:
- print "deheader: remove %s from %s" % (trim(line), sourcefile)
+ print "deheader: remove %s from %s" % (trim(line), sourcefile) # XXX
if remove:
remove_it = SaveForModification(sourcefile)
remove_it.remove_headers(unneeded)