diff options
Diffstat (limited to 'man')
-rwxr-xr-x | man/docgen | 68 |
1 files changed, 54 insertions, 14 deletions
@@ -6,7 +6,7 @@ # //! # // @arg <extra arguments> # // @category Category -# // @platform <some platform that the parameter is specific to +# // @platform <some platform that the parameter is specific to> # // # // Long description of the parameter # // @@ -19,6 +19,7 @@ import sys import re import glob +import getopt class Category: def __init__(self, description): @@ -54,7 +55,8 @@ class Category: w = self.paramtext_width() for p in self.params: - result += p.plaintext_output(w) + if p.should_show(): + result += p.plaintext_output(w) result = result.rstrip() + "\n" @@ -66,8 +68,9 @@ class Category: self.params.sort() for p in self.params: - result += ".TP\n" - result += p.manpage_output() + if p.should_show(): + result += ".TP\n" + result += p.manpage_output() return result @@ -77,7 +80,14 @@ class Category: self.params.sort() for p in self.params: - result += "; " + p.wiki_output() + "\n" + if p.should_show(): + result += "; " + p.wiki_output() + "\n" + + # Escape special HTML characters + + result = result.replace("&", "&") + result = result.replace("<", "<") + result = result.replace(">", ">") return result @@ -90,6 +100,10 @@ categories = { "compat": Category("Compatibility"), } +# Show options that are in Vanilla Doom? Or only new options? + +show_vanilla_options = True + class Parameter: def __cmp__(self, other): if self.name < other.name: @@ -103,12 +117,16 @@ class Parameter: self.args = None self.platform = None self.category = None + self.vanilla_option = False + + def should_show(self): + return not self.vanilla_option or show_vanilla_options def add_text(self, text): if len(text) <= 0: pass elif text[0] == "@": - match = re.match('@(\S+)\s+(.*)', text) + match = re.match('@(\S+)\s*(.*)', text) if not match: raise "Malformed option line: %s" % text @@ -122,6 +140,8 @@ class Parameter: self.platform = data elif option_type == "category": self.category = data + elif option_type == "vanilla": + self.vanilla_option = True else: raise "Unknown option type '%s'" % option_type @@ -158,7 +178,7 @@ class Parameter: result += self.text if self.platform: - result += "'''(%s only)'''" + result += "'''(%s only)'''" % self.platform return result @@ -305,12 +325,32 @@ def plaintext_output(dir): if c != None: print categories[c].plaintext_output() -if len(sys.argv) > 2 and sys.argv[1] == "-m": - manpage_output(sys.argv[2]) -elif len(sys.argv) > 2 and sys.argv[1] == "-w": - wiki_output(sys.argv[2]) -elif len(sys.argv) > 2 and sys.argv[1] == "-p": - plaintext_output(sys.argv[2]) +def usage(): + print "Usage: %s [-V] ( -m | -w | -p ) <directory>" % sys.argv[0] + print " -m : Manpage output" + print " -w : Wikitext output" + print " -p : Plaintext output" + print " -V : Don't show Vanilla Doom options" + sys.exit(0) + +# Parse command line + +opts, args = getopt.getopt(sys.argv[1:], "mwpV") + +output_function = None + +for opt in opts: + if opt[0] == "-m": + output_function = manpage_output + elif opt[0] == "-w": + output_function = wiki_output + elif opt[0] == "-p": + output_function = plaintext_output + elif opt[0] == "-V": + show_vanilla_options = False + +if output_function == None or len(args) != 1: + usage() else: - print "%s [ -m | -w | -p ] <directory>" % sys.argv[0] + output_function(args[0]) |