MCPcopy Create free account
hub / github.com/ActiveState/code / doCFile

Function doCFile

recipes/Python/577546_linecountpy/recipe-577546.py:119–148  ·  view source on GitHub ↗
(file)

Source from the content-addressed store, hash-verified

117
118
119def doCFile(file):
120 count = 0
121 f = open(file, 'r')
122
123 incomment = False
124
125 for line in f:
126 line = line.strip()
127 if incomment:
128 end = line.find('*/')
129 if end < 0:
130 continue
131 else:
132 incomment = False
133 line = line[end+2:]
134 if len(line) == 0:
135 continue
136 if line.startswith('//'):
137 continue
138 ind = line.find('/*')
139 if ind >= 0:
140 incomment = True
141 ind2 = line[ind+2:].find('*/') >= 0
142 if ind2 >= 0:
143 incomment = False
144 if ind > 0 or ind2 < len(line)-2:
145 count += 1
146 continue
147 count += 1
148 return count
149
150
151def doRegularFile(file, cmtStr):

Callers 1

doFileFunction · 0.85

Calls 4

startswithMethod · 0.80
openFunction · 0.50
stripMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected