16799N/A#!/usr/perl5/bin/perl -w
16799N/A
16799N/A#
16799N/A# Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
16799N/A# Use subject to license terms.
16799N/A#
16799N/A# Permission is hereby granted, free of charge, to any person obtaining a
16799N/A# copy of this software and associated documentation files (the
16799N/A# "Software"), to deal in the Software without restriction, including
16799N/A# without limitation the rights to use, copy, modify, merge, publish,
16799N/A# distribute, and/or sell copies of the Software, and to permit persons
16799N/A# to whom the Software is furnished to do so, provided that the above
16799N/A# copyright notice(s) and this permission notice appear in all copies of
16799N/A# the Software and that both the above copyright notice(s) and this
16799N/A# permission notice appear in supporting documentation.
16799N/A#
16799N/A# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16799N/A# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16799N/A# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
16799N/A# OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
16799N/A# HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
16799N/A# INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
16799N/A# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
16799N/A# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
16799N/A# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16799N/A#
16799N/A# Except as contained in this notice, the name of a copyright holder
16799N/A# shall not be used in advertising or otherwise to promote the sale, use
16799N/A# or other dealings in this Software without prior written authorization
16799N/A# of the copyright holder.
16799N/A#
16799N/A# @(#)suntouch-manpages.pl 1.5 08/08/08
16799N/A#
16799N/A
16799N/A# Updates manual pages to include standard Sun man page sections
16799N/A#
16799N/A# Arguments:
16799N/A# -a '{attribute, value}, ...' - entries for Attributes section table
16799N/A# -l libname - add library line to synopsis
16799N/A# -p path - add path to command in synopsis
16799N/A
16799N/Ause Getopt::Long;
16799N/Ause integer;
16799N/Ause strict;
16799N/A
16799N/Amy @attributes;
16799N/Amy $library;
16799N/Amy $synpath;
16799N/A
16799N/Amy $result = GetOptions('a|attribute=s' => \@attributes,
16799N/A 'l|library=s' => \$library,
16799N/A 'p|path=s' => \$synpath);
16799N/A
16799N/Amy $add_attributes = 0;
16799N/A
16799N/Aif (scalar(@attributes) > 0) {
16799N/A $add_attributes = 1;
16799N/A}
16799N/A
16799N/Amy $add_library_to_synopsis = 0;
16799N/A
16799N/Aif (defined($library)) {
16799N/A $add_library_to_synopsis = 1;
16799N/A}
16799N/A
16799N/Amy $add_path_to_synopsis = 0;
16799N/A
16799N/Aif (defined($synpath)) {
16799N/A $add_path_to_synopsis = 1;
16799N/A}
16799N/A
16799N/Amy $filename;
16799N/A
16799N/Awhile ($filename = shift) {
16799N/A rename($filename, "$filename.orig")
16799N/A || die "Cannot rename $filename to $filename.orig";
16799N/A open(IN, "<$filename.orig")
16799N/A || die "Cannot read $filename.orig";
16799N/A open(OUT, ">$filename")
16799N/A || die "Cannot write to $filename";
16799N/A
16799N/A my $firstline = <IN>;
16799N/A
16799N/A if ($add_attributes > 0) {
16799N/A # Check for man page preprocessor list - if found, make sure t is in it for
16799N/A # table processing, if not found, add one;
16799N/A
16799N/A if ($firstline =~ m/\'\\\"/) {
16799N/A # Found preprocessor list
16799N/A if ($firstline =~ m/t/) {
16799N/A # Do nothing - tbl preprocessing already selected
16799N/A } else {
16799N/A chomp($firstline);
16799N/A $firstline .= "t\n";
16799N/A }
16799N/A } else {
16799N/A # No preprocessor list found
16799N/A print OUT q('\" t), "\n";
16799N/A }
16799N/A }
16799N/A
16799N/A print OUT $firstline;
16799N/A
16799N/A my $nextline;
16799N/A while ($nextline = <IN>) {
16799N/A print OUT $nextline;
16799N/A
16799N/A if ($nextline =~ m/.SH[\s "]*(SYNOPSIS|SYNTAX)/) {
16799N/A if ($add_library_to_synopsis) {
16799N/A print OUT ".nf\n",
16799N/A q(\fBcc\fR [ \fIflag\fR\&.\&.\&. ] \fIfile\fR\&.\&.\&. \fB\-l),
16799N/A $library, q(\fR [ \fIlibrary\fR\&.\&.\&. ]), "\n.fi\n";
16799N/A }
16799N/A elsif ($add_path_to_synopsis) {
16799N/A $nextline = <IN>;
16799N/A $nextline =~ s/^(\.B[IR]*\s+\"?)/$1$synpath/;
16799N/A $nextline =~ s/^(\\fB)/$1$synpath/;
16799N/A print OUT $nextline;
16799N/A }
16799N/A }
16799N/A }
16799N/A
16799N/A if ($add_attributes) {
16799N/A print OUT &get_attributes_table(join(" ", @attributes));
16799N/A }
16799N/A
16799N/A close(IN);
16799N/A close(OUT);
16799N/A}
16799N/A
16799N/A
16799N/Asub get_attributes_table {
16799N/A my $attribute_list = $_[0];
16799N/A
16799N/A my $attributes_table = q{
16799N/A.\\" Begin Sun update
16799N/A.SH "ATTRIBUTES"
16799N/ASee \fBattributes\fR(5) for descriptions of the following attributes:
16799N/A.sp
16799N/A.TS
16799N/Aallbox;
16799N/Acw(2.750000i)| cw(2.750000i)
16799N/Alw(2.750000i)| lw(2.750000i).
16799N/AATTRIBUTE TYPE ATTRIBUTE VALUE
16799N/A<attributes>
16799N/A.TE
16799N/A.sp
16799N/A.\\" End Sun update
16799N/A};
16799N/A
16799N/A # Parse input list of attributes
16799N/A $attribute_list =~ s/^\s*{//;
16799N/A $attribute_list =~ s/}\s*$//;
16799N/A my @attribs = split /}\s*{/, $attribute_list;
16799N/A
16799N/A my $a;
16799N/A my $attribute_entries = "";
16799N/A
16799N/A foreach $a (@attribs) {
16799N/A my ($name, $value) = split /,\s*/, $a, 2;
16799N/A
16799N/A $attribute_entries .= $name . "\t" . $value . "\n";
16799N/A }
16799N/A
16799N/A $attributes_table =~ s/<attributes>\n/$attribute_entries/;
16799N/A
16799N/A return $attributes_table;
16799N/A}