summaryrefslogtreecommitdiff
path: root/macro2m4.py
diff options
context:
space:
mode:
authorPeter Simons <simons@cryp.to>2009-08-03 21:19:23 +0200
committerPeter Simons <simons@cryp.to>2009-08-03 22:28:13 +0200
commitb3bacd22f2b3fc5d1da1175e3a8a277f028c9b4f (patch)
treedf8fa10da86340b77a2bfb3d21960f0b3b51dbe4 /macro2m4.py
parent45749e88243cd62fb32f2e6f39c255e97689158c (diff)
downloadautoconf-archive-b3bacd22f2b3fc5d1da1175e3a8a277f028c9b4f.tar.gz
macro2m4.py: generate canon m4 distribution format
Diffstat (limited to 'macro2m4.py')
-rwxr-xr-xmacro2m4.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/macro2m4.py b/macro2m4.py
new file mode 100755
index 0000000..30a8659
--- /dev/null
+++ b/macro2m4.py
@@ -0,0 +1,60 @@
+#! /usr/bin/env python
+
+assert __name__ == "__main__"
+
+import sys
+from macro import Macro, writeFile
+
+tmpl = """\
+%(url)s
+#
+%(obsolete)s# SYNOPSIS
+#
+%(synopsis)s
+#
+# DESCRIPTION
+#
+%(description)s
+#
+# LICENSE
+#
+%(authors)s
+#
+%(license)s
+
+%(body)s"""
+
+def formatParagraph(para):
+ assert para
+ assert para[0]
+ assert para[0][0]
+ if para[0][0].isspace():
+ return "# " + "\n# ".join(para)
+ else:
+ return "# " + "\n# ".join(para)
+
+def formatAuthor(a):
+ assert a
+ if "email" in a:
+ return "# Copyright (c) %(year)s %(name)s <%(email)s>" % a
+ else:
+ return "# Copyright (c) %(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)
+url = "http://www.nongnu.org/autoconf-archive/%s.html" % m.name
+lineLen = max(len(url) + 2, 75)
+m.url = "# %s\n# %s\n# %s" % ('=' * lineLen, (' ' * ((lineLen - len(url)) / 2)) + url, '=' * lineLen)
+if m.__dict__.get("obsolete"):
+ m.obsolete = "# OBSOLETE MACRO\n#\n" + '\n'.join(map(formatParagraph, m.obsolete)) + "\n#\n"
+else:
+ m.obsolete = ""
+m.synopsis = "\n".join([ "# %s" % l for l in m.synopsis ])
+m.description = '\n#\n'.join(map(formatParagraph, m.description))
+m.authors = "\n".join(map(formatAuthor, m.authors))
+m.license = '\n#\n'.join(map(formatParagraph, m.license))
+m.body = '\n'.join(m.body)
+writeFile(outFile, tmpl % m.__dict__)