From 3e42c24ee60b8a4153782ccceb6c5e71278b683b Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Sat, 8 Nov 2008 14:15:44 +0000 Subject: Integrate baton twirling. --- deheader | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/deheader b/deheader index 29ce34c..7ab4028 100755 --- a/deheader +++ b/deheader @@ -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 -- cgit v1.2.3-70-g09d2