--- a/tools/userland-mangler Tue Sep 17 16:15:04 2013 -0700
+++ b/tools/userland-mangler Wed Sep 18 12:23:43 2013 -0700
@@ -19,7 +19,7 @@
#
# CDDL HEADER END
#
-# Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
#
#
# userland-mangler - a file mangling utility
@@ -115,12 +115,14 @@
so_re = re.compile('^\.so.+$', re.MULTILINE)
section_re = re.compile('\.SH "?([^"]+).*$', re.IGNORECASE)
+TH_re = re.compile('\.TH\s+(?:"[^"]+"|\S+)\s+(\S+)', re.IGNORECASE)
#
# mangler.man.stability = (mangler.man.stability)
# mangler.man.modified_date = (mangler.man.modified-date)
# mangler.man.availability = (pkg.fmri)
# mangler.man.source-url = (pkg.source-url)
# mangler.man.upstream-url = (pkg.upstream-url)
+# mangler.man.rewrite-section = ('true'/'false') default 'true'
#
def mangle_manpage(manifest, action, text):
# manpages must have a taxonomy defined
@@ -132,6 +134,11 @@
# manpages may have a 'modified date'
modified_date = action.attrs.pop('mangler.man.modified-date', None)
+
+ # Rewrite the section in the .TH line to match the section in which
+ # we're delivering it.
+ rewrite_sect = action.attrs.pop('mangler.man.rewrite-section', 'true')
+
attributes_written = False
notes_seen = False
@@ -170,6 +177,15 @@
attributes_written = True
if section == 'NOTES':
notes_seen = True
+
+ match = TH_re.match(line)
+ if match and rewrite_sect.lower() == "true":
+ # Use the section defined by the filename, rather than
+ # the directory in which it sits.
+ sect = os.path.splitext(action.attrs["path"])[1][1:]
+ line = line[:match.span(1)[0]] + sect + \
+ line[match.span(1)[1]:]
+
result += ("%s\n" % line)
if attributes_written == False: