Publishing nanopb-0.3.3
[apps/agl-service-can-low-level.git] / generator / nanopb_generator.py
index fc32e2c..364a22c 100755 (executable)
@@ -1,9 +1,10 @@
 #!/usr/bin/python
 
 '''Generate header file for nanopb from a ProtoBuf FileDescriptorSet.'''
-nanopb_version = "nanopb-0.3.3-dev"
+nanopb_version = "nanopb-0.3.3"
 
 import sys
+import re
 
 try:
     # Add some dummy imports to keep packaging tools happy.
@@ -164,6 +165,13 @@ class Enum:
         result = 'typedef enum _%s {\n' % self.names
         result += ',\n'.join(["    %s = %d" % x for x in self.values])
         result += '\n} %s;' % self.names
+        
+        if not self.options.long_names:
+            # Define the long names always so that enum value references
+            # from other files work properly.
+            for i, x in enumerate(self.values):
+                result += '\n#define %s %s' % (self.value_longnames[i], x[0])
+        
         return result
 
 class Field:
@@ -1157,9 +1165,13 @@ def read_options_file(infile):
         [(namemask, options), ...]
     '''
     results = []
-    for i, line in enumerate(infile):
+    data = infile.read()
+    data = re.sub('/\*.*?\*/', '', data, flags = re.MULTILINE)
+    data = re.sub('//.*?$', '', data, flags = re.MULTILINE)
+    data = re.sub('#.*?$', '', data, flags = re.MULTILINE)
+    for i, line in enumerate(data.split('\n')):
         line = line.strip()
-        if not line or line.startswith('//') or line.startswith('#'):
+        if not line:
             continue
         
         parts = line.split(None, 1)
@@ -1372,8 +1384,15 @@ def main_plugin():
     data = sys.stdin.read()
     request = plugin_pb2.CodeGeneratorRequest.FromString(data)
     
+    try:
+        # Versions of Python prior to 2.7.3 do not support unicode
+        # input to shlex.split(). Try to convert to str if possible.
+        params = str(request.parameter)
+    except UnicodeEncodeError:
+        params = request.parameter
+    
     import shlex
-    args = shlex.split(request.parameter)
+    args = shlex.split(params)
     options, dummy = optparser.parse_args(args)
     
     Globals.verbose_options = options.verbose