From 21c9dd60751f17acbbf918da8c3facad1e0e093e Mon Sep 17 00:00:00 2001 From: Peter Simons Date: Mon, 27 Jul 2009 23:17:58 +0200 Subject: maint: implemented texinfo generator --- macro2texi.py | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 macro2texi.py (limited to 'macro2texi.py') diff --git a/macro2texi.py b/macro2texi.py new file mode 100755 index 0000000..1445e2d --- /dev/null +++ b/macro2texi.py @@ -0,0 +1,63 @@ +#! /usr/bin/env python + +assert __name__ == "__main__" + +import sys +from macro import Macro, writeFile + +tmpl = """\ +@node %(name)s +@unnumbered %(name)s + +@majorheading Synopsis + +%(synopsis)s + +@majorheading Description + +%(description)s + +@majorheading Homepage + +@url{http://www.nongnu.org/autoconf-archive/%(name)s.html} + +@majorheading License + +%(authors)s + +%(license)s +""" + +def quoteTexi(buf): + return buf.replace('@', "@@").replace('{', "@{").replace('}', "@}") + +def formatParagraph(para): + assert para + assert para[0] + assert para[0][0] + if para[0][0].isspace(): + return "@smallexample\n%s\n@end smallexample" % quoteTexi('\n'.join(para)) + else: + return quoteTexi('\n'.join(para)) + +def formatAuthor(a): + assert a + a["year"] = quoteTexi(a["year"]) + a["name"] = quoteTexi(a["name"]) + if "email" in a: + a["email"] = quoteTexi(a["email"]) + return "Copyright @copyright{} %(year)s %(name)s @email{%(email)s}" % a + else: + return "Copyright @copyright{} %(year)s %(name)s" % a + +if len(sys.argv) != 3: + raise Exception("invalid command line syntax: %s" % ' '.join(map(repr, sys.argv))) +(m4File,outFile) = sys.argv[1:] +assert outFile != m4File +m = Macro(m4File) +m.synopsis = "@smallexample\n%s\n@end smallexample" % "\n".join(map(quoteTexi, m.synopsis)) +m.description = '\n\n'.join(map(formatParagraph, m.description)) +m.description = m.description.replace("@end smallexample\n@smallexample", "\n") +m.authors = " @* ".join(map(formatAuthor, m.authors)) +m.license = "\n\n".join(map(formatParagraph, m.license)) +writeFile(outFile, tmpl % m.__dict__) -- cgit v1.2.1