avoid duplicate events in translation file

This commit is contained in:
Robin Müller 2022-03-22 10:19:37 +01:00
parent 8829f3face
commit 8a2caf120d
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
1 changed files with 12 additions and 9 deletions

View File

@ -302,21 +302,24 @@ def write_translation_source_file(
):
outputfile = open(filename, "w")
definitions = ""
# Look up table to avoid duplicate events
lut = dict()
function = (
"const char *translateEvents(Event event) {\n switch ((event & 0xFFFF)) {\n"
)
for entry in event_list:
event_id = entry[0]
event_value = entry[1]
definitions += (
f"const char *{event_value[EVENT_ENTRY_NAME_IDX]}_STRING "
f'= "{event_value[EVENT_ENTRY_NAME_IDX]}";\n'
)
function += (
f" case ({event_id}):\n "
f"return {event_value[EVENT_ENTRY_NAME_IDX]}_STRING;\n"
)
if event_value[EVENT_ENTRY_NAME_IDX] not in lut:
definitions += (
f"const char *{event_value[EVENT_ENTRY_NAME_IDX]}_STRING "
f'= "{event_value[EVENT_ENTRY_NAME_IDX]}";\n'
)
function += (
f" case ({event_id}):\n "
f"return {event_value[EVENT_ENTRY_NAME_IDX]}_STRING;\n"
)
lut.update({event_value[EVENT_ENTRY_NAME_IDX] : event_value})
function += ' default:\n return "UNKNOWN_EVENT";\n'
outputfile.write(
f"/**\n * @brief Auto-generated event translation file. "