[widgets/graph] offset fixed now.
[awesome.git] / build-utils / extractuicbdoc.py
blob7978df8f45bccf702352485dae6c2f4b3a867b56
1 #!/usr/bin/env python
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.
9 import sys
10 import os.path
12 def extract_doc(file):
13 function_doc = {}
14 doc = []
15 doc_begin = False
16 catch_name = 0
18 for line in file.readlines():
19 if catch_name == 1:
20 catch_name = 2
21 continue
22 if catch_name > 1:
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
30 catch_name = False
31 else:
32 catch_name = 0
33 doc = []
34 if line.startswith("/**"):
35 doc_begin = True
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(" */"):
40 doc_begin = False
41 catch_name = 1
43 return function_doc
45 def doc_print(function_doc, filename):
46 if not len(function_doc):
47 return
48 filename = os.path.basename(filename)
49 # Special case
50 if filename == "uicb.c":
51 filename = "general.c"
52 # Print header
53 tmptitle = filename.replace(".c", "")
54 title = tmptitle[0].upper() + tmptitle[1:]
55 print title
56 i = 0
57 underline = ""
58 while i < len(title):
59 underline += "~"
60 i += 1
61 print underline
62 # Print documentation
63 for uicb, doc in function_doc.items():
64 # Special case
65 print "*%s*::" % uicb
66 print " %s" % " ".join(doc)
67 print
69 for f in sys.argv[1:]:
70 doc_print(extract_doc(file(f)), f)