From 2a1e388e7c3298d4184bf137bd672f296c624ead Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 25 Oct 2011 16:30:01 -0400 Subject: [PATCH] Added source code analyzer. --- src/utils/analyze_source.py | 53 +++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100755 src/utils/analyze_source.py diff --git a/src/utils/analyze_source.py b/src/utils/analyze_source.py new file mode 100755 index 0000000000..1334bbb130 --- /dev/null +++ b/src/utils/analyze_source.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +import sys + +if len(sys.argv) <= 1: + print("Usage:") + sys.exit() + +source = sys.argv[1:] +source.sort() + +totalCode = 0 +totalComment = 0 +totalSpace = 0 + +for sourceFile in source: + code = 0 + comment = 0 + space = 0 + + ending = sourceFile[sourceFile.rindex('.') + 1:] + if ending == 'c': + commentChar = '/*' + elif ending == 'f': + commentChar = '!' + elif ending == 'f90': + commentChar = '!' + + for line in open(sourceFile, 'r'): + line = line.strip() + if line.startswith(commentChar): + comment += 1 + elif line == '': + space += 1 + else: + code += 1 + + total = comment + space + code + totalCode += code + totalComment += comment + totalSpace += space + + print("------ {0} ------".format(sourceFile)) + print("Code: {0} ({1:4.1f}%)".format(code, 100.0*float(code)/total)) + print("Comments: {0} ({1:4.1f}%)".format(comment, 100.0*float(comment)/total)) + print("Spaces: {0} ({1:4.1f}%)\n".format(space, 100.0*float(space)/total)) + +total = totalCode + totalComment + totalSpace + +print("------ TOTALS ------") +print("Code: {0} ({1:4.1f}%)".format(totalCode, 100.0*float(totalCode)/total)) +print("Comments: {0} ({1:4.1f}%)".format(totalComment, 100.0*float(totalComment)/total)) +print("Spaces: {0} ({1:4.1f}%)\n".format(totalSpace, 100.0*float(totalSpace)/total))