diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2008-11-08 14:15:44 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2008-11-08 14:15:44 +0000 |
commit | 3e42c24ee60b8a4153782ccceb6c5e71278b683b (patch) | |
tree | f777072c162ba931ff8f13339c70701ae222b4eb | |
parent | 1c50c0216f1f791bd336e10cf6874889aefa7395 (diff) | |
download | deheader-3e42c24ee60b8a4153782ccceb6c5e71278b683b.tar.gz deheader-3e42c24ee60b8a4153782ccceb6c5e71278b683b.tar.bz2 deheader-3e42c24ee60b8a4153782ccceb6c5e71278b683b.tar.xz deheader-3e42c24ee60b8a4153782ccceb6c5e71278b683b.zip |
Integrate baton twirling.
-rwxr-xr-x | deheader | 37 |
1 files changed, 20 insertions, 17 deletions
@@ -149,22 +149,21 @@ def deheader(sourcefile, includes, remove, verbose): # Sanity check against broken sourcefiles; we want this to # complain visibly if the sourcefile won't build at all. (st, t) = compile(sourcefile, min(1, verbose)) - if st != 0: - return - # Now do the analysis - if sourcefile.endswith(".c") or sourcefile.endswith(".cpp"): - unneeded = c_analyze(sourcefile, includes, verbose) - if unneeded: - for line in unneeded: - print "deheader: remove %s from %s" % (trim(line), sourcefile) - if remove: - os.rename(sourcefile, original) - for header in includes: - ofp = open(sourcefile, "w") - for line in open(original): - if line not in unneeded: - ofp.write(line) - ofp.close() + if st == 0: + # Now do the analysis + if sourcefile.endswith(".c") or sourcefile.endswith(".cpp"): + unneeded = c_analyze(sourcefile, includes, verbose) + if unneeded: + for line in unneeded: + print "deheader: remove %s from %s" % (trim(line), sourcefile) + if remove: + os.rename(sourcefile, original) + for header in includes: + ofp = open(sourcefile, "w") + for line in open(original): + if line not in unneeded: + ofp.write(line) + ofp.close() def c_analyze(source, includes, verbosity): "Given a C file and a list of includes, return those that can be omitted." @@ -173,8 +172,9 @@ def c_analyze(source, includes, verbosity): includes.reverse() unneeded = [] original = sourcefile + ".orig" + baton = Baton(sourcefile + ": ", "Done") + os.rename(sourcefile, original) try: - os.rename(sourcefile, original) while True: keepgoing = False for header in includes: @@ -188,9 +188,12 @@ def c_analyze(source, includes, verbosity): unneeded.append(header) includes.remove(header) keepgoing = True + if verbosity == 0: + baton.twirl() if not keepgoing: break finally: + baton.end() os.remove(sourcefile) os.rename(original, sourcefile) return unneeded |