python提取c结构体

import os
import re
import sys

def extract(pattern1, str0):
result1 = pattern1.findall(str0)
str = “”
if (result1):
str = result1[0]
return str

def ExtractVariablesFromFile (sourceFileStr, resultFileStr):
sourceFile = open(sourceFileStr, mode=‘r’, encoding=‘UTF-8’)
resultFile = open(resultFileStr, “w”)
pattern1 = re.compile(r’} \w+’)
str = “”
for line in sourceFile:
str = extract(pattern1, line)
resultFile.write(str)
resultFile.write("\n")
sourceFile.close()
resultFile.close()
def count(f, str):
total = 0
reStr=’ '+str+ ‘( |;|[)’
pattern1 = re.compile(reStr)
result1 = pattern1.findall(str)
str = “”
if (result1):
str = result1[0]
for line in f:
result1 = pattern1.findall(line.strip())
if(result1):
total += 1
# if str in line:
# total += 1
return total

def VariablesFromFile(sourceFileStr, valuesFileStr, resultFileStr):
sourceFile = open(sourceFileStr, mode=‘r’, encoding=‘UTF-8’)
valuesFile = open(valuesFileStr)
resultFile = open(resultFileStr, “w”)
for line in valuesFile:
if(line.strip() != “”):
sourceFile.seek(0, 0)
line=line.strip()
num = count(sourceFile,line )
resultFile.write(line+" “)
resultFile.write(str(num))
resultFile.write(”\n")
sourceFile.close()
valuesFile.close()
resultFile.close()

sourceFile = sys.argv[1]
valuesFile = sys.argv[2]
ExtractVariablesFromFile (sourceFile, valuesFile)

你可能感兴趣的:(python)