import os
functionHead = ['U32','U16', 'VOI']
deadCodeFlag = 0
endIfFlag = 0
def isDeadCode(string):
global deadCodeFlag
global endIfFlag
if deadCodeFlag == 0:
endIfFlag = 0
if "#if 0" in string:
deadCodeFlag = 1
else:
if "#endif" in string:
deadCodeFlag = 0
endIfFlag = 1
def isFunction(string):
isFunctionFlag = 0
isDeadCode(string)
if (deadCodeFlag == 0) and (endIfFlag == 0):
if len(string) >= 5 and (string[0:3] in functionHead):
isFunctionFlag = 1
return isFunctionFlag
def printFunctionInFile(filename):
filestyle = filename.split('.')
if filestyle[1] == 'c':
fp = open(filename, 'r+')
lines = fp.readlines()
for index, line in enumerate(lines):
if isFunction(line) == 1:
if line.endswith("\\\n"):
print line + lines[index + 1]
else:
print line
if __name__ == '__main__':
filenames = os.listdir(os.curdir)
for filename in filenames:
printFunctionInFile(filename)
python 判断是否为函数
最新推荐文章于 2024-06-06 08:52:53 发布