1 #!/usr/perl5/bin/perl -w 2 3 # 4 # Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 5 # Use subject to license terms. 6 # 7 # Permission is hereby granted, free of charge, to any person obtaining a 8 # copy of this software and associated documentation files (the 9 # "Software"), to deal in the Software without restriction, including 10 # without limitation the rights to use, copy, modify, merge, publish, 11 # distribute, and/or sell copies of the Software, and to permit persons 12 # to whom the Software is furnished to do so, provided that the above 13 # copyright notice(s) and this permission notice appear in all copies of 14 # the Software and that both the above copyright notice(s) and this 15 # permission notice appear in supporting documentation. 16 # 17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 20 # OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 21 # HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 22 # INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 23 # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 24 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 25 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 26 # 27 # Except as contained in this notice, the name of a copyright holder 28 # shall not be used in advertising or otherwise to promote the sale, use 29 # or other dealings in this Software without prior written authorization 30 # of the copyright holder. 31 # 32 # @(#)suntouch-manpages.pl 1.5 08/08/08 33 # 34 35 # Updates manual pages to include standard Sun man page sections 36 # 37 # Arguments: 38 # -a '{attribute, value}, ...' - entries for Attributes section table 39 # -l libname - add library line to synopsis 40 # -p path - add path to command in synopsis 41 42 use Getopt::Long; 43 use integer; 44 use strict; 45 46 my @attributes; 47 my $library; 48 my $synpath; 49 50 my $result = GetOptions('a|attribute=s' => \@attributes, 51 'l|library=s' => \$library, 52 'p|path=s' => \$synpath); 53 54 my $add_attributes = 0; 55 56 if (scalar(@attributes) > 0) { 57 $add_attributes = 1; 58 } 59 60 my $add_library_to_synopsis = 0; 61 62 if (defined($library)) { 63 $add_library_to_synopsis = 1; 64 } 65 66 my $add_path_to_synopsis = 0; 67 68 if (defined($synpath)) { 69 $add_path_to_synopsis = 1; 70 } 71 72 my $filename; 73 74 while ($filename = shift) { 75 rename($filename, "$filename.orig") 76 || die "Cannot rename $filename to $filename.orig"; 77 open(IN, "<$filename.orig") 78 || die "Cannot read $filename.orig"; 79 open(OUT, ">$filename") 80 || die "Cannot write to $filename"; 81 82 my $firstline = <IN>; 83 84 if ($add_attributes > 0) { 85 # Check for man page preprocessor list - if found, make sure t is in it for 86 # table processing, if not found, add one; 87 88 if ($firstline =~ m/\'\\\"/) { 89 # Found preprocessor list 90 if ($firstline =~ m/t/) { 91 # Do nothing - tbl preprocessing already selected 92 } else { 93 chomp($firstline); 94 $firstline .= "t\n"; 95 } 96 } else { 97 # No preprocessor list found 98 print OUT q('\" t), "\n"; 99 } 100 } 101 102 print OUT $firstline; 103 104 my $nextline; 105 while ($nextline = <IN>) { 106 print OUT $nextline; 107 108 if ($nextline =~ m/.SH[\s "]*(SYNOPSIS|SYNTAX)/) { 109 if ($add_library_to_synopsis) { 110 print OUT ".nf\n", 111 q(\fBcc\fR [ \fIflag\fR\&.\&.\&. ] \fIfile\fR\&.\&.\&. \fB\-l), 112 $library, q(\fR [ \fIlibrary\fR\&.\&.\&. ]), "\n.fi\n"; 113 } 114 elsif ($add_path_to_synopsis) { 115 $nextline = <IN>; 116 $nextline =~ s/^(\.B[IR]*\s+\"?)/$1$synpath/; 117 $nextline =~ s/^(\\fB)/$1$synpath/; 118 print OUT $nextline; 119 } 120 } 121 } 122 123 if ($add_attributes) { 124 print OUT &get_attributes_table(join(" ", @attributes)); 125 } 126 127 close(IN); 128 close(OUT); 129 } 130 131 132 sub get_attributes_table { 133 my $attribute_list = $_[0]; 134 135 my $attributes_table = q{ 136 .\\" Begin Sun update 137 .SH "ATTRIBUTES" 138 See \fBattributes\fR(5) for descriptions of the following attributes: 139 .sp 140 .TS 141 allbox; 142 cw(2.750000i)| cw(2.750000i) 143 lw(2.750000i)| lw(2.750000i). 144 ATTRIBUTE TYPE ATTRIBUTE VALUE 145 <attributes> 146 .TE 147 .sp 148 .\\" End Sun update 149 }; 150 151 # Parse input list of attributes 152 $attribute_list =~ s/^\s*{//; 153 $attribute_list =~ s/}\s*$//; 154 my @attribs = split /}\s*{/, $attribute_list; 155 156 my $a; 157 my $attribute_entries = ""; 158 159 foreach $a (@attribs) { 160 my ($name, $value) = split /,\s*/, $a, 2; 161 162 $attribute_entries .= $name . "\t" . $value . "\n"; 163 } 164 165 $attributes_table =~ s/<attributes>\n/$attribute_entries/; 166 167 return $attributes_table; 168 } 169