Removal of two more large blocks of unused code. For anyone interested in searching for more, I have attached a script that prints out the line size of the greatest code block in every file below a supplied directory. It is quick and dirty and certainly not bullet-proof, but gives a hint of which files are worth looking into. Anders Jonsson, (LGPLv3+,MPL)
Attachment:
0001-filters-Remove-large-block-of-unused-code.patch
Description: application/mbox
Attachment:
0001-Remove-large-block-of-unused-code.patch
Description: application/mbox
#! /usr/bin/env python
import os
import re
import sys
if len(sys.argv)<3:
print "Usage: ./comcount.py file_ending directory [threshold (default 0)]"
print "Example: ./comcount.py .cxx bootstrap/clone/"
print "threshold sets that only files with comment blocks of at least"
print "that many lines are printed"
sys.exit(0)
arg=sys.argv[1:]
#Counts commented lines of a file
def countComments(filename):
file= open (filename, "r")
maxblock=0
block=0
total=0
ended=True
lineno=0
for line in file:
if lineno<27:#Avoid counting the license
lineno=lineno+1
elif '/*' in line or '//' in line or '*/' in line:
clist=re.findall("/\*|//|\*/",line)
total = total + 1
block = block + 1
if clist[0]=='/*':
first=line.find("/*")
nr=line.count("\"",0,first)
if (nr % 2 !=1):#an even number means that /* not is commented
if not '*/' in clist:
ended=False
else:
ended=True
if clist[0]=='*/':
first=line.find("*/")
nr=line.count("\"",0,first)
if (nr % 2 !=1):#an odd number means that */ not is commented
ended = True
else:
if not ended:
total = total + 1
block = block + 1
else:
block=0
if (block > maxblock):
maxblock=block
file.close()
threshold=0
if len(sys.argv)==4:
threshold=arg[2]
if(maxblock >= int(threshold)):
print maxblock, "lines in max_block.Total comments:",total, filename
#Recursive running on all files
def handleDirectory(directory):
try:
filelist = os.listdir(directory)
except OSError:
print 'Cannot open directory ', directory
else:
for filename in filelist:
if os.path.isdir(directory +"/"+ filename):
handleDirectory(directory +"/"+ filename)
elif filename.endswith(arg[0]):
countComments(directory +"/"+ filename)
#Main program
directory=arg[1]
handleDirectory(directory)