shithub: choc

Download patch

ref: 2ac909b51f542a876a058f7210c846f9fc53cc19
parent: 3a0c475b39f4366c16d0c5646cdb0e68f7bf3617
author: Simon Howard <fraggle@gmail.com>
date: Sun Dec 24 21:40:14 EST 2006

Fix up some text escaping errors. Add wikitext output for docgen.

Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 809

--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -6,5 +6,5 @@
 EXTRA_DIST = $(man_MANS) $(MANPAGE_GEN_FILES)
 
 chocolate-doom.6: $(MANPAGE_GEN_FILES)
-	./docgen > $@
+	./docgen -m > $@
 
--- a/man/docgen
+++ b/man/docgen
@@ -1,5 +1,22 @@
 #!/usr/bin/env python
+# 
+# Command line parameter self-documentation tool.  Reads comments from
+# the source code in the following form:
+#
+#   //!
+#   // @arg <extra arguments>
+#   // @category Category
+#   // @platform <some platform that the parameter is specific to
+#   //
+#   // Long description of the parameter
+#   //
+#
+#   something_involving = M_CheckParm("-param");
+#
+# From this, a manpage can be automatically generated of the command
+# line parameters.
 
+import sys
 import re
 import glob
 
@@ -11,15 +28,27 @@
     def add_param(self, param):
         self.params.append(param)
 
-    def format(self):
+    def manpage_output(self):
         result = ".SH " + self.description.upper() + "\n"
 
+        self.params.sort()
+
         for p in self.params:
             result += ".TP\n"
-            result += p.format()
+            result += p.manpage_output()
 
         return result
 
+    def wiki_output(self):
+        result = "=== %s ===\n" % self.description
+
+        self.params.sort()
+
+        for p in self.params:
+            result += "; " + p.wiki_output() + "\n"
+
+        return result
+
 categories = {
     None:      Category("General options"),
     "video":   Category("Display options"),
@@ -30,6 +59,12 @@
 }
 
 class Parameter:
+    def __cmp__(self, other):
+        if self.name < other.name:
+            return -1
+        else:
+            return 1
+
     def __init__(self):
         self.text = ""
         self.name = ""
@@ -61,7 +96,7 @@
         else:
             self.text += text + " "
 
-    def format(self):
+    def manpage_output(self):
         result = self.name
 
         if self.args:
@@ -74,10 +109,27 @@
         if self.platform:
             result += "[%s only] " % self.platform
 
-        result += self.text + "\n"
+        escaped = re.sub('\\\\', '\\\\\\\\', self.text)
 
+        result += escaped + "\n"
+
         return result
 
+    def wiki_output(self):
+        result = self.name
+
+        if self.args:
+            result += " " + self.args
+
+        result += ": "
+
+        result += self.text
+
+        if self.platform:
+            result += "'''(%s only)'''"
+
+        return result
+
 def process_file(file):
     f = open(file)
 
@@ -125,6 +177,14 @@
     finally:
         f.close()
 
+def process_files():
+    # Process all C source files.
+
+    files = glob.glob("../src/*.c")
+
+    for file in files:
+        process_file(file)
+
 def print_file_contents(file):
     f = open(file)
 
@@ -135,20 +195,33 @@
     finally:
         f.close()
 
-# Process all C source files.
+def manpage_output(): 
 
-files = glob.glob("../src/*.c")
+    process_files()
 
-for file in files:
-    process_file(file)
+    print_file_contents("header")
 
-print_file_contents("header")
+    print categories[None].manpage_output()
 
-print categories[None].format()
+    for c in categories:
+        if c != None:
+            print categories[c].manpage_output()
 
-for c in categories:
-    if c != None:
-        print categories[c].format()
+    print_file_contents("footer")
 
-print_file_contents("footer")
+def wiki_output():
+    process_files()
+
+    print categories[None].wiki_output()
+
+    for c in categories:
+        if c != None:
+            print categories[c].wiki_output()
+
+if len(sys.argv) > 1 and sys.argv[1] == "-m":
+    manpage_output()
+elif len(sys.argv) > 1 and sys.argv[1] == "-w":
+    wiki_output()
+else:
+    print "%s [ -m | -w ]" % sys.argv[0]