2008-03-27 17:13:14 +01:00
|
|
|
#!/usr/bin/env python
|
2008-03-27 16:48:52 +01:00
|
|
|
#
|
|
|
|
# extractoptsdoc.py - extract options documentation from awesome sour code
|
|
|
|
# Copyright (C) 2008 Julien Danjou <julien@danjou.info>
|
|
|
|
#
|
|
|
|
# This indeed crappy. Any better version, even with awk, would be welcome.
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def section_print(section, options):
|
|
|
|
print section
|
|
|
|
i = 0
|
|
|
|
underline = ""
|
|
|
|
while i < len(section):
|
|
|
|
underline += "~"
|
|
|
|
i += 1
|
|
|
|
print underline
|
2008-03-27 17:22:35 +01:00
|
|
|
if options.has_key("comments"):
|
|
|
|
print "%s\n" % options.pop("comments")
|
2008-03-27 16:48:52 +01:00
|
|
|
for option, format in options.items():
|
|
|
|
print "%s::" % option
|
|
|
|
print " %s" % format
|
|
|
|
print
|
|
|
|
|
|
|
|
def sections_print(sections):
|
2008-03-27 17:22:35 +01:00
|
|
|
section_print("Base sections", sections.pop("awesome"))
|
2008-03-27 16:48:52 +01:00
|
|
|
keylist = sections.keys()
|
|
|
|
keylist.sort()
|
|
|
|
for key in keylist:
|
2008-03-27 17:22:35 +01:00
|
|
|
section_print(key, sections[key])
|
2008-03-27 16:48:52 +01:00
|
|
|
|
|
|
|
def sections_get(file):
|
|
|
|
sections = {}
|
|
|
|
section_doc = {}
|
|
|
|
section_begin = False
|
|
|
|
for line in file.readlines():
|
|
|
|
if line.startswith("cfg_opt_t"):
|
|
|
|
section_name = (line.split(" ", 1)[1]).split("_opts")[0]
|
2008-03-27 17:22:35 +01:00
|
|
|
section_doc['comments'] = lastline[4:-3]
|
2008-03-27 16:48:52 +01:00
|
|
|
section_begin = True
|
2008-03-27 17:22:35 +01:00
|
|
|
elif section_begin and line.startswith("};"):
|
2008-03-27 16:48:52 +01:00
|
|
|
section_begin = False
|
|
|
|
sections[section_name] = section_doc
|
|
|
|
section_doc = {}
|
2008-03-27 17:22:35 +01:00
|
|
|
elif section_begin and line.startswith(" CFG_"):
|
2008-03-27 16:48:52 +01:00
|
|
|
if line.startswith(" CFG_AWESOME_END"):
|
|
|
|
continue
|
|
|
|
option_title = line.split("\"")[1].split("\"")[0]
|
|
|
|
if lastline.startswith(" /**"):
|
|
|
|
section_doc[option_title] = lastline[8:-3]
|
|
|
|
else:
|
|
|
|
section_doc[option_title] = "Undocumented option. "
|
|
|
|
if line.startswith(" CFG_INT"):
|
|
|
|
section_doc[option_title] += "This option must be an integer value."
|
|
|
|
elif line.startswith(" CFG_BOOL"):
|
|
|
|
section_doc[option_title] += "This option must be a boolean value."
|
|
|
|
elif line.startswith(" CFG_FLOAT"):
|
|
|
|
section_doc[option_title] += "This option must be a float value."
|
|
|
|
elif line.startswith(" CFG_ALIGNMENT"):
|
|
|
|
section_doc[option_title] += "This option must be an alignment value."
|
|
|
|
elif line.startswith(" CFG_POSITION"):
|
|
|
|
section_doc[option_title] += "This option must be a position value."
|
2008-03-27 18:02:53 +01:00
|
|
|
elif line.startswith(" CFG_STR_LIST"):
|
|
|
|
section_doc[option_title] += "This option must be string list."
|
2008-03-27 16:48:52 +01:00
|
|
|
elif line.startswith(" CFG_STR"):
|
|
|
|
section_doc[option_title] += "This option must be string value."
|
|
|
|
elif line.startswith(" CFG_SEC"):
|
|
|
|
secname = (line.split(", ")[1]).split("_opts", 1)[0]
|
|
|
|
section_doc[option_title] += "This option must be a section `%s'" % secname
|
|
|
|
if line.find("CFGF_MULTI") != -1:
|
|
|
|
section_doc[option_title] += ", can be specified multiple times"
|
|
|
|
if line.find("CFGF_NO_TITLE_DUPES") != -1:
|
|
|
|
section_doc[option_title] += ", must have a unique title"
|
|
|
|
elif line.find("CFGF_TITLE") != -1:
|
|
|
|
section_doc[option_title] += ", must have a title"
|
|
|
|
section_doc[option_title] += "."
|
|
|
|
|
|
|
|
lastline = line
|
|
|
|
|
|
|
|
return sections
|
|
|
|
|
|
|
|
sections_print(sections_get(file(sys.argv[1])))
|