From: Ben Pfaff Date: Fri, 16 Apr 2010 17:31:05 +0000 (-0700) Subject: ovsdb-doc: Distinguish hyphens and minus signs in nroff output. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fcbaf28cb38d2a848e78d7ba42800eb03fbe6579;p=openvswitch ovsdb-doc: Distinguish hyphens and minus signs in nroff output. In nroff, a minus sign (\-) should generally be used in literal text, whereas hyphens are generally correct elsewhere. This roughly corresponds to bold versus non-bold text, so this commit makes ovsdb-doc output "-" that appears in input as a minus sign if it is bold or a hyphen if it is not. --- diff --git a/ovsdb/ovsdb-doc.in b/ovsdb/ovsdb-doc.in index cb21c1f4..c4faf6f2 100755 --- a/ovsdb/ovsdb-doc.in +++ b/ovsdb/ovsdb-doc.in @@ -14,9 +14,14 @@ from OVSDB import * argv0 = sys.argv[0] -def textToNroff(s): +def textToNroff(s, font=r'\fR'): def escape(match): c = match.group(0) + if c == '-': + if font == r'\fB': + return r'\-' + else: + return '-' if c == '\\': return r'\e' elif c == '"': @@ -26,17 +31,18 @@ def textToNroff(s): else: raise Error("bad escape") - s = re.sub('([\\\\"\'])', escape, s) + # Escape - \ " ' as needed by nroff. + s = re.sub('([-"\'\\\\])', escape, s) if s.startswith('.'): s = '\\' + s return s def escapeNroffLiteral(s): - return r'\fB%s\fR' % textToNroff(s) + return r'\fB%s\fR' % textToNroff(s, r'\fB') def inlineXmlToNroff(node, font): if node.nodeType == node.TEXT_NODE: - return textToNroff(node.data) + return textToNroff(node.data, font) elif node.nodeType == node.ELEMENT_NODE: if node.tagName == 'code' or node.tagName == 'em': s = r'\fB'