diff options
Diffstat (limited to 'buildtools/makeman')
-rwxr-xr-x | buildtools/makeman | 67 |
1 files changed, 44 insertions, 23 deletions
diff --git a/buildtools/makeman b/buildtools/makeman index 94ee2172..dc8e45ce 100755 --- a/buildtools/makeman +++ b/buildtools/makeman @@ -24,8 +24,15 @@ # # By Eric S. Raymond <esr@thyrsus.com> # Version 1.0, July 26 2004 +# +# Modified by Akira F. Urushibata <afu@wta.att.ne.jp> +# Version 1.1, February 11 2016 +# +# Added ability to process — − +# Added footer message to clarify original source. +# -import os, sys, exceptions, re +import os, sys, re source = "netpbm documentation" section = 1 @@ -37,7 +44,13 @@ warning = r'''\ .\" against that, and send it to the Netpbm maintainer. ''' -class LiftException(exceptions.Exception): +footerprefix = '''.SH DOCUMENT SOURCE +This manual page was generated by the Netpbm tool 'makeman' from HTML +source. The master documentation is at +.IP +.B http://netpbm.sourceforge.net/doc/''' + +class LiftException(Exception): def __init__(self, message, retval=1): self.message = message self.retval = retval @@ -56,6 +69,7 @@ def makeman(name, file, indoc): indoc = indoc.replace('<meta http-equiv="Content-Type" content="text/html; charset=us-ascii"/>', "") indoc = indoc.replace('<?xml version="1.1" encoding="iso-8859-1" ?>\n',"") indoc = indoc.replace('<html xmlns="http://www.w3.org/1999/xhtml">', "") + indoc = indoc.replace('<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">', "") indoc = indoc.replace("<HEAD>", "").replace("</HEAD>", "") indoc = indoc.replace("<head>", "").replace("</head>", "") indoc = re.sub('(?i)<A HREF="#index">Table Of Contents</A>', "", indoc) @@ -92,6 +106,7 @@ def makeman(name, file, indoc): title = None indoc = titlematch.sub("", indoc) indoc = re.sub("(?i)\n*<BR>\n+", "\n", indoc) + indoc = re.sub("(?i)<BR>", "\n", indoc) indoc = ('.TH "%s" %d "%s" "%s"\n' % (title,section,date,source)) + indoc # Literal layout indoc = re.sub("(?i)\n *<PRE>", "\n.nf", indoc) @@ -145,7 +160,7 @@ def makeman(name, file, indoc): if xrefsection == 0: return "\n.I " + xrefto else: - return "\n.BR %s (%d)\n" % (xrefto, xrefsection) + return '\n.BR "%s" (%d)\\c\n\\&' % (xrefto, xrefsection) indoc = re.sub(r'(?i)\n* *(?:\\fB)?<A[ \n]+HREF="?([^>]+.html)"?>([^<]+)</A>(?:\\fP)?', xrefmatch, indoc) # Format URLs @@ -203,31 +218,39 @@ def makeman(name, file, indoc): indoc = re.sub(r"<\?makeman (.*) \?>", r'\1', indoc) # Comments indoc = re.sub("<!--([^\n])*-->", r'.\"\1', indoc) + # Acronyms + indoc = re.sub('<acronym [a-zA-Z0-9:= \n"]*>', "", indoc) + indoc = re.sub("</acronym>", "", indoc) # Image tags indoc = re.sub(' *<img src="([^"]*)" alt="([^"]*)"( *[a-z]*="?[0-9]*"?)*>', ".B \\2\n.IMG -C \\1", indoc) # Special characters indoc = indoc.replace(""", "'") indoc = indoc.replace(" ", "\\ ") + indoc = indoc.replace("−", "-") + indoc = indoc.replace("—", "-") + indoc = indoc.replace("μ", "mu") + indoc = indoc.replace("σ", "sigma") # Tables - indoc = re.sub(' *<table[^>]*>.*', ".TS", indoc) - indoc = re.sub(" *</table>.*", ".TE", indoc) + # This will not handle rowspan + indoc = re.sub('(?i) *<table[^>]*>.*', ".TS", indoc) + indoc = re.sub("(?i) *</table>.*", ".TE", indoc) # First the single-line case - indoc = re.sub("</td> *<td>", "\t", indoc) - indoc = re.sub("<tr> *<td>", "", indoc) - indoc = re.sub("</td> *</tr>", "", indoc) + indoc = re.sub("(?i)</td> *<td>", "\t", indoc) + indoc = re.sub("(?i)<tr> *<td>", "", indoc) + indoc = re.sub("(?i)</td> *</tr>", "", indoc) # Then the multiline case - indoc = re.sub(r'\s*<t[hd][^>]*>([^<\n]*)</t[dh]>\s*', '\t\\1', indoc) - indoc = re.sub(r'\s*<t[hd][^>]*>([^<]*)</t[dh]>\s*', '\tT{\n\\1T}', indoc) + indoc = re.sub(r'(?i)\s*<t[hd][^>]*>([^<\n]*)</t[dh]>\s*', '\t\\1', indoc) + indoc = re.sub(r'(?i)\s*<t[hd][^>]*>([^<]*)</t[dh]>\s*', '\tT{\n\\1T}', indoc) indoc = indoc.replace("\n\\&T}", "\nT}") - indoc = re.sub(" *</tr>", "", indoc) - indoc = re.sub(" *<tr[^>]*>\t*", "", indoc) - indoc = re.sub(r"\.TS\s+<caption>([^<]*)</caption>\s*", ".B \\1\n.TS\n", indoc) + indoc = re.sub("(?i) *</tr>", "", indoc) + indoc = re.sub("(?i) *<tr[^>]*>\t*", "", indoc) + indoc = re.sub(r"\.TS\s+<[Cc][Aa][Pp][Tt][Ii][Oo][Nn]>([^<]*)</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]>\s*", ".B \\1\n.TS\n", indoc) # Debugging #sys.stderr.write("Name: %s, Title: %s, Date: %s\n" % (name, title, date)) # Time for error checking now badlines = [] for line in indoc.split("\n"): - if "<" in line or ">" in line.replace(" >", "") or re.search("&.*;", line): + if "<" in line or ">" in line.replace(" >", "") or re.search(r'(?<!^\\)&.*;', line): badlines.append(line) if badlines: sys.stderr.write(("Bad lines from %s:\n-----------------\n" % file) + "\n".join(badlines) + "\n-----------------\n") @@ -241,6 +264,7 @@ def makeman(name, file, indoc): indoc = indoc.replace("\n@%@%@", "\n\\&.") # Mark these generated pages so people won't hand-hack them. indoc = warning + indoc + indoc = indoc + footerprefix + os.path.basename(file) +"\n.PP" return indoc def main(args, mainout=sys.stdout, mainerr=sys.stderr): @@ -308,9 +332,7 @@ def main(args, mainout=sys.stdout, mainerr=sys.stderr): outdoc = makeman(name, file, indoc) except: os.remove(tempfile) - # Pass the exception upwards - (exc_type, exc_value, exc_traceback) = sys.exc_info() - raise exc_type, exc_value, exc_traceback + raise if outdoc == indoc: os.remove(tempfile) if outdoc is None: @@ -319,11 +341,11 @@ def main(args, mainout=sys.stdout, mainerr=sys.stderr): outfp.write(outdoc) outfp.close() # under Windows you can't rename an open file stem = file[:file.find(".")] - os.rename(tempfile, stem + "." + `sectmap[file]`) - except LiftException, e: + os.rename(tempfile, stem + "." + repr(sectmap[file])) + except LiftException as e: mainerr.write("makeman: " + e.message + "\n") return e.retval - except IOError, e: + except IOError as e: mainerr.write("makeman: file I/O error: %s\n" % e) return 3 except KeyboardInterrupt: @@ -331,15 +353,14 @@ def main(args, mainout=sys.stdout, mainerr=sys.stderr): return 4 except: if verbosity: - (exc_type, exc_value, exc_traceback) = sys.exc_info() - raise exc_type, exc_value, exc_traceback + raise else: mainerr.write("makeman: internal error!\n") return 5 if __name__ == "__main__": # Run the main sequence - raise SystemExit, main(sys.argv[1:]) + raise SystemExit(main(sys.argv[1:])) # The following sets edit modes for GNU EMACS # Local Variables: |