scripts/lst_diff.py
2022-05-02 16:34:13 +02:00

50 lines
1.3 KiB
Python

#-------------------------------------------------------------------------------
# lst_diff
# 22/03/2022
# tool script used to summarize the code size of a list of .lst, which display
# the size of segment CODE in their last lines
#
# usage ex: find lst_folder -name *.lst | python lst_diff.py > output.txt
# the output can then be compared using diff
#-------------------------------------------------------------------------------
import fileinput
import re
code_size = 0
p_code = re.compile("CODE")
# list of input lst files
for lst_file in fileinput.input():
lst = lst_file.rstrip('\n')
i = 0
buff = []
# get 3 lines containing code size infos
for line in reversed(list(open(lst, encoding="latin-1"))):
i += 1
if i > 3 and i < 7:
buff.append(line)
elif i >= 7:
break
#parse lines
for line in buff:
if re.search(p_code, line):
toks = line.split()
size = 0
try:
size += int(toks[1])
except:
pass
if size != 0:
size += 1000 * int(toks[0])
else:
size += int(toks[0])
code_size += size
print(lst.split('/').pop() + ": " + str(size))
print("total: " + str(code_size))