From 88b572f40853d80933f802007354ae95b5e70992 Mon Sep 17 00:00:00 2001 From: Marcel Peterkau Date: Thu, 25 Jan 2024 14:33:09 +0100 Subject: [PATCH] codegenerator now supports char-arrays --- Software/codegen/struct2json.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Software/codegen/struct2json.py b/Software/codegen/struct2json.py index 2940397..17ed754 100644 --- a/Software/codegen/struct2json.py +++ b/Software/codegen/struct2json.py @@ -45,9 +45,14 @@ def extract_struct_fields(file_content, variable_types): if match: # Extrahiere die Felder aus dem Treffer - fields_match = re.findall(r'\b(\w+)\s+(\w+)\s*;', match.group(1)) + fields_match = re.findall(r'\b(\w+)\s+(\w+)(?:\[(\d+)\])?\s*;', match.group(1)) if fields_match: - result[var_name] = {'type': var_type, 'fields': {field_name: field_type for field_type, field_name in fields_match}} + result[var_name] = {'type': var_type, 'fields': {}} + for field_type, field_name, array_size in fields_match: + if array_size: + result[var_name]['fields'][field_name] = {'type': field_type, 'size': int(array_size)} + else: + result[var_name]['fields'][field_name] = {'type': field_type} return result