]> sigrok.org Git - libsigrok.git/blobdiff - bindings/swig/doc.py
bindings: Transfer C++ documentation strings to Python and Java wrappers.
[libsigrok.git] / bindings / swig / doc.py
diff --git a/bindings/swig/doc.py b/bindings/swig/doc.py
new file mode 100644 (file)
index 0000000..16cc165
--- /dev/null
@@ -0,0 +1,59 @@
+##
+## This file is part of the libsigrok project.
+##
+## Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
+##
+## This program is free software: you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation, either version 3 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program.  If not, see <http://www.gnu.org/licenses/>.
+##
+
+from xml.etree import ElementTree
+import sys, os
+
+language, input_file = sys.argv[1:]
+input_dir = os.path.dirname(input_file)
+
+index = ElementTree.parse(input_file)
+
+def get_text(node):
+    paras = node.findall('para')
+    return str.join('\n\n', [p.text.rstrip() for p in paras if p.text])
+
+for compound in index.findall('compound'):
+    if compound.attrib['kind'] != 'class':
+        continue
+    class_name = compound.find('name').text
+    if not class_name.startswith('sigrok::'):
+        continue
+    doc = ElementTree.parse("%s/%s.xml" % (input_dir, compound.attrib['refid']))
+    cls = doc.find('compounddef')
+    brief = get_text(cls.find('briefdescription'))
+    if brief:
+        if language == 'python':
+            print '%%feature("docstring") %s "%s";' % (class_name, brief)
+        elif language == 'java':
+            print '%%typemap(javaclassmodifiers) %s "/** %s */\npublic class"' % (
+            class_name, brief)
+    for section in cls.findall('sectiondef'):
+        if section.attrib['kind'] != 'public-func':
+            continue
+        for function in section.findall('memberdef'):
+            function_name = function.find('name').text
+            brief = get_text(function.find('briefdescription'))
+            if brief:
+                if language == 'python':
+                    print '%%feature("docstring") %s::%s "%s";' % (
+                        class_name, function_name, brief)
+                elif language == 'java':
+                    print '%%javamethodmodifiers %s::%s "/** %s */\npublic"' % (
+                    class_name, function_name, brief)