summaryrefslogtreecommitdiffstats
path: root/generator/nanopb_generator.py
diff options
context:
space:
mode:
authorPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-02-07 17:40:17 +0200
committerPetteri Aimonen <jpa@git.mail.kapsi.fi>2013-02-07 17:40:17 +0200
commit47b10ec0ab370475c51294707c0fe6e160046973 (patch)
treec3035169f58a463564dbb3d0bc286ecd83a09f6f /generator/nanopb_generator.py
parent4b7ddabbcf2b4e272675edbd20fd64fe921c99cf (diff)
Sanitize filenames before putting them in #ifndef.
Update issue 50 Status: FixedInGit
Diffstat (limited to 'generator/nanopb_generator.py')
-rw-r--r--generator/nanopb_generator.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py
index 9e85a11d..d35a4252 100644
--- a/generator/nanopb_generator.py
+++ b/generator/nanopb_generator.py
@@ -452,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.
@@ -460,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'