diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2007-03-30 02:51:36 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2007-03-30 02:51:36 +0000 |
commit | 97e432df4e7ffae5ae89939539172d5923a46014 (patch) | |
tree | 7890f85ba00bbd9a15488a54278ba250f41946ec /buildtools/makeman | |
parent | 64dd4a03dedeea0f0240951d8ec73cd519fb3900 (diff) | |
download | netpbm-mirror-97e432df4e7ffae5ae89939539172d5923a46014.tar.gz netpbm-mirror-97e432df4e7ffae5ae89939539172d5923a46014.tar.xz netpbm-mirror-97e432df4e7ffae5ae89939539172d5923a46014.zip |
Move Advanced series to 10.38
git-svn-id: http://svn.code.sf.net/p/netpbm/code/advanced@267 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'buildtools/makeman')
-rwxr-xr-x | buildtools/makeman | 50 |
1 files changed, 31 insertions, 19 deletions
diff --git a/buildtools/makeman b/buildtools/makeman index 634a2c79..2e122779 100755 --- a/buildtools/makeman +++ b/buildtools/makeman @@ -19,7 +19,8 @@ # * Loses summary information from tables. # * Only permits one <HR> in the HTML, right before the index. # -# Use the makeman: passthrough to insert format lines for tables. +# You can use the <?makeman ?> PI to pass text directly through to the +# generated manual page, A major use is to insert format lines for tables. # # By Eric S. Raymond <esr@thyrsus.com> # Version 1.0, July 26 2004 @@ -29,7 +30,7 @@ import os, sys, exceptions, re source = "netpbm documentation" section = 1 -warning = '''\ +warning = r'''\ .\" This man page was generated by the Netpbm tool 'makeman' from HTML source. .\" Do not hand-hack it! If you have bug fixes or improvements, please find .\" the corresponding HTML page on the Netpbm website, generate a patch @@ -47,11 +48,15 @@ def makeman(name, file, indoc): # Dot at left margin confuses troff. # This program generates these, indoc = indoc.replace("\n.", "\n@%@%@") + # Protect escapes before we try generating font changes. + indoc = indoc.replace("\\", r"\e") # Header-bashing + indoc = indoc.replace('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "DTD/xhtml11.dtd">', "") + indoc = indoc.replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">', "") indoc = indoc.replace('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">\n',"") indoc = indoc.replace('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">', "") + 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('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "DTD/xhtml11.dtd">', "") indoc = indoc.replace('<html xmlns="http://www.w3.org/1999/xhtml">', "") indoc = indoc.replace("<HEAD>", "").replace("</HEAD>", "") indoc = indoc.replace("<head>", "").replace("</head>", "") @@ -93,8 +98,8 @@ def makeman(name, file, indoc): # Literal layout indoc = re.sub("(?i)\n *<PRE>", "\n.nf", indoc) indoc = re.sub("(?i)\n *</PRE>", "\n.fi", indoc) - indoc = re.sub("(?i)\n *<BLOCKQUOTE>", "\n.nf", indoc) - indoc = re.sub("(?i)\n *</BLOCKQUOTE>", "\n.fi", indoc) + indoc = re.sub("(?i)\n *<BLOCKQUOTE>", "\n.RS", indoc) + indoc = re.sub("(?i)\n *</BLOCKQUOTE>", "\n.RE", indoc) # Highlight processing indoc = re.sub("(?i)<B>", r"\\fB", indoc) indoc = re.sub("(?i)</B>", r"\\fP", indoc) @@ -108,6 +113,8 @@ def makeman(name, file, indoc): indoc = re.sub("(?i)</TT>", r"\\fP", indoc) indoc = re.sub("(?i)<KBD>", r"\\f(CW", indoc) indoc = re.sub("(?i)</KBD>", r"\\fP", indoc) + indoc = re.sub("(?i)<CODE>", r"\\f(CW", indoc) + indoc = re.sub("(?i)</CODE>", r"\\fP", indoc) indoc = re.sub("(?i)<STRONG>", r"\\fB", indoc) indoc = re.sub("(?i)</STRONG>", r"\\fP", indoc) indoc = re.sub("(?i)<SUP>", r"\\u", indoc) @@ -150,6 +157,7 @@ def makeman(name, file, indoc): indoc = indoc.replace("<", "@#!#@").replace(">", "#@!@#").replace("&", "#!@!@!#") indoc = indoc.replace("×", r"\(mu") indoc = indoc.replace("®", r"\*R") + indoc = indoc.replace("©", r"\(co") # Turn anchors into .UN tags indoc = re.sub('(?i)<A NAME *= *"#?([a-zA-Z][a-zA-Z0-9.-]+)">(?: )*</A>\s*', ".UN \\1\n", indoc) # Strip off the index trailer @@ -159,17 +167,17 @@ def makeman(name, file, indoc): indoc = indoc.replace("</BODY>", "").replace("</HTML>", "") indoc = indoc.replace("</body>", "").replace("</html>", "") # Recognize sections with IDs - indoc = re.sub('(?i)<H2><A (?:ID|NAME)="([a-zA-Z]+)">([^><]*)</A></H2>', + indoc = re.sub('(?i)<H2><A (?:ID|NAME)="([a-zA-Z][_a-zA-Z0-9-]+)">([^><]*)</A></H2>', ".UN \\1\n.SH \\2", indoc) - indoc = re.sub('(?i)<H3><A (?:ID|NAME)="([a-zA-Z]+)">([^><]*)</A></H3>', + indoc = re.sub('(?i)<H3><A (?:ID|NAME)="([a-zA-Z][_a-zA-Z0-9-]+)">([^><]*)</A></H3>', ".UN \\1\n.SS \\2", indoc) - indoc = re.sub('(?i)<H4><A (?:ID|NAME)="([a-zA-Z]+)">([^><]*)</A></H4>', + indoc = re.sub('(?i)<H4><A (?:ID|NAME)="([a-zA-Z][_a-zA-Z0-9-]+)">([^><]*)</A></H4>', ".UN \\1\n.B \\2", indoc) - indoc = re.sub('(?i)<H2 (?:ID|NAME)="([a-zA-Z]+)">([^><]*)</H2>', + indoc = re.sub('(?i)<H2 (?:ID|NAME)="([a-zA-Z][_a-zA-Z0-9-]+)">([^><]*)</H2>', ".UN \\1\n.SH \\2", indoc) - indoc = re.sub('(?i)<H3 (?:ID|NAME)="([a-zA-Z]+)">([^><]*)</H3>', + indoc = re.sub('(?i)<H3 (?:ID|NAME)="([a-zA-Z][_a-zA-Z0-9-]+)">([^><]*)</H3>', ".UN \\1\n.SS \\2", indoc) - indoc = re.sub('(?i)<H4 (?:ID|NAME)="([a-zA-Z]+)">([^><]*)</H4>', + indoc = re.sub('(?i)<H4 (?:ID|NAME)="([a-zA-Z][_a-zA-Z0-9-]+)">([^><]*)</H4>', ".UN \\1\n.B \\2", indoc) # Sections without IDs indoc = re.sub('(?i)<H2>([^><]*)</H2>', ".SH \\1", indoc) @@ -192,7 +200,7 @@ def makeman(name, file, indoc): # Passthrough indoc = re.sub(r"<\?makeman (.*) \?>", r'\1', indoc) # Comments - indoc = re.sub("<!--([^-])*-->", r'.\"\1', indoc) + indoc = re.sub("<!--([^\n])*-->", r'.\"\1', indoc) # Image tags indoc = re.sub(' *<img src="([^"]*)" alt="([^"]*)"( *[a-z]*="?[0-9]*"?)*>', ".B \\2\n.IMG -C \\1", indoc) # Special characters @@ -217,7 +225,7 @@ def makeman(name, file, indoc): # Time for error checking now badlines = [] for line in indoc.split("\n"): - if "<" in line or ">" in line or re.search("&.*;", line): + if "<" in line or ">" in line.replace(" >", "") or re.search("&.*;", line): badlines.append(line) if badlines: sys.stderr.write(("Bad lines from %s:\n-----------------\n" % file) + "\n".join(badlines) + "\n-----------------\n") @@ -236,19 +244,22 @@ def makeman(name, file, indoc): def main(args, mainout=sys.stdout, mainerr=sys.stderr): global sectmap import getopt - (options, arguments) = getopt.getopt(args, "v") + (options, arguments) = getopt.getopt(args, "vd:") + dirprefix = "" verbosity = 0 for (switch, val) in options: - if switch == '-v': + if switch == '-d': # Set HTML input directory + dirprefix = val + elif switch == '-v': # Enable verbose error reporting verbosity += 1 try: # First pass: gather locations for crossreferences: sectmap = {} for file in arguments: try: - infp = open(file) + infp = open(os.path.join(dirprefix, file)) except: - sys.stderr.write("can't open %s" % name) + sys.stderr.write("makeman: can't open %s\n" % file) continue indoc = infp.read() infp.close() @@ -277,9 +288,9 @@ def main(args, mainout=sys.stdout, mainerr=sys.stderr): # Second pass: do formatting for file in arguments: try: - infp = open(file) + infp = open(os.path.join(dirprefix, file)) except: - sys.stderr.write("can't open %s" % name) + sys.stderr.write("makeman: can't open %s\n" % file) continue indoc = infp.read() infp.close() @@ -321,6 +332,7 @@ def main(args, mainout=sys.stdout, mainerr=sys.stderr): (exc_type, exc_value, exc_traceback) = sys.exc_info() raise exc_type, exc_value, exc_traceback else: + mainerr.write("makeman: internal error!\n") return 5 if __name__ == "__main__": |