1 #!/bin/sh 2 3 # 4 # CDDL HEADER START 5 # 6 # The contents of this file are subject to the terms of the 7 # Common Development and Distribution License (the "License"). 8 # You may not use this file except in compliance with the License. 9 # 10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11 # or http://www.opensolaris.org/os/licensing. 12 # See the License for the specific language governing permissions 13 # and limitations under the License. 14 # 15 # When distributing Covered Code, include this CDDL HEADER in each 16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17 # If applicable, add the following below this CDDL HEADER, with the 18 # fields enclosed by brackets "[]" replaced with your own identifying 19 # information: Portions Copyright [yyyy] [name of copyright owner] 20 # 21 # CDDL HEADER END 22 # 23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24 # Use is subject to license terms. 25 # 26 # ident "@(#)sunman.sh 1.1 08/04/30 SMI" 27 # 28 29 # 30 # Environment 31 # 32 33 PATH="/usr/bin" 34 export PATH 35 36 basename=`basename $0` 37 usage="\ 38 Usage: $basename -n <name> -p <package> -s <stability> <file>... 39 $basename --help" 40 41 help="$usage 42 43 Amends the given man pages to add a Solaris stability 44 classification and a note about source availability. 45 46 -n, -p, and -s affect man pages specified thereafter and may be 47 specified multiple times. 48 49 Arguments: 50 51 <file> 52 The man page file to amend (in place). 53 54 -n <name> 55 Specify the name of the project (required). 56 57 -p <package> 58 Specify the name of the package (required). 59 60 -s <stability> 61 A solaris stability level (required). 62 63 --help 64 Display this message." 65 66 # 67 # Functions 68 # 69 70 # Usage: die [<message>] [<exitcode>] 71 die() { 72 test -n "$1" && echo "$basename: $1" 73 test -n "$2" && test "$2" -gt 0 && exit "$2" 74 exit 0 75 } 76 77 # Adds the given nroff preprocessing flags to the flags on stdin, avoiding 78 # duplicates; outputs to stdout 79 addflags() { 80 read flags 81 82 for f in "$@" 83 do 84 case "$flags" in 85 *${f}*) ;; 86 *) flags="${flags}$f" ;; 87 esac 88 done 89 90 echo "$flags" 91 } 92 93 # Amend the given man page file 94 process() { 95 file="$1" 96 flagre="^'"'\\" ' 97 98 # Add tbl (t) nroff preprocessing flag to existing flags, if any 99 flags=`head -1 "$file" | grep "$flagre" | cut -f2 -d' ' | addflags t` 100 101 # Remove existing flags from input 102 grep -v "$flagre" "$file" | ( 103 104 # Replace flags and add comment header 105 cat <<EOF 106 '\" $flags 107 .\" 108 .\" Modified to add a Solaris stability classification 109 .\" and a note about source availability. 110 .\" 111 EOF 112 113 cat 114 115 cat <<EOF 116 .\" Begin Sun update 117 .SH ATTRIBUTES 118 See 119 .BR attributes (5) 120 for descriptions of the following attributes: 121 .sp 122 .TS 123 box; 124 cbp-1 | cbp-1 125 l | l . 126 ATTRIBUTE TYPE ATTRIBUTE VALUE 127 = 128 Availability $pkg 129 = 130 Interface Stability $stability 131 .TE 132 .PP 133 .SH NOTES 134 Source for $project is available on http://opensolaris.org. 135 .\" End Sun update 136 EOF 137 ) > "$file"- 138 139 mv -f "$file"- "$file" || die "could not amend $opt" 1 140 } 141 142 # 143 # Main 144 # 145 146 project= 147 pkg= 148 stability= 149 150 test $# -gt 0 || set -- --help 151 152 while [ $# -gt 0 ] 153 do 154 opt="$1" 155 shift 156 157 case "$opt" in 158 --help) 159 echo "$help" 160 exit 161 ;; 162 163 -[nps]) 164 test $# -gt 0 || die "\"$opt\" requires an argument\n\n$usage" 165 optarg="$1" 166 shift 167 168 case "$opt" in 169 -n) project="$optarg" ;; 170 -p) pkg="$optarg" ;; 171 -s) stability="$optarg" ;; 172 esac 173 ;; 174 175 *) 176 test -f "$opt" || die "no such file: $opt" 177 test -z "$project" && die "-n not specified\n\n$usage" 178 test -z "$pkg" && die "-p not specified\n\n$usage" 179 test -z "$stability" && die "-s not specified\n\n$usage" 180 181 process "$opt" 182 ;; 183 esac 184 done 185