Sanitize filenames before putting them in #ifndef.
[apps/agl-service-can-low-level.git] / generator / nanopb_generator.py
index a583b3f..d35a425 100644 (file)
@@ -306,7 +306,13 @@ class Field:
 class Message:
     def __init__(self, names, desc, message_options):
         self.name = names
-        self.fields = [Field(self.name, f, get_nanopb_suboptions(f, message_options)) for f in desc.field]
+        self.fields = []
+        
+        for f in desc.field:
+            field_options = get_nanopb_suboptions(f, message_options)
+            if field_options.type != nanopb_pb2.FT_IGNORE:
+                self.fields.append(Field(self.name, f, field_options))
+        
         self.packed = message_options.packed_struct
         self.ordered_fields = self.fields[:]
         self.ordered_fields.sort()
@@ -446,6 +452,16 @@ def sort_dependencies(messages):
         if msgname in message_by_name:
             yield message_by_name[msgname]
 
+def make_identifier(headername):
+    '''Make #ifndef identifier that contains uppercase A-Z and digits 0-9'''
+    result = ""
+    for c in headername.upper():
+        if c.isalnum():
+            result += c
+        else:
+            result += '_'
+    return result
+
 def generate_header(dependencies, headername, enums, messages):
     '''Generate content for a header file.
     Generates strings, which should be concatenated and stored to file.
@@ -454,7 +470,7 @@ def generate_header(dependencies, headername, enums, messages):
     yield '/* Automatically generated nanopb header */\n'
     yield '/* Generated by %s at %s. */\n\n' % (nanopb_version, time.asctime())
     
-    symbol = headername.replace('.', '_').upper()
+    symbol = make_identifier(headername)
     yield '#ifndef _PB_%s_\n' % symbol
     yield '#define _PB_%s_\n' % symbol
     yield '#include <pb.h>\n\n'