2 ## This file is part of the libsigrok project.
4 ## Copyright (C) 2014 Martin Ling <martin-sigrok@earth.li>
6 ## This program is free software: you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, either version 3 of the License, or
9 ## (at your option) any later version.
11 ## This program is distributed in the hope that it will be useful,
12 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ## GNU General Public License for more details.
16 ## You should have received a copy of the GNU General Public License
17 ## along with this program. If not, see <http://www.gnu.org/licenses/>.
20 from xml.etree import ElementTree
23 language, input_file = sys.argv[1:]
24 input_dir = os.path.dirname(input_file)
26 index = ElementTree.parse(input_file)
29 paras = node.findall('para')
30 return str.join('\n\n', [p.text.rstrip() for p in paras if p.text])
32 for compound in index.findall('compound'):
33 if compound.attrib['kind'] != 'class':
35 class_name = compound.find('name').text
36 if not class_name.startswith('sigrok::'):
38 doc = ElementTree.parse("%s/%s.xml" % (input_dir, compound.attrib['refid']))
39 cls = doc.find('compounddef')
40 brief = get_text(cls.find('briefdescription'))
42 if language == 'python':
43 print '%%feature("docstring") %s "%s";' % (class_name, brief)
44 elif language == 'java':
45 print '%%typemap(javaclassmodifiers) %s "/** %s */\npublic class"' % (
47 for section in cls.findall('sectiondef'):
48 if section.attrib['kind'] != 'public-func':
50 for function in section.findall('memberdef'):
51 function_name = function.find('name').text
52 brief = get_text(function.find('briefdescription'))
54 if language == 'python':
55 print '%%feature("docstring") %s::%s "%s";' % (
56 class_name, function_name, brief)
57 elif language == 'java':
58 print '%%javamethodmodifiers %s::%s "/** %s */\npublic"' % (
59 class_name, function_name, brief)