Created
February 22, 2011 14:09
-
-
Save zdxerr/838713 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os, os.path | |
dir = 'E:\\profiler\\' | |
suffix = ('.c', '.h', '.rc', 'Makefile') | |
comment_start = '/*' | |
comment_end = '*/' | |
comment_line = '//' | |
lines = {'count': 0, | |
'blank': 0, | |
'comment': 0, | |
'code': 0, | |
'code and comment': 0} | |
for root, dirs, files in os.walk(dir): | |
for f in files: | |
fullpath = os.path.join(root, f) | |
if f.endswith(suffix): | |
temp = open(fullpath) | |
comment = False | |
for line in temp: | |
lines['count'] += 1 | |
line = line.strip() | |
if line is '': | |
lines['blank'] += 1 | |
elif comment: | |
if line.endswith(comment_end): | |
lines['comment'] += 1 | |
comment = False | |
elif comment_end in line: | |
lines['code and comment'] += 1 | |
else: | |
lines['comment'] += 1 | |
elif line.startswith(comment_line): | |
lines['comment'] += 1 | |
elif line.startswith(comment_start): | |
if line.endswith(comment_end): | |
lines['comment'] += 1 | |
elif comment_end in line: | |
lines['code and comment'] += 1 | |
else: | |
comment = True | |
else: | |
lines['code'] += 1 | |
print lines |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment