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