From 3712dc75949603484e2d2d70e1b5a6bd4ecefd34 Mon Sep 17 00:00:00 2001 From: Daniel Brooks Date: Sat, 4 Jul 2015 23:32:45 -0700 Subject: Notice preprocessor directives with whitespace after the hash-mark... ...and before the directive name --- deheader | 48 ++++++++++++++++++++++++++++-------------------- 1 file 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) -- cgit v1.2.3-70-g09d2