import os
import sys
def processFile(fileName):
f = open(fileName)
switchFound = False
foundOneBracket = False
openBrackets = 0
switchLineCount = 0
lineCounter = 1
switchStartedAt = 0
printedFileName = False
for line in f.readlines():
if line.find("switch") > 0:
switchLineCount = 0
switchFound = True
foundOneBracket = False
switchStartedAt = lineCounter
# now we need to count brackets
if switchFound :
if line.find("{") > 0:
openBrackets += 1
foundOneBracket = True
if line.find("}") > 0 :
openBrackets -= 1
switchLineCount += 1
if switchFound and foundOneBracket and openBrackets == 0:
if not printedFileName :
print fileName + ":"
printedFileName = True
switchFound = False
print "switch: %d size %d" % (switchStartedAt, switchLineCount)
lineCounter += 1
pass
def processFolder(folderName):
for root, dirs, files in os.walk(folderName):
for name in files:
filename = os.path.join(root, name)
if filename.find(".svn") == -1 and filename[-2:] in ( ".m") :
processFile(filename)
pass
processFolder("/Users/alex/test/IPHTWO/")