From 1a7aa73b262f3ab0ac7529957ea6de9ba9122031 Mon Sep 17 00:00:00 2001 From: Cas Cremers Date: Wed, 20 Aug 2008 16:02:19 +0200 Subject: [PATCH] Created a small program that can find unused functions. --- src/find-unused-functions.py | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 src/find-unused-functions.py diff --git a/src/find-unused-functions.py b/src/find-unused-functions.py new file mode 100755 index 0000000..dac13b3 --- /dev/null +++ b/src/find-unused-functions.py @@ -0,0 +1,59 @@ +#!/usr/bin/python + +import commands +import sys + + +def findfunctions(excludes): + """ + Extract functions from tags file + """ + fh = open("tags",'r') + dict = {} + for l in fh.readlines(): + data = l.strip().split('\t') + if len(data) >= 4: + fn = data[0] + sourcefile = data[1] + etype = data[3] + if not fn.startswith("!_TAG_"): + if sourcefile not in excludes: + if etype in ['f']: + dict[fn] = sourcefile + return dict + +def main(): + args = [] + if len(sys.argv) > 0: + args = sys.argv[1:] + + mincount = 0 + if len(args) > 0: + mincount = int(args[0]) + + """ Force indent """ + cmd = "indent *.c *.h" + output = commands.getoutput(cmd) + + """ Force ctags """ + cmd = "ctags *.c *.h" + output = commands.getoutput(cmd) + + excludes = ['scanner.c','scanner.h','parser.c','parser.h'] + fnames = findfunctions(excludes) + for fname in fnames.keys(): + """ + The ..* construct makes sure that function definitions are + skipped (based on the indent settings + """ + cmd = "grep '..*%s' *.c" % (fname) + #print cmd + output = commands.getoutput(cmd).splitlines() + if len(output) <= mincount: + print "%s\t%s" % (fnames[fname],fname) + if len(output) > 0: + print output + +if __name__ == '__main__': + main() +