<div dir="ltr">Address multiple comments:<div><br></div><div>1. Refactored makedoc2rst class.</div><div>2. Refactored main module</div><div>3. Removed strcmp.rst</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Aug 2, 2018 at 9:44 PM, Dannie Huang <span dir="ltr"><<a href="mailto:danxue.huang@gmail.com" target="_blank">danxue.huang@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">---<br>
README.md | 4 +-<br>
gen_rst_from_makedoc.py | 31 +++++----------<br>
makedoc2rst.py | 99 ++++++++++++++++++++++++++++++<wbr>++++++++++++++++++<br>
makedoc2rst_converter.py | 85 ------------------------------<wbr>-----------<br>
strcmp.rst | 47 -----------------------<br>
5 files changed, 110 insertions(+), 156 deletions(-)<br>
create mode 100644 makedoc2rst.py<br>
delete mode 100644 makedoc2rst_converter.py<br>
delete mode 100644 strcmp.rst<br>
<br>
diff --git a/README.md b/README.md<br>
index 8ebb224..64a3ba9 100644<br>
--- a/README.md<br>
+++ b/README.md<br>
@@ -1,2 +1,2 @@<br>
-# NewlibMarkup2SphinxConvertorPr<wbr>ivate<br>
-(PRIVATE) This repo contains code for NewlibMarkup2SphinxConvertorPr<wbr>ivate.<br>
+# NewlibMarkup2SphinxConverter<br>
+This repo contains code for NewlibMarkup2SphinxConverter<br>
diff --git a/gen_rst_from_makedoc.py b/gen_rst_from_makedoc.py<br>
index 4100756..8e4d9b0 100755<br>
--- a/gen_rst_from_makedoc.py<br>
+++ b/gen_rst_from_makedoc.py<br>
@@ -30,7 +30,7 @@<br>
#<br>
<br>
import argparse<br>
-import makedoc2rst_converter<br>
+import makedoc2rst<br>
<br>
<br>
def get_parser():<br>
@@ -38,37 +38,24 @@ def get_parser():<br>
description='Convert newlib style markup to rst markup'<br>
)<br>
parser.add_argument(<br>
- '-s',<br>
- '--source_file_path',<br>
+ '-c',<br>
+ '--c_file_path',<br>
type=str,<br>
- help='Path of source file with newlib style comments',<br>
+ help='Path of c source file with newlib style comments',<br>
)<br>
parser.add_argument(<br>
- '-d',<br>
- '--dest_file_path',<br>
+ '-r',<br>
+ '--rst_file_path',<br>
type=str,<br>
help='Path of destination file with rst markup',<br>
)<br>
return parser<br>
<br>
<br>
-def main(source_file_dir, dest_file_dir):<br>
- with open(source_file_dir, 'r') as source_file, open(dest_file_dir, 'w') as dest_file:<br>
- file_content = source_file.read()<br>
-<br>
- makedoc2rst = makedoc2rst_converter.<wbr>makedoc2rst_converter()<br>
- # Get comments inside of /* */<br>
- comments = makedoc2rst.extract_comments(<wbr>file_content)<br>
-<br>
- # Parse comments<br>
- command_text_dict = makedoc2rst.extract_command_<wbr>and_text(comments)<br>
-<br>
- # Process text based on command type<br>
- rst_str = makedoc2rst.generate_rst(<wbr>command_text_dict)<br>
-<br>
- dest_file.write(rst_str)<br>
+def main(c_file, rst_file):<br>
+ makedoc2rst.makedoc2rst(c_<wbr>file, rst_file).convert()<br>
<br>
<br>
if __name__ == '__main__':<br>
args = get_parser().parse_args()<br>
- main(args.source_file_path, args.dest_file_path)<br>
+ main(args.c_file_path, args.rst_file_path)<br>
diff --git a/makedoc2rst.py b/makedoc2rst.py<br>
new file mode 100644<br>
index 0000000..d887323<br>
--- /dev/null<br>
+++ b/makedoc2rst.py<br>
@@ -0,0 +1,99 @@<br>
+#!/usr/bin/env python<br>
+#<br>
+# RTEMS Tools Project (<a href="http://www.rtems.org/" rel="noreferrer" target="_blank">http://www.rtems.org/</a>)<br>
+# Copyright 2018 Danxue Huang (<a href="mailto:danxue.huang@gmail.com">danxue.huang@gmail.com</a>)<br>
+# All rights reserved.<br>
+#<br>
+# This file is part of the RTEMS Tools package in 'rtems-tools'.<br>
+#<br>
+# Redistribution and use in source and binary forms, with or without<br>
+# modification, are permitted provided that the following conditions are met:<br>
+#<br>
+# 1. Redistributions of source code must retain the above copyright notice,<br>
+# this list of conditions and the following disclaimer.<br>
+#<br>
+# 2. Redistributions in binary form must reproduce the above copyright notice,<br>
+# this list of conditions and the following disclaimer in the documentation<br>
+# and/or other materials provided with the distribution.<br>
+#<br>
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE<br>
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
+# POSSIBILITY OF SUCH DAMAGE.<br>
+#<br>
+<br>
+import re<br>
+import rst<br>
+<br>
+<br>
+class makedoc2rst():<br>
+ """ Convert c source file with makedoc markup to rst markup file<br>
+ c_file: c source file containing block comments (/* */) at the beginning<br>
+ rst_file: destination file with rst markup<br>
+ """<br>
+ def __init__(self, c_file, rst_file):<br>
+ self.c_file = c_file<br>
+ self.rst_file = rst_file<br>
+<br>
+ def convert(self):<br>
+ """ Implementation of converting c file to rst file """<br>
+ rst_str = ''<br>
+ with open(self.c_file, 'r') as c_file:<br>
+ # Get comments inside of /* */<br>
+ comments = self._extract_comments(c_file.<wbr>read())<br>
+ # Parse comments<br>
+ command_text_dict = self._extract_command_and_<wbr>text(comments)<br>
+ # Process text based on command type<br>
+ for command, text in command_text_dict.items():<br>
+ rst_str += rst.get_command_processor(<wbr>command)(command, text)<br>
+<br>
+ with open(self.rst_file, 'w') as rst_file:<br>
+ rst_file.write(rst_str)<br>
+ return rst_str<br>
+<br>
+ def _is_command(self, s):<br>
+ """<br>
+ A command is a single word of at least 3 characters, all uppercase<br>
+ :param s: input string<br>
+ :return: True if s is a single command, otherwise False<br>
+ """<br>
+ return True if re.match('^[A-Z_]{3,}\s*$', s) else False<br>
+<br>
+ def _extract_comments(self, content):<br>
+ """<br>
+ Extract content inside of /* */<br>
+ :param content: input file content<br>
+ :return: extracted comments<br>
+ """<br>
+ comments = ''<br>
+ comments_match = re.match('/\*(\*(?!/)|[^*])*\*<wbr>/', content)<br>
+ if comments_match:<br>
+ wrapped_comments = comments_match.group()<br>
+ comments = wrapped_comments.lstrip('/*').<wbr>rstrip('*/').lstrip().rstrip()<br>
+ return comments<br>
+<br>
+ def _extract_command_and_text(<wbr>self, comments):<br>
+ """<br>
+ Extract command and text from input string content<br>
+ :param comments: input string containing command and text<br>
+ :return: a tuple containing command and text<br>
+ """<br>
+ command = ''<br>
+ text = ''<br>
+ command_text_dict = {}<br>
+ for line in comments.splitlines():<br>
+ if self._is_command(line):<br>
+ if command and text:<br>
+ command_text_dict[command] = text<br>
+ command = line.rstrip()<br>
+ text = ''<br>
+ else:<br>
+ text += line + '\n'<br>
+ return command_text_dict<br>
diff --git a/makedoc2rst_converter.py b/makedoc2rst_converter.py<br>
deleted file mode 100644<br>
index e4d2d72..0000000<br>
--- a/makedoc2rst_converter.py<br>
+++ /dev/null<br>
@@ -1,85 +0,0 @@<br>
-#!/usr/bin/env python<br>
-#<br>
-# RTEMS Tools Project (<a href="http://www.rtems.org/" rel="noreferrer" target="_blank">http://www.rtems.org/</a>)<br>
-# Copyright 2018 Danxue Huang (<a href="mailto:danxue.huang@gmail.com">danxue.huang@gmail.com</a>)<br>
-# All rights reserved.<br>
-#<br>
-# This file is part of the RTEMS Tools package in 'rtems-tools'.<br>
-#<br>
-# Redistribution and use in source and binary forms, with or without<br>
-# modification, are permitted provided that the following conditions are met:<br>
-#<br>
-# 1. Redistributions of source code must retain the above copyright notice,<br>
-# this list of conditions and the following disclaimer.<br>
-#<br>
-# 2. Redistributions in binary form must reproduce the above copyright notice,<br>
-# this list of conditions and the following disclaimer in the documentation<br>
-# and/or other materials provided with the distribution.<br>
-#<br>
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"<br>
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE<br>
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE<br>
-# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE<br>
-# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR<br>
-# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF<br>
-# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS<br>
-# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN<br>
-# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br>
-# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE<br>
-# POSSIBILITY OF SUCH DAMAGE.<br>
-#<br>
-<br>
-import re<br>
-import rst<br>
-<br>
-<br>
-class makedoc2rst_converter():<br>
- @staticmethod<br>
- def is_command(s):<br>
- """<br>
- A command is a single word of at least 3 characters, all uppercase<br>
- :param s: input string<br>
- :return: True if s is a single command, otherwise False<br>
- """<br>
- return True if re.match('^[A-Z_]{3,}\s*$', s) else False<br>
-<br>
- @staticmethod<br>
- def extract_comments(content):<br>
- """<br>
- Extract content inside of /* */<br>
- :param content: input file content<br>
- :return: extracted comments<br>
- """<br>
- comments = ''<br>
- comments_match = re.match('/\*(\*(?!/)|[^*])*\*<wbr>/', content)<br>
- if comments_match:<br>
- wrapped_comments = comments_match.group()<br>
- comments = wrapped_comments.lstrip('/*').<wbr>rstrip('*/').lstrip().rstrip()<br>
- return comments<br>
-<br>
- @staticmethod<br>
- def extract_command_and_text(<wbr>content):<br>
- """<br>
- Extract command and text from input string content<br>
- :param content: input string containing command and text<br>
- :return: a tuple containing command and text<br>
- """<br>
- command = ''<br>
- text = ''<br>
- command_text_dict = {}<br>
- for line in content.splitlines():<br>
- if makedoc2rst_converter.is_<wbr>command(line):<br>
- if command and text:<br>
- command_text_dict[command] = text<br>
- command = line.rstrip()<br>
- text = ''<br>
- else:<br>
- text += line + '\n'<br>
- return command_text_dict<br>
-<br>
- @staticmethod<br>
- def generate_rst(command_text_<wbr>dict):<br>
- rst_str = ''<br>
- for command, text in command_text_dict.items():<br>
- rst_str += rst.get_command_processor(<wbr>command)(command, text)<br>
- return rst_str<br>
diff --git a/strcmp.rst b/strcmp.rst<br>
deleted file mode 100644<br>
index c1dc543..0000000<br>
--- a/strcmp.rst<br>
+++ /dev/null<br>
@@ -1,47 +0,0 @@<br>
-.. strcmp:<br>
-<br>
-strcmp - Character string compare<br>
------------------------------<wbr>------------<br>
-.. index:: strcmp<br>
-.. index:: character string compare<br>
-<br>
-**INDEX:**<br>
-<br>
- strcmp<br>
-<br>
-<br>
-<br>
-**SYNOPSIS:**<br>
-<br>
-.. code-block:: c<br>
-<br>
- #include <string.h><br>
- int strcmp(const char *<[a]>, const char *<[b]>);<br>
-<br>
-<br>
-<br>
-**DESCRIPTION:**<br>
-<br>
- <<strcmp>> compares the string at <[a]> to<br>
- the string at <[b]>.<br>
-<br>
-<br>
-<br>
-**RETURNS:**<br>
-<br>
- If <<*<[a]>>> sorts lexicographically after <<*<[b]>>>,<br>
- <<strcmp>> returns a number greater than zero. If the two<br>
- strings match, <<strcmp>> returns zero. If <<*<[a]>>><br>
- sorts lexicographically before <<*<[b]>>>, <<strcmp>> returns a<br>
- number less than zero.<br>
-<br>
-<br>
-<br>
-**PORTABILITY:**<br>
-<br>
-<<strcmp>> is ANSI C.<br>
-<br>
-<<strcmp>> requires no supporting OS subroutines.<br>
-<br>
-<br>
-<br>
<span class="HOEnZb"><font color="#888888">-- <br>
2.7.4<br>
<br>
</font></span></blockquote></div><br></div>