diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2008-11-06 19:20:44 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2008-11-06 19:20:44 +0000 |
commit | 51fa42fd9de57324e80e17dca884b257cba2cc1a (patch) | |
tree | 037648c618020ca5bbbfd5f5b100d8e3925b9086 | |
parent | 95fc7de08928a7b19930be8446707ba7bfbafbe4 (diff) | |
download | deheader-51fa42fd9de57324e80e17dca884b257cba2cc1a.tar.gz deheader-51fa42fd9de57324e80e17dca884b257cba2cc1a.tar.bz2 deheader-51fa42fd9de57324e80e17dca884b257cba2cc1a.tar.xz deheader-51fa42fd9de57324e80e17dca884b257cba2cc1a.zip |
Allow the ignoreargument to be a regexp.
-rwxr-xr-x | deheader | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -4,7 +4,7 @@ deheader -- find (optionally remove) unneeded includes in C or C++ sourcefiles. Usage: deheader [-h] [-v] [-r] [-i str] sourcefiles -h, --help Emit this help message and quit. - -i, --ignore Ignore (don't remove) headers containing the arg string + -i, --ignore Ignore (don't remove) headers matching the argument regexp -r, --remove Remove the final set of unneeded headers -v, --verbose Be chatty about what you're doing. @@ -18,7 +18,7 @@ on interrupt or after processing with its original timestamp, unless the -r option was given and headers removed. """ -import sys, os, tempfile, getopt, time +import sys, os, tempfile, getopt, time, re def trim(line): "Get file reference from an #include, retaining <> if a system header." @@ -36,9 +36,11 @@ def extract_includes(sourcefile, ignores): for line in open(sourcefile): if line.startswith("#include"): if verbose: - print "deheader: %s requires %s" % (sourcefile, `line`) + print "deheader: %s requires %s" % (sourcefile, trim(line)) for stopper in ignores: - if stopper in line: + if stopper.search(line): + if verbose: + print "deheader: ignoring %s" % (trim(line)) break else: includes.append(line) @@ -107,7 +109,7 @@ if __name__ == "__main__": sys.stderr.write(__doc__) sys.exit(0) elif switch in ('-i', '--ignore'): - ignores.append(val) + ignores.append(re.compile(val)) elif switch in ('-r', '--remove'): remove = True elif switch in ('-v', '--verbose'): |