3 # extractuicbdoc.py - extract uicb documentation from awesome sour code
4 # Copyright (C) 2008 Julien Danjou <julien@danjou.info>
6 # This indeed crappy. Any better version, even with awk, would be welcome.
12 def extract_doc(file):
18 for line
in file.readlines():
23 # We only want functions with uicb
24 if line
.startswith("uicb_"):
25 if line
.endswith("arg __attribute__ ((unused)))\n"):
26 doc
.append("No argument needed.")
27 uicb_name
= line
.split('_', 1)[1]
28 uicb_name
= uicb_name
.split('(', 1)[0]
29 function_doc
[uicb_name
] = doc
34 if line
.startswith("/**"):
36 doc
.append(line
[4:].replace("\n", ""))
37 if doc_begin
and line
.startswith(" * ") and not line
.startswith(" * \\"):
38 doc
.append(line
[3:].replace("\n", ""))
39 if line
.startswith(" */"):
45 def doc_print(function_doc
, filename
):
46 if not len(function_doc
):
48 filename
= os
.path
.basename(filename
)
50 if filename
== "uicb.c":
51 filename
= "general.c"
53 tmptitle
= filename
.replace(".c", "")
54 title
= tmptitle
[0].upper() + tmptitle
[1:]
63 for uicb
, doc
in function_doc
.items():
66 print " %s" % " ".join(doc
)
69 for f
in sys
.argv
[1:]:
70 doc_print(extract_doc(file(f
)), f
)