diff options
author | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-02-28 16:42:34 +0200 |
---|---|---|
committer | Petteri Aimonen <jpa@git.mail.kapsi.fi> | 2013-02-28 16:42:34 +0200 |
commit | 0e3053894ff200288fc16056a50ac37b62785471 (patch) | |
tree | 244ee6d0f77b333f584a0298f24f9eb48cbc222c | |
parent | 57e81ca73b0e0f54e29ca29ec13af551a5335a9b (diff) |
Add --extension option to generator.
Patch courtesy of Michael Haberler.
-rw-r--r-- | generator/nanopb_generator.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/generator/nanopb_generator.py b/generator/nanopb_generator.py index 45b2ac68..c51798de 100644 --- a/generator/nanopb_generator.py +++ b/generator/nanopb_generator.py @@ -439,7 +439,7 @@ def make_identifier(headername): result += '_' return result -def generate_header(dependencies, headername, enums, messages): +def generate_header(dependencies, headername, enums, messages, options): '''Generate content for a header file. Generates strings, which should be concatenated and stored to file. ''' @@ -454,7 +454,7 @@ def generate_header(dependencies, headername, enums, messages): for dependency in dependencies: noext = os.path.splitext(dependency)[0] - yield '#include "%s.pb.h"\n' % noext + yield '#include "%s.%s.h"\n' % (noext,options.extension) yield '#ifdef __cplusplus\n' yield 'extern "C" {\n' @@ -582,6 +582,8 @@ optparser = OptionParser( "Output will be written to file.pb.h and file.pb.c.") optparser.add_option("-x", dest="exclude", metavar="FILE", action="append", default=[], help="Exclude file from generated #include list.") +optparser.add_option("-e", "--extension", dest="extension", metavar="EXTENSION", default="pb", + help="use extension instead of 'pb' for generated files.") optparser.add_option("-q", "--quiet", dest="quiet", action="store_true", default=False, help="Don't print anything except errors.") optparser.add_option("-v", "--verbose", dest="verbose", action="store_true", default=False, @@ -638,8 +640,8 @@ def process(filenames, options): enums, messages = parse_file(fdesc.file[0], file_options) noext = os.path.splitext(filename)[0] - headername = noext + '.pb.h' - sourcename = noext + '.pb.c' + headername = noext + '.' + options.extension + '.h' + sourcename = noext + '.' + options.extension + '.c' headerbasename = os.path.basename(headername) if not options.quiet: @@ -651,7 +653,7 @@ def process(filenames, options): dependencies = [d for d in fdesc.file[0].dependency if d not in excludes] header = open(headername, 'w') - for part in generate_header(dependencies, headerbasename, enums, messages): + for part in generate_header(dependencies, headerbasename, enums, messages, options): header.write(part) source = open(sourcename, 'w') |