summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2010-12-07 17:20:30 -0500
committerEric S. Raymond <esr@thyrsus.com>2010-12-07 17:20:30 -0500
commitebf834d064115e67b6d1050b2cd3d6532201227a (patch)
treefc51d91bcecbca2648f42194689274cc515ad1ff
parentbd618133879ccaa661cac0ae4ca4baaef72dad19 (diff)
downloaddeheader-ebf834d064115e67b6d1050b2cd3d6532201227a.tar.gz
deheader-ebf834d064115e67b6d1050b2cd3d6532201227a.tar.bz2
deheader-ebf834d064115e67b6d1050b2cd3d6532201227a.tar.xz
deheader-ebf834d064115e67b6d1050b2cd3d6532201227a.zip
Refactoring step.
-rwxr-xr-xdeheader24
1 files changed, 12 insertions, 12 deletions
diff --git a/deheader b/deheader
index bc161f8..243b868 100755
--- a/deheader
+++ b/deheader
@@ -67,19 +67,19 @@ class Baton:
self.stream.write("...(%2.2f sec) %s.\n" % (time.time() - self.time, msg))
return
-def c_source(filename):
- "Predicate: return true if the filename appears to be C or C++ source."
- return filename.endswith(".c") or filename.endswith(".cpp")
-
class InclusionMap:
"Map the inclusion dependencies of a set of files and directories."
+ @staticmethod
+ def c_source(filename):
+ "Predicate: return true if the filename appears to be C or C++ source."
+ return filename.endswith(".c") or filename.endswith(".cpp")
def __init__(self, roots, ignore, verbosity):
"Build the initial inclusion map."
self.verbosity = verbosity
self.files = []
for root in roots:
if not os.path.isdir(root):
- if c_source(root):
+ if InclusionMap.c_source(root):
self.files.append(root)
else:
print >>sys.stderr, "deheader: can't analyze %s" % root
@@ -88,9 +88,9 @@ class InclusionMap:
dirs = filter(lambda x: not x.startswith("."), dirs)
for name in files:
path = os.path.join(root, name)
- if c_source(path):
+ if InclusionMap.c_source(path):
self.files.append(path)
- self.c_to_h = {}
+ self.depends_on = {}
for sourcefile in self.files:
includes = []
ifdepth = 0
@@ -111,13 +111,13 @@ class InclusionMap:
includes.append(line)
elif verbose > 1:
print "deheader: ignoring %s (conditional inclusion)" % name
- self.c_to_h[sourcefile] = includes
+ self.depends_on[sourcefile] = includes
def forget(self, sourcefile, header):
"Forget a header dependency."
- self.c_to_h[sourcefile].remove(header)
+ self.depends_on[sourcefile].remove(header)
def remember(self, sourcefile, header):
"Undo forgetting of a dependency."
- self.c_to_h[sourcefile].append(header)
+ self.depends_on[sourcefile].append(header)
class SaveForModification:
"Prepare a file to be temporarily modified, with guaranteed reversion."
@@ -276,8 +276,8 @@ if __name__ == "__main__":
inclusion_map = InclusionMap(arguments, ignore, verbose)
summaries = []
- for sourcefile in inclusion_map.c_to_h:
- summaries.append(deheader(sourcefile, maker, inclusion_map.c_to_h[sourcefile], remove, verbose))
+ for sourcefile in inclusion_map.depends_on:
+ summaries.append(deheader(sourcefile, maker, inclusion_map.depends_on[sourcefile], remove, verbose))
stats = Summary()
for summary in summaries:
stats = stats + summary