import os
def isSpaceAfterPreCommentRight(codeString):
preSlashIndex = codeString.find("/*")
if preSlashIndex == -1:
return 1
if codeString[preSlashIndex + 2] == ' ':
return 1
else:
return 0
def isSpaceBeforePostCommentRight(codeString):
postSlashIndex = codeString.find("*/")
if postSlashIndex == -1:
return 1
if codeString[postSlashIndex - 1] == ' ':
return 1
else:
return 0
def walk_dir(dir, topdown=True):
for root, dirs, files in os.walk(dir, topdown):
for name in files:
if 'c' == os.path.splitext(name)[1][1:]:
line_num = 0
file_handle = open(os.path.join(name), 'r')
for lines in file_handle:
line_num = line_num + 1
if not (isSpaceAfterPreCommentRight(lines) and isSpaceBeforePostCommentRight(lines)):
print os.path.join(name)
print line_num
print lines
file_handle.close()
if __name__ == '__main__':
def isSpaceAfterPreCommentRight(codeString):
preSlashIndex = codeString.find("/*")
if preSlashIndex == -1:
return 1
if codeString[preSlashIndex + 2] == ' ':
return 1
else:
return 0
def isSpaceBeforePostCommentRight(codeString):
postSlashIndex = codeString.find("*/")
if postSlashIndex == -1:
return 1
if codeString[postSlashIndex - 1] == ' ':
return 1
else:
return 0
def walk_dir(dir, topdown=True):
for root, dirs, files in os.walk(dir, topdown):
for name in files:
if 'c' == os.path.splitext(name)[1][1:]:
line_num = 0
file_handle = open(os.path.join(name), 'r')
for lines in file_handle:
line_num = line_num + 1
if not (isSpaceAfterPreCommentRight(lines) and isSpaceBeforePostCommentRight(lines)):
print os.path.join(name)
print line_num
print lines
file_handle.close()
if __name__ == '__main__':