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