I really can't stand nroff syntax.  This makes it possible to install
nroff but write in a more sensible XML syntax.

The following commit adds the first user.

Signed-off-by: Ben Pfaff <b...@nicira.com>
---
 Makefile.am         |   1 +
 build-aux/xml2nroff | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 111 insertions(+)
 create mode 100755 build-aux/xml2nroff

diff --git a/Makefile.am b/Makefile.am
index 28496b3..0480d20 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -104,6 +104,7 @@ EXTRA_DIST = \
        build-aux/dist-docs \
        build-aux/sodepends.pl \
        build-aux/soexpand.pl \
+       build-aux/xml2nroff \
        $(MAN_FRAGMENTS) \
        $(MAN_ROOTS) \
        Vagrantfile
diff --git a/build-aux/xml2nroff b/build-aux/xml2nroff
new file mode 100755
index 0000000..817abc6
--- /dev/null
+++ b/build-aux/xml2nroff
@@ -0,0 +1,110 @@
+#! /usr/bin/python
+
+from datetime import date
+import getopt
+import os
+import sys
+import xml.dom.minidom
+
+from build.nroff import *
+
+argv0 = sys.argv[0]
+
+def usage():
+    print """\
+%(argv0)s: XML to nroff converter
+Converts the XML format supplied as input into an nroff-formatted manpage.
+usage: %(argv0)s [OPTIONS] INPUT.XML
+where INPUT.XML is a manpage in an OVS-specific XML format.
+
+The following options are also available:
+  --version=VERSION           use VERSION to display on document footer
+  -h, --help                  display this help message\
+""" % {'argv0': argv0}
+    sys.exit(0)
+
+def manpage_to_nroff(xml_file, version=None):
+    doc = xml.dom.minidom.parse(xml_file).documentElement
+    d = date.fromtimestamp(os.stat(xml_file).st_mtime)
+
+    if version == None:
+        version = "UNKNOWN"
+    program = doc.attributes['program'].nodeValue
+    title = doc.attributes['title'].nodeValue
+    section = doc.attributes['section'].nodeValue
+
+    # Putting '\" p as the first line tells "man" that the manpage
+    # needs to be preprocessed by "pic".
+    s = r''''\" p
+.\" -*- nroff -*-
+.TH "%s" %s "%s" "Open vSwitch %s" "Open vSwitch Manual"
+.fp 5 L CR              \\" Make fixed-width font available as \\fL.
+.de TQ
+.  br
+.  ns
+.  TP "\\$1"
+..
+.de ST
+.  PP
+.  RS -0.15in
+.  I "\\$1"
+.  RE
+..
+''' % (textToNroff(program), textToNroff(section), textToNroff(title), 
textToNroff(version))
+
+    s += blockXmlToNroff(doc.childNodes) + "\n"
+
+    return s
+
+def usage():
+    print """\
+%(argv0)s: ovsdb schema documentation generator
+Prints documentation for an OVSDB schema as an nroff-formatted manpage.
+usage: %(argv0)s [OPTIONS] SCHEMA XML
+where SCHEMA is an OVSDB schema in JSON format
+  and XML is OVSDB documentation in XML format.
+
+The following options are also available:
+  --version=VERSION           use VERSION to display on document footer
+  -h, --help                  display this help message\
+""" % {'argv0': argv0}
+    sys.exit(0)
+
+if __name__ == "__main__":
+    try:
+        try:
+            options, args = getopt.gnu_getopt(sys.argv[1:], 'hV',
+                                              ['version=', 'help'])
+        except getopt.GetoptError, geo:
+            sys.stderr.write("%s: %s\n" % (argv0, geo.msg))
+            sys.exit(1)
+
+        er_diagram = None
+        title = None
+        version = None
+        for key, value in options:
+            if key == '--version':
+                version = value
+            elif key in ['-h', '--help']:
+                usage()
+            else:
+                sys.exit(0)
+
+        if len(args) != 1:
+            sys.stderr.write("%s: exactly 1 non-option arguments required "
+                             "(use --help for help)\n" % argv0)
+            sys.exit(1)
+
+        s = manpage_to_nroff(args[0], version)
+        for line in s.split("\n"):
+            line = line.strip()
+            if len(line):
+                print line
+
+    except error.Error, e:
+        sys.stderr.write("%s: %s\n" % (argv0, e.msg))
+        sys.exit(1)
+
+# Local variables:
+# mode: python
+# End:
-- 
2.1.3

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to