[PATCH 3/6] autodoc: convert extracted doc to reST

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The extracted doc can't be used as is by sphinx as it needs
to have some additional annotations.

Convert the extracted doc into a true reST format wich can
directy be used by sphinx.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 Documentation/sphinx/cdoc.py | 66 ++++++++++++++++++++++++++++--------
 1 file changed, 51 insertions(+), 15 deletions(-)

diff --git a/Documentation/sphinx/cdoc.py b/Documentation/sphinx/cdoc.py
index ba875242a..29690f6f0 100755
--- a/Documentation/sphinx/cdoc.py
+++ b/Documentation/sphinx/cdoc.py
@@ -156,25 +156,61 @@ def process_file(f):
 
 	return docs
 
+def convert_to_rst(info):
+	lst = []
+	#print('info= ' + str(info))
+	typ = info.get('type', '???')
+	if typ == '???':
+		## uh ?
+		pass
+	elif typ == 'bloc':
+		if 'short' in info:
+			(n, l) = info['short']
+			lst.append((n, l + '\n'))
+		if 'desc' in info:
+			(n, l) = info['desc']
+			lst.append((n, l + '\n'))
+	elif typ == 'func':
+		(n, l) = info['func']
+		l = '.. c:function:: ' + l
+		lst.append((n, l + '\n'))
+		if 'short' in info:
+			(n, l) = info['short']
+			l = l[0].capitalize() + l[1:].strip('.')
+			l = '\t' + l + '.'
+			lst.append((n, l + '\n'))
+		if 'args' in info:
+			for (n, name, l) in info.get('args', []):
+				if name != 'return':
+					name = 'param ' + name
+				l = '\t:%s: %s' % (name, l)
+				lst.append((n, l))
+			lst.append((n+1, ''))
+		if 'desc' in info:
+			desc = info['desc']
+			n = desc[0]
+			r = ''
+			for l in desc[1:]:
+				r += '\t' + l + '\n'
+			lst.append((n, r))
+	return lst
+
+def extract(f):
+	res = process_file(f)
+	res = [ i for r in res for i in convert_to_rst(r) ]
+	return res
+
+def dump_doc(f):
+	lst = extract(f)
+	for (n, lines) in lst:
+		for l in lines.split('\n'):
+			print('%4d: %s' % (n, l))
+			n += 1
 
 if __name__ == '__main__':
 	""" extract the doc from stdin """
 	import sys
 
-	res = process_file(sys.stdin)
-	for info in res:
-		print('###');
-		print('type: %s' % (info.get('type', '???')))
-		val = info.get('short', None)
-		if val:
-			print('short:%4d: %s' % val)
-		for val in info.get('args', []):
-			print('para: %4d: @%s: %s' % val)
-		val = info.get('desc', None)
-		if val:
-			n = val[0]
-			print('desc: %4d:\n\t%s' % (n, '\n\t'.join(val[1:])))
-		for val in info.get('tags', []):
-			print('tags: %4d: @%s: %s' % val)
+	dump_doc(sys.stdin)
 
 # vim: tabstop=4
-- 
2.17.0

--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux