-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract.py
103 lines (75 loc) · 2.57 KB
/
extract.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import re
from xml.dom import minidom
xmldoc = minidom.parse('xml/classn_tuple_reader.xml')
xmldoc2 = minidom.parse('xml/class_root_file_reader_base.xml')
itemlist = xmldoc.getElementsByTagName('memberdef')
itemlist2 = xmldoc2.getElementsByTagName('memberdef')
#for s in itemlist :
# print s.attributes['name'].value
functionList=[item for item in itemlist if item.attributes['kind'].value=='function']+[item for item in itemlist2 if item.attributes['kind'].value=='function']
def getTextFromNode(elem):
children=elem.childNodes
if len(children)==0:
return None
ret=[]
if len(children)>=1:
for child in children:
if child.nodeType==minidom.Node.TEXT_NODE:
ret.append(child.data)
if child.nodeType==minidom.Node.ELEMENT_NODE and child.tagName==u'verbatim':
ret.append(child.childNodes[0].data)
if child.nodeType==minidom.Node.ELEMENT_NODE and child.tagName==u'ref':
ret.append(child.childNodes[0].data)
return ''.join(ret)
def getText(item,name):
elems=item.getElementsByTagName(name)
if len(elems)>0:
return getTextFromNode(elems[0])
else :
return None
ii=None
excluded=['readNextEntry']
all={}
for item in functionList:
#print item.attributes['kind'].value
if item.attributes['kind'].value=='function':
d={}
for n in ['name','argsstring','type']:
d[n]=getText(item,n)
if d['name'] in excluded:
continue
params=item.getElementsByTagName('param')
pars=[]
for par in params:
pars.append( (getText(par,'type'),getText(par,'declname')) )
desc=item.getElementsByTagName('detaileddescription')[0]
paras=desc.getElementsByTagName('para')
if len(paras)>=1:
d['description']=getTextFromNode(paras[0]).replace('\n','').rstrip()
argDescr=[]
for i in range(1,len(paras)):
argDescr.append( (pars[i-1][0],pars[i-1][1],getTextFromNode(paras[i])) )
d['argDescr']=argDescr
all[d['name']]=d
print all
head=r'''
\item[]
\verb|%(type)s %(name)s%(argsstring)s|\\
%(description)s'''
argTemplate=r'''\\
\null\hspace{7mm}\varref{%s} {\it %s\/}
'''
txt=''
names=all.keys()[:]
names.sort()
for name in names :
d=all[name]
if d.get('description'):
txt=txt+( head % d)
for t,n,desc in d['argDescr']:
print (argTemplate % (n,desc))
txt+= (argTemplate % (n,desc))
txt=re.sub('< ','<',txt)
txt=re.sub(' >','>',txt)
f=open('members.tex','w')
f.write(txt)