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