diff options
author | Peter Simons <simons@cryp.to> | 2009-07-27 23:17:58 +0200 |
---|---|---|
committer | Peter Simons <simons@cryp.to> | 2009-07-27 23:17:58 +0200 |
commit | 21c9dd60751f17acbbf918da8c3facad1e0e093e (patch) | |
tree | 83f297b283772da94f3ebac8721746a961fcf33a /macro2texi.py | |
parent | 8968e9db39f4e5bb7abb0ab32cb0b33aab705a63 (diff) | |
download | autoconf-archive-21c9dd60751f17acbbf918da8c3facad1e0e093e.tar.gz |
maint: implemented texinfo generator
Diffstat (limited to 'macro2texi.py')
-rwxr-xr-x | macro2texi.py | 63 |
1 files changed, 63 insertions, 0 deletions
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__) |