#! /usr/bin/python2
# coding=utf-8
def read_file(fpath):
BLOCK_SIZE = 1024
with open(fpath, 'rb') as f:
while True:
#block = f.read(BLOCK_SIZE)
block = f.readline()
if block:
yield block
else:
return
with open("reg.txt", 'wb') as f:
f.write("static const short buf_reg[][2] = {")
for str in read_file("a.txt"):
#print i
addr = str[str.find("addr=") + len("addr="):str.find(",")]
val = str[str.find("val=") + len("val="):str.find(";")]
str1 = addr + "," + val + ","
print str1, str
f.write(str1)
#pos = str.find('addr=') + len('addr=')
#if pos > 0:
#print str[pos:]
f.seek(-1, 2)
f.write("};")