import getopt
import os.path
import re
-import string
import StringIO
import sys
import xml.sax
content = open(f).read()
if content:
content = content.replace('&', '&')
+ # Strip newlines after comments so they don't turn into
+ # spurious paragraph separators.
+ content = content.replace('-->\n', '-->')
input = xml_preamble + content + xml_postamble
try:
saxparser.parse(StringIO.StringIO(input))
class SCons_XML_to_XML(SCons_XML):
def write(self, files):
- gen, mod = string.split(files, ',')
+ gen, mod = files.split(',')
g.write_gen(gen)
g.write_mod(mod)
def write_gen(self, filename):
for chunk in v.summary.body:
f.write(str(chunk))
if v.sets:
- s = map(lambda x: '&cv-link-%s;' % x, v.sets)
+ s = ['&cv-link-%s;' % x for x in v.sets]
f.write('<para>\n')
f.write('Sets: ' + ', '.join(s) + '.\n')
f.write('</para>\n')
if v.uses:
- u = map(lambda x: '&cv-link-%s;' % x, v.uses)
+ u = ['&cv-link-%s;' % x for x in v.uses]
f.write('<para>\n')
f.write('Uses: ' + ', '.join(u) + '.\n')
f.write('</para>\n')
f.write('<!ENTITY %s%s "<%s>%s</%s>">\n' %
(v.prefix, v.idfunc(),
v.tag, v.entityfunc(), v.tag))
+ if self.env_signatures:
+ f.write('\n')
+ for v in self.values:
+ f.write('<!ENTITY %senv-%s "<%s>env.%s</%s>">\n' %
+ (v.prefix, v.idfunc(),
+ v.tag, v.entityfunc(), v.tag))
f.write('\n')
f.write(Warning)
f.write('\n')
(v.prefix, v.idfunc(),
v.prefix, v.idfunc(),
v.tag, v.entityfunc(), v.tag))
+ if self.env_signatures:
+ f.write('\n')
+ for v in self.values:
+ f.write('<!ENTITY %slink-env-%s \'<link linkend="%s%s"><%s>env.%s</%s></link>\'>\n' %
+ (v.prefix, v.idfunc(),
+ v.prefix, v.idfunc(),
+ v.tag, v.entityfunc(), v.tag))
f.write('\n')
f.write(Warning)
for v in self.values:
chunks.extend(v.mansep())
chunks.extend(v.initial_chunks())
- chunks.extend(map(str, v.summary.body))
+ chunks.extend(list(map(str, v.summary.body)))
body = ''.join(chunks)
- body = string.replace(body, '<programlisting>', '.ES')
- body = string.replace(body, '</programlisting>', '.EE')
- body = string.replace(body, '\n</para>\n<para>\n', '\n\n')
- body = string.replace(body, '<para>\n', '')
- body = string.replace(body, '<para>', '\n')
- body = string.replace(body, '</para>\n', '')
- body = re.sub('\.EE\n\n+(?!\.IP)', '.EE\n.IP\n', body)
- body = re.sub('&(scons|SConstruct|SConscript|jar);', r'\\fB\1\\fP', body)
- body = string.replace(body, '&Dir;', r'\fBDir\fP')
- body = string.replace(body, '⌖', r'\fItarget\fP')
- body = string.replace(body, '&source;', r'\fIsource\fP')
+ body = body.replace('<programlisting>', '.ES')
+ body = body.replace('</programlisting>', '.EE')
+ body = body.replace('\n</para>\n<para>\n', '\n\n')
+ body = body.replace('<para>\n', '')
+ body = body.replace('<para>', '\n')
+ body = body.replace('</para>\n', '')
+
+ body = body.replace('<variablelist>\n', '.RS 10\n')
+ # Handling <varlistentry> needs to be rationalized and made
+ # consistent. Right now, the <term> values map to arbitrary,
+ # ad-hoc idioms in the current man page.
+ body = re.compile(r'<varlistentry>\n<term><literal>([^<]*)</literal></term>\n<listitem>\n').sub(r'.TP 6\n.B \1\n', body)
+ body = re.compile(r'<varlistentry>\n<term><parameter>([^<]*)</parameter></term>\n<listitem>\n').sub(r'.IP \1\n', body)
+ body = re.compile(r'<varlistentry>\n<term>([^<]*)</term>\n<listitem>\n').sub(r'.HP 6\n.B \1\n', body)
+ body = body.replace('</listitem>\n', '')
+ body = body.replace('</varlistentry>\n', '')
+ body = body.replace('</variablelist>\n', '.RE\n')
+
+ body = re.sub(r'\.EE\n\n+(?!\.IP)', '.EE\n.IP\n', body)
+ body = body.replace('\n.IP\n\'\\"', '\n\n\'\\"')
+ body = re.sub('&(scons|SConstruct|SConscript|jar|Make|lambda);', r'\\fB\1\\fP', body)
+ body = re.sub('&(TARGET|TARGETS|SOURCE|SOURCES);', r'\\fB$\1\\fP', body)
+ body = body.replace('&Dir;', r'\fBDir\fP')
+ body = body.replace('⌖', r'\fItarget\fP')
+ body = body.replace('&source;', r'\fIsource\fP')
body = re.sub('&b(-link)?-([^;]*);', r'\\fB\2\\fP()', body)
body = re.sub('&cv(-link)?-([^;]*);', r'$\2', body)
+ body = re.sub('&f(-link)?-env-([^;]*);', r'\\fBenv.\2\\fP()', body)
body = re.sub('&f(-link)?-([^;]*);', r'\\fB\2\\fP()', body)
- body = re.sub(r'<(command|envar|filename|function|literal|option)>([^<]*)</\1>',
+ body = re.sub(r'<(application|command|envar|filename|function|literal|option)>([^<]*)</\1>',
r'\\fB\2\\fP', body)
body = re.sub(r'<(classname|emphasis|varname)>([^<]*)</\1>',
r'\\fI\2\\fP', body)
body = re.compile(r'^\\f([BI])(.*)\\fP\s*$', re.M).sub(r'.\1 \2', body)
body = re.compile(r'^\\f([BI])(.*)\\fP(\S+)$', re.M).sub(r'.\1R \2 \3', body)
body = re.compile(r'^(\S+)\\f([BI])(.*)\\fP$', re.M).sub(r'.R\2 \1 \3', body)
- body = string.replace(body, '<', '<')
- body = string.replace(body, '>', '>')
+ body = re.compile(r'^(\S+)\\f([BI])(.*)\\fP([^\s\\]+)$', re.M).sub(r'.R\2 \1 \3 \4', body)
+ body = re.compile(r'^(\.R[BI].*[\S])\s+$;', re.M).sub(r'\1', body)
+ body = body.replace('<', '<')
+ body = body.replace('>', '>')
body = re.sub(r'\\([^f])', r'\\\\\1', body)
body = re.compile("^'\\\\\\\\", re.M).sub("'\\\\", body)
body = re.compile(r'^\.([BI]R?) --', re.M).sub(r'.\1 \-\-', body)
return ['\n', "'\\" + '"'*69 + '\n']
def initial_chunks(self):
try:
- x = self.arguments
+ arguments = self.arguments
except AttributeError:
- x = '()'
+ arguments = ['()']
result = []
- if self.global_signature != "0":
- result.append('.TP\n.RI %s%s\n' % (self.name, x))
- if self.env_signature != "0":
- result.append('.TP\n.IR env .%s%s\n' % (self.name, x))
+ for arg in arguments:
+ try:
+ signature = arg.signature
+ except AttributeError:
+ signature = "both"
+ if signature in ('both', 'global'):
+ result.append('.TP\n.RI %s%s\n' % (self.name, arg))
+ if signature in ('both', 'env'):
+ result.append('.TP\n.IR env .%s%s\n' % (self.name, arg))
return result
class Tool(Proxy):
prefix = 't-'
tag = 'literal'
def idfunc(self):
- return string.replace(self.name, '+', 'X')
+ return self.name.replace('+', 'X')
def termfunc(self):
return [self.name]
def entityfunc(self):
sys.exit(1)
if buildersfiles:
- g = processor_class([ Builder(b) for b in sorted(h.builders.values()) ])
+ g = processor_class([ Builder(b) for b in sorted(h.builders.values()) ],
+ env_signatures=True)
g.write(buildersfiles)
if functionsfiles:
- g = processor_class([ Function(b) for b in sorted(h.functions.values()) ])
+ g = processor_class([ Function(b) for b in sorted(h.functions.values()) ],
+ env_signatures=True)
g.write(functionsfiles)
if toolsfiles:
- g = processor_class([ Tool(t) for t in sorted(h.tools.values()) ])
+ g = processor_class([ Tool(t) for t in sorted(h.tools.values()) ],
+ env_signatures=False)
g.write(toolsfiles)
if variablesfiles:
- g = processor_class([ Variable(v) for v in sorted(h.cvars.values()) ])
+ g = processor_class([ Variable(v) for v in sorted(h.cvars.values()) ],
+ env_signatures=False)
g.write(variablesfiles)
# Local Variables: