From 3e30b94615d64cf02713b23060f985f953751bb8 Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Thu, 19 Apr 2018 09:49:44 +0200 Subject: [PATCH 01/15] Bugfix and new features Include changes from University of California. Separate statement and comments to treat both parts different (remove bugs regarding string modifications). Remove "option" statements. Add support for "extend" statements. Change "repeat" from Template to standard member. --> Better collaboration diagrams. Fix problems with references of nested messages (replace "." with "::"). --- proto2cpp.py | 95 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 74 insertions(+), 21 deletions(-) diff --git a/proto2cpp.py b/proto2cpp.py index 96506aa..c3a5ffd 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -1,9 +1,10 @@ +#!/usr/bin/env python ## # Doxygen filter for Google Protocol Buffers .proto files. # This script converts .proto files into C++ style ones # and prints the output to standard output. # -# version 0.6-beta +# version 0.7-beta OSI # # How to enable this filter in Doxygen: # 1. Generate Doxygen configuration file with command 'doxygen -g ' @@ -12,7 +13,7 @@ # JAVADOC_AUTOBRIEF = YES # 3. In the Doxygen configuration file, find FILE_PATTERNS and add *.proto # FILE_PATTERNS = *.proto -# 4. In the Doxygen configuration file, find EXTENSION_MAPPING and add proto=C +# 4. In the Doxygen configuration file, find EXTENSION_MAPPING and add proto=C++ # EXTENSION_MAPPING = proto=C # 5. In the Doxygen configuration file, find INPUT_FILTER and add this script # INPUT_FILTER = "python proto2cpp.py" @@ -20,7 +21,9 @@ # doxygen doxyfile # # -# Copyright (C) 2012-2015 Timo Marjoniemi +# Version 0.7 2018 Bugfix and extensions have been made by Open Simulation Interface (OSI) Carsten Kuebler https://github.com/OpenSimulationInterface +# Copyright (C) 2016 Regents of the University of California https://github.com/vgteam/vg +# Copyright (C) 2012-2015 Timo Marjoniemi https://sourceforge.net/p/proto2cpp/wiki/Home/ # All rights reserved. # # This library is free software; you can redistribute it and/or @@ -72,7 +75,7 @@ def __init__(self): self.logFile = "proto2cpp.log" ## Error log file name. self.errorLogFile = "proto2cpp.error.log" - ## Logging level. + ## Logging level. self.logLevel = self.logNone ## Handles a file. @@ -88,7 +91,7 @@ def handleFile(self, fileName): self.log('\nXXXXXXXXXX\nXX ' + filename + '\nXXXXXXXXXX\n\n') # Open the file. Use try to detect whether or not we have an actual file. try: - with open(filename, 'r') as inputFile: + with open(filename, 'r', encoding='utf8') as inputFile: self.parseFile(inputFile) pass except IOError as e: @@ -97,7 +100,7 @@ def handleFile(self, fileName): elif not fnmatch.fnmatch(filename, os.path.basename(inspect.getfile(inspect.currentframe()))): self.log('\nXXXXXXXXXX\nXX ' + filename + '\nXXXXXXXXXX\n\n') try: - with open(filename, 'r') as theFile: + with open(filename, 'r', encoding='utf8') as theFile: output = '' for theLine in theFile: output += theLine @@ -120,6 +123,7 @@ def handleFile(self, fileName): def parseFile(self, inputFile): # Go through the input file line by line. isEnum = False + inPackage = False # This variable is here as a workaround for not getting extra line breaks (each line # ends with a line separator and print() method will add another one). # We will be adding lines into this var and then print the var out at the end. @@ -129,24 +133,54 @@ def parseFile(self, inputFile): # block to make Doxygen detect it. matchComment = re.search("//", line) # Search for semicolon and if one is found before comment, add a third slash character - # ("/") and a smaller than ("<") chracter to the comment to make Doxygen detect it. + # ("/") and a smaller than ("<") character to the comment to make Doxygen detect it. matchSemicolon = re.search(";", line) if matchSemicolon is not None and (matchComment is not None and matchSemicolon.start() < matchComment.start()): - line = line[:matchComment.start()] + "///<" + line[matchComment.end():] + comment = "///<" + line[matchComment.end():] + # Replace '.' in nested message references with '::' + # don't work for multi-nested references and generates problems with URLs and acronyms + #comment = re.sub(r'\s(\w+)\.(\w+)\s', r' \1::\2 ', comment) + line = line[:matchComment.start()] elif matchComment is not None: - line = line[:matchComment.start()] + "///" + line[matchComment.end():] + comment = "///" + line[matchComment.end():] + # replace '.' in nested message references with '::' + # don't work for multi-nested references and generates problems with URLs and acronyms + #comment = re.sub(r'\s(\w+)\.(\w+)\s', r' \1::\2 ', comment) + line = line[:matchComment.start()] + else: + comment = "" + + # line = line.replace(".", "::") but not in quoted strings (Necessary for import statement) + line = re.sub(r'\.(?=(?:[^"]*"[^"]*")*[^"]*$)',r'::',line) - # Search for "enum" and if one is found before comment, - # start changing all semicolons (";") to commas (","). - matchEnum = re.search("enum", line) - if matchEnum is not None and (matchComment is None or matchEnum.start() < matchComment.start()): + # Search for " option ...;", remove it + line = re.sub(r'\boption\b[^;]+;', r'', line) + + # Search for " package ", make a namespace + matchPackage = re.search(r"\bpackage\b", line) + if matchPackage is not None: + isPackage = True + # Convert to C++-style separator and block instead of statement + line = "namespace" + line[:matchPackage.start()] + line[matchPackage.end():].replace(";", " {") + + # Search for " repeated " fields and make them ... + #matchRepeated = re.search(r"\brepeated\b", line) + #if matchRepeated is not None: + # # Convert + # line = re.sub(r'\brepeated\s+(\S+)', r' repeated \1', line) + + # Search for "enum", start changing all semicolons (";") to commas (","). + matchEnum = re.search(r"\benum\b", line) + if matchEnum is not None: isEnum = True + # Search again for semicolon if we have detected an enum, and replace semicolon with comma. if isEnum is True and re.search(";", line) is not None: matchSemicolon = re.search(";", line) line = line[:matchSemicolon.start()] + "," + line[matchSemicolon.end():] + # Search for a closing brace. - matchClosingBrace = re.search("}", line[:matchComment.start()] if matchComment else line) + matchClosingBrace = re.search("}", line) if isEnum is True and matchClosingBrace is not None: line = line[:matchClosingBrace.start()] + "};" + line[matchClosingBrace.end():] isEnum = False @@ -154,13 +188,32 @@ def parseFile(self, inputFile): # Message (to be struct) ends => add semicolon so that it'll # be a proper C(++) struct and Doxygen will handle it correctly. line = line[:matchClosingBrace.start()] + "};" + line[matchClosingBrace.end():] - # Search for 'message' and replace it with 'struct' unless 'message' is behind a comment. - matchMsg = re.search("message", line) - if matchMsg is not None and (matchComment is None or matchMsg.start() < matchComment.start()): - output = "struct" + line[:matchMsg.start()] + line[matchMsg.end():] - theOutput += output - else: - theOutput += line + + # Replacements change start of comment... + matchMsg = re.search(r"\bmessage\b", line) + if matchMsg is not None: + line = line[:matchMsg.start()] + "struct" + line[matchMsg.end():] + + # Replacements change start of comment... + matchExt = re.search(r"\bextend\b", line) + if matchExt is not None: + a_extend = line[matchExt.end():] + matchName = re.search(r"\b\w[\S:]+\b", a_extend) + if matchName is not None: + name = a_extend[matchName.start():matchName.end()] + name = re.sub(r'\w+::',r'',name) + a_extend = a_extend[:matchName.start()] + name + ": public " + a_extend[matchName.start():] + else: + a_extend = "_Dummy: public " + a_extend; + line = line[:matchExt.start()] + "struct " + a_extend + + theOutput += line + comment + + if isPackage: + # Close the package namespace + theOutput += "}" + isPackage = False + # Now that we've got all lines in the string let's split the lines and print out # one by one. # This is a workaround to get rid of extra empty line at the end which print() method adds. From 7c75d7dc7beb49f9ad679e6af08338fd3b9de64b Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Thu, 19 Apr 2018 09:58:45 +0200 Subject: [PATCH 02/15] Update documentation --- README | 14 +++++++++++++- doxyfile | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README b/README index 647dc8d..7929291 100644 --- a/README +++ b/README @@ -47,4 +47,16 @@ Version history: not moving member comments before the member but keeping it after the member instead * these changes lead into need of enabling JAVADOC_AUTOBRIEF - - added steps for enabling the filter in Doxygen in this file \ No newline at end of file + - added steps for enabling the filter in Doxygen in this file +-------------------- + 0.7-beta (2018-04-19) OSI + - Include changes from University of California. + - Support for all OSI *.proto files. + - Separate statement and comments totreat both parts different (remove bugs + regarding string modifications). + - Remove "option" statements. + - Add support for "extend" statements. + - Change "repeat" from Template to standard member. --> Better collaboration + diagrams. + - Fix problems with references of nested messages (replace "." with "::"). + - Change mapping from C to C++. diff --git a/doxyfile b/doxyfile index ad14802..5a89ee2 100644 --- a/doxyfile +++ b/doxyfile @@ -32,7 +32,7 @@ PROJECT_NAME = "Protocol Buffers demo project" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 0.6-beta +PROJECT_NUMBER = 0.7-beta # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer @@ -238,7 +238,7 @@ OPTIMIZE_OUTPUT_VHDL = NO # (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions # you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. -EXTENSION_MAPPING = proto=C +EXTENSION_MAPPING = proto=C++ # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should From 4d5b26ca912f855f2f8a97d7fcf1401ed9d1ae9d Mon Sep 17 00:00:00 2001 From: Carlo van Driesten Date: Fri, 20 Apr 2018 14:15:48 +0200 Subject: [PATCH 03/15] Fixed Typo --- README | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README b/README index 7929291..0994dc3 100644 --- a/README +++ b/README @@ -52,7 +52,7 @@ Version history: 0.7-beta (2018-04-19) OSI - Include changes from University of California. - Support for all OSI *.proto files. - - Separate statement and comments totreat both parts different (remove bugs + - Separate statement and comments to treat both parts differently (remove bugs regarding string modifications). - Remove "option" statements. - Add support for "extend" statements. From 57e1d321f494ac0ea336cea3574dab2154ea8aa3 Mon Sep 17 00:00:00 2001 From: carsten-kuebler <32508295+carsten-kuebler@users.noreply.github.com> Date: Mon, 23 Apr 2018 15:35:13 +0200 Subject: [PATCH 04/15] Add support for python2 I --- proto2cpp.py | 55 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/proto2cpp.py b/proto2cpp.py index c3a5ffd..2275927 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -90,25 +90,48 @@ def handleFile(self, fileName): if fnmatch.fnmatch(filename, '*.proto'): self.log('\nXXXXXXXXXX\nXX ' + filename + '\nXXXXXXXXXX\n\n') # Open the file. Use try to detect whether or not we have an actual file. - try: - with open(filename, 'r', encoding='utf8') as inputFile: - self.parseFile(inputFile) - pass - except IOError as e: - self.logError('the file ' + filename + ' could not be opened for reading') + if (sys.version_info > (3, 0)): + try: + with open(filename, 'r', encoding='utf8') as inputFile: + self.parseFile(inputFile) + pass + except IOError as e: + self.logError('the file ' + filename + ' could not be opened for reading') + else: + # Python 2 code in this block + try: + with open(filename, 'r') as inputFile: + self.parseFile(inputFile) + pass + except IOError as e: + self.logError('the file ' + filename + ' could not be opened for reading') elif not fnmatch.fnmatch(filename, os.path.basename(inspect.getfile(inspect.currentframe()))): self.log('\nXXXXXXXXXX\nXX ' + filename + '\nXXXXXXXXXX\n\n') - try: - with open(filename, 'r', encoding='utf8') as theFile: - output = '' - for theLine in theFile: - output += theLine - print(output) - self.log(output) - pass - except IOError as e: - self.logError('the file ' + filename + ' could not be opened for reading') + if (sys.version_info > (3, 0)): + try: + with open(filename, 'r', encoding='utf8') as theFile: + output = '' + for theLine in theFile: + output += theLine + print(output) + self.log(output) + pass + except IOError as e: + self.logError('the file ' + filename + ' could not be opened for reading') + else: + # Python 2 code in this block + try: + with open(filename, 'r') as theFile: + output = '' + for theLine in theFile: + output += theLine + print(output) + self.log(output) + pass + except IOError as e: + self.logError('the file ' + filename + ' could not be opened for reading') + else: self.log('\nXXXXXXXXXX\nXX ' + filename + ' --skipped--\nXXXXXXXXXX\n\n') From 87a1555352f8c1619a71b689248da8c92b12cff9 Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Tue, 24 Apr 2018 17:14:47 +0200 Subject: [PATCH 05/15] Improve code Change code --- proto2cpp.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/proto2cpp.py b/proto2cpp.py index 2275927..1f8789c 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -197,10 +197,9 @@ def parseFile(self, inputFile): if matchEnum is not None: isEnum = True - # Search again for semicolon if we have detected an enum, and replace semicolon with comma. - if isEnum is True and re.search(";", line) is not None: - matchSemicolon = re.search(";", line) - line = line[:matchSemicolon.start()] + "," + line[matchSemicolon.end():] + # Search semicolon if we have detected an enum, and replace semicolon with comma. + if isEnum is True and matchSemicolon is not None: + line = line.replace(";", ",") # Search for a closing brace. matchClosingBrace = re.search("}", line) From 940f628138e1008e05137a9a81f4a2b4dff3c829 Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Wed, 25 Apr 2018 09:24:04 +0200 Subject: [PATCH 06/15] Bugfix Name of a messag extension could be only one char. --- proto2cpp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proto2cpp.py b/proto2cpp.py index 1f8789c..bbfd55f 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -220,7 +220,7 @@ def parseFile(self, inputFile): matchExt = re.search(r"\bextend\b", line) if matchExt is not None: a_extend = line[matchExt.end():] - matchName = re.search(r"\b\w[\S:]+\b", a_extend) + matchName = re.search(r"\b\w[\S:]*\b", a_extend) if matchName is not None: name = a_extend[matchName.start():matchName.end()] name = re.sub(r'\w+::',r'',name) From 8d50f19dd9fd4610b2ea126ed5c6f764a86a542f Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Wed, 25 Apr 2018 09:43:13 +0200 Subject: [PATCH 07/15] Documentation Remove spaces at eol. Bugfix: Python 3 is ">= (3,0)" --- proto2cpp.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/proto2cpp.py b/proto2cpp.py index bbfd55f..e0703b0 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -49,7 +49,7 @@ import inspect ## Class for converting Google Protocol Buffers .proto files into C++ style output to enable Doxygen usage. -## +## ## The C++ style output is printed into standard output.
## There are three different logging levels for the class: ##
  • #logNone: do not log anything
  • @@ -75,7 +75,7 @@ def __init__(self): self.logFile = "proto2cpp.log" ## Error log file name. self.errorLogFile = "proto2cpp.error.log" - ## Logging level. + ## Logging level. self.logLevel = self.logNone ## Handles a file. @@ -90,7 +90,7 @@ def handleFile(self, fileName): if fnmatch.fnmatch(filename, '*.proto'): self.log('\nXXXXXXXXXX\nXX ' + filename + '\nXXXXXXXXXX\n\n') # Open the file. Use try to detect whether or not we have an actual file. - if (sys.version_info > (3, 0)): + if (sys.version_info >= (3, 0)): try: with open(filename, 'r', encoding='utf8') as inputFile: self.parseFile(inputFile) @@ -136,11 +136,11 @@ def handleFile(self, fileName): self.log('\nXXXXXXXXXX\nXX ' + filename + ' --skipped--\nXXXXXXXXXX\n\n') ## Parser function. - ## + ## ## The function takes a .proto file object as input ## parameter and modifies the contents into C++ style. ## The modified data is printed into standard output. - ## + ## ## @param inputFile Input file object # def parseFile(self, inputFile): @@ -161,46 +161,46 @@ def parseFile(self, inputFile): if matchSemicolon is not None and (matchComment is not None and matchSemicolon.start() < matchComment.start()): comment = "///<" + line[matchComment.end():] # Replace '.' in nested message references with '::' - # don't work for multi-nested references and generates problems with URLs and acronyms + # don't work for multi-nested references and generates problems with URLs and acronyms #comment = re.sub(r'\s(\w+)\.(\w+)\s', r' \1::\2 ', comment) line = line[:matchComment.start()] elif matchComment is not None: comment = "///" + line[matchComment.end():] # replace '.' in nested message references with '::' - # don't work for multi-nested references and generates problems with URLs and acronyms + # don't work for multi-nested references and generates problems with URLs and acronyms #comment = re.sub(r'\s(\w+)\.(\w+)\s', r' \1::\2 ', comment) line = line[:matchComment.start()] else: comment = "" - + # line = line.replace(".", "::") but not in quoted strings (Necessary for import statement) line = re.sub(r'\.(?=(?:[^"]*"[^"]*")*[^"]*$)',r'::',line) # Search for " option ...;", remove it line = re.sub(r'\boption\b[^;]+;', r'', line) - + # Search for " package ", make a namespace matchPackage = re.search(r"\bpackage\b", line) if matchPackage is not None: isPackage = True # Convert to C++-style separator and block instead of statement line = "namespace" + line[:matchPackage.start()] + line[matchPackage.end():].replace(";", " {") - + # Search for " repeated " fields and make them ... #matchRepeated = re.search(r"\brepeated\b", line) #if matchRepeated is not None: # # Convert # line = re.sub(r'\brepeated\s+(\S+)', r' repeated \1', line) - + # Search for "enum", start changing all semicolons (";") to commas (","). matchEnum = re.search(r"\benum\b", line) if matchEnum is not None: isEnum = True - + # Search semicolon if we have detected an enum, and replace semicolon with comma. if isEnum is True and matchSemicolon is not None: line = line.replace(";", ",") - + # Search for a closing brace. matchClosingBrace = re.search("}", line) if isEnum is True and matchClosingBrace is not None: @@ -210,12 +210,12 @@ def parseFile(self, inputFile): # Message (to be struct) ends => add semicolon so that it'll # be a proper C(++) struct and Doxygen will handle it correctly. line = line[:matchClosingBrace.start()] + "};" + line[matchClosingBrace.end():] - + # Replacements change start of comment... matchMsg = re.search(r"\bmessage\b", line) if matchMsg is not None: line = line[:matchMsg.start()] + "struct" + line[matchMsg.end():] - + # Replacements change start of comment... matchExt = re.search(r"\bextend\b", line) if matchExt is not None: @@ -226,16 +226,16 @@ def parseFile(self, inputFile): name = re.sub(r'\w+::',r'',name) a_extend = a_extend[:matchName.start()] + name + ": public " + a_extend[matchName.start():] else: - a_extend = "_Dummy: public " + a_extend; + a_extend = "_Dummy: public " + a_extend; line = line[:matchExt.start()] + "struct " + a_extend - + theOutput += line + comment - + if isPackage: # Close the package namespace theOutput += "}" isPackage = False - + # Now that we've got all lines in the string let's split the lines and print out # one by one. # This is a workaround to get rid of extra empty line at the end which print() method adds. @@ -246,7 +246,7 @@ def parseFile(self, inputFile): # Our logger does not add extra line breaks so explicitly adding one to make the log more readable. self.log(line + '\n') else: - self.log('\n --- skipped empty line') + self.log('\n --- skipped empty line\n') ## Writes @p string to log file. ## From 90bdbd99f7ef11a4ed449e91888792972a2d0852 Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Fri, 7 Dec 2018 17:21:14 +0100 Subject: [PATCH 08/15] Update proto2cpp.py Bugfix - Typo remove - Multiline Comments use "/**" , " *" and "*/" instead of "///" Doxygen can not handle long comments with "///". HTML output-Files contains sometimes "///" --- proto2cpp.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/proto2cpp.py b/proto2cpp.py index e0703b0..8cf3f8e 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -146,7 +146,8 @@ def handleFile(self, fileName): def parseFile(self, inputFile): # Go through the input file line by line. isEnum = False - inPackage = False + isPackage = False + isMultilineComment = False # This variable is here as a workaround for not getting extra line breaks (each line # ends with a line separator and print() method will add another one). # We will be adding lines into this var and then print the var out at the end. @@ -165,13 +166,20 @@ def parseFile(self, inputFile): #comment = re.sub(r'\s(\w+)\.(\w+)\s', r' \1::\2 ', comment) line = line[:matchComment.start()] elif matchComment is not None: - comment = "///" + line[matchComment.end():] + if isMultilineComment: + comment = " * " + line[matchComment.end():] + else: + comment = "/** " + line[matchComment.end():] + isMultilineComment = True # replace '.' in nested message references with '::' # don't work for multi-nested references and generates problems with URLs and acronyms #comment = re.sub(r'\s(\w+)\.(\w+)\s', r' \1::\2 ', comment) line = line[:matchComment.start()] else: comment = "" + if isMultilineComment: + theOutput += " */\n" + isMultilineComment = False # line = line.replace(".", "::") but not in quoted strings (Necessary for import statement) line = re.sub(r'\.(?=(?:[^"]*"[^"]*")*[^"]*$)',r'::',line) From 4c5a0457357f8382f64fadfaffa8a248208e691e Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Fri, 7 Dec 2018 17:55:32 +0100 Subject: [PATCH 09/15] Update proto2cpp.py Bugfix --- proto2cpp.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proto2cpp.py b/proto2cpp.py index 8cf3f8e..d1b0988 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -177,7 +177,9 @@ def parseFile(self, inputFile): line = line[:matchComment.start()] else: comment = "" - if isMultilineComment: + + # End multiline comment, if there is no comment or if there are some chars before the comment. + if (matchComment is None or len(re.sub(r'\S*',r'',line))>0) and isMultilineComment: theOutput += " */\n" isMultilineComment = False From 2a5d5c1db1896b13c94188bd5b9aec3daadd6fbf Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Fri, 7 Dec 2018 18:43:50 +0100 Subject: [PATCH 10/15] Update proto2cpp.py Documentation --- proto2cpp.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/proto2cpp.py b/proto2cpp.py index d1b0988..7cc374d 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -4,7 +4,7 @@ # This script converts .proto files into C++ style ones # and prints the output to standard output. # -# version 0.7-beta OSI +# version 0.8-beta OSI # # How to enable this filter in Doxygen: # 1. Generate Doxygen configuration file with command 'doxygen -g ' @@ -21,7 +21,8 @@ # doxygen doxyfile # # -# Version 0.7 2018 Bugfix and extensions have been made by Open Simulation Interface (OSI) Carsten Kuebler https://github.com/OpenSimulationInterface +# Version 0.8 2018 Bugfix regarding long comments, remove typo +# Version 0.7 2018 Bugfix and extensions have been made by Open Simulation Interface (OSI) Carsten Kuebler https://github.com/OpenSimulationInterface, # Copyright (C) 2016 Regents of the University of California https://github.com/vgteam/vg # Copyright (C) 2012-2015 Timo Marjoniemi https://sourceforge.net/p/proto2cpp/wiki/Home/ # All rights reserved. From a6378871e5835d2bba71644438c10c70e5dc7cf6 Mon Sep 17 00:00:00 2001 From: Carsten Kuebler Date: Fri, 7 Dec 2018 20:25:00 +0100 Subject: [PATCH 11/15] Update proto2cpp.py Bugfix long comments --- proto2cpp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proto2cpp.py b/proto2cpp.py index 7cc374d..b8d3d63 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -180,9 +180,9 @@ def parseFile(self, inputFile): comment = "" # End multiline comment, if there is no comment or if there are some chars before the comment. - if (matchComment is None or len(re.sub(r'\S*',r'',line))>0) and isMultilineComment: - theOutput += " */\n" - isMultilineComment = False + if (matchComment is None or re.search("\S", line) is not None) and isMultilineComment: + theOutput += " */\n" + isMultilineComment = False # line = line.replace(".", "::") but not in quoted strings (Necessary for import statement) line = re.sub(r'\.(?=(?:[^"]*"[^"]*")*[^"]*$)',r'::',line) From d8641d1890f8c3a479c5399853df22e38f53e57f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20K=C3=BCbler?= <32508295+carsten-kuebler@users.noreply.github.com> Date: Sun, 9 Dec 2018 15:30:28 +0100 Subject: [PATCH 12/15] Update proto2cpp.py additional work arounds for doxygen --- proto2cpp.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/proto2cpp.py b/proto2cpp.py index b8d3d63..e31f113 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -180,7 +180,7 @@ def parseFile(self, inputFile): comment = "" # End multiline comment, if there is no comment or if there are some chars before the comment. - if (matchComment is None or re.search("\S", line) is not None) and isMultilineComment: + if (matchComment is None or len(line.strip())>0) and isMultilineComment: theOutput += " */\n" isMultilineComment = False @@ -240,7 +240,7 @@ def parseFile(self, inputFile): a_extend = "_Dummy: public " + a_extend; line = line[:matchExt.start()] + "struct " + a_extend - theOutput += line + comment + theOutput += (line.strip() + ' ' + comment.strip()).strip() + '\n' if isPackage: # Close the package namespace @@ -253,11 +253,8 @@ def parseFile(self, inputFile): lines = theOutput.splitlines() for line in lines: if len(line) > 0: - print(line) - # Our logger does not add extra line breaks so explicitly adding one to make the log more readable. + print(line) # Add linebreak to generate documentation correct. self.log(line + '\n') - else: - self.log('\n --- skipped empty line\n') ## Writes @p string to log file. ## From 6972ae8cf574244c908fc9e3415232e2cf216099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20K=C3=BCbler?= <32508295+carsten-kuebler@users.noreply.github.com> Date: Sun, 9 Dec 2018 17:40:22 +0100 Subject: [PATCH 13/15] Change file format for README Change Readme file format to md --- README => README.md | 97 ++++++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 33 deletions(-) rename README => README.md (68%) diff --git a/README b/README.md similarity index 68% rename from README rename to README.md index 0994dc3..607d8d4 100644 --- a/README +++ b/README.md @@ -1,5 +1,6 @@ -Doxygen filter for Google Protocol Buffers .proto files. -==================== +Doxygen filter for Google Protocol Buffers .proto files +======================================================= + How to enable this filter in Doxygen: 1. Generate Doxygen configuration file with command 'doxygen -g ' e.g. doxygen -g doxyfile @@ -14,20 +15,44 @@ How to enable this filter in Doxygen: INPUT_FILTER = "python proto2cpp.py" 6. Run Doxygen with the modified configuration doxygen doxyfile -==================== -Version history: --------------------- - 0.1-pre-alpha (2012-06-13) - - initial version + +Version history +=============== + +0.8-beta (2018-12-09) OSI +------------------------- + - Bugfix regarding long comments, remove typo + - Bugfix and extensions have been made by Open Simulation Interface (OSI) Carsten Kuebler https://github.com/OpenSimulationInterface + +0.7-beta (2018-04-19) OSI +------------------------- + - Include changes from University of California. + - Support for all OSI *.proto files. + - Separate statement and comments to treat both parts differently (remove bugs + regarding string modifications). + - Remove "option" statements. + - Add support for "extend" statements. + - Change "repeat" from Template to standard member. --> Better collaboration + diagrams. + - Fix problems with references of nested messages (replace "." with "::"). + - Change mapping from C to C++. + - Bugfix and extensions have been made by Open Simulation Interface (OSI) Carsten Kuebler https://github.com/OpenSimulationInterface + +0.6-beta (2015-07-27) -------------------- - 0.2-pre-alpha (2012-06-15) - - added support for enums + - made output to be more compact by removing extra empty lines and + not moving member comments before the member but keeping it after + the member instead + * these changes lead into need of enabling JAVADOC_AUTOBRIEF + - added steps for enabling the filter in Doxygen in this file + +0.5-beta (2014-11-16) -------------------- - 0.3-alpha (2013-01-29) - - moved .proto file parsing logic to another function - - added comments to the file + - fixed enum ending to have semicolon to have proper enum syntax + in struct (thanks to m47iast for pointing this out) + +0.4-beta (2013-08-29) -------------------- - 0.4-beta (2013-08-29) - 'classified' proto2cpp and updated documentation to make the script itself Doxygen compatible - changed all print statements to print() functions @@ -37,26 +62,32 @@ Version history: - made a change so that .proto files are converted before printing and other files are printed to stdout as is * this allows using the filter with multiple file types + +0.3-alpha (2013-01-29) -------------------- - 0.5-beta (2014-11-16) - - fixed enum ending to have semicolon to have proper enum syntax - in struct (thanks to m47iast for pointing this out) + - moved .proto file parsing logic to another function + - added comments to the file + +0.2-pre-alpha (2012-06-15) -------------------- - 0.6-beta (2015-07-27) - - made output to be more compact by removing extra empty lines and - not moving member comments before the member but keeping it after - the member instead - * these changes lead into need of enabling JAVADOC_AUTOBRIEF - - added steps for enabling the filter in Doxygen in this file + - added support for enums + +0.1-pre-alpha (2012-06-13) -------------------- - 0.7-beta (2018-04-19) OSI - - Include changes from University of California. - - Support for all OSI *.proto files. - - Separate statement and comments to treat both parts differently (remove bugs - regarding string modifications). - - Remove "option" statements. - - Add support for "extend" statements. - - Change "repeat" from Template to standard member. --> Better collaboration - diagrams. - - Fix problems with references of nested messages (replace "." with "::"). - - Change mapping from C to C++. + - initial version + + +Copyright +========= + +Version 0.7-beta - +------------------ +Extensions for Open Simulation Interface - License MIT + +Version 0.7-beta +---------------- +Copyright (C) 2016 Regents of the University of California https://github.com/vgteam/vg + +Version 0.1-beta - 0.6-beta +---------------------------- +Copyright (C) 2012-2015 Timo Marjoniemi https://sourceforge.net/p/proto2cpp/wiki/Home/ From 2fa212b2b0e5757f3c7403e27457136feccaf63e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20K=C3=BCbler?= <32508295+carsten-kuebler@users.noreply.github.com> Date: Sun, 9 Dec 2018 18:15:47 +0100 Subject: [PATCH 14/15] Update documentation. Update documentation. --- README.md | 19 ++++++++++--------- proto2cpp.py | 12 +++++------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 607d8d4..10a9b73 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,19 @@ Doxygen filter for Google Protocol Buffers .proto files How to enable this filter in Doxygen: 1. Generate Doxygen configuration file with command 'doxygen -g ' e.g. doxygen -g doxyfile - 2. In the Doxygen configuration file, find JAVADOC_AUTOBRIEF and set it enabled - JAVADOC_AUTOBRIEF = YES - This is required since version 0.6-beta - 3. In the Doxygen configuration file, find FILE_PATTERNS and add *.proto + 2. In the Doxygen configuration file, find FILE_PATTERNS and add *.proto FILE_PATTERNS = *.proto - 4. In the Doxygen configuration file, find EXTENSION_MAPPING and add proto=C - EXTENSION_MAPPING = proto=C - 5. In the Doxygen configuration file, find INPUT_FILTER and add this script + 3. In the Doxygen configuration file, find EXTENSION_MAPPING and add proto=C + EXTENSION_MAPPING = proto=C++ + 4. In the Doxygen configuration file, find INPUT_FILTER and add this script INPUT_FILTER = "python proto2cpp.py" - 6. Run Doxygen with the modified configuration + 5. Run Doxygen with the modified configuration doxygen doxyfile - + +Following change is recommended by Timo Marjoniemi but must not be used: + In the Doxygen configuration file, find JAVADOC_AUTOBRIEF and set it enabled + JAVADOC_AUTOBRIEF = YES + Version history =============== diff --git a/proto2cpp.py b/proto2cpp.py index e31f113..a355aaa 100644 --- a/proto2cpp.py +++ b/proto2cpp.py @@ -9,15 +9,13 @@ # How to enable this filter in Doxygen: # 1. Generate Doxygen configuration file with command 'doxygen -g ' # e.g. doxygen -g doxyfile -# 2. In the Doxygen configuration file, find JAVADOC_AUTOBRIEF and set it enabled -# JAVADOC_AUTOBRIEF = YES -# 3. In the Doxygen configuration file, find FILE_PATTERNS and add *.proto +# 2. In the Doxygen configuration file, find FILE_PATTERNS and add *.proto # FILE_PATTERNS = *.proto -# 4. In the Doxygen configuration file, find EXTENSION_MAPPING and add proto=C++ -# EXTENSION_MAPPING = proto=C -# 5. In the Doxygen configuration file, find INPUT_FILTER and add this script +# 3. In the Doxygen configuration file, find EXTENSION_MAPPING and add proto=C++ +# EXTENSION_MAPPING = proto=C++ +# 4. In the Doxygen configuration file, find INPUT_FILTER and add this script # INPUT_FILTER = "python proto2cpp.py" -# 6. Run Doxygen with the modified configuration +# 5. Run Doxygen with the modified configuration # doxygen doxyfile # # From c75f9f6508f22840e77f2500602e5d32c4b9aa48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carsten=20K=C3=BCbler?= <32508295+carsten-kuebler@users.noreply.github.com> Date: Sun, 9 Dec 2018 18:26:55 +0100 Subject: [PATCH 15/15] Update README.md Update readme format --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 10a9b73..7035741 100644 --- a/README.md +++ b/README.md @@ -2,19 +2,19 @@ Doxygen filter for Google Protocol Buffers .proto files ======================================================= How to enable this filter in Doxygen: - 1. Generate Doxygen configuration file with command 'doxygen -g ' + 1. Generate Doxygen configuration file with command 'doxygen -g ': e.g. doxygen -g doxyfile - 2. In the Doxygen configuration file, find FILE_PATTERNS and add *.proto + 2. In the Doxygen configuration file, find FILE_PATTERNS and add *.proto: FILE_PATTERNS = *.proto - 3. In the Doxygen configuration file, find EXTENSION_MAPPING and add proto=C + 3. In the Doxygen configuration file, find EXTENSION_MAPPING and add proto=C++: EXTENSION_MAPPING = proto=C++ - 4. In the Doxygen configuration file, find INPUT_FILTER and add this script + 4. In the Doxygen configuration file, find INPUT_FILTER and add this script: INPUT_FILTER = "python proto2cpp.py" - 5. Run Doxygen with the modified configuration + 5. Run Doxygen with the modified configuration: doxygen doxyfile Following change is recommended by Timo Marjoniemi but must not be used: - In the Doxygen configuration file, find JAVADOC_AUTOBRIEF and set it enabled + In the Doxygen configuration file, find JAVADOC_AUTOBRIEF and set it enabled: JAVADOC_AUTOBRIEF = YES Version history